akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il void getmin(T &x,const T &y){if(y<x) x=y;}
template<typename T> il void getmax(T &x,const T &y){if(y>x) x=y;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const int N=3e5+7,mod=998244353;

ll fac[N],inv[N];
ll k,a,b;
int n;

il ll C(int n,int k){
	return fac[n]*inv[k]%mod*inv[n-k]%mod;
}

int main(){
//	fileio("test");
	fac[0]=inv[0]=inv[1]=1;
	rep(i,2,N-1){
		inv[i]=mod-(mod/i)*inv[mod%i]%mod;
//		assert(inv[i]*i%mod==1);
	}
	rep(i,1,N-1){
		fac[i]=fac[i-1]*i%mod;
		inv[i]=inv[i-1]*inv[i]%mod;
	}
	scanf("%d%lld%lld%lld",&n,&a,&b,&k);
	ll ans=0;
	rep(i,0,n){
		if(a*i>k) break;
		if((k-a*i)%b||(k-a*i)/b>n) continue;
	//	cerr<<i<<endl;
		ans+=C(n,i)*C(n,(k-a*i)/b)%mod;
	}
	printf("%lld\n",ans%mod);
	return 0;
}

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

pub 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 x: i64 = read();
    let a: i64 = read();
    let b: i64 = read();

    if (x - a).abs() > (x - b).abs() {
        println!("B")
    } else {
        println!("A")
    }
}


Measured memory_bytes: 4352
module Main(main) where
import Data.List

unqcnt [] = 0
unqcnt (x:[]) = 1
unqcnt (x:y:xs) = if x /= y then 1 + unqcnt (y:xs)
                  else unqcnt (y:xs)

main :: IO ()
main = do
  n <- read <$> getLine
  xs <- map read <$> (sequence $ replicate n getLine) :: IO [Int]
  print $ unqcnt $ sort xs


Measured memory_bytes: 1020
//Program.cpp
//Author : Aaryan Srivastava 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#define pb push_back
#define popb pop_back
#define ull unsigned long long  
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii,int>
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second 
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 2*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace std;
#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#define AaryanS 0 
#endif


 
int  dp[101][2*100*1000 + 5] = {} ;
void solve()
{
	int n,k;
	scanf("%lld%lld",&n,&k);
	vector<int> a(n);
	for(auto &it: a) scanf("%lld",&it);
	dp[0][0] = 1; 
	for(int i = 0 ; i < n ; ++i){
		for(int cur= 0 ; cur <= k ; ++cur){
			dp[i+1][cur] += dp[i][cur]; 
			dp[i+1][cur] %= mod;
			dp[i+1][cur+a[i]+1] -= dp[i][cur]; 
			dp[i+1][cur+a[i]+1] %= mod ;
			if(dp[i+1][cur+a[i]+1] < 0)
				dp[i+1][cur+a[i]+1] += mod ;
		}
		for(int cur = 1 ; cur <= k ; ++cur)
			dp[i+1][cur] += dp[i+1][cur-1], dp[i+1][cur] %= mod; 
	}
	cout << dp[n][k]; 
}

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case " << t << ":\n" ;
        solve();
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}


Measured memory_bytes: 156544
N = int(input())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 

Asum = sum(A)

for i in range(N):
    a = A[i]
    b = B[i]
    A[i] = max(a - b, 0)
    B[i] = max(b - a, 0)
    A[i+1] = max(A[i+1]-B[i], 0)

print(Asum - sum(A))

Measured memory_bytes: 18468
#include<stdio.h>
#define N 199
void enqueue(int);
int dequeue(void);
int top;
int stack[N];
int main(){
  char input[11];
  top = 0;
  while( scanf("%s",input) != EOF ){
    if( input[0] == '+' ){
      stack[top-1] += dequeue();
    }
    else if( input[0] == '-' ){
      stack[top-1] -= dequeue();
    }
    else if( input[0] == '*' ){
      stack[top-1] *= dequeue();
    }
    else {
      enqueue( atoi(input) );
    }
  }
  printf("%d\n",stack[top]);
  return 0;
}
void enqueue(int input){
  stack[++top] = input;
}
int dequeue(void){
  return stack[top--];
}

Measured memory_bytes: 548
#include <iostream>
#include <cmath>

