akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>

using namespace std;

struct AP {
    int n;
    vector<vector<int>> g;
    set<int> points;
    vector<int> parent;
    vector<int> discTime;
    vector<int> lowTime;
    vector<bool> visited;
    int time = 0;
    
    AP(int n): n(n) {
        g.assign(n, vector<int>());
        parent.assign(n, -1);
        discTime.assign(n, 0);
        lowTime.assign(n, n + 1);
        visited.assign(n, false);
    }
    
    void addEdge(int from, int to) {
        g[from].push_back(to);
        g[to].push_back(from);
    }
    
    int solve() {
        dfs(0, -1);
        
        int son = 0;
        for (int i = 1; i < n; i++) {
            int p = parent[i];
            if (p == 0) {
                son++;
            }
            else if (discTime[p] <= lowTime[i]) {
                points.insert(p);
            }
        }
        if (son > 1) {
            points.insert(0);
        }
//        for (int point: points) {
//            cout << point << endl;
//        }
        return points.size();
    } 
    
    void dfs(int u, int p) {
        discTime[u] = time++;
        lowTime[u] = discTime[u];
        visited[u] = true;
        for (int v : g[u]) {
            if (!visited[v]) {
                parent[v] = u;
                dfs(v, u);
                lowTime[u] = min(lowTime[u], lowTime[v]);
            }
            else if (v != p) {
                lowTime[u] = min(lowTime[u], discTime[v]);
            }
        }
    }   
};

int main() {
    int n, m;
    cin >> n >> m;
    AP ap(n);
    
    for (int i = 0; i < m; i++) {
        int from, to;
        cin >> from >> to;
        ap.addEdge(from, to);
    }
    
    int ans = ap.solve();
    for (int p : ap.points) {
        cout << p << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4408
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int k = parseInt(sc.next());
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		sc.close();
		out.println(ceil((double)a/k)<=floor((double)b/k)?"OK":"NG");
	}
}


Measured memory_bytes: 26960
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;

static const int INF = 1<<29;
int N, A, B, C;
int l[8];
int dfs(int a, int b, int c, int i){
    int minv = INF;
    if(i == N)return ((a == 0 || b == 0 || c == 0) ? 
    INF : abs(a - A) + abs(b - B) + abs(c - C) - 30);
    minv = min(minv, dfs(a + l[i], b, c, i + 1) + 10);
    minv = min(minv, dfs(a, b + l[i], c, i + 1) + 10);
    minv = min(minv, dfs(a, b, c + l[i], i + 1) + 10);
    minv = min(minv, dfs(a, b, c, i + 1));
    return minv;
}
 
int main(){
    cin >> N >> A >> B >> C;
    rep(i, N)cin >> l[i];
    cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int number;
    string str;
    cin >> number;
    cin >> str;

    for(int i = 0; str[i] != '\0'; i++) {
        str[i] += number;
        if(str[i] > 90) {
            str[i] -= 26;
        }
    }
    cout << str << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}

const int N=110;
int head[N],ecnt,n;
struct ed { int to,next; }e[N<<1];
void ad(int x,int y) {
	e[++ecnt]=(ed){y,head[x]}; head[x]=ecnt;
	e[++ecnt]=(ed){x,head[y]}; head[y]=ecnt;
}
int dis[N];
void dfs(int u,int last,int dep) {
//	cout<<"dfs : "<<u<<' '<<dep<<endl;
	dis[u]=max(dis[u],dep);
	for(int k=head[u];k;k=e[k].next) {
		int v=e[k].to; if(v==last) continue;
		dfs(v,u,dep+1);
	}
}

vector<int> node[N];
int son[N];
void dfs2(int u,int last,int dep) {
//	cerr<<u<<':'<<"dep = "<<dep<<endl;
	son[last]++;
	node[dep].PB(u);
	for(int k=head[u];k;k=e[k].next) {
		int v=e[k].to; if(v==last) continue;
		dfs2(v,u,dep+1);
	}
}

ll min_cnt=(1ull<<63)-1;

void solve(int p0,int p1) {
	for(int i=0;i<=n;++i) node[i].clear(),son[i]=0;
	if(!p1) {
		dfs2(p0,0,0);
	}
	else {
		dfs2(p0,p1,0),dfs2(p1,p0,0);
		son[p0]--,son[p1]--;
	}
	ll cnt=node[0].size();
	int tot=0;
	for(int i=0;i<=n;++i) {
		tot++;
		int mx=0;
		for(int j=0;j<node[i].size();++j)
			mx=max(mx,son[node[i][j]]);
		if(mx) cnt*=mx;
		else break;
	}
	min_cnt=min(min_cnt,cnt);
}

