akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1285>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int n,w;
double solve(){
    double res =0;
    vector<int> v(n); for(auto& in:v) cin >> in;
    vector<int> hist((*max_element(v.begin(),v.end()))/w+1);
    for(int i = 0; i < n;i++){
        hist[v[i]/w]++;
    }
    double ink = 1;
    double base = *max_element(hist.begin(),hist.end());
    for(int i = 0; i < hist.size();i++){
        res += ink*hist[i]/base;
        ink-=1/(double)(hist.size()-1);
    }
    res += 0.01;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> n >> w,n){
        cout << fixed << setprecision(12) << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3224
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <utility>
using namespace std;

template <typename T>
void print_vec(const vector<T> &v) {
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    if (i > 0) cout << ' ';
    cout << v[i];
  }
  cout << '\n';
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  int i = 0, j = n - 1;
  int cnt = 0;
  while (i < j) {
    while (i < n && s[i] == 'R') ++i;
    while (j >= 0 && s[j] == 'W') --j;
    if (i == n) break;
    if (j < 0) break;
    if (i < j) {
      ++i; --j; ++cnt;
    }
  }

  cout << cnt << '\n';

  return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n;
string s;

int main(){
	cin >> n >> s;
	
	int a = 0, b = 0, ans = INF;
	for(int i = 0; i < n; i++){
		if(s[i] == '.') b++;
	}
	ans = min(ans,a+b);
	for(int i = 0; i < n; i++){
		if(s[i] == '#'){
			a++;
		}
		else b--;
		ans = min(ans,a+b);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <math.h>

using namespace std;
int main()
{
    int ans = 0;
    int N;
    int M;
    int count = 0;
    cin >> N;

    for (int i = 1; i <= N; i+=2)
    {
        for (int j = 1; j <=i; j+=1)
        {
            if (i%j == 0)
            {
                count++;
            }
        }
        if (count == 8)
        {
            ans++;
        }
        count = 0;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3588
from collections import Counter
def main(n,v):
    # n = int(input())
    # v = list(map(int, input().split()))
    odd = Counter(v[0::2]).most_common(2) + [(0, 0)]
    even = Counter(v[1::2]).most_common(2) + [(0, 0)]

    n_half = int(n / 2)

    if (len(odd) == 1 and len(even) == 1) and odd[0][0] == even[0][0]:
        ans = n_half
    elif odd[0][0] == even[0][0]:
        ans = min(n_half - odd[0][1] + n_half - even[1][1],\
                n_half - odd[1][1] + n_half - even[0][1])
    else:
        ans = n_half - odd[0][1] + n_half - even[0][1]

    print(ans)
    return 0

if __name__ == "__main__":
    n = int(input())
    v = list(map(int, input().split()))
    main(n,v)

Measured memory_bytes: 15588
N,M = map(int,input().split())
a=[]
b=[]
for i in range(N):
  a.append(input())

for i in range(M):
  b.append(input())
ans="No"

for i in range(N-M+1):
  for j in range(N-M+1):
    c=[a[k][j:j+M] for k in range(i,i+M)]
    #print(c)
    if c==b:
      ans="Yes"
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define     ll              long long
#define     MAX             100000
#define     FI              freopen("input.txt","r",stdin)
#define     FO              freopen("output.txt","w",stdout)
#define     fast            ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define     sc(a)           scanf("%d",&a)
#define     sc2(a,b)        scanf("%d %d",&a,&b)


int main()
{
    int n;
    cin>>n;
    string ans = "No\n";
    while(n)
    {
        if(n%10==7)
            ans = "Yes\n";
        n/=10;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3600
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (n, m) = input_tuple();
    for i in (1..m/n + 1).rev() {
        if m % i == 0 {
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int N;
int A[210];
int main() {
    cin >> N;
    for (int i=0; i < N; ++i) cin >> A[i];
    int res = 0;

    while (true) {
        bool exist_odd = false;
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;
        }
        if (exist_odd) break;

        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(a*b-(1*a)-(1*b)+1);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main(){
  int n,k;cin>>n>>k;bool d[10];rep(i,10)d[i] = false;
  rep(i,k){
    int dd;cin>>dd;
    d[dd] = true;
  }
  repd(i,n,100000){
    string s = to_string(i);
    vector<int> a;
    rep(j,s.length()){
      a.push_back(s[j] - '0');
    }
    bool ok = true;
    rep(i,a.size()){
      if(d[a[i]]){
        ok = false;
        continue;
      }
    }
    if(ok){
      cout << i << endl;
      return 0;
    }

  }
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]

total = 0
is_odd = 0
min_number = 1000000001

for i in range(N):
    abs_num = abs(A[i])
    total += abs_num
    if abs_num < min_number:
        min_number = abs_num
    if A[i] < 0:
        is_odd = 1 - is_odd

if is_odd == 1:
    total -= min_number * 2

print(total)


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

int main(void){
    long long N;
    long long X, M;
    cin >> N >> X >> M;
    
    vector<long long> vec;
    long long a = X;
    long long cycleStart = N - 1, cycleEnd = N - 1;
    
    long long answer = 0;
    for (long long i = 0; i < N; i++) {
        vec.push_back(a);
        a = (long long)pow(a, 2) % M;
        answer += vec[i];
        
        vector<long long>::iterator itr = find(vec.begin(), vec.end(), a);
        if (itr != vec.end()){
            cycleStart = distance(vec.begin(), itr);
            cycleEnd = i;
            break;
        }
        
    }
    
    
    long long cycle = cycleEnd - cycleStart + 1;
    long long numCycle = (N - cycleStart) / cycle - 1;
    long long res = (N - cycleStart) % cycle;
    
    if (numCycle > 0) {
        for (long long i = cycleStart; i <= cycleEnd; i++) {
            if (i < cycleStart + res){
                answer += vec[i] * (numCycle + 1);
            } else {
                answer += vec[i] * numCycle;
            }
        }
    }
    
    cout << answer;

}


Measured memory_bytes: 3920
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        int e = a/d;
        e+=(a%d==0)?0:1;
        int f = c/b;
        f+=(c%b==0)?0:1;
        String ans = (e<f)?"No":"Yes";
        System.out.println(ans);
    }
}


Measured memory_bytes: 27076
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 week = ["SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"];
    let s: String = read();

    for i in 0..7 {
        if s == week[i] {
            println!("{}", i + 1);
        }
    }
}


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

int main() {
    int h, w;
    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++) {
            if (s[i][j] == '#') continue;
            s[i][j] = '0';
            if (i - 1 >= 0 && j - 1 >= 0) s[i][j] += (s[i - 1][j - 1] == '#');
            if (i - 1 >= 0) s[i][j] += (s[i - 1][j] == '#');
            if (i - 1 >= 0 && j + 1 < w) s[i][j] += (s[i - 1][j + 1] == '#');
            if (j + 1 < w) s[i][j] += (s[i][j + 1] == '#');
            if (i + 1 < h && j + 1 < w) s[i][j] += (s[i + 1][j + 1] == '#');
            if (i + 1 < h) s[i][j] += (s[i + 1][j] == '#');
            if (i + 1 < h && j - 1 >= 0) s[i][j] += (s[i + 1][j - 1] == '#');
            if (j - 1 >= 0) s[i][j] += (s[i][j - 1] == '#');
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


int main(){
    ll w, a, b;
    cin >> w >> a >> b;
    if((a <= b && b <= a+w) || (a <= b+w && b+w <= a+w)){
        cout << 0 << endl;
    }
    else cout << min(abs(a+w-b), abs(a-(b+w))) << endl;
}


Measured memory_bytes: 3608
import java.util.Scanner;
class Main
{ 
   public static void main(String[] args)
      {
   Scanner sc = new Scanner(System.in);
    int r, c, i, j;
    r = sc.nextInt();
    c = sc.nextInt();
    int[][] a = new int[101][101];
    
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            a[i][j]=sc.nextInt();
             a[i][c]+=a[i][j];
             a[r][j]+=a[i][j];
             a[r][c]+=a[i][j];
}
}

    for(i=0;i<r+1;i++){
        for(j=0;j<c;j++){
               System.out.print(a[i][j]+" ");
        }
         System.out.println(a[i][j]);
    }
    }
}



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

int N;
int a[100010];
bool lights[100010];
int main(){
  cin >> N;
  rep(i,N) cin >> a[i];
  rep(i,N) lights[i] = true;

  int next_s = 0, c = 0,g = 2;
  rep(i,N){
    if(lights[next_s] == false){
      cout << "-1" << endl;
      return 0;
    }
    lights[next_s] = false;
    next_s = a[next_s];
    if(next_s == g) break;
    next_s--;
  }
  rep(i,N) if(!lights[i]) c++;
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 768
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<String> set = new HashSet<>();
		
		
		for(int i=0;i<N;i++) {
			String s=sc.next();
			set.add(s);
		}
		
		System.out.println(set.size());
		
		
		
		sc.close();
	}
}

Measured memory_bytes: 76784
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<limits.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
typedef pair<ll,ll> PL;
typedef pair<ll,pair<ll,ll>> PLL;
static const int IINF=INT32_MAX;
static const ll LINF=INT64_MAX;
static const ll mod=1e9+7;
static const double eps=1e-13;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};

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;}

string N;

int main(){
    cin>>N;
    reverse(N.begin(),N.end());
    N+='0';
    int ans=0;
    int c=0;
    for(int i=0;i<N.size()-1;++i){
        int n=N[i]-'0';
        //cout<<n<<" "<<c<<endl;
        if(n+c<=4){
            ans+=n+c;
            c=0;
        }
        else if(n+c==5){
            if(N[i+1]-'0'<=4){
                ans+=n+c;
                c=0;
            }
            else {
                ans+=10-(n+c);
                c=1;
            }
        }
        else if(n+c>5){
            ans+=10-(n+c);
            c=1;
        }
    }
    ans+=c;
    cout<<ans<<endl;
}

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

uint32_t xor128(){
	static uint32_t x = 123456789,y = 362436069,z = 521288629,w = 88675123;
	uint32_t t;
	t = x ^ (x << 11);
	x = y; y = z; z = w;
	return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

template<class T>
struct SkipListSSet{
	static const int MAX_HEIGHT = 100;
	struct Node{
		T x;
		int h;
		vector<Node*> nxt;
		Node(T x,int h) : x(x),h(h),nxt(h + 1){}
	};

	int h,n;
	Node *root;//,*stack[MAX_HEIGHT];

	SkipListSSet() : h(0),n(0){
		root = new Node(0,MAX_HEIGHT);
	}

	~SkipListSSet(){
		Node *u = root;
		while(u != NULL){
			Node *nxt = u->nxt[0];
			delete u;
			u = nxt;
		}
	}

	inline int pickHeight() const{ return __builtin_ctz(xor128()); }

	/*bool add(T x){
		Node *u = root;
		int r = h;
		while(r >= 0){
			while(u->nxt[r] != NULL && u->nxt[r]->x < x) u = u->nxt[r];
			if(u->nxt[r] != NULL && u->nxt[r]->x == x) return false; //already exists
			stack[r--] = u;
		}
		Node *w = new Node(x,pickHeight());
		while(h < w->h) stack[++h] = root;
		for(int i = 0;i <= w->h;i++){
			w->nxt[i] = stack[i]->nxt[i];
			stack[i]->nxt[i] = w;
		}
		n++;
		return true;
	}*/

	bool add(T x){
		Node *u = findPredNode(x);
		if(u->nxt[0] != NULL && u->nxt[0]->x == x) return false;
		Node *w = new Node(x,pickHeight());
		h = max(h,w->h);
		u = root;
		int r = h;
		while(r >= 0){
			while(u->nxt[r] != NULL && u->nxt[r]->x < x) u = u->nxt[r];
			if(r <= w->h){
				w->nxt[r] = u->nxt[r];
				u->nxt[r] = w;
			}
			r--;
		}
		n++;
		return true;
	}

	bool remove(T x){
		Node *u = root,*del = NULL;
		int r = h;
		while(r >= 0){
			while(u->nxt[r] != NULL && u->nxt[r]->x < x) u = u->nxt[r];
			if(u->nxt[r] != NULL && u->nxt[r]->x == x){
				del = u->nxt[r];
				u->nxt[r] = u->nxt[r]->nxt[r];
				if(u == root && u->nxt[r] == NULL) h--;
			}
			r--;
		}
		if(del != NULL){
			delete del;
			n--;
		}
		return (del != NULL);
	}

	Node* findPredNode(T x) const{
		Node *u = root;
		int r = h;
		while(r >= 0){
			while(u->nxt[r] != NULL && u->nxt[r]->x < x) u = u->nxt[r];
			r--;
		}
		return u;
	}

	T find(T x) const{
		Node *u = findPredNode(x);
		return (u->nxt[0] == NULL ? -1 : u->nxt[0]->x);
	}

	friend ostream &operator<<(ostream &os,const SkipListSSet &s){
		Node *u = s.root;
		os << '{';
		while(u->nxt[0] != NULL){
			u = u->nxt[0];
			os << u->x << ',';
		}
		return os << '}';
	}
};

signed main(){
	SkipListSSet<int> sset;
	int q;
	cin >> q;
	for(int i = 0;i < q;i++){
		int t,x;
		cin >> t >> x;
		if(t == 0){
			sset.add(x);
			cout << sset.n << endl;
		}else if(t == 1){
			cout << (sset.find(x) == x) << endl;
		}else{
			sset.remove(x);
		}
	}
}


Measured memory_bytes: 19124
N=gets.to_i
A,B=2.times.map{gets.split.map(&:to_i)}
ans=0
N.times do |i|
  n=[A[i],B[i]].min
  A[i]-=n
  B[i]-=n
  ans+=n
  n=[A[i+1],B[i]].min
  A[i+1]-=n
  ans+=n
end
p ans


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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

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

   int N,K;
   cin>>N>>K;
   vector<ll>h(N);
   for(int i=0;i<N;i++)cin>>h[i];
   //h.erase(h.end()-1);
   //for(int i=0;i<h.size();i++)cout<<h[i]<<endl;
   sort(h.begin(),h.end());

   vector<ll>sum(N);
   sum[0] = 0;
   //cout<<sum[0]<<endl;
   for(int i=1;i<N;i++){
      sum[i] = h[i]-h[i-1];
      //cout<<sum[i]<<" "<<h[i]<<" "<<sum[i-1]<<endl;
   }
   for(int i=1;i<N;i++){
      sum[i] += sum[i-1];
   }
   ll ans = 10000000000;
   //for(int i=0;i<h.size();i++)cout<<h[i]<<" "<<sum[i]<<endl;
   for(int i=0;i<=N-K;i++){
   //   cout<<i<<" "<<i+K<<" "<<sum[i+K]<<" "<<sum[i]<<endl;
      //cout<<sum[i+K]<<" "<<sum[i]<<endl;
      ans = min(abs(sum[i+K-1]-sum[i]),ans);
   }
   cout<<ans<<endl;
   return 0; 
}


Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

class Eratosthenes:
    # https://cp-algorithms.com/algebra/prime-sieve-linear.html
    def __init__(self, n):
        primes, lp = [], [0] * (n + 1)
        for i in range(2, n + 1):
            if lp[i] == 0:
                primes.append(i)
                lp[i] = i

            for pj in primes:
                if pj > lp[i] or i * pj > n: break
                lp[i * pj] = pj
        self.primes, self.lp = primes, lp

    def is_prime(self, x): return self.lp[x] == x

    def factors(self, x):
        ret = []
        while x > 1:
            ret.append(self.lp[x])
            x //= self.lp[x]
        return ret

    def factors_count(self, x):
        ret = defaultdict(int)
        while x > 1:
            ret[self.lp[x]] += 1
            x //= self.lp[x]
        return ret


def main():
    N = I()
    era = Eratosthenes(N)
    d = defaultdict(int)
    for i in range(1, N):
        cnt = era.factors_count(i)
        tmp = 1
        for v in cnt.values():
            tmp *= v+1
        d[i] = tmp

    ans = 0
    for c in range(1, N):
        ans+= d[N - c]

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 181360
x,a,b = input().split()
x = int(x)
a = int(a)
b = int(b)
# print("x = ", x)
# print("a = ", a)
# print("b = ", b)

if x < a:
    distance_xa = a - x
else:
    distance_xa = x - a
# print("distance_xa = ", distance_xa)

if x < b:
     distance_xb = b - x
else:
     distance_xb = x - b
# print("distance_xb = ", distance_xb) 

if distance_xa < distance_xb:
      print("A")
else:
      print("B")

Measured memory_bytes: 3060
char*w,W[101],*p;main(t){for(;scanf("%s%s",W,&t),t-'X';puts(""))for(w=W;*w;w+=*w==95){for(p=w;*++p&&*p-95&&*p&32;);putchar(t&1?*w++&~32:t&8?w-W?*w++&~32:*w++|32:w-W?95:*w++|32);for(;w<p;w++)putchar(*w|32);}exit(0);}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
mod = pow(10, 9)+7
memo = dict()
def dfs(n):
    if n in memo:
        return memo[n]
    if n < 3:
        return 0
    ans = 0
    for i in range(n-3, 2, -1):
        ans += dfs(i)+1
        ans %= mod
    memo[n] = ans%mod
    return ans

def main():
    n = int(input())
    ans = dfs(n)
    if n >= 3:
        ans += 1
    print(ans)



    
if __name__ == "__main__":
    main()



Measured memory_bytes: 9444
defmodule Main do
  def main do
    n=IO.gets("")|>String.trim |>String.to_integer
    m=1000000000000000000

    a=IO.gets("") |> String.trim |> String.split(" ") |>Enum.map(fn x->String.to_integer(x)end)
    Enum.reduce(a, 1, fn (x, acc)-> if (x*acc>m) || (acc*x<0) do 
        acc=-1
      else
        x*acc
      end
      end)
      |> IO.puts()
  end
end


Measured memory_bytes: 60688
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define end cout<<'\n';
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
ll x,y;
    cin>>x>>y;
    cout<<x*y;
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<cmath>


using namespace std;
int F_keta(long long, long long);
int main()
{
	long long N;
	long long A,B;
	int min = 1000;
	int keta_data;
	cin >> N;
	for (A = 1; A<sqrt(N + 1); ++A) {
		if (N%A == 0) {
			B = N / A;
			keta_data=F_keta(A,B);
			if (keta_data < min) {
				min = keta_data;
			}
		}
	}
	
	cout << min << endl;
	return 0;

}

int F_keta(long long A, long long B) {
	int answer;
	string ast, bst;
	ast = to_string(A);
	bst = to_string(B);
	if (ast.size() >= bst.size()) {
		answer = ast.size();
	}
	else {
		answer = bst.size();
	}

	return answer;
}

Measured memory_bytes: 256
import java.util.*;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int[] c=new int [a];
		for(int i=0;i<b;i++)
		{
			c[i]=sc.nextInt();
		}
		System.out.println((int) Math.ceil((double) (a - b) / (b - 1) + 1));
	}
}

Measured memory_bytes: 47968
#include<cstdio>
#include<ctime>
#include<cstdlib>
using namespace std;
int main(){

  srand((unsigned int)time(NULL));

  int n, k, data[500][500];
  bool flag[1000];
  scanf("%d %d", &n, &k);
  for(int i = 0 ; i < k ; i++ ){
    for(int j = 0 ; j < n / 2 ; j++ ) scanf("%d",&data[i][j]);
  }
  while(true){
    bool ok = true;
    for(int i = 0 ; i < n ; i++ ) flag[i] = (unsigned int)rand() % 2;
    for(int i = 0 ; i < k ; i++ ){
      int sum = 0;
      for(int j = 0 ; j < n / 2 ; j++ ) sum += flag[data[i][j]-1];
      if(!(sum >= n / 8 && sum <= 3 * n / 8)){
        ok = false;
        break;
      }
    }
    if(ok) break;
  }
  for(int i = 0 ; i < n ; i++ ) printf("%d",flag[i]);
  printf("\n");
}

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

int gcd(int x, int y) { if(x<y) swap(x, y); if(y==0) return x; return gcd(y, x%y);};

int main(void){
  int N;
  cin >> N;
  int ans;
//  int ans = 2e9;
  cin >> ans;
  for(int i=0; i<N-1; i++){
    int tmp;
    cin >> tmp;
    ans = min(ans, gcd(ans, tmp));
  }
  cout << ans << endl;
  return 0;
}


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

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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

const int MAX = 3000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int n, k;
    cin >> n >> k;
    COMinit();
    rep(i, 1, k+1){
        cout << COM(n-k+1,i)*COM(k-1,i-1)%MOD << endl;
    }
}