using namespace std;

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

    int ans = 1;
    for (int b = 2; b <= sqrt(x); b++) {
        int bp = b;
        for (int p = 2; bp*b <= x; p++) {
            bp *= b;
            if (ans < bp) ans = bp;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin>>N>>M;
    int a[N],b[N],c[M],d[M];
    for(int i=0;i<N;i++){
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<M;i++){
        cin>>c[i]>>d[i];
    }
    for(int i=0;i<N;i++){
        int P=0;
        int D=500000000;
        int pD;
        for(int j=0;j<M;j++){
            pD=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(pD<D){P=j+1;D=pD;}
        }
        cout<<P<<endl;
    }
}

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

#define MOD 1000000007
#define MAX_N 100000
#define MAX_P 200005
Int fact[MAX_P],inv[MAX_P];

void init(Int mod){
  fact[0]=1;
  for(Int i=1;i<MAX_P;i++)
    fact[i]=(fact[i-1]*i)%mod;

  inv[1]=1;
  for(Int i=2;i<MAX_P;i++)
    inv[i]=inv[mod%i]*(mod-mod/i)%mod;
}

Int dp[111][256];
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(Int i=0;i<n;i++)
    for(Int j=100;j>=0;j--)
      for(Int k=0;k<256;k++)
	(dp[j+1][k^a[i]]+=dp[j][k])%=MOD;

  init(MOD);
  Int ans=0;
  for(Int i=1;i<=n;i++){
    Int tmp=dp[i][m]*fact[i]%MOD;
    ans+=tmp;
    ans%=MOD;
  }
  
  cout<<ans<<endl;
  return 0;
}


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


def main():
    N,L = map(int, input().split())
    
    L2 = L+N-1
    x = (L-1)*N + N*(N+1)//2 - (L if L > 0 else L2 if L2 < 0 else 0)
    
    print(x)





if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin>>N;
  int sum=0;
  for(int i=1;i<=N;i++){
    int A;
    cin>>A;
    if(i%2==1&&A%2==1) sum++;
  }
  cout<<sum<<endl;
      
}

Measured memory_bytes: 3612
# -*- coding: utf-8 -*-
import sys
from itertools import product
from collections import Counter, defaultdict
from string import ascii_uppercase as ABC
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N = int(input())
S = input()
ans = []
for s in S:
    ans.append(ABC[(ord(s)-65+N)%26])
print("".join(ans))


Measured memory_bytes: 39152
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:char,
    b:char,
    }
    println!("{}",if a==b{"H"}else{"D"})
}

Measured memory_bytes: 2076
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

#include <numeric>
using namespace std;


int main(){
	int N,C,K;
	vector<int> T;
	cin >> N >> C >> K;
	for (int i = 0; i < N; i++){
		int inp;
		cin >> inp;
		T.push_back(inp);
	}
	std::sort(T.begin(), T.end());
	vector<vector<int>> v;
	int first = T[0]+K;
	vector<int> tmp;
	for (int i = 0; i < N; i++){
		if (T[i] <= first && tmp.size()<C){
			tmp.push_back(T[i]);
		}
		else if (tmp.size()==C ){
			v.push_back(tmp);
			tmp.clear();
			tmp.push_back(T[i]);
			first = T[i] + K;
		}
		else if(T[i]>first){
			v.push_back(tmp);
			tmp.clear();
			tmp.push_back(T[i]);
			first = T[i] + K;
		}

	}
	v.push_back(tmp);

	cout << v.size() << endl;



	return 0;
}

Measured memory_bytes: 6384
#include<stdio.h>

