akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000

struct unionfind{
	vector<int> data;
	vector<int> size;
	unionfind(int n){
		for(int i=0;i<n;i++){
			data.push_back(i);
			size.push_back(1);
		}
	}
	
	int find(int x){
		if(data[x]==x)return x;
		return data[x]=find(data[x]);
	}
	
	bool unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		if(size[x]>size[y])swap(x,y);
		data[x]=y;
		size[y]+=size[x];
		return true;
	}
	
	bool check(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_size(int x){
		int X = find(x);
		return size[X];
	}
};

//aのb乗
int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
	int catalan(int n){
		return mod(combination(2*n,n)*gyakugen(n+1));
	}
	
};

int main(){
	
	int N,X,Y;
	cin>>N>>X>>Y;
	
	vector<int> c(N),w(N);
	vector<vector<pair<int,int>>> num(N,vector<pair<int,int>>());
	for(int i=0;i<N;i++){
		cin>>c[i]>>w[i];
		c[i]--;
		num[c[i]].emplace_back(w[i],i);
	}
	
	unionfind uf(N);
	vector<pair<int,int>> P;

	for(int i=0;i<N;i++){
		if(num[i].size()==0)continue;
		sort(num[i].begin(),num[i].end());
		for(int j=0;j<num[i].size();j++){
			if(num[i][0].first + num[i][j].first <= X){
				uf.unite(num[i][0].second,num[i][j].second);
			}
		}
		P.push_back(num[i][0]);
	}
	sort(P.begin(),P.end());
	
	for(int i=0;i<min((int)P.size(),2);i++){
		int W = P[i].first;
		int C = c[P[i].second];
		for(int j=0;j<N;j++){
			if(C==c[j])continue;
			if(W+w[j]<=Y)uf.unite(j,P[i].second);
		}
	}

	vector<map<int,int>> mp(N,map<int,int>());
	
	for(int i=0;i<N;i++){
		mp[uf.find(i)][c[i]]++;
	}
	
	combi C(1000000);
	int ans = 1;
	for(int i=0;i<N;i++){
		int sum = 0;
		for(auto a:mp[i]){
			ans = mod(ans * C.kaijou_[a.second]);
			sum += a.second;
		}
		ans = mod(ans * C.kaijou[sum]);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 40552
#include <bits/stdc++.h>
using namespace std;
using namespace std;
 
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

vector<vector<ll> >vii;

int main() 

{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,m,c=0;
    cin>>n>>m;
    map<ll,ll>k;
    vii.resize(n+n);
    f(i,1,n+1){
    	ll x;
    	cin>>x;
    	k[i]=x;
    }
    while(m--){
    	ll x,y;
    	cin>>x>>y;
    	vii[x].pb(y);
    	vii[y].pb(x);
    }
    f(i,1,n+1){
    	if(vii[i].size()>0){
	     	ll flag=1;
	    	f(j,0,vii[i].size()){
	     		if(k[vii[i][j]]>=k[i]){
	     			flag=0; break;
	     		} 
	     	}
	     	if(flag==1) c++;
    	}
    	else c++;
    }
    cout<<c<<endl;
}

Measured memory_bytes: 17716
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int main()
{
  int N,K;
  cin >> N >> K;
  cout << (N-K+1) << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func inputAsInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func inputAsString() string {
	sc.Scan()
	return sc.Text()
}

func inputIntSlice(n int) []int {
	strSlice := strings.Split(inputAsString(), " ")

	arr := make([]int, n)
	for i, a := range strSlice {
		arr[i] = mustAtoi(a)

	}
	return arr
}

func mustAtoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

//
//type sortable [][]int
//
//func (s sortable) Len() int { return len(s) }
//
//func (s sortable) Less(i, j int) bool { return s[i][0] < s[j][0] }
//
//func (s sortable) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

func main() {
	sc.Buffer([]byte{}, 100000000)

	n := inputAsInt()
	as := inputIntSlice(n)

	ans := make([]string, n)
	for i, a := range as {
		ans[a-1] = strconv.Itoa(i + 1)
	}

	fmt.Println(strings.Join(ans, " "))
}


Measured memory_bytes: 7808
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    cin >> n;
    vi p_(n);
    rep(i, n) {
        int p;
        cin >> p;
        --p;
        p_[p] = i;
    }

    int ans = 0;
    int now = 1;
    rep(i, n-1) {
        if(p_[i] < p_[i+1]) {
            now++;
        } else {
            ans = max(ans, now);
            now = 1;
        }
    }
    ans = max(now, ans);

    cout << n-ans << endl;
}

Measured memory_bytes: 1024
/*
  The Island Was Silent before.
  .....
  And One day again it became Silent.
*/
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define rtt cerr << "Time: " << clock()*1.0 / CLOCKS_PER_SEC << endl;
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout);

int main() {
  #ifndef ONLINE_JUDGE
  ioso ffe
  #endif
  ll a,b,h,m;

  cin >> a >> b >> h >> m;

  h*= 60;
  m *= 11;
  double pi = acos(-1);
  double ff = (((abs(h-m))*1.00000/2*1.00000) * (pi/180.0000));
  double ans = sqrt(((double)(a*a) + (double)(b*b)) - (2.000*a*b*cos(ff)));

  printf("%.25lf\n", ans);
}

Measured memory_bytes: 4168
s = input()
x=int(s[:2])
y=int(s[2:])
if 1<=x and x<=12:
    if 1<=y and y<=12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif 1<=y and y<=12:
    print('YYMM')
else:
    print('NA')

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

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

 
    cout << (n*(n-1)+m*(m-1)) / 2 << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <assert.h>
#include <vector>

#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <climits>

#define N 4
#define N2 16

using namespace std;

// const int N = 4;
// const int N2 = 16;

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'}; 


struct Node
{
	int puzzle[N2];
	int space;
	int md;
};

class Npuzzle
{
private:
	Node s_node;
	Node cur_n;
	int limit;
	int md[N2][N2];
	// vector<int> path;
	int ans;
public:
	Npuzzle() {
		s_node = Node();
		int in[N2];
		for (int i = 0; i < N2; ++i)
		{
			int tmp;
			cin >> tmp;
			if(tmp == 0) {
				tmp = N2;
				s_node.space = i;
			}
			s_node.puzzle[i] = tmp;
		}
		set_md();
		s_node.md = get_md_sum(s_node.puzzle);
	}

	int get_md_sum(int *puzzle) {
		int sum = 0;
		for (int i = 0; i < N2; ++i)
		{
			if(puzzle[i] == N2) continue;
			sum += md[i][puzzle[i]-1];
		}
		return sum;
	}

	void set_md() {
		for (int i = 0; i < N2; ++i)
		{
			for (int j = 0; j < N2; ++j)
			{
				md[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
			}
		}
	}

	bool dfs(int depth, int pre) {
		if(cur_n.md == 0 ) {
			ans = depth;
			return true;
		}
		if(depth + cur_n.md > limit) return false;
		int s_x = cur_n.space / N;
		int s_y = cur_n.space % N;
		for (int i = 0; i < 4; ++i)
		{
			Node tmp = cur_n;
			int new_x = s_x + dx[i];
			int new_y = s_y + dy[i];
			if(new_x < 0  || new_y < 0 || new_x >= N || new_y >= N) continue; 
			if(max(pre, i) - min(pre, i) == 2) continue;

			//incremental manhattan distance
			cur_n.md -= md[new_x * N + new_y][cur_n.puzzle[new_x * N + new_y] - 1];
			cur_n.md += md[s_x * N + s_y][cur_n.puzzle[new_x * N + new_y] - 1];

			swap(cur_n.puzzle[new_x * N + new_y], cur_n.puzzle[s_x * N + s_y]);
			cur_n.space = new_x * N + new_y;
			// assert(get_md_sum(new_n.puzzle) == new_n.md);
			// return dfs(new_n, depth+1, i);
			if(dfs(depth + 1, i)){
				// path[depth] = i;
				return true;
			}
			cur_n = tmp;
		}
		return false;
	}

	void ida_star() {
		for (limit = s_node.md; limit < 1000; ++limit, ++limit)
		{
			// path.resize(limit);
			cur_n = s_node;
			if(dfs(0, -10)) {
				cout << limit << endl;
				// string str = "";
				// for (int i = 0; i < limit; ++i)
				// {
				// 	str += dir[path[i]];
				// }
				// cout << str << endl;
				return;
			}
		}
	}

	void exec() {
		ida_star();
	}
};


int main() {
	Npuzzle np = Npuzzle();
	np.exec(); 
}

Measured memory_bytes: 3096
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        list: [usize; m*2],
    }
    let mut cnt = HashMap::new();

    for i in 1..n + 1 {
        cnt.insert(i, 0);
    }

    for c in list {
        *cnt.entry(c).or_insert(0) += 1;
    }

    for i in 1..n + 1 {
        println!("{}", cnt[&i])
    }
}


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