int main() {
	rd(n);
	for(int i=1,x,y;i<n;++i) rd(x),rd(y),ad(x,y);
	for(int i=1;i<=n;++i) dfs(i,0,0);
	
	int p0=0,p1=0,mi=n;
	for(int i=1;i<=n;++i) {
		if(dis[i]<mi) mi=dis[i],p0=p1=0;
		if(dis[i]==mi) {
			if(!p0) p0=i;
			else p1=i;
		}
	}
	
//	cout<<mi<<':'<<p0<<' '<<p1<<endl;
	
	if(!p1) {
		solve(p0,0);
		for(int k=head[p0];k;k=e[k].next) {
			int v=e[k].to;
			solve(p0,v);
		}
		printf("%d ",dis[p0]+1);
	}
	else {
		solve(p0,p1);
		printf("%d ",dis[p0]);
	}
	printf("%lld",min_cnt);
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
	console.log(input.split("\n")[0].indexOf("YAKI")===0?"Yes":"No");
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
	int N;
	string S;
	cin >> N >> S;
	int n = S.size();
	int res = 0;
	while (N--) {
		string T;
		cin >> T;
		int l = T.size();
		bool ok = false;
		for (int i = 0; i < l; i++) {
			for (int j = 1; j < l; j++) {
				bool flag = true;
				for (int k = 0; k < n; k++) {
					if (i + j * k >= l || T[i + j * k] != S[k]) {
						flag = false;
						break;
					}
				}
				if (flag) {
					ok = true;
				}
			}
		}
		res += ok;
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3200
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;

int main() {
	int x; cin >> x;
	int ans = 0;
	if (x <= 2) {
		cout << 1 << endl;
	}
	else {
		for (int i = 1; i < x; i++) {
			for (int j = 2; j < x; j++) {
				int num = pow(i, j);
				if (num <= x) {
					ans = max(ans, num);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main(){
    string s; cin >> s;
    stack<int> stk, ans;

    for(int i=0; i<s.length(); i++){
        if(s[i] == '0') stk.push(0);
        else if(s[i] == '1') stk.push(1);
        else if(!stk.empty()) stk.pop();
    }

    while(!stk.empty()){
        ans.push(stk.top());
        stk.pop();
    }
    while(!ans.empty()){
        cout << ans.top();
        ans.pop();
    }

}

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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

const int INF = 1 << 29;

auto solve() {
    int N, M, R;
    cin >> N >> M >> R;
    vi r(R);
    for (auto &&e: r) { cin >> e; --e; };
    sort(all(r));
    vector<vi> dp(N, vi(N, INF));
    REP(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        dp[a][b] = dp[b][a] = c;
    }
    REP(i, N) dp[i][i] = 0;
    REP(k, N) {
        REP(i, N) {
            REP(j, N) {
                int t = dp[i][k] + dp[k][j];
                if (dp[i][j] >= t)
                    dp[i][j] = t;
            }
        }
    }

    ll mn = INF;
    do {
        ll res = 0;
        FOR(i, 1, R)
            res += dp[r[i - 1]][r[i]];
        mn = min(mn, res);
    } while (next_permutation(all(r)));

    return mn;
}


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

    cout << solve() << endl;
//    solve();
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(string[] args){
    var N = int.Parse(Console.ReadLine());
    var A = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
    var B= Enumerable.Range(1, N+1).ToArray();
    var sorted = A.Zip(B, (x, y) => new { x, y }) //BとCから1要素ずつ取ってきた新たな配列？を作る
 .OrderBy(p => p.x)
 .ToArray(); 
 for(int i=0;i<N;i++){
    Console.Write(sorted[i].y+" ");
 }
    }
}


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

typedef long long ll;
typedef pair<int, ll> p;
const int maxn = 100000 + 10;

ll dp[110][maxn];

int n;

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

	int w;
	cin >> n >> w;
	vector<p> snacks;
	snacks.resize(n);

	for(int i = 0; i < n; i++)
		cin >> snacks[i].first >> snacks[i].second;

	for(int i = 0; i < n; i++)
		for(int j = 0; j <= w; j++) {
			if(j < snacks[i].first) dp[i+1][j] = dp[i][j];
			else {
				dp[i+1][j] = max(dp[i][j], dp[i][j-snacks[i].first]+snacks[i].second);
			}
		}

	cout << dp[n][w] << endl;

	return 0;
}


Measured memory_bytes: 79360
#include <iostream>
int main(){
int A,B,C,D;
std::cin >> A >> B >> C >> D;
	
if(A+B > C+D)
std::cout << "Left" << std::endl;
else if(A+B == C+D)
std::cout << "Balanced" << std::endl;
else
std::cout << "Right" << std::endl;
}

Measured memory_bytes: 256
use std::iter::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let  s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        a:[i32;9],
        n:usize,
        b:[i32;n],
    }
    let mut a = a;
    for x in b {
        for y in a.iter_mut().filter(|z| **z == x) {
            *y = 0;
        }
    }
    for r in a.chunks(3) {
        if r == &[0, 0, 0] {
            println!("Yes");
            return;
        }
    }
    for c in 0..3 {
        if a[c + 0] + a[c + 3] + a[c + 6] == 0 {
            println!("Yes");
            return;
        }
    }
    if a[0] + a[4] + a[8] == 0 || a[2] + a[4] + a[6] == 0 {
        println!("Yes");
        return;
    }
    println!("No");
}


Measured memory_bytes: 4352
#include<stdio.h>
int n;
int ans;
int i;
int c[6]={500,100,50,10,5,1};

int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		ans=0;
		n=1000-n;
		for(i=0;i<6;i++){
			ans+=(int)n/c[i];
			n%=c[i];
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1028
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

def gcd(a, b):
  if a > b:
    a, b = b, a
  new_a = b % a
  if new_a == 0:
    return a
  else:
    return gcd(new_a, a)


if __name__=='__main__':
  a, b = map(int, input().strip().split())
  print(int(a * b / gcd(a ,b)))

Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 10000

void dfs(int);

    int n,t=1;
    int d[MAX],f[MAX];
    int A[MAX][MAX];
    int visit[MAX];

int main(){

    int i,j,u,k,v;

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

    for (i = 1; i <= n; i++){
        scanf("%d%d", &u, &k);
        if(k==0) continue;
        for (j = 1; j <= k; j++){
            scanf("%d", &v);
            A[u][v] = 1;
        }
    }

    for(i=1;i<=n;i++) visit[i]=0;
    
    for(i=1;i<=n;i++){
        if(visit[i]==0) dfs(i);//訪れた回数が0の時次に進む
    }

    for(i=1;i<=n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }

    return 0;
}

void dfs(int i){
    int j;
    visit[i]=1;//1度訪れる
    d[i]=t++;
    for(j=1;j<=n;j++){
        if(A[i][j]==0) continue;    //頂点同士が繋がっている時
        if(visit[j]==0) dfs(j);
    }
    visit[i]=2;//2度目
    f[i]=t++;
}


Measured memory_bytes: 2196
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){
	int a,b;
	while(cin>>a>>b){
		int lcm, gcd;
		
		int n=min(a,b);
		if(!(a%n) && !(b%n)){
			gcd = n;
		}else{
			for(int i=n/2; i>=1; i--){
				if(!(a%i) && !(b%i)){
					gcd = i;
					break;
				}
			}
		}
		lcm = a * (b / gcd);		//()必要。intの範囲のため
		
		cout<< gcd<< " "<< lcm<< endl;
	}

	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1160
#include<stdio.h>
 
int main(void){
  int N,b,i;
  int a[200050] = {0};
  
  scanf("%d",&N);
  for(i=2;i<=N;i++){
    scanf("%d",&b);
    a[b]++;
  }
 for(i=1;i<=N;i++){
 printf("%d\n",a[i]);
 }
 return 0;
}

Measured memory_bytes: 2496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=1000003,INF=1<<30;
vector<ll> G[MAX];

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}
vector<int> prime;
bool is_prime[MAX+1];

void sieve(int n){
    int p=0;
    for(int i=0;i<=n;i++){
        is_prime[i]=true;
    }
    
    is_prime[0]=is_prime[1]=false;
    
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i;j<=n;j+=i){
                is_prime[j] = false;
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    sieve(1000002);
    
    int N;cin>>N;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        for(int j=1;j*j<=a;j++){
            if(a%j==0){
                G[j].push_back(a);
                if(j*j!=a) G[a/j].push_back(a);
            }
        }
    }
    
    ll ans=0;
    
    for(int g=1;g<=1000000;g++){
        if(G[g].size()>=2){
            vector<ll> S(G[g].size());
            S[0]=G[g][0];
            for(int i=1;i<G[g].size();i++){
                S[i]=S[i-1]+G[g][i];
                S[i]%=mod;
            }
            
            ll sum=0;
            
            for(int i=0;i<G[g].size();i++){
                sum+=G[g][i]*((S[G[g].size()-1]-S[i]+mod)%mod);
                sum%=mod;
            }
            
            sum*=rui(g,mod-2);
            sum%=mod;
            
            ll res=sum;
            
            vector<int> use;
          
          int gg=g;
            
            for(int p:prime){
                if(g%p==0){
                  use.push_back(p);
                  while(g%p==0){
                    g/=p;
                  }
                }
              if(g==1) break;
              if(is_prime[g]){
                use.push_back(g);
                break;
              }
            }
          
          g=gg;
            
            for(int bit=1;bit<1<<int(use.size());bit++){
                int q=1,cnt=0;
                for(int i=0;i<use.size();i++){
                    if(bit&(1<<i)){
                        q*=use[i];
                        cnt++;
                    }
                }
                if(cnt%2==0){
                    res+=sum*q;
                    res%=mod;
                }else{
                    res+=mod-sum*q%mod;
                    res%=mod;
                }
            }
            
            ans+=res;
            ans%=mod;
            
        }
    }
    
    cout<<ans<<endl;
    
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int r, l;
  l = a + b;
  r = c + d;
  
  if(l < r){
    cout << "Right" << endl;
  } else if(r < l){
    cout << "Left" << endl;
  } else {
    cout << "Balanced" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import itertools

def j(a,b):
    for i in range(len(a)):
        if a[i]!=b[i]:
            return False
    return True
a=0
n=int(input())
p=int(input().replace(" ",""))
q=int(input().replace(" ",""))
k,l=0,0
for i in itertools.permutations("".join([str(i+1)for i in range(n)])):
    a+=1
    if j(i,str(p)):
        k=a
    if j(i,str(q)):
        l=a
print(abs(l-k))

Measured memory_bytes: 3064
N = int(input())

used_word = []
cher = ""
for _ in range(N):
    W = input()
    if not cher:
        used_word.append(W)
        cher = W[-1]
    else:
        if W[0] == cher and W not in used_word:
            used_word.append(W)
            cher = W[-1]
        else:
            print("No")
            break
else:
    print("Yes")

Measured memory_bytes: 9000
#pragma warning(disable : 4996)
#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<stdio.h>
#include<map>
#include<set>
#include<limits.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
	int n, mx = 0;
	cin >> n;
	vector<int> v1(n), v2(n);
	for (int i = 0; i < n; i++)
		cin >> v1[i];
	for (int i = 0; i < n; i++)
		cin >> v2[i];
	for (int i = 1; i < n; i++)
		v1[i] += v1[i - 1];
	for (int i = n - 2; i >= 0; i--)
		v2[i] += v2[i + 1];
	for (int i = 0; i < n; i++)
		mx = max<int>(mx, v1[i] + v2[i]);
	cout << mx;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, x;
  cin >> a >> b >> x;
  long long count = 0;
  if (a == 0) count = b / x + 1;
  else count = b / x - (a - 1) / x;
  cout << count << endl;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

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

  ll n, m; cin >> n >> m;
  vll a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
    a[i]--;
  }

  vll v(m);
  vll suin(2*m), suout(2*m);
  vll cntin(2*m), cntout(2*m);

  ll ans = 0;
  for(int i=0;i<n-1;++i) {
    int x = a[i], y = a[i+1];
    if(x > y) {
      y += m;
    }
    ans += y - x;
    suin[x] += x;
    cntin[x]++;
    suout[y] += x;
    cntout[y]++;
  }
  ll su = 0, cnt = 0;
  for(int i=0;i<2*m;++i) {
    v[i%m] += (i-1) * cnt - su;

    su += suin[i] - suout[i];
    cnt += cntin[i] - cntout[i];
  }
  //printv(v);

  ll ma = 0;
  for(int i=0;i<m;++i) {
    ma = max(ma, v[i]);
  }

  cout << ans - ma << endl;
}


Measured memory_bytes: 8064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define N 1000002
const int p=924844033;
struct edge{int to,nxxt;}e[N];
int head[N],cnt=1,n,siz[N],f[N],inv[N],finv[N],fa[N],ct[N],tt[N],rev[N];
int a[N],b[N],c[N];
inline void ins(int u,int v){e[cnt].to=v;e[cnt].nxxt=head[u];head[u]=cnt++;}
void df5(int te,int la)
{siz[te]=1;
	for(int i=head[te];i;i=e[i].nxxt)
	{
		int j=e[i].to;if(j==la)continue;
		fa[j]=te;df5(j,te);siz[te]+=siz[j];
	}
}
inline int C(int nn,int mm)
{
	if(nn<mm)return 0;
	return 1ll*f[nn]*finv[mm]%p*finv[nn-mm]%p;
}
inline int ksm(int d,int k){int ret=1;while(k){if(k&1)ret=1ll*ret*d%p;d=1ll*d*d%p;k>>=1;}return ret;}
inline void ntt(int x[],int len,int mde)
{
	for(int i=0;i<len;i++)if(i<rev[i])swap(x[i],x[rev[i]]);
	for(int i=2;i<=len;i<<=1)
	{
		int wn=ksm(5,(p-1)/i);if(mde<0)wn=ksm(wn,p-2);
		for(int j=0,stp=i>>1;j<len;j+=i)for(int k=j,w=1;k<j+stp;k++,w=1ll*w*wn%p)
		{
			int t1=x[k],t2=1ll*x[k+stp]*w%p;
			x[k]=(t1+t2)%p,x[k+stp]=(t1-t2+p)%p;
		}
	}if(mde<0)for(int i=0,te=ksm(len,p-2);i<len;i++)x[i]=1ll*x[i]*te%p;
}
int main()
{
    scanf("%d",&n);
	f[0]=finv[0]=f[1]=finv[1]=inv[1]=1;
	for(int i=2;i<=500000;i++)
	{
		inv[i]=1ll*(p-p/i)*inv[p%i]%p;
		f[i]=1ll*f[i-1]*i%p;finv[i]=1ll*finv[i-1]*inv[i]%p;
	}
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		ins(x,y),ins(y,x);
	}
	df5(1,1);
	for(int i=2;i<=n;i++)ct[siz[i]]++;
	for(int i=1;i<=n;i++)tt[n-i]=ct[i];
	for(int i=1;i<=n;i++)ct[i]+=tt[i];
	int len=1;while(len<(n<<1))len<<=1;
	for(int i=1;i<=len;i++){rev[i]=rev[i>>1]>>1;if(i&1)rev[i]|=len>>1;}
	for(int i=1;i<=n;i++)a[i]=1ll*f[i]*ct[i]%p;
	for(int i=0;i<=n;i++)b[i]=finv[n-i];
	ntt(a,len,1);ntt(b,len,1);
	for(int i=0;i<len;i++)a[i]=1ll*a[i]*b[i]%p;
	ntt(a,len,-1);
	for(int i=1;i<=n;i++)a[i]=a[i+n];
	for(int i=1;i<=n;i++)
	{
		int ts=(1ll*n*C(n,i)%p-1ll*finv[i]*a[i]%p+p)%p;
		printf("%d\n",ts);
	}
}


Measured memory_bytes: 35940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define db double
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}