int main(void){
    int A, B;
    scanf("%d %d",&A,&B);
    if(A+B>=A-B&&A+B>=A*B){
        printf("%d", A+B);
    }
    else if(A-B>=A*B&&A-B>=A+B){
        printf("%d", A-B);
    }
    else{
        printf("%d", A*B);
    }
    return 0;
    
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A,B,m;
	cin>>A>>B>>m;
	vector<int> a(A),b(B);
	rep(i,A) cin>>a[i];
	rep(i,B) cin>>b[i];
	int ans=INF;
	rep(i,m){
		int x,y,c;
		cin>>x>>y>>c;
		x--,y--;
		chmin(ans,a[x]+b[y]-c);
	}
	chmin(ans,*min_element(begin(a),end(a))+*min_element(begin(b),end(b)));
	cout<<ans<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int a, b;
  cin >> a >> b;
  if(a == b) {
    cout << "Draw" << endl;
  }else if(a < b) {
    if(a == 1) {
      cout << "Alice" << endl;
    }else {
      cout << "Bob" << endl;
    }
  }else {
    if(b == 1) {
      cout << "Bob" << endl;
    }else {
      cout << "Alice" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main( void )
{
	long n;
	while(cin >> n) {
		string str;
		int outCount = 0, point = 0, base = 0;
		while(n) {
			cin >> str;
			switch(str[1]) {
				case 'I': // HIT
					++base;
					point += base/4;
					base = min(3, base);
					break;
				case 'U': // OUT
					if(++outCount == 3) {
						cout << point << endl;
						point = outCount = base = 0;
						--n;
					}
					break;
				case 'O': // HOMERUN
					point += base + 1;
					base = 0;
					break;
			}
		}
	}
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
vector<int> a;
int ans = 0;
/**********************************************/

void bfs(int depth, int a, int b, int c){
    if(a == b && b == c){
        ans = depth;
    }

}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    a.resize(3);
    cin >> a[0] >> a[1] >> a[2];

    sort(all(a)); 
    while(a[2] != a[1]){
        ans++;
        a[0]++;
        a[1]++;
    }

    while(a[0] < a[1]){
        a[0] += 2;
        ans++;
    }

    while(a[0] > a[1]){
        ans++;
        a[1]++;
        a[2]++;
    }

    cout << ans << endl;
}


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

int main() {
	string S;
	cin >> S;
	string ACGT="ACGT";
	int count=0, max_count=0;
	for (int i=0; i<S.size();i++){
	    bool isACGT=false;
	    for (int j=0; j<ACGT.size(); j++){
	        if (S[i]==ACGT[j]) isACGT=true;
	    }
	    if (isACGT){
	        count++;
	        max_count=max(max_count, count);
	    }
	    else count=0;
	}
	cout << max_count << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            string[] s1 = Console.ReadLine().Split(' ');
            int n = int.Parse(s1[0]), k = int.Parse(s1[1]);

            int kMax = (n - 1) * (n - 2) / 2;
            if (k > kMax)
            {
                Console.WriteLine(-1);
                return;
            }

            Console.WriteLine(n - 1 + kMax - k);
            for (int i=2; i<=n; i++)
            {
                Console.WriteLine("1 " + i);
            }
            int c = 2, d = 3;
            while(kMax - k > 0)
            {
                Console.WriteLine(c + " " + d);
                if (d < n) d++;
                else
                {
                    c++;
                    d = c + 1;
                }
                kMax--;
            }
            
        }
    }

Measured memory_bytes: 13268
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const int maxn=200050;
inline ll read()
{
	ll x=0,t=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*t;
}
ll n,a[maxn],l[maxn],r[maxn];
int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++)
	{
		l[i]=i;ll j=i;
		while(j>=1&&a[l[j]-1]>=a[i]) j=l[l[j]-1];
		l[i]=j;
	}
	
	for(ll i=n;i>=1;i--)
	{
		r[i]=i;ll j=i;
		while(j<=n&&a[r[j]+1]>=a[i]) j=r[r[j]+1];
		r[i]=j;
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans+=a[i]*(i-l[i]+1)*(r[i]-i+1);
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

string s, a, b;
int n;

int dif(string a, string b) {
    int res = 0;
    for (int i = 0; i < a.size(); i++)
	res += (a[i] != b[i]);
    return res;
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; i++) {
	a += (i % 2 ? '0' : '1');
	b += (i % 2 ? '1' : '0');
    }
    return cout << min(dif(s, a), dif(s, b)), 0;
}

Measured memory_bytes: 1104
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N, K = mi()
Hs = sorted([int(input()) for _ in range(N)])
gaps = [0] * (N-1)
for i in range(N-1):
  gaps[i] = Hs[i+1] - Hs[i]

mingapsum = 10**9

#最初のgapは元々計算しておく
nowgapsum = sum(gaps[0:K-1])
mingapsum = min(nowgapsum, mingapsum)

prevgap = gaps[0]
for i in range(1, N-K+1):
  nowgapsum = nowgapsum - prevgap + gaps[K-2+i]
  prevgap = gaps[i]
  mingapsum = min(nowgapsum, mingapsum)

print(mingapsum)



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

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    Data[] datas = new Data[n];
    for (int i = 0; i < n; i++) {
      long a = scanner.nextLong();
      long b = scanner.nextLong();
      datas[i] = new Data(a, b);
    }
    Arrays.sort(datas, new Comparator<Data>() {
      @Override
      public int compare(Data d1, Data d2) {
        return (int) (d1.getPrice() - d2.getPrice());
      }
    });

    long sum = 0;
    long money = 0;

    for (int i = 0; i < n; i++) {
      if (sum + datas[i].getStock() >= m) {
        money += datas[i].getPrice() * (m - sum);
        break;
      } else {
        sum += datas[i].getStock();
        money += datas[i].getPrice() * datas[i].getStock();
      }
    }
    System.out.println(money);
  }

}

class Data {
  private long a;
  private long b;

  public Data(long a, long b) {
    this.a = a;
    this.b = b;
  }

  public long getPrice() {
    return a;
  }

  public long getStock() {
    return b;
  }
}


Measured memory_bytes: 89356
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val wList = readLine()!!.split(' ').map(String::toLong)
    var min = Long.MAX_VALUE
    for (i in 1..n) {
        val sa = Math.abs(wList.take(i).sum() - wList.takeLast(n - i).sum())
        min = Math.min(min, sa)
    }

    println(min)
}

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