using namespace std;

int main(){
    int A,B,C,X,Y,D,E,F;
    long long min=999999999999;
    cin>>A>>B>>C>>X>>Y;
    for(int i=0;i<=200000;i++){
        D=i*2;
        E=X-i;
        F=Y-i;
        if(E<0) E=0;
        if(F<0) F=0;
        if(min>A*E+B*F+C*D){
            min=A*E+B*F+C*D;
        }
    }
    cout<<min<<endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < static_cast<int>(n); ++i)
#define per(i, n) for(int i = static_cast<int>(n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}

using ll = long long;

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

constexpr char sp = ' ';
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n, ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

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 T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s<<'[';for(size_t i=0;i<v.size();++i){s << v[i];if(i < v.size()-1) s << ", ";}s<<']';return s;
}
struct __{ __(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15); } };

int main(){

    int h, w, n;
    cin >> h >> w >> n;
    cout << (n+max(h, w)-1)/max(h, w) << endl;


    return 0;
}


Measured memory_bytes: 256
#ifndef TestHeader_hpp
    #define TestHeader_hpp
    #include<bits/stdc++.h>
    typedef long long int lli;
    #ifndef UNS
        #define UNS
        using namespace std;
    #endif // UNS
    #ifndef Nstdio
        #define Nstdio
        //#include<stdio.h>
    #endif // Nstdio
    #ifndef Nvector
        #define Nvector
        //#include<vector>
        typedef vector<lli> vl;
        typedef vector<int> vi;
    #endif // Nvector
    #ifndef Nutility
        #define Nutility
        //#include<utility>
        typedef pair<int,int> pii;
        typedef pair<lli,lli> pll;
    #endif // Nutility
    #define DP(H,W) lli[H][W] = {0}
    #define PUB push_back
    #define MsP make_pair
    #define F first
    #define S second
    #define INT 1
    #define LLI 2
    #define DOUBLE 3
    #define FLOAT 4
    #define CHAR 5
    #define STRING 6
    #define READ scanf
    #define PL printf
    #define SPACE PL(" ")
    #define ENTER PL("\n")
    #define REPI(ite) for(int i = 0;i < ite;i++)
    #define REPJ(ite) for(int j = 0;j < ite;j++)
    #define REPK(ite) for(int k = 0;k < ite;k++)
    #define DREPI(ite) for(int i = ite-1;i >= 0;i--)
    #define DREPJ(ite) for(int j = ite-1;j >= 0;j--)
    #define DREPK(ite) for(int k = ite-1;k >= 0;k--)
    #define AREPI(ite) for(int Ai = 0;Ai < ite;Ai++)
    #define AREPJ(ite) for(int Aj = 0;Aj < ite;Aj++)
    #define AREPK(ite) for(int Ak = 0;Ak < ite;Ak++)
    #define INPUT(address,type) if(type == INT){READ("%d",address);}else if(type == LLI){READ("%lld",address);}else if(type == DOUBLE){READ("%lf",address);}else if(type == FLOAT){READ("%f",address);}else if(type == CHAR){READ("%c",address);}else if(type == STRING){READ("%s",address);}
    #define OUTPUT(address,type) if(type == INT){PL("%d",*(address));}else if(type == LLI){PL("%lld",*(address));}else if(type == DOUBLE){PL("%lf",*(address));}else if(type == FLOAT){PL("%f",*(address));}else if(type == CHAR){PL("%c",*(address));}else if(type == STRING){PL("%s",*(address));}
    #define INARRAY(addredd,len,type) AREPI(len){INPUT(address+Ai,type);}
    #define OUTARRAY(address,len,type) AREPI(len){OUTPUT(address+Ai,type);SPACE;}ENTER
    lli GCD(lli a,lli b){
        if(a%b == 0){
            return b;
        }
        else{
            return GCD(b,a%b);
        }
    }
    lli NT(lli x,lli n){
        int XN = 0;
        while(1){
            if(x%n != 0){
                return XN;
            }
            XN++;
            x/=n;
        }
    }