int const N=1e5+3;
int top,n,m,cnt,sta[N];
struct point{
	db x,y;
    point operator - (point A) const{return (point){x-A.x,y-A.y};}
    point operator + (point A) const{return (point){x+A.x,y+A.y};}
    void print(){printf("%.10lf %.10lf\n",x,y);}
}A,B,C,c[N],p1[N],p2[N];

point operator *(db x,point A){return (point){x*A.x,x*A.y};}
db CJ(point A,point B){return A.x*B.y-B.x*A.y;}//叉积 
db DJ(point A,point B){return A.x*B.x+A.y*B.y;}//点积 
db dis(point A){return sqrt(A.x*A.x+A.y*A.y);}//向量长度 
bool cmp(point A,point B){return (CJ(A,B)>0 || CJ(A,B)==0 && dis(A)<dis(B));}//按极角排序 
void Convex(point *A,int &n){//求凸包 
	for (int i=1;i<=n;i++)
	  if (A[i].y<A[1].y || A[i].y==A[1].y && A[i].x<A[1].x) swap(A[i],A[1]);
    point base=A[1];top=0;
	for (int i=1;i<=n;i++) A[i]=A[i]-base;
	sort(A+2,A+n+1,cmp);
	sta[++top]=1;
	for (int i=2;i<=n;sta[++top]=i,i++)
	  while (top>1 && CJ(A[i]-A[sta[top-1]],A[sta[top]]-A[sta[top-1]])>=0) top--;
	for (int i=1;i<=top;i++) A[i]=A[sta[i]]+base;
	n=top;A[n+1]=A[1];
}
void Minkowski(point A[],point B[]){//闵可夫斯基（凸包合并） 
	for (int i=1;i<=n;i++) p1[i]=A[i+1]-A[i];
	for (int i=1;i<=m;i++) p2[i]=B[i+1]-B[i];
	int i=1,j=1;c[cnt=1]=A[1]+B[1];
	while (i<=n && j<=m)
	  if (CJ(p1[i],p2[j])>=0) cnt++,c[cnt]=c[cnt-1]+p1[i++];
	  else cnt++,c[cnt]=c[cnt-1]+p2[j++];
	while (i<=n) cnt++,c[cnt]=c[cnt-1]+p1[i++];
	while (j<=m) cnt++,c[cnt]=c[cnt-1]+p2[j++];	
}
int check(point p){//判断一个点是否在凸包内 
	if (CJ(p,c[2])>0 || CJ(c[cnt],p)>0) return 0;
	int pos=lower_bound(c+1,c+cnt+1,p,cmp)-c-1;
	return CJ(c[pos%cnt+1]-c[pos],p-c[pos])>=0; 
}