int main() {
  int r;
  cin >> r;
  if(r < 1200) cout << "ABC" << endl;
  else if(r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}

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

P h[3000];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n)scanf("%d%d", &h[i].first, &h[i].second);
		sort(h, h + n, [](P a, P b) {return a.second < b.second; });
		stable_sort(h, h + n);
		int Max = 0;
		rep(i, n) {
			for (int j = i + 1; j < n; j++) {
				int x = h[j].first - h[i].first,
					y = abs(h[j].second - h[i].second);
				if (!x)continue;
				P a = { h[i].first,h[i].second + x },
					b = { h[j].first,h[j].second + x };
				if (h[i].second < h[j].second) {
					a.first -= y; b.first -= y;
				}
				else {
					a.first += y; b.first += y;
				}
				if (binary_search(h, h + n, a) && binary_search(h, h + n, b))
					Max = max(Max, (x + y)*(x + y) - x*y * 2);
			}
		}
		printf("%d\n", Max);
	}
	return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define WEST 1
#define NORTH 2

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
short pass[20][20];	// 0: 通行不能 1: 西から来た 2: 北から来た 3: 両方から来た
ll dp[20][20];

int main()
{
//	cut here before submit 
//	freopen ("testcase.Heian-Kyo_Walking", "r", stdin );
	int n;
	scanf ("%d", &n );
	while (n-- ){
		memset (pass, 0, sizeof (pass ) );
		memset (dp, 0LL, sizeof (dp ) );
		int gx, gy;
		scanf ("%d %d", &gx, &gy );
		rep (i, gy+1 ) rep (j, gx+1 ) pass[i][j] = (WEST | NORTH);
		pass[0][0] = 0;
		for (int i = 1; i <= gy; i++ ) pass[i][0] = NORTH;
		for (int j = 1; j <= gx; j++ ) pass[0][j] = WEST;

		int p;
		scanf ("%d", &p );
		rep (i, p ){
	//		int x1, y1, x2, y2;
			int a, b, c, d;
			scanf ("%d %d %d %d", &a, &b, &c, &d );
			int x1 = min (a, c ), x2 = max (a, c );
			int y1 = min (b, d ), y2 = max (b, d );
			if (x1 == x2 ){	// 北から来れない
				pass[y2][x2] = pass[y2][x2] & ~NORTH;
			}else{	// if (y1 == y2 ) // 西から来れない
				pass[y2][x2] = pass[y2][x2] & ~WEST;
			} // end if
		} // end rep
		dp[0][0] = 1LL;
		for (int j = 1; j <= gx; j++ ){
			if (pass[0][j] & WEST ){
				dp[0][j] = dp[0][j-1];
			} // end if
		} // end for
		for (int i = 1; i <= gy; i++ ){
			if (pass[i][0] & NORTH ){
				dp[i][0] = dp[i-1][0];
			} // end rep
		} // end rep
		for (int i = 1; i <= gy; i++ ){
			for (int j = 1; j <= gx; j++ ){
				if (pass[i][j] & WEST ){
					dp[i][j] += dp[i][j-1];
				} // end if
				if (pass[i][j] & NORTH ){
					dp[i][j] += dp[i-1][j];
				} // end if
			} // end for
		} // end for
/*
		rep (i, gy+1 ){
			rep (j, gx+1 ){
				cout << pass[i][j];
			} // end rep
			cout << endl;
		} // end rep
		cout << endl;

		rep (i, gy+1 ){
			rep (j, gx+1 ){
				cout << setw(3) << dp[i][j];
			} // end rep
			cout << endl;
		} // end rep
*/
		if (dp[gy][gx] == 0LL ){
			cout << "Miserable Hokusai!"<< endl;
		}else{
			cout << dp[gy][gx] << endl;
		} // end if

	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    map<ll, ll> cnt;
    rep(i, 3){
        ll a, b;
        cin >> a >> b;
        cnt[a]++, cnt[b]++;
    }
    vi ans(5, 0);
    for(auto &num: cnt) ans[num.second]++;
    (ans[1] == 2 && ans[2] == 2) ? YES() : NO();
}

Measured memory_bytes: 3640
import math
a1,b1 = map(int,input().split())
a2 = a1+1
b2 = b1+1
p1 = a1/0.08
p2 = a2/0.08
p3 = b1/0.1
p4 = b2/0.1

i1 = math.ceil(p1)
i2 = math.floor(p2-0.000001)
i3 = math.ceil(p3)
i4 = math.floor(p4-0.000001)

for i in range(i1, i2):
  if i >=i3 and i<i4:
    print(i)
    exit()
print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H;
  cin >>H;
  if(H==25)cout<<"Christmas"<<endl;
  else if(H==24)cout<<"Christmas Eve"<<endl;
  else if(H==23)cout<<"Christmas Eve Eve"<<endl;
  else
  cout<<"Christmas Eve Eve Eve"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 200000

int A[N];

int main() {

	int n, m, i, j;

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

	int max = 0;
	int submax = 0;

	for (int j = 0; j < n; j++) {
		if (max <= A[j]) {
			submax = max;
			max = A[j];
		}
		else {
			if (submax <= A[j]) submax = A[j];
		}
	}

	for (int h = 0; h < n; h++) {
		if (A[h] == max) printf("%d\n", submax);
		else printf("%d\n", max);
	}
}

Measured memory_bytes: 2304
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	double a,b;
	cin >> a >> b;
	int c = (a + b ) / 2 + 0.999999;
	cout << c << endl;
	ret 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {

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

	int N; cin >> N;
	vector<int>p(N);
	rep(i, N)cin >> p[i];

	vector<int>ans = p;
	int cnt = 0;
	sort(ans.begin(), ans.end());
	rep(i, N) {
		if (p[i] != ans[i])++cnt;
	}
	if (cnt > 2)cout << "NO" << "\n";
	else cout << "YES" << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int loop = scanner.nextInt();
		for (int i = 1; i <= loop; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				int x = i;
				while (x != 0) {
					if (x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					x /= 10;
				}
			}
		}

		System.out.println();
	}
}