#endif // TestHeader_hpp

int main(){
    char s[1050] = {0};
    INPUT(s,STRING);
    int w;
    INPUT(&w,INT);
    int i = 0;
    int cnt = 0;
    while(s[i] != 0){
        if(cnt%w == 0){
            PL("%c",s[i]);
        }
        cnt++;
        i++;
    }
    ENTER;
    return 0;
}


Measured memory_bytes: 256
mod = 10**9+7

def factorials(n,m):
    # 0~n!のリスト
    f = [1,1]
    for i in range(2,n+1):
        f.append(f[-1]*i%m)

    # 0~n!の逆元のリスト
    g = [1]
    for i in range(n):
        g.append(pow(f[i+1],m-2,m))

    return f,g

f,g = factorials(4*10**5,mod)


n,k = map(int, input().split())
if k>=n-1:
    print((f[2*n-1]*g[n]*g[n-1])%mod)
else:
    ans = 0
    for x in range(k+1):
        ans += f[n-1]*g[x]*g[n-x-1]*f[n]*g[n-x]*g[x]
        ans %= mod
    print(ans)

Measured memory_bytes: 73004
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

int h,w;
int board[52][52];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
bool check(int i, int j) {
	return (i >= 0) && (i < h) && (j >= 0) && (j < w) && (board[i][j] ==1);
}