Measured memory_bytes: 3676
use std::io;

fn main() {
    let mut buf: String = String::new();
	io::stdin().read_line(&mut buf).unwrap();
	let n : u32 = buf.trim().parse::<u32>().unwrap();
	let f_n : u32 = buf.trim().chars().map(|x| x.to_digit(10).unwrap()).sum();
	println!("{}", if n % f_n == 0 { "Yes" } else {"No"});
}


Measured memory_bytes: 4352
import java.util.Scanner;

//KND is So Sexy
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = sc.nextInt(), l = sc.nextInt(), x = sc.nextInt();
			double t = (2*l+a)/2., s = (2*l+x)/2.;
			System.out.printf("%.8f\n", 2*Math.sqrt(s*(s-l)*(s-(l+x)/2.)*(s-(l+x)/2.)) + Math.sqrt(t*(t-a)*(t-l)*(t-l)));
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.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 dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1e9+7) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

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

const int INF = 1e18;

// idx, (未処理, 偶数左, 奇数, 偶数右)
const int VARI = 5;
int dp[200010][VARI];

signed main() {
  int N;
  cin >> N;
  vec<int> v(N);
  rep (i, N) {
    cin >> v[i];
  }

  const int one = 0; // 左のゼロ区間
  const int two = 1; // 右のゼロ区間
  const int three = 2; // 左の偶数区間
  const int four = 3; // 右の偶数区間
  const int five = 4; // 奇数区間

  // 初期化
  fill(dp[0], dp[N+1], INF);
  dp[0][one] = 0;
  dp[0][two] = 0;
  dp[0][three] = 0;
  dp[0][four] = 0;
  dp[0][five] = 0;

  // DP
  rep (i, N) {
    // 左のゼロ区間
    int cost1 = v[i];
    chmin(dp[i+1][one], dp[i][one] + cost1);

    // 左の偶数区間
    int cost2 = v[i] == 0 ? 2 : v[i] % 2;
    chmin(dp[i+1][two], min(dp[i][one], dp[i][two]) + cost2);

    // 奇数区間
    int cost3 = v[i] == 0 ? 1 : (v[i] % 2 == 0);
    chmin(dp[i+1][three], min({dp[i][two], dp[i][three], dp[i][one]}) + cost3);

    // 右の偶数区間
    int cost4 = v[i] == 0 ? 2 : v[i] % 2;
    chmin(dp[i+1][four], min({dp[i][three], dp[i][four], dp[i][two], dp[i][one]}) + cost4);

    // 右のゼロ区間
    int cost5 = v[i];
    chmin(dp[i+1][five], min({dp[i][four], dp[i][three], dp[i][two], dp[i][one], dp[i][five]}) + cost5);
  }

  int ans = INF;
  rep (i, VARI) {
    chmin(ans, dp[N][i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9600
s=input()
n=len(s)
s=s[::-1]
cnt_mod=[0]
m=0
d=1
for i in range(n):
  m+=int(s[i])*d
  m%=2019
  d*=10
  d%=2019
  cnt_mod.append(m)

from collections import Counter
c=Counter(cnt_mod)
ans=0
for v in c.values():
  ans+=v*(v-1)//2
print(ans)

Measured memory_bytes: 16592
import collections
import sys
sys.setrecursionlimit(10**9)

def dfs(v):
  ret=0
  for u in g[v]:
    if checked[u]==0:
      checked[u]=1
      ret+=1+dfs(u)
  return ret

n=int(input())
g=[[] for _ in range(n+1)]
for _ in range(n-1):
  u,v=map(int,input().split())
  g[u].append(v)
  g[v].append(u)
q=collections.deque()
pn=[-1]*(n+1)
checked=[0]*(n+1)
checked[1]=1
q.append(1)
cnt=0
while cnt!=n-1:
  v=q.popleft()
  for u in g[v]:
    if checked[u]==0:
      cnt+=1
      checked[u]=1
      q.append(u)
      pn[u]=v
path=[n]
while 1:
  tmp=pn[path[-1]]
  if tmp==1:
    break
  path.append(tmp)
path=path[::-1]
l=len(path)
if l==1:
  fg=n
  sg=1
else:
  fg=path[l//2]
  sg=path[l//2-1]
checked=[0]*(n+1)
checked[1]=1
checked[fg]=1
ans1=dfs(1)
ans2=(n-2)-ans1
if ans1>ans2:
  print('Fennec')
else:
  print('Snuke')

Measured memory_bytes: 67952
import Control.Applicative
import Control.Monad
import Data.List

-- Top, Front, Right. Back, Left, Bottom
-- X: Right-Left, Y: Front-Back, Z: Top-Bottom
type Dice a = (a,a,a,a,a,a)

rollPX :: Dice a -> Dice a
rollPX (tp,fr,rg,bk,lf,bt) = (fr,bt,rg,tp,lf,bk)

rollNX :: Dice a -> Dice a
rollNX (tp,fr,rg,bk,lf,bt) = (bk,tp,rg,bt,lf,fr)

rollPY :: Dice a -> Dice a
rollPY (tp,fr,rg,bk,lf,bt) = (lf,fr,tp,bk,bt,rg)

rollNY :: Dice a -> Dice a
rollNY (tp,fr,rg,bk,lf,bt) = (rg,fr,bt,bk,tp,lf)

rollPZ :: Dice a -> Dice a
rollPZ (tp,fr,rg,bk,lf,bt) = (tp,rg,bk,lf,fr,bt)

rollNZ :: Dice a -> Dice a
rollNZ (tp,fr,rg,bk,lf,bt) = (tp,lf,fr,rg,bk,bt)

rollX :: Int -> Dice a -> Dice a
rollX n = if n >= 0 then (foldl (.) id (replicate (n `mod` 4) rollPX)) else (foldl (.) id (replicate ((-n) `mod` 4) rollNX))

rollY :: Int -> Dice a -> Dice a
rollY n = if n >= 0 then (foldl (.) id (replicate (n `mod` 4) rollPY)) else (foldl (.) id (replicate ((-n) `mod` 4) rollNY))

rollZ :: Int -> Dice a -> Dice a
rollZ n = if n >= 0 then (foldl (.) id (replicate (n `mod` 4) rollPZ)) else (foldl (.) id (replicate ((-n) `mod` 4) rollNZ))

allRolls :: Dice a -> [Dice a]
allRolls dice = tail $ scanl (\d f -> f d) dice  (concatMap (\f -> (rollPZ . f) : replicate 3 rollPZ) (take 6 (cycle [rollPX, rollPY])))

dTop (tp,_,_,_,_,_) = tp
dBottom (_,_,_,_,_,bt) = bt
dRight (_,_,rg,_,_,_) = rg
dLeft (_,_,_,_,lf,_) =lf
dFront (_,fr,_,_,_,_) = fr
dBack (_,_,_,bk,_,_) = bk



sameDice :: Eq a => Dice a -> Dice a -> Bool
sameDice d1 d2 = any (==d1) (allRolls d2)

main = do
  n <- readLn :: IO Int
  
  dices <- replicateM n $ do
    [d1,d2,d3,d4,d5,d6] <- map read . words <$> getLine :: IO [Int]
    return (d1,d5,d3,d2,d4,d6)
  
  let ans = or [sameDice di dj | (i,di) <- zip [1..] dices, (j,dj) <- zip [1..] dices, i<j]

  putStrLn $ if ans then "No" else "Yes"



Measured memory_bytes: 4244
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    int a;
    int b;
    int c;
    int d;
    int e;
    int f;
    cin >> a >> b >> c >> d >> e >> f;
    double answer = 0;
    int ans_total = a * 100 * 100;
    int ans_sugar = 0;

    int water;
    int sugar;
    int max_sugar;

    //for (int i = 0; i <= 30; i++) {
        //for (int j = 0; j <= 30; j++) {
    for (int i = 0; i <= 3; i++) {
        for (int j = 0; j <= 3; j++) {
            //cout << "I = " << i << ", J = " << j << endl;
            if (i == 0 && j == 0) {
                continue;
            }
            water = (100 * i * a + 100 * j * b) * 100;
            if (water > 100 * f) {
                continue;
            }
            max_sugar = water * e / 100;
            if (water + max_sugar > 100 * f) {
                max_sugar = 100 * f - water;
            }
            //cout << "W = " << water << endl;
            //cout << "MAX = " << max_sugar << endl;
            for (int m = 0; m * c * 100 <= max_sugar; m++) {
                for (int n = 0; n * d * 100 <= max_sugar - m * c * 100; n++) {
                    sugar = (m * c + n * d) * 100;
                    double temp = (double)(100 * sugar) / (double)(water + sugar);
                    //cout << temp << endl;
                    if (temp > answer) {
                        //cout << "M = " << m << ", N = " << n << endl;
                        answer = temp;
                        ans_total = water + sugar;
                        ans_sugar = sugar;
                    }
                }
            }
        }
    }
    cout << ans_total / 100 << " " << ans_sugar / 100 << endl;
    return 0;
}



Measured memory_bytes: 256
import numpy as np
import sys
n = int(input())
s = input()
ans = 0
for i in range(n-2):
    count = len(set(s[:i+1]))+len(set(s[i+1:]))-len(set(list(set(s[:i+1]))+list(set(s[i+1:]))))
    ans = max(ans,count)
print(ans)


Measured memory_bytes: 21500
#include<bits/stdc++.h>
using namespace std;
#include<vector>
#include<algorithm>
#include<unordered_set>
#include<unordered_set>
#include<cmath>
#include<set>
#include<string>
#define mod 1000000007
#define lld long long int
int main()
{
int a;int b;
cin>>a>>b;
cout<<a*b<<"\n";
     return 0;
}

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

int main(){
    int n;
    int a, b;

    //input
    cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
    }else if(n == 2){
        cin >> a >> b;
        cout << a + b << endl;
    }
}


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

double SumOfVector(const std::vector<double>& vec)
{
	double sum=0;

	for(size_t i=0; i<vec.size(); ++i)
	{
		sum += vec[i];
	}
	
	return sum;
}

double Sequence(double a)
{
	std::vector<double> vec(10);

	vec[0] = a;

	int oddeven = 2;

	for(size_t i=1; i<vec.size(); ++i)
	{
		vec[i] = (oddeven%2==0 ? vec[i-1]*2.0 : vec[i-1]/3.0);

		++oddeven;
	}

	return SumOfVector(vec);
}

int main()
{
	double a;

	while(std::cin >> a)
	{
		printf("%10.7f\n",Sequence(a));
	}

}

Measured memory_bytes: 1244
#include <stdio.h>

#define N 251
#define NIL -2100000000


int main() {
  int data[N], h, i;

  scanf("%d", &h);

  for (i = 0; i < N; i++) {
    data[i] = NIL;
  }

  for (i = 1; i <= h; i++) {
    scanf("%d", &data[i]);
  }

  for (i = 1; i <= h; i++) {
    printf("node %d: ", i);
    printf("key = %d, ", data[i]);
    if (data[i/2] != NIL) {
      printf("parent key = %d, ", data[i/2]);
    }
    if (data[i*2] != NIL && i*2 <= h) {
      printf("left key = %d, ", data[i*2]);
    }
    if (data[i*2+1] != NIL && i*2+1 <= h) {
      printf("right key = %d, ", data[i*2+1]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2052
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Maybe as Maybe
import qualified Data.Char as Char

-------------------------------------------------------------------------------

main :: IO ()
main = do
    input <- getInput
    B.putStrLn (solve input)

getInput :: IO (Int, Int)
getInput =
    let
        parser = (,) <$> parseInt <*> parseInt
    in
        runParser parser <$> B.getContents

solve :: (Int, Int) -> B.ByteString
solve (a, b) =
    if a * b `mod` 2 == 0 then
        "Even"
    else
        "Odd"

-------------------------------------------------------------------------------

newtype Parser a =
    Parser (B.ByteString -> (a, B.ByteString))

instance Functor Parser where
    fmap f (Parser parser) =
        Parser $ \input ->
            let (v, remainder) = parser input in
                (f v, remainder)

instance Applicative Parser where
    pure v =
        Parser $ \input ->
            (v, input)

    (Parser parser1) <*> (Parser parser2) =
        Parser $ \input ->
            let
                (f, remainder1) = parser1 input
                (v, remainder2) = parser2 remainder1
            in
                (f v, remainder2)

consumeSpace :: Parser ()
consumeSpace =
    Parser $ \input ->
        ((), B.dropWhile Char.isSpace input)

lexeme :: Parser a -> Parser a
lexeme parser =
    consumeSpace *> parser

parseInt_ :: Parser Int
parseInt_ =
    Parser $ \input ->
        Maybe.fromJust (B.readInt input)

parseInt :: Parser Int
parseInt =
    lexeme parseInt_

runParser :: Parser a -> B.ByteString -> a
runParser (Parser parser) input =
    fst $ parser input

-------------------------------------------------------------------------------


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

int main() { 	
  string N;
    char M,P;
  int p,m;
	cin >> N;
  M=N.at(0);
  m=1;
  p=0;
	if(M==N.at(1)){
      m++;
    }else{
    P=N.at(1);
      p++;
    }
  if(p==0){
        P=N.at(2);
      p++;
}else if(M==N.at(2)){
      m++;
    }else if(P==N.at(2)){
      p++;
    }
  
  if(M==N.at(3)){
      m++;
    }else if(P==N.at(3)){
      p++;
    }
  
  if(p==2 && m==2){
    cout << "Yes"<<endl;}else{
  cout << "No"<<endl;
  } 
  
}



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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

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

	VVI happy(n, VI(3, 0));
	for (int i = 0; i < n; i++) {
		cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
	}

	VVI dp(n + 1, VI(3, 0));

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) { //今
			for (int k = 0; k < 3; k++) { //次
				if (j == k) {
					continue;
				}
				dp[i+1][k] = max(dp[i+1][k], dp[i][j] + happy[i][k]);
			}
		}
	}

	int ans = *max_element(dp[n].begin(), dp[n].end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define pi 3.14159265358979323846
#define Endl endl
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int rem[214514],cnt[114514];
signed main(){
	int n,p;
	string s;
	cin>>n>>p>>s;
	reverse( s.begin(), s.end() );
	if( p != 2 && p != 5 ){
		int po = 10;
		rem[0] = ( s[0] - '0' ) % p;
		for(int i=1;i<n;i++){
			rem[i] = ( rem[i-1] + (s[i] - '0' ) * po ) % p;
			po = (po * 10) % p;
		}
		int ans = 0;
		cnt[0]++;
		for(int i=0;i<n;i++){
			ans += cnt[ rem[i] ];
			cnt[rem[i]]++;
			//cout<<i<<" "<<rem[i]<<endl;
		}
		cout<<ans<<Endl;
	}
	else{
		int ans = 0;
		for(int i=0;i<n;i++){
			if( ( s[i] - '0' ) % p == 0 ){
				ans += n-i;
			}
		}
		cout<<ans<<Endl;
	}
	return 0;
}

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

template <typename T> inline void read (T &x) {bool b = 0; char c; while (!isdigit (c = getchar()) && c != '-');
if (c == '-') c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x<<3) + (x<<1) + c - 48; if (b)x=-x;}
template <typename T> inline void wrip(T x) {if (x > 9) wrip(x / 10); putchar(x%10 + 48); }

template <typename T> inline void write(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar(' ');}
template <typename T> inline void writeln(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar('\n');}
inline char readch() {char c; do c = getchar(); while (c == '\n' || c == ' '); return c;}
inline void reads(string &s) {char c; while((c=getchar())==' '||c =='\n'); s=c; while((c=getchar())!=' '&&c!='\n') s+=c;}
inline void getlines(string &s) {char c; while((c=getchar())=='\n'); s=c; while((c=getchar())!='\n') s+=c;}
typedef const int csint;

#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;

const ld pi = acos(-1);
const ll inf = 1e16,
mod = 1e9 + 7,
N = 5011;
struct node{
    node *left, *right;
    ll ans, rem;
    int l, r, m;
    node() {
        l = r = NULL;
        ans = 0, rem = 0;
    }
    void Build(int u, int v) {
        l = u, r = v;
        if (u == v)
            return;
        m = u + v >> 1;
        left = new node();
        right = new node();
        left->Build(l, m);
        right->Build(m + 1, r);
    }
    void Push() {
        left->ans += rem;
        left->rem += rem;
        right->ans += rem;
        right->rem += rem;
        rem = 0;
    }
    void Update(int u, int v, ll val) {
        if (l > v || r < u)
            return;
        if (u <= l && r <= v) {
            rem += val;
            ans += val;
            return;
        }
        Push();
        left->Update(u, v, val);
        right->Update(u, v, val);
        ans = max(left->ans,  right->ans);
    }
};
int n, m;
ll res, s[N], a[N][211], amax[N][211];
stack <int> q[211];
int main() {
    #ifdef makacha
        freopen("m.inp", "r", stdin);
        freopen("m.out", "w", stdout);
    #endif // makacha
    node *it = new node();
    read(n);
    read(m);
    for (int i = 2, x; i <= n; i++) {
        read(x);
        s[i] = s[i - 1] + x;
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            read(a[i][j]);
    for (int i = 1; i <= m; i++) {
        a[0][i] = INT_MAX;
        q[i].push(0);
    }
    it->Build(1, n);
    for (int i = 1; i <= n; i++) {
        it->Update(i, i, s[i]);
        for (int j = 1; j <= m; j++) {
            while (a[q[j].top()][j] <= a[i][j]) {
                int pos = q[j].top();
                q[j].pop();
                it->Update(q[j].top() + 1, pos, a[i][j] - a[pos][j]);
            }
            q[j].push(i);
            it->Update(i, i, a[i][j]);
        }
        res = max(res, it->ans - s[i]);
    }
    cout << res;
}


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

using namespace std;

#define inf 1<<30
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;

vector<P> v;

llong memo[51][10001];
llong npr[51][51] = {};

llong NPR(int n, int r){
	if(npr[n][r] != 0)
		return npr[n][r];

	llong ret = 1;
	for(int i = 1; i <= r; i++)
		ret = ret * (n - (i - 1)) / i;

	return npr[n][r] = ret;
}

llong solve(int now, int ave){
	if(memo[now][ave+5000] > -1)
		return memo[now][ave+5000];
	if(ave > 0) return 0;
	if(now == v.size()){
		if(ave == 0) return 1;
		else return 0;
	}

	llong ret = 0;
	for(int i = 0; i <= v[now].second; i++){
		ret += NPR(v[now].second, i) * solve(now+1, ave + v[now].first*i);
	}

	return memo[now][ave+5000] = ret;
}

int main(){
	fn(*memo, 51*10001, -1);
	int N, A;
	map<int,int> m;
	cin >> N >> A;
	int in;
	for(int i = 0; i < N; i++){
		cin >> in;
		m[in-A]++;
	}
	for(auto it = m.begin(); it != m.end(); it++){
		v.pb(*it);
	}

	cout << solve(0,0) - 1 << endl;

	return 0;
}

Measured memory_bytes: 4224
#!/usr/bin/env python3
import itertools
def solve(n, a, b, c, l):
    answer = float('inf')
    for p in itertools.product(range(4), repeat=n):
        sum_l = [ 0, 0, 0, 0 ]
        cnt = [ 0, 0, 0, 0 ]
        for i in range(n):
            sum_l[p[i]] += l[i]
            cnt[p[i]] += 1
        if cnt[0] and cnt[1] and cnt[2]:
            cost = 10 * (cnt[0] + cnt[1] + cnt[2] - 3) + abs(sum_l[0] - a) + abs(sum_l[1] - b) + abs(sum_l[2] - c)
            answer = min(answer, cost)
    return answer

n, a, b, c = map(int, input().split())
l = [ int(input()) for _ in range(n) ]
print(solve(n, a, b, c, l))


Measured memory_bytes: 3064