point CGL_1_A(point A,point B,point C){//点在直线上的投影点
	db d=dis(B-A);
	return (A+(DJ(C-A,B-A)/d/d*(B-A)));
}
point CGL_1_B(point A,point B,point C){//点关于直线的对称点
	point P=CGL_1_A(A,B,C);
	return (C+2*(P-C));
}

signed main(){
	scanf("%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y);
	for (int q=read();q;q--){
		scanf("%lf%lf",&C.x,&C.y);
		CGL_1_B(A,B,C).print();
	}
	return 0;
}


Measured memory_bytes: 3260
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f

int main()
{
    int k,n;
    double p[200050];
    double sum[200050];
    while(~scanf("%d%d",&n,&k))
    {
        double ans=-1;
        sum[0]=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%lf",&p[i]);
            p[i]=(1+p[i])/2;
            sum[i]=sum[i-1]+p[i];
        }
        for(int l=1,r=k;r<=n;l++,r++)
        {
            ans=max(ans,sum[r]-sum[l-1]);
        }
        printf("%.12lf\n",ans);
    }
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(1){
        c-=b;
        if(c<=0){
            cout << "Yes";
            return 0;
        }
        a-=d;
        if(a<=0){
            cout << "No";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r;
ll x[500005],y[500005],z[500005];
char s[200005],t[200005];
ll dp[1005][1005];
bool flag,dame;

int main(){
	cin >> n;
	ll l=0,r=0;
	for(i=1;i*i<=n;i++){
		if(n % i == 0){
			//pe(i);
			l = i;
			r = n/i;
			if(r-1 > l){
				ans += r - 1;
			}
			if(i*i != n){
				l = n/i;
				r = i;
				if(r-1 > l){
					ans += r - 1;
				}
			}
		}
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 25216
#ifndef ONPC
  #define _FORTIFY_SOURCE 0
  #pragma GCC optimize("Ofast")
  #pragma GCC optimize("no-stack-protector")
  #pragma GCC optimize("unroll-loops")
  #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
  #pragma GCC optimize("fast-math")
#endif

#include <bits/stdc++.h>

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    string s;
    cin >> s;
    int n = (int)s.size();

    if (n & 1){
      cout << "No\n";
      return 0;
    }

    for (int i = 0; i < n; i+=2){
      if (s[i] != 'h' || s[i+1] != 'i'){
        cout << "No\n";
        return 0;
      }
    }
    cout << "Yes\n";
    return 0;

    return 0;
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i];
        if(i<N-1) cout << ' ';
    }
    cout << endl;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

class Shop
{
    public:
    ll open = 0;
};

void ALLIN_SHOPS(vector<Shop>& shops)
{
    for(auto& x : shops)
    {
        for(ll i=0;i<10;i++)
        {
            ll A; cin >> A;
            x.open += A<<(9-i);
        }
    }
}

void ALLOUT_SHOPS(vector<Shop> shops)
{
    for(auto x : shops)
    {
        OUT0(x.open);
    }
}

class Joisino_Shop
{
    public:
    vector<vector<ll>> P;
};

void ALLSET_J_SHOP(ll N, Joisino_Shop& J)
{
    J.P.resize(N);
    for(ll i=0;i<N;i++)
    {
        J.P[i].resize(11);
        for(auto& x : J.P[i])
        {
            cin >> x;
        }
    }
}

void ALLOUT_J_SHOP(Joisino_Shop J)
{
    for(auto x : J.P)
    {
        for(auto y : x)
        {
            cout << y << ' ';
        }
        cout << endl;
    }
}

ll Ans(ll N, Joisino_Shop J, vector<Shop> shops)
{
    ll max_gains = -1e10;
    for(ll i=1;i<1024;i++)
    {
        ll gains = 0;
        for(ll k=0;k<N;k++)
        {
            ll And_of_shopsk_i = (shops[k].open & i);
            ll bit_counter = 0;
            for(ll j=0;j<10;j++)
            {
                if(((And_of_shopsk_i)&(1<<j)) == (1<<j)) bit_counter++; 
            }
            gains += J.P[k][bit_counter];
        }
        max_gains = max(max_gains,gains);
    }
    return max_gains;
}

int main()
{
    ll N;
    cin >> N;

    vector<Shop> shops(N);
    ALLIN_SHOPS(shops);

    Joisino_Shop J;
    ALLSET_J_SHOP(N,J);

    OUT0(Ans(N,J,shops));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(ll n, ll k){
    ll cnt=0;
    while(n>0){
        ++cnt;
        n/=k;
    }
    cout<<cnt<<endl;
}

int main(){
    ll n;
    scanf("%lld",&n);
    ll k;
    scanf("%lld",&k);
    solve(n, k);
}


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

using namespace std;
typedef long long ll;

int main() {
  ll H; cin >> H;
  ll W; cin >> W;
  ll h; cin >> h;
  ll w; cin >> w;
  cout << (H*W - (h*W+H*w-(h*w))) << endl;

  return 0;
}


Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
struct Baby{
    ll actv, x;
    bool operator>(Baby r) const{
        return actv>r.actv;
    }
};
ll dp[2020][2020];
int main(void){
    ll N;cin>>N;
    vector<Baby> v(N);//0-idxで並べる
    REP(i,N){
        cin>>v[i].actv;v[i].x=i;
    }
    sort(ALLv(v),greater<Baby>());
    ll i;ll ans=0;
    REP(l,N){
        REP(r,N){
            i=l+r;
            if(l+r==N){
                ans=max(ans,dp[l][r]);
                break;
            }
            dp[l+1][r]=max(dp[l][r]+abs(v[i].x-l)*v[i].actv,dp[l+1][r]);
            dp[l][r+1]=max(dp[l][r]+abs(v[i].x-(N-1-r))*v[i].actv,dp[l][r+1]);
        }
    }
    
    cout<<ans<<"\n";
}

Measured memory_bytes: 26272
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;
typedef long long ll;

const ll INF = 1e18;//极大值 

ll fmx(ll a,ll b,ll c){
	ll t=a;
	if(t<b)	t=b;
	if(t<c)	t=c;
	return t;
}

ll fmn(ll a,ll b,ll c){
	ll t=a;
	if(t>b)	t=b;
	if(t>c)	t=c;
	return t;
}

ll find(ll x,ll y){
	ll tmx,tmn;
	ll a1,a2,a3;
 	ll ans=INF;
 	//全部横切或者全部竖切 
 	a1=(ceil(x*1.0/3))*y;
	a2=(floor(x*1.0/3))*y;
	a3=y*x-a1-a2;
	ans=min(ans,fmx(a1,a2,a3)-fmn(a1,a2,a3));
	for(int h1=1;h1<=x/2;h1++){
		a1=y*h1;
		a2=(x-h1)*(y/2);
		a3=x*y-a1-a2;
		if(a1==0||a2==0||a3==0)	continue;

		ans=min(ans,fmx(a1,a2,a3)-fmn(a1,a2,a3));
	}
	return ans;
}


 int main() {
 	ll h,w;
 	cin>>h>>w;
	if(w%3==0||h%3==0){
		cout<<"0"<<endl;
		return 0;
	}
	//横竖 
	ll ans=min(find(h,w),find(w,h));
	cout<<ans<<endl;
 	return 0;
 }

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n;
    cin>>n;
    int d1[n], d2[n];
    for(int i=0; i<n; i++)
        cin>>d1[i]>>d2[i];
    bool l=false;
    for(int i=0; i<n-2; i++){
        if(d1[i]==d2[i] && d1[i+1]==d2[i+1] && d1[i+2]==d2[i+2])
        {
            l=true;
            break;
        }
    }
    if(l)
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;

int main() {
    int n;ll x; cin >> n >> x;
    ll a[n];
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(a,a+sizeof(a)/sizeof(a[0]));
    int cnt = 0;
    for(int i = 0;i < n;i++){
        if(x >= a[i]){
          x -= min(a[i],x);
            cnt++;
        }else{
            cout << cnt;
            return 0;
        }
    }
    if(x > 0){
        cout << cnt-1;
    }else{
        cout << cnt;
    }
}



Measured memory_bytes: 256
# 頭に0を足して、累積和のmod Mを取る
# 各mod Mの個数に対して、個数C2を取って足し合わせる

import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
A = [0] + list(map(int,readline().split()))

for i in range(1,len(A)):
  A[i] = A[i - 1] + A[i]
  
A = list(map(lambda x:x % M, A))

from collections import Counter
c = Counter(A)

ans = 0
for v in c.values():
  ans += (v * (v - 1)) // 2
  
print(ans)

Measured memory_bytes: 14168
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}

int main(){
  int N,K;
  cin >> N>>K;
  int ans=0;
  while(N>0){
    N = N/K;
    ans++;
  }

  cout << ans << endl;


}

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

int n;
string s;

bool check(int x) {
    map<string, int> v;
    for(int i = 1; i <= n + 1 - x; i++) {
        string a = s.substr(i - 1, x);
        if(v[a]) {
            if(i - v[a] >= x) return true;
        }
        else v[a] = i;
    }
    return false;
}

int main() {
    cin >> n >> s;
    int l = 0, r = n / 2;
    while(l <= r) {
        int m = (l + r) >> 1;
        if(check(m)) l = m + 1;
        else r = m - 1;
    }
    cout << r << endl;
}

Measured memory_bytes: 6668
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, k;

int main() {
    cin >> n >> k;
    Vl x(n);
    REP(i, n) cin >> x[i];

    ll mini = 1e18;
    REP(i, n-k+1) {
        if (x[i] <= 0 && x[i+k-1] <= 0) {
            mini = min(mini, abs(x[i]));
        } else if (x[i] >= 0 && x[i+k-1] >= 0) {
            mini = min(mini, abs(x[i+k-1]));
        } else {
            mini = min({mini, abs(x[i])*2+x[i+k-1], abs(x[i])+x[i+k-1]*2});
        }
    }
    cout << mini << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  lvector A(n);rep(i,n) cin>>A[i];
  rep(i,n-k) {
    if(A[i]<A[i+k]) print("Yes");
    else print("No");
  }
  return 0;
}

Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

#define max_n 100

int N;

int H[100001];

int main() {

	cin >> N;

	rep(i,N)
	{
		cin >> H[i];
	}

	int ans = 0;
	int now = 0;
	int nowhigh = 0;
	rep(i,N)
	{
		if (nowhigh >= H[i]) { 
			now++; nowhigh = H[i];
		}
		else{
			if (ans < now)ans = now;
			now = 0;
			nowhigh = H[i];
		}
	}

	if (ans < now)ans = now;
	

	cout << ans <<endl;

	return 0;	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  int64_t ans;
  ans = 100 * (N - M) + 1900 * M;
  for(int i=0;i<M;i++){
    ans *= 2;
  }
  cout << ans << endl;
}

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

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>

using namespace std;

class abcC {
private:
    int F(int A, int B) {
        int cnt1 = 0, cnt2 = 0;
        while (A) {
            ++cnt1;
            A /= 10;
        }
        while (B) {
            ++cnt2;
            B /= 10;
        }
        return max(cnt1, cnt2);
    }
public:
    void solve(istream& in, ostream& out) {
        long long N;
        in >> N;
        
        long long sqrtn = 1;
        while ((sqrtn+1)*(sqrtn+1) <= N) {
            ++sqrtn;
        }
        
        int mn = 10000;
        for (int A = 1; A <= sqrtn; ++A) {
            if (N % A == 0) {
                long long B = N / A;
                mn = min(mn, F(A, B));
            }
        }
        out << mn << "\n";
    }
};


int main() {
	std::ios::sync_with_stdio(false);

	abcC solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;
const int MOD=1000000007;

int N,W;
int w[110],v[110];
map<int,int> dp[103];
set<P> U,U2;

int DP(int a,int b){
	if(U.find(make_pair(a,b))!=U.end()){
		return dp[a][b];
	}
	if(a==N){
		if(b<=W){
			return 0;
		}
		else{
			return -INF;
		}
	}
	U.insert(make_pair(a,b));
	return dp[a][b]=max(DP(a+1,b+w[a])+v[a],DP(a+1,b));
}

signed main(){
	cin>>N>>W;
	REP(i,N){
		cin>>w[i]>>v[i];
	}
	int ans=DP(0,0);
	cout<<ans<<endl;
	return 0;
}


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

int main() {
    int n,a,g=1,gmax=1;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        if (a%2==0) {g *= 2; }
        gmax *= 3;
    }
    cout << (gmax - g) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int a,b,c;
  int temp;

  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);

  
if(a > b){
temp = a;
a = b;
b = temp;
}

if(b > c){
temp = b;
b = c;
c = temp;
}
if(a > b){
temp = a;
a = b;
b = temp;
}

printf("%d %d %d\n",a,b,c);
  

  return 0;
}


Measured memory_bytes: 2040
#include<stdio.h>
#include<queue>
#include<string.h>
#include<stdlib.h>
using namespace std;
int a[100005];
int main()
{
    int sum1=0,sum2=0;
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum1+=a[i];
    }
    int minn=1e9+1e8;
    for(int i=0;i<n;i++)
    {
        sum2+=a[i];
        sum1-=a[i];
        minn=min(minn,abs(sum1-sum2));
    }
    printf("%d",minn);
    return 0;
}


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

int main() {
    int n,d;
	cin >> n >> d;
   int ans;
	int area = d  * 2 +1 ;
	if(n % area == 0){
		ans = n / area;
	}else{
		ans = n / area + 1;
	}
	
 
    cout << ans << endl;
    return 0;
}


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

using namespace std;


 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int vis[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
           cin>>vis[i][j]; 
        }
    }
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int a[3][3]={0};
    for(int i=0;i<n;i++){
        int z=arr[i];
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(vis[j][k]==z){
                    a[j][k]=1;
                }
            }
        }
    }
    int f=0;
    if((a[0][0]==1 && a[0][1]==1 && a[0][2]==1) || 
         (a[1][0]==1 && a[1][1]==1 && a[1][2]==1) ||
         (a[2][0]==1 && a[2][1]==1 && a[2][2]==1)||
         (a[0][0]==1 && a[1][0]==1 && a[2][0]==1)||
         (a[0][1]==1 && a[1][1]==1 && a[2][1]==1)||
         (a[0][2]==1 && a[1][2]==1 && a[2][2]==1)||
         (a[0][0]==1 && a[1][1]==1 && a[2][2]==1)||
         (a[0][2]==1 && a[1][1]==1 && a[2][0]==1)){
             f=1;
             cout<<"Yes"<<endl;
         }
    if(f==0){
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
#define pii pair<int, int>
#define pt(xx) cout << "\n" \
                    << xx << "\n"
#define debugv(x, n)               \
    cout << "\n"                   \
         << #x << ": ";            \
    rep(i, n) cout << x[i] << " "; \
    cout << endl
#define debug2d(x, m, n)            \
    cout << "\n"                    \
         << #x << " is: \n";        \
    for (int i = 0; i < m; ++i)     \
    {                               \
        for (int j = 0; j < n; ++j) \
        {                           \
            cout << x[i][j] << " "; \
        }                           \
        cout << endl;               \
    }
#define nl cout << endl

#define MOD 1000000007

int N, M, K;
int ans;

int dp[2001][2001];
int S[2003],T[2003];
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    cin>>N>>M;
 
    rep(i,N) cin>>S[i];
    rep(i,M) cin>>T[i];
    rep(i,N+1)dp[i][0] = 1;
    rep(i,M+1)dp[0][i] = 1;
 
 
    for(int i = 1; i <= N; i++){
        for (int j = 1; j <= M; j++){
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % MOD;
            if (S[i-1]==T[j-1]) dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MOD;
        }
    }
    ans = (dp[N][M] + MOD) % MOD;
    cout<<ans<<endl;
    
 
 
    return 0;
}

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

class Main{
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		int[] alp1=new int[26];
		int[] alp2=new int[26];
		int mjs=Integer.parseInt(bfr.readLine());
		String uketuke=bfr.readLine();
		char[] ret=new char[mjs];
		int max=0;
		int counter=0;
		for(int i=0; i<mjs; i++) {
			ret[i]=uketuke.charAt(i);
		}

		for(int i=0; i<mjs; i++) {
			counter=0;
			for(int j=0; j<i; j++) {
				alp1[ret[j]*1-97]++;
			}
			for(int j=i; j<mjs; j++) {
				alp2[ret[j]*1-97]++;
			}

			for(int j=0; j<26; j++) {
				if(alp1[j]>0 &&alp2[j]>0) {
					counter++;
				}
				alp1[j]=0;
				alp2[j]=0;
			}
			if(counter>max) {
				max=counter;
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 21204