Measured memory_bytes: 28844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  vector<int> t(3);
  //cin >> t.at(0) >> t.at(1) >> t.at(2);
  int p, q, r;
  cin >> p >> q >> r;
  
  
  int M = max({p, q, r});
  
  //int sum = t.at(0) + t.at(1) +t.at(2) - M;
  int sum = q + p + r - M;
  cout << sum << endl;
}

Measured memory_bytes: 256
M, D = gets.split.map(&:to_i)

c = 0
1.upto(M) do |m|
  22.upto(D) do |d|
    if d.to_s[0].to_i >= 2 && d.to_s[1].to_i >= 2
      c += 1 if d.to_s[0].to_i * d.to_s[1].to_i == m
    end
  end
end
p c


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


void solve(unsigned long long N){
  vector<int> nums = {};
  while (N >= 0) {
    if (N >= 26) {
      int r = N % 26;
      long long div = (r == 0) ? (N - r - 1) : (N - r);
      N = div / 26;
      if (r == 0) r = 26;
      nums.push_back(r);
  } else {
      if (N == 0) N = 26;
      nums.push_back(N);
      break;
    }
  }
  string s = "";
  for (int num : nums) s += 'a' + num - 1;
  reverse(s.begin(), s.end());
  if (s[0] == 'z') cout << s.substr(1, s.size()) << endl;
  else cout << s << endl;
}

int main(){
    unsigned long long N;
    scanf("%llu",&N);
    solve(N);
    return 0;
}

Measured memory_bytes: 3696
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = (10**6)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

H, W, a, b = map(int, input().split())
r = 0
for i in range(H-a):
    r = (r + mul(cmb(b-1+i, i), cmb(W-b-1+H-i-1, W-b-1))) % mod
print(r)


Measured memory_bytes: 128268
<?php
fscanf(STDIN, "%d", $N);
$sum = [];
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%s", $s);
    $a = str_split($s);
    sort($a);
    $ss = implode("", $a);
    if (isset($sum[$ss])) {
        $sum[$ss]++;
    } else {
        $sum[$ss] = 1;
    }
}
$ans = 0;
foreach ($sum as $key => $val) {
    $ans += ($val * ($val - 1) / 2);
}
echo $ans;

Measured memory_bytes: 13048
#include <cstdio>
#include <algorithm>
#include <vector>
#include <bitset>

struct edge
{
  int from;
  int to;
  int cost;
};

long long dist[2500];
std::bitset<2500> reach;
std::bitset<2500> rreach;