void dfs(int x,int y){
    if(board[x][y]==0)return;
    board[x][y]=0;
    for(int i=x-1;i<=x+1;i++){
        for(int j=y-1;j<=y+1;j++){
            if(i==x && j==y)continue;
            if(check(i,j))dfs(i,j);
        }
    }
    return;
}

int main(void){
    while(true){
        int ans = 0;
        cin>>w>>h;
        if(w==0 && h==0)break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>board[i][j];
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(board[i][j]==1){
                    dfs(i,j);
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

typedef unsigned long long ull;

ull mod_pow(ull x,ull n){
  ull res=1;
  while(n){
    if(n%2) res=res*x;
    x=x*x;
    n/=2;
  }
  return res;
}



signed main(){
  int n;
  cin>>n;
  vector<int> A(n);
  cin>>A;

  vector<int> ans;
  
  ull B = 1777771;
  ull hash1=0,hash2=0;

  for(int i=0;i<n;i++){
    hash1 += mod_pow(B,A[i]);
    hash2 += mod_pow(B,A[n-i-1]);
    if(hash1 == hash2) ans.push_back(i+1);
  }

  cout<<ans<<endl;  

  return 0;
}



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

N = int(raw_input())
A = []
for i in range(N):
    A.append(int(raw_input()))
cnt = 0
G = [1]
while G[-1]*3+1 < N:
    G.append(G[-1]*3+1)
G.reverse()
m = len(G)
for i in range(m):
    g = G[i]
    for j in range(g, N):
        v = A[j]
        k = j-g
        while k >= 0 and A[k] > v:
            A[k+g] = A[k]
            k -= g
            cnt += 1
        A[k+g] = v
print m
print " ".join(map(str, G))
print cnt
for i in range(N):
    print A[i]

Measured memory_bytes: 69764
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

class union_find {
private:
    vector<ll> par;
    vector<ll> ran;
    vector<ll> m_size;
public:
    union_find(ll n);
    ll find(ll x);
    void unite(ll x, ll y);
    bool same(ll x, ll y);
    ll size(ll x);
};

union_find::union_find(ll n){
    par.resize(n);
    ran.resize(n, 0);
    m_size.resize(n, 1);
    REP(i,n) par[i] = i;
};

ll union_find::find(ll x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll t = size(x)+size(y);
    m_size[x] = m_size[y] = t;
    if (ran[x] < ran[y]) {
        par[x] = y;
        //size[y] += size[x];
    } else {
        par[y] = x;
        //ize[x] += size[y];
        if (ran[x]==ran[y]) ran[x]++;
    }
};

ll union_find::size(ll x) {
    if (par[x] == x) return m_size[x];
    return size(par[x] = find(par[x]));
}

bool union_find::same(ll x, ll y) {
    return (find(x) == find(y));
};

int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    vector<bool> b(n, false);
    int ans = 0;
    union_find uf(n);
    REP(i,m) {
        int x, y, z;
        cin >> x >> y >> z;
        uf.unite(x-1, y-1);
    }
    for (int i = 0; i < n; ++i) {
        int x = uf.find(i);
        if (!b[x]) ans++, b[x] = true;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
// 写経AC

#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

//
const long long INF = 1LL << 60;
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 N;
long long h[100010];

//DP table
long long dp[100010];

void input(void){
    cin >> N;
    for(int i=0; i< N; i++){
        cin >> h[i];
    }
    return;
}

void init(void){
    for(int i=0; i< 100010; i++){
        dp[i]= INF;
    }
    return;
}

void solve(){
    //初期条件
    dp[0] = 0;

    // dp
    for(int i=1; i<N; i++){
        chmin(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1){
            chmin(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
        }
    }

    cout << dp[N-1] << endl;
    return;
}

int main(void){
    input();
    init();
    solve();
    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define For(i,j,k)	for(int i=j;i<=k;++i)
#define Dow(i,j,k)	for(int i=k;i>=j;--i)
#define ll long long
#define PI acos(-1)

using namespace std;

inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(!isdigit(c))	{if(c=='-')	f=-1;c=getchar();}
	while(isdigit(c))	t=t*10+c-48,c=getchar();
	return t*f;
}
inline void write(ll x){if(x<0)	{putchar('-');x=-x;}	if(x>=10)	write(x/10);putchar(x%10+48);}
inline void writeln(ll x){write(x);puts("");}
inline void write_p(ll x){write(x);putchar(' ');}

const int N=500006;
char s[N];
int jump[N],nxt[N],Fa[N][22],n,que,to[N][31],q[N],trans[N][31];
int main()
{
//	freopen("fusion.in","r",stdin);freopen("fusion.out","w",stdout);
	scanf("\n%s",s+1);
	n=strlen(s+1);que=read();
	to[n][s[n]-'a']=n;
	Dow(i,1,n-1)
	{
		to[i][s[i]-'a']=i;
		int now=i+1,nc=s[i]-'a';
		while(1)
		{
			int tmp=now,top=0;
			while(!to[now][nc]&&nxt[now])	
			{
				q[++top]=now;
				now=nxt[now]+1;
				if(trans[now][nc])	now=trans[now][nc];
			}
			if(!to[now][nc])	break;
			For(j,1,top)	trans[q[j]][nc]=now;
			now=to[now][nc]+1;nc++;to[i][nc]=now-1;
			if(nc>'z'-'a')	break;
		}
		nxt[i]=to[i]['z'-'a'+1];
	}
	For(i,1,n-1)	if(nxt[i])	Fa[i][0]=nxt[i]+1;
	For(j,1,21)	
		For(i,1,n-1)	
				if(Fa[i][j-1])	Fa[i][j]=Fa[Fa[i][j-1]][j-1];
	
	For(i,1,que)
	{
		int l=read(),r=read();
		bool cg=0;
		Dow(j,0,21)
		{
			if(Fa[l][j])	if(Fa[l][j]<=r)	l=Fa[l][j];else	if(Fa[l][j]-1==r)	{puts("Yes");cg=1;break;}
		}
		if(!cg)	puts("No");
	}
}
/*
xxyzzwwxzzyz
1
6 12
*/

Measured memory_bytes: 171136
import java.util.Scanner

import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  val es = Element(0, Position(0, 0)) +: Seq.fill(N)(Element(sc.nextInt, Position(sc.nextInt, sc.nextInt)))

  println(if (solve(es)) "Yes" else "No")

  @tailrec
  def solve(es: Seq[Element]): Boolean = es match {
    case h +: n +: rest =>
      h.validNext(n) && solve(n +: rest)
    case _ => true
  }
}

case class Element(t: Int, p: Position) {
  def validNext(destination: Element): Boolean = {
    val distance = p.distance(destination.p)
    val dt = destination.t - t
    if (distance > dt) false
    else if ((dt - distance) % 2 == 0) true
    else false
  }
}

case class Position(x: Int, y: Int) {
  def distance(that: Position): Int =
    Math.abs(that.x - x) + Math.abs(that.y - y)
}


Measured memory_bytes: 110808
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
const int mod=1e9+7;
inline int ad(int x){return x>=mod?x-mod:x;}
int f[5010][5010];
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read(),m=read();
	for(int i=1;i<=m;i++)f[0][i]=1;
	for(int i=1;i<=n;i++)
	{
		int ul=0;
		for(int j=1;j<=m;j++)
		{
			ul=ad(ad(ul*2)+1LL*f[i-1][j-1]*(j-1)%mod);
			f[i][j]=ad(ul+1LL*f[i-1][j]*(j+1)%mod);
		}
	}pr2(f[n][m]);
	return 0;
}

Measured memory_bytes: 99384
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define mkp make_pair
int n,m;
vector <pll> v; 
ll a[100004],b[100004],ans=0;
int main(){
	cin>>n>>m;
	for (int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		v.push_back(mkp(a[i],b[i])); 
	}
	sort (v.begin(),v.end());
	for (int i=0;m>0;i++){
		ll x=v[i].first,y=v[i].second;
		ans+=min(y,1ll*m)*x;
		m-=y;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3444
#include <stdio.h>
int i,j,N;
int count=0;


void Process(int A[ ], int n){
	for(i=0;i<n-1;i++)
		printf("%d ",A[i]);
	printf("%d\n",A[i]);
}


void BubbleSort(int A[ ], int n){
	int j,temp;
		for(i = 0; i < N-1; i++){
			for(j = N-1; j > i; j--)
			if(A[j-1] > A[j]){
				temp = A[j-1];
				A[j-1] = A[j];
				A[j] = temp;
				count++;
			}		
	}
}


int main(void){
	scanf("%d",&N);
	int A[100];
	for(i=0;i<N;i++)
		scanf("%d",&A[i]);
	
	BubbleSort(A, N);
	Process(A, N);

	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 1852
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	if _, err := fmt.Scan(&a, &b, &c); err != nil {
		panic(err)
	}

	if a < b && b < c {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}



Measured memory_bytes: 1124
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	int N, M; cin >> N >> M;
	vector<ll> A(N); rep(i, N)cin >> A[i];

	double sum = 0; rep(i, N)sum += A[i];
	double c = sum / (4 * M);

	ll cnt = 0;
	rep(i, N) if (A[i] >= c)cnt++;
	
	if (cnt >= M)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []

for i in range(1,n):
  b.append(a[i] - a[i - 1])
b.append(k - a[n-1] + a[0])

b = sorted(b)
print(sum(b[:n-1]))

Measured memory_bytes: 26436
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        var A = cin.scanint;
        var S = A.Sum();
        int MIN = int.MaxValue;
        int idx = -1;
        for (int i = 0; i < N; i++)
        {
            var diff = Math.Abs(S - A[i] * N);
            if (diff < MIN)
            {
                MIN = diff;
                idx = i;
            }
        }
        WriteLine(idx);

    }


}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
    public void join<T>(IEnumerable<T> values) { WriteLine(string.Join(" ", values)); }
}

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

int main(){
    int n;
  	cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int sum = 0;
    int m = 1;
    rep(i,n){
        sum += l[i];
        m = max(m,l[i]);
    }
    int res = sum - m;
    if (res > m) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main(){

  string S;   cin >> S;

  int num[8] = {0};

  for(int i = 0;i < S.size()-2;i++){

    num[i] = stoi(S.substr(i,3));

  }

  int min = abs(753 - num[0]);

  for(int i = 1;i < S.size() - 2;i++){

    if(min > abs(753 - num[i])) min = abs(753 - num[i]);

  }

  cout << min << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b) swap(a,b);
	if(b>c) swap(b,c);
	if(a>b) swap(a,b);

	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define mp make_pair
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define de(a) cout<<#a<<"="<<a<<endl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//--------

int n;

int main() {
	while(~scanf("%d",&n)) {
		int x=0,y=0;
		rep(i,0,n) {
			int a;scanf("%d",&a);
			if(a%4==0) ++x;
			else if(a%2==0) ++y;
		}
		if(x+1>=n-x-y+(bool)(y)) puts("Yes");
		else puts("No");
	}
	return 0;

}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()
    ans = 0
    index = 0

    for i in range(N):
        s1 = S[index:i+1]
        s2 = S[i+1:]
        if s1 in s2:
            ans = len(s1)
        else:
            index += 1

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
using namespace std;
ll a[114514]; ll n, ans = 0, b = 1;
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	if (a[0] < a[1])b = 0;
	if (a[0] > a[1])b = 2;
	for (int i = 1; i < n - 1; i++) {
		if (b == 0 && a[i] > a[i + 1]) {
			ans++;
			b = 1;
			i++;
		}
		else if (b == 2 && a[i] < a[i + 1]) {
			ans++;
			b = 1;
			i++;
		}
			if (a[i] < a[i + 1])b = 0;
			if (a[i] > a[i + 1])b = 2;
	}
	cout << ans+1 << endl;
	getchar(); getchar(); return 0;
}

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

int main(){
  int n, m, c;
  int a[20] = {0}, b[20] = {0};
  cin >> n >> m >> c;
  
  for(int i = 0; i < m; i++){
    cin >> b[i];
  }
  
  int num = 0, ans = 0;
  for(int i = 0; i < n; i++){
    num = 0;
    for(int j = 0; j < m; j++){
      cin >> a[j];
      num += a[j] * b[j];
    }
    
    if(num + c > 0){
      ans ++;
    }
  }
  
  cout << ans<< endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    ABCD = [x for x in sys.stdin.readline().split()][0]
    A, B, C, D = [int(x) for x in ABCD]
    logger.debug('{}'.format([A, B, C, D]))

    op_list = ["+", "-"]
    for op1 in op_list:
        if op1 == "+":
            s1 = A + B
        else:
            s1 = A - B
        for op2 in op_list:
            if op2 == "+":
                s2 = s1 + C
            else:
                s2 = s1 - C
            for op3 in op_list:
                if op3 == "+":
                    s3 = s2 + D
                else:
                    s3 = s2 - D

                if s3 == 7:
                    print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))
                    return


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1222"""
        output = """1+2+2+2=7"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """0290"""
        output = """0-2+9+0=7"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3242"""
        output = """3+2+4-2=7"""
        self.assertIO(input, output)


Measured memory_bytes: 5784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=1e6+4;
const ld pi=3.14159265359;
const ll INF=(1LL<<63);
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll n,x,m,d[N],q,ans,k,s;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>k>>q;
	REP(i,k)cin>>d[i];
	while(q--){
		cin>>n>>x>>m;
		ans=n-1;s=0;
		x%=m;
		REP(i,k)s+=(d[i]%m==0?m:d[i]%m),x+=((n-1)%(k)>i?(d[i]%m==0?m:d[i]%m):0);
		cout<<ans-(x+s*((n-1)/k))/m<<"\n";
	}
	return 0;
}


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

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll ma = max(max(a * c, a * d), max(b * c, b * d));
  cout << ma << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

bool is(string s)
{
        if (len(s) & 1) return false;
        ll half = len(s) / 2;
        string s1 = s.substr(0, half);
        string s2 = s.substr(half, half);
        if (s1 == s2) return true;
        else return false;
}

int main()
{
        string S;
        cin >> S;
        repreverse(i, len(S)-1, 1) {
                if (is(S.substr(0, i))) {
                        cout << i << endl;
                        return 0;
                }
        }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int score[100]={0};
	int n;
	cin>>n;
	for(int i=0;i<n*(n-1)/2;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--;b--;
		if(c<d)score[b]+=3;
		else if(c>d)score[a]+=3;
		else{
			score[a]++;
			score[b]++;
		}
	}
	vector<int> v(score,score+n);
	sort(v.begin(),v.end(),greater<int>());
	for(int i=0;i<n;i++){
		cout<<lower_bound(v.begin(),v.end(),score[i],greater<int>())-v.begin()+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
//little jump frog txdy
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define pb push_back
using namespace std;
const int N=2e5+10,P=1e9+7;
vector<int> F[N],G[N];
int vis[N],s[N],tp,x,y,n,u,v,fac[N],inv[N],ifac[N],sz[N],dsy[N],tot;
void dfs(int u,int fa=0){
    vis[u]=1;s[++tp]=u;tot+=G[u].size();
    for(int v:G[u]) if(v^fa){
        if(!vis[v]) dfs(v,u);
        else x=u,y=v;
    }
}
void DFS(int u,int fa){for(int v:G[u]) if((v^fa)&&(v^x)) DFS(v,u),dsy[v]=u;}
void cmz(int u){
    sz[u]=1;
    for(int v:F[u]) cmz(v),sz[u]+=sz[v];
}
int QFJ(){
    dsy[x]=y;DFS(x,y);
    rep(i,1,tp) vis[s[i]]=0,F[s[i]].clear();
    rep(i,1,tp) for(int v:G[s[i]]) if(v<dsy[s[i]]) vis[v]=1,F[s[i]].pb(v);
    rep(i,1,tp) if(!vis[s[i]]) cmz(s[i]);
    int ans=fac[tp];
    rep(i,1,tp) ans=1ll*ans*inv[sz[s[i]]]%P;
    rep(i,1,tp) vis[s[i]]=1;
    return ans;
}
int main(){
    scanf("%d",&n);
    rep(i,1,(n<<1)) scanf("%d%d",&u,&v),G[u].pb(v+n),G[v+n].pb(u);
    fac[0]=inv[1]=ifac[0]=1;
    rep(i,2,(n<<1)) inv[i]=1ll*(P-P/i)*inv[P%i]%P;
    rep(i,1,(n<<1)) fac[i]=1ll*fac[i-1]*i%P,ifac[i]=1ll*ifac[i-1]*inv[i]%P;
    int qfj=0,ans=fac[n<<1];
    rep(i,1,(n<<1)) if(!vis[i]){
        tp=tot=0,dfs(i);if(tot^(tp<<1)) return puts("0"),0;
        qfj=QFJ(),swap(x,y),qfj=(qfj+QFJ())%P,ans=1ll*ans*ifac[tp]%P*qfj%P;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 27136
n, m, x, y = map(int, input().split())
a, b = [list(map(int, input().split())) for i in range(2)]

for i in range(x + 1, y + 1):
  if all(j < i for j in a) and all(k >= i for k in b):
    print("No War")
    break
else:
  print("War")

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll, int> pl;
const ll N = 1e5 + 100;
const ll MOD = 1e9+7;



int a[10];


int main() {
	for(int i=0;i<5;i++) {
    	cin>>a[i];
    }

  for(int i=0;i<5;i++) {
  	if(a[i] == 0) {
    	cout<<i+1<<endl;
      break;
    }
  }
    return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<double> a(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    double sol = 0;
    for(int i=0; i<n; i++){
        sol+=1.0/(a[i]);
    }
    cout << fixed << setprecision(15) << 1.0/sol;
}

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

vector<ll> z_function(string s)
{
    vector<ll> z(s.size(),0);
    ll l=0,r=0;
    z[0]=0;
    for(int i=1;i<s.size();i++)
    {
        if(i<=r)
            z[i]=min(r-i+1,z[i-l]);
        while(i+z[i]<s.size() && s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r)
        {
            l=i; r=i+z[i]-1;
        }
    }
    return z;
}

vector<ll> prefix_function(string s)
{
    vector<ll> pi(s.size());
    pi[0]=0;
    for(int i=1;i<s.size();i++)
    {
        ll j=pi[i-1];
        while(j>0 && s[j]!=s[i]) j=pi[j-1];
        if(s[j]==s[i]) j++;
        pi[i]=j;
    }
    return pi;
}

int main()
{
    ll a,b,c,d; cin>>a>>b>>c>>d;
    cout<<max( max(a*c,a*d), max(b*c,b*d) );
}

Measured memory_bytes: 3640
//Warmdust Code
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define db double
#define ll long long
#define inf 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=10005;

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

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

using namespace std;

list <int> *adj;
vector <long long> *suffix, *prefix;
long long *dp, *ans;
int n, m;

void dfs1(int u, int p) {

	prefix[u].push_back(1);
	int cnt = 0;
	long long prod = 1;
	for (int nxt : adj[u]) {
		if (nxt != p) {
			dfs1(nxt, u);
			prod = prod * (dp[nxt] + 1) % m;
			prefix[u].push_back(prefix[u][cnt] * (dp[nxt] + 1) % m);
		}
		else
			prefix[u].push_back(prefix[u][cnt]);
		cnt++;
	}
	cnt = 0;
	suffix[u].push_back(1);
	for (auto nxt = adj[u].rbegin(); nxt != adj[u].rend(); ++nxt) {
		if (*nxt != p)
			suffix[u].push_back(suffix[u][cnt] * (dp[*nxt] + 1) % m);
		else
			suffix[u].push_back(suffix[u][cnt]);
		cnt++;
	}
	dp[u] = prod;
}

void dfs2(int u, int p, long long val) {

	int cnt = 0;
	long long temp;
	for (int nxt : adj[u]) {
		if (nxt != p) {
			int len = suffix[u].size();
			temp = suffix[u][len - cnt - 2] * prefix[u][cnt] % m;
			temp = temp * val % m;
			ans[nxt] = dp[nxt] * (temp + 1) % m;
			//cout<<temp<<" "<<u<<" "<<nxt<<endl;
			dfs2(nxt, u, (temp + 1) % m);
		}
		cnt++;
	}
}

int main() {

	scanf("%d%d", &n, &m);
	adj = new list <int> [n];
	suffix = new vector <long long> [n];
	prefix = new vector <long long> [n];
	dp = new long long [n];
	ans = new long long [n];
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		adj[y - 1].push_back(x - 1);
		adj[x - 1].push_back(y - 1);
	}
	dfs1(0, 0);
	//cout<<dp[3]<<endl;
	ans[0] = dp[0];
	dfs2(0, 0, 1);
	for (int i = 0; i < n; ++i)
		printf("%lld\n", ans[i]);
	//delete adj, suffix, prefix, dp, ans;
	return 0;
}


Measured memory_bytes: 32000
A_D = str(input())
op = ['']*3
l = []
for i in range(4):
  l.append(A_D[i])
for i in range(2**3):
  i = format(i,"03b")
  for j in range(3):
    if i[j] == '0':
      op[j] = '+'
    elif i[j] == '1':
      op[j] = '-'
  if eval(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]) == 7:
    break
print(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]+'=7')

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

const ll INF= (1e+12) +2;

int main() {
    ll N; cin >> N;
    ll min_len = INF;
    for (int i=1; i<(sqrt(N)+1); ++i) {
        if (N%i == 0) {
            min_len = min(min_len, (N/i+i-2));
        }
    }
    cout << min_len << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ld long double
#define pi 3.1415926535897932384626433832795028841971693993
#define MOD 998244353
#define sec setprecision
using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	if (n == 0)
		return 1;
	else if (x == 1)return(1);
	else if (n % 2 == 0)
		return pow(x * x, (n / 2));
	else
		return x * pow(x, n - 1);
}
int ketasuu(ll h) {
	if (h < 0)return(-(ketasuu(-h)));
	else if (h < 10)return(1);
	else return(1 + ketasuu(h / 10));
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll 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 a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int jikann = 0;;
	if (a <= c)jikann = (60 * (c - a)) + d - b;
	else jikann = (60 * (24 + a - c) ) + d - b;
	cout << max((jikann  -e),0) << endl;
}


Measured memory_bytes: 3636