int main()
{
  int n, m, p;
  scanf("%d%d%d", &n, &m, &p);
  std::vector<edge> edges;
  for (int i = 0; i < m; ++i)
  {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    edges.emplace_back(edge{a - 1, b - 1, c - p});
  }
  constexpr long long NEGINF = -1e18;
  reach[0] = true;
  rreach[n - 1] = true;
  std::fill(dist + 1, dist + n, NEGINF);
  for (int i = 0; i < n - 1; ++i)
  {
    for (auto &e : edges)
    {
      if (rreach[e.to]) rreach[e.from] = true;
      if (!reach[e.from]) continue;
      reach[e.to] = true;
      long long c = dist[e.from] + e.cost;
      if (c > dist[e.to]) dist[e.to] = c;
    }
  }

  for (auto &e: edges)
  {
    if (!reach[e.from] || !rreach[e.to]) continue;
    long long c = dist[e.from] + e.cost;
    if (c > dist[e.to])
    {
      puts("-1");
      return 0;
    }
  }
  printf("%lld\n", std::max(0LL, dist[n - 1]));
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(0, c - a + b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}

template <class T>
T lcm(T a,T b){
    return a*(b/gcd(a,b));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<unsigned long long> t(n);
    rep(i,n){
        cin>>t[i];
    }
    unsigned long long ans=t[0];
    //cout<<ans<<'\n';
    rep(i,n){
        ans=lcm(ans,t[i]);
        //cout<<t[i]<<' '<<ans<<'\n';
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>
int main()
{
    int i,odd=0;
    double ans,n;
    scanf("%lf",&n);
    for(i=1;i<=n;i++){
        if(i%2==1){
            odd++;
        }
    }
    ans = odd/n;
    printf("%.10lf\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s;cin>>s;
    int n=(int)s.size();
    deque<char> q;
    for(auto x:s) q.push_back(x);
    bool rev=0;
    int m;cin>>m;
    while(m--){
        int t;cin>>t;
        if(t==1){
            rev^=1;
        }
        else{
            int f;char c;cin>>f>>c;
            if((f==1 and rev==false) or (f==2 and rev==true)) q.push_front(c);
            else        q.push_back(c);
        }
    }
    if(rev){
        while(!q.empty()){
            cout<<q.back();
            q.pop_back();
        }
        cout<<endl;
    }
    else{
        while(!q.empty()){
            cout<<q.front();
            q.pop_front();
        }cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 976
#include <iostream>

using namespace std;

int main() {
    long long x;    cin >> x;
    long long p = x / 11, q = x % 11;
    
    if (0 == q)
        cout << 2 * p << endl;
    else if (q > 6)
        cout << 2 * p + 2 << endl;
    else 
        cout << 2 * p + 1 << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  vector<int> sort(N);
  for (int j = 0; j < N; j++){
    int max = 0;
    int max_i = -1;
    for (int i = 0; i < N; i++){
      if (A.at(i) > max){
        max = A.at(i);
        max_i = i;
      }
    }
    sort.at(j) = max;
    A.at(max_i) = 0;
//    cout << sort.at(j) << endl;
  }
  
  int Alice = 0;
  int Bob = 0;
  for (int j = 0; j < N; j++){
    if (j%2==0)
      Alice += sort.at(j);
    else
      Bob += sort.at(j);
  }
  cout << Alice - Bob << endl;
  
}

Measured memory_bytes: 256
#!/usr/bin/env python3


def solve(N, H):
    last_h = float('inf')
    _max = 0
    _count = -1
    for h in H:
        if h <= last_h:
            _count += 1
        else:
            if _max < _count:
                _max = _count
            _count = 0
        last_h = h
    if _max < _count:
        _max = _count
    return _max


if __name__ == '__main__':
    N = int(input())
    H = map(int, input().split())

    ans = solve(N, H)

    print(ans)


Measured memory_bytes: 11128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    n = n * (n-1) / 2;
    m = m * (m-1) / 2;
    int ans = 0;
    ans = n + m;
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
c = input().split()

a=int(c[0])
b=int(c[1])
c=int(c[2])
num = [1]
#print(num)
d = a
if a>b:
    d = b
i=int(2)
while i <= d:
    if a%i==0  and b%i==0:
        num.append(i)
        i += 1
    else:
        i += 1

#print(num)
print(num[len(num)-c])


Measured memory_bytes: 3064
s=input()
v=[]
d=[]
for i in range(len(s)):
  if s[i] == 'o':
    v.append(1)
  elif s[i] == 'x':
    d.append(1)
if len(v)>=8:
  print ('YES')
else:
  if len(d)>=8:
    print ('NO')
  elif 15-(len(v)+len(d))+len(v)>=8:
    print('YES')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

string s;
int n;
bool dp[505][505];
bool visit[505][505];

bool dfs(int l, int r){
	if(l > r) return true;
	if(visit[l][r]) return dp[l][r];
	visit[l][r] = true;
	if(s[l] != 'm' || s[r] != 'w') return false;
	bool res = false;
	for(int i=l+1; i<r; i++){
		if(s[i] == 'e'){
			res |= dfs(l+1,i-1) && dfs(i+1,r-1);
		}
	}
	return dp[l][r] = res;
}

int main(){
	cin >> s;
	n = s.size();
	if(dfs(0,n-1)) puts("Cat");
	else puts("Rabbit");
}


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

const long N=1000000;

bool prime[N+1];
bool dp[N+1];

int main(){
	prime[0]=prime[1]=false;
	for(long i=2; i<=N; ++i) prime[i]=true;
	
	for(long i=2; i<=N; ++i){
		if(prime[i]) for(long j=2; i*j<=N; ++j) prime[i*j]=false;
	}
	
	while(1){
		int n;
		long x, c[30];
	
		scanf(" %d %ld", &n, &x);
		if(n==0) break;
		for(int i=0; i<n; ++i) scanf(" %ld", &c[i]);
		
		for(long i=0; i<=N; ++i) dp[i]=false;
		
		dp[0]=true;
		for(int i=0; i<n; ++i){
			for(long j=0; j+c[i]<=x; ++j){
				if(dp[j]) dp[j+c[i]]=true;		
			}
		}
		
		long max=0;
		for(long i=0; i<=x; ++i){
			if(dp[i] && prime[i]) max=i;
		}
			
		if(max==0) printf("NA\n");
		else printf("%ld\n", max);
	}
}

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

#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
int main()
{
    string s;
    cin >> s;
    auto check = [](char ch) {
        if (ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T') { return true; }
        return false;
    };
    /*

    int ans = 0, t = 0;
    for (auto c : s)
    {
        if (check(c)) { t++; }
        else
        {
#ifdef DEBUG
            cout << "dbg t" << t << endl;
#endif
            ans = max(ans, t);
            t = 0;
        }
    }
    cout << ans << endl;
*/
    int ans = 0;
    rep(i, s.size())
    {
        int now = 0;
        for (int j = i; j != s.size(); ++j)
        {
            bool ok = false;
            if (check(s[j])) { ok = true; }

            if (ok)
            {
                now++;
                ans = max(ans, now);
            }
	    else{break;}
        }
    }
    cout<<ans<<endl;
    return 0;
}
/*author  https://qiita.com/drken/items/0c88a37eec520f82b788*/
ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int s;
	cin >> s;
	set<int> Set;
	while (true)
	{
		if (Set.find(s) != Set.end())
		{
			break;
		}
		Set.insert(s);
		if (s % 2 == 0)
		{
			s /= 2;
		}
		else
		{
			s = 3 * s + 1;
		}
	}
	cout << Set.size() + 1 << endl;
}

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

Measured memory_bytes: 256
h, w =map(int, input().split())
ch1 = h//3
ch2 = ch1+1
cw1 = w//3
cw2 = cw1+1
ans = float('inf')

#ch1で切ってwの真ん中で切る。
s = [0,0,0]
s[0]=ch1*w
yoko1 = w//2
yoko2 = w-yoko1
s[1]=(h-ch1)*yoko1
s[2]=(h-ch1)*yoko2
temp = max(s)-min(s)
ans = min(ans, temp)
#ch2で切ってwの真ん中で切る。
s = [0,0,0]
s[0]=ch2*w
yoko1 = w//2
yoko2 = w-yoko1
s[1]=(h-ch2)*yoko1
s[2]=(h-ch2)*yoko2
temp = max(s)-min(s)
ans = min(ans, temp)
#全部横
s = [0,0,0]
s[0]=ch1*w
tate1=(h-ch1)//2
tate2=h-ch1-tate1
s[1]=tate1*w
s[2]=tate2*w
temp = max(s)-min(s)
ans = min(ans, temp)

#全部縦
s = [0,0,0]
s[0]=cw1*h
yoko1=(w-cw1)//2
yoko2=w-cw1-yoko1
s[1]=yoko1*h
s[2]=yoko2*h
temp = max(s)-min(s)
ans = min(ans, temp)

#cw1で切ってhの真ん中で切る。
s = [0,0,0]
s[0]=cw1*h
tate1 = h//2
tate2 = h-tate1
s[1]=(w-cw1)*tate1
s[2]=(w-cw1)*tate2
temp = max(s)-min(s)
ans = min(ans, temp)

#cw2で切ってhの真ん中で切る。
s = [0,0,0]
s[0]=cw2*h
tate1 = h//2
tate2 = h-tate1
s[1]=(w-cw2)*tate1
s[2]=(w-cw2)*tate2
temp = max(s)-min(s)
ans = min(ans, temp)


print(ans)

Measured memory_bytes: 9352
#include<stdio.h>

int dad[100100];
int rec[100100];

int finddad(int n)
{
    return n==dad[n]?n:(dad[n]=finddad(dad[n]));
}

void Union(int a,int b)
{
    int x=finddad(a);
    int y=finddad(b);
    dad[x]=y;
}

int main()
{
    int n,m,i,a,b;
    int ans=0;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
        dad[i]=i;
    for(i=1;i<=n;i++)
        scanf("%d",rec+i);
    for(i=1;i<=m;i++)
    {
        scanf("%d%d",&a,&b);
        Union(a,b);
    }
    for(i=1;i<=n;i++)
    {
        if(finddad(i)==finddad(rec[i]))
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


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

#include <iostream>
#include <fstream>

#include <iostream>

class ANChildrenAndCandiesABCEdit {
public:
	void solve(std::istream& in, std::ostream& out) {
        int t;
        in >> t;
        out << t*(t+1)/2 << std::endl;
	}
};


int main() {
	ANChildrenAndCandiesABCEdit solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

mod = 10**9 + 7
inf = 1<<30

def solve():
    H, W, K = map(int, sys.stdin.readline().split())

    A = [[False]*W for i in range(H)]
    si = sj = -1

    for i in range(H):
        ai = sys.stdin.readline().rstrip()

        for j in range(W):
            if ai[j] == 'S':
                si = i
                sj = j
                A[i][j] = True
            elif ai[j] == '.':
                A[i][j] = True

    ans = bfs(H, W, K, A, si, sj)

    print(ans)

def bfs(H, W, K, A, si, sj):
    dx = (1, 0, -1, 0,)
    dy = (0, 1, 0, -1,)

    min_step = inf

    visited = [[False]*W for i in range(H)]
    visited[si][sj] = True
    nxts = deque([(si, sj, 0)])

    while nxts:
        r, c, d = nxts.popleft()

        min_step = min(min_step, r, H - 1 - r, c, W - 1 - c)

        if min_step == 0:
            return 1

        if d + 1 > K:
            continue

        for k in range(len(dx)):
            nr = r + dy[k]
            nc = c + dx[k]

            if 0 <= nr < H and 0 < nc < W:
                if A[nr][nc] and not visited[nr][nc]:
                    visited[nr][nc] = True
                    nxts.append((nr, nc, d + 1))

    ans = (min_step + K - 1) // K + 1

    return ans

if __name__ == '__main__':
    solve()

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


int main() {
  int A, B, C, D, E, F, total, totalsugar;
  cin >> A >> B >> C >> D >> E >> F;
  int ansTotal=100*A, ansSugar=0;
  double maxsugar = F * E / (100+E);
  for (int i = maxsugar / C; i>=0; i--) {
    for (int j = (maxsugar-i*C)/D; j>=0; j--) {
        for (int k = (F-i*C-j*D)/A/100; k>=1; k--) {
          for (int l = (F-i*C-j*D-k*A*100)/B/100; l>=0; l--) {
            total = C*i+D*j+A*k*100+B*l*100;
            totalsugar = C*i+D*j;
            if(E*total == totalsugar*100) {
              ansTotal = total;
              ansSugar = totalsugar;
            }
            else if(totalsugar*ansTotal > ansSugar*total && totalsugar <= total*E/(100+E)) {
              ansTotal = total;
              ansSugar = totalsugar;
            }
          }
        }
    }
  }
  cout << ansTotal << ' ' << ansSugar << "\n";
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 08.10.2017 15:31:52       
**/
#include <bits/stdc++.h>

using namespace std;

const int N = 1234567;

char s[N];
int f[N];
int nxt[N], prv[N];

int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i <= n; i++) {
    f[i] = 0;
  }
  nxt[n] = n;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '0') {
      nxt[i] = i;
    } else {
      nxt[i] = nxt[i + 1];
    }
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      prv[i] = i;
    } else {
      prv[i] = (i == 0 ? -1 : prv[i - 1]);
    }
  }
  for (int i = 0; i <= n; i++) {
    if (i >= 3 && s[i - 1] == '1' && s[i - 2] == '0' && s[i - 3] == '1') {
      int j = prv[i - 3];
      f[i] = max(f[i], f[j + 1] + (i - j - 3));
      if (j != i - 4) {
        f[i] = max(f[i], f[j + 2] + (i - j - 4));
      }
    }
    if (i == n) {
      break;
    }
    if (i + 3 <= n && s[i] == '1' && s[i + 1] == '0' && s[i + 2] == '1') {
      int j = nxt[i + 2];
      f[j] = max(f[j], f[i] + (j - i - 2));
      if (j != i + 3) {
        f[j - 1] = max(f[j - 1], f[i] + (j - i - 3));
      }
    }
    f[i + 1] = max(f[i + 1], f[i]);
  }
  printf("%d\n", f[n]);
  return 0;
}


Measured memory_bytes: 10880
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
	int sale[5][3];
	while(1){
		scanf("%d %d",&sale[0][0],&sale[0][1]);
		if(sale[0][0]==0 && sale[0][1]==0) break;
		for(int i=1;i<5;i++){
			cin>>sale[i][0]>>sale[i][1];
		}
		for(int i=0;i<5;i++){
			sale[i][2] = sale[i][0]+sale[i][1];
		}

		int max = sale[0][2];
		int maxi = 0;
		for(int i=1;i<5;i++){
			if(max <sale[i][2]){
				max = sale[i][2];
				maxi = i;
			}
		}

		printf("%c %d\n",'A'+maxi,max);

	}

	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int MOD = 1000000007;

int main(){
    int h,w;
    cin >> h >> w;
    int map[h][w];
    rep(i,h){
        rep(j,w){
            cin >> map[i][j];
        }
    }
    int k=0;
    int x1[250005],y1[250005],x2[250005],y2[250005];
    rep(i,h){
        rep(j,w){
            if(map[i][j]%2==1){
                if(j!=w-1){
                    map[i][j+1]++;
                    y1[k]=i+1,x1[k]=j+1;
                    y2[k]=i+1,x2[k]=j+2;
                    k++;
                }
                else if(i!=h-1){
                    map[i+1][j]++;
                    y1[k]=i+1,x1[k]=j+1;
                    y2[k]=i+2,x2[k]=j+1;
                    k++;
                }
            }
        }
    }
    cout << k << endl;
    rep(i,k){
        cout << y1[i] << " " << x1[i] << " " << y2[i] << " " << x2[i] << endl;
    }
}


Measured memory_bytes: 6144