akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int N;

int sum(int x)
{
    int sum=0;
    for(int i=0;i<9;i++){
	sum+=x%10;
	x/=10;
    }

    return sum;
}

int main()
{
    scanf("%d",&N);

    if(N%sum(N)==0)
	printf("Yes\n");
    else
	printf("No\n");

    return 0;
}





Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int s,ans=0;
    bool a[1000005];
    cin>>s;
    memset(a,0,sizeof a);
    while(true){
        a[s]=true;
        ans++;
        if(s%2==0){
            s/=2;
        }
        else{
            s=s*3+1;
        }
        if(a[s]==true){
            break;
        }
    }
    cout<<ans+1<<endl;
    return(0);
}

Measured memory_bytes: 4596
import sys

n = int(input())

# 奇数始まりは必ず0
if n % 2 == 1:
    print(0)
    sys.exit()

# 5の因子を数える
# 5の倍数は10個ごと、25の倍数は50個ごと、125の倍数は250個ごとに登場する
ans = 0
cnt = 1
while 5**cnt * 2 <= n:
    ans += n // (5**cnt * 2)
    cnt += 1
print(ans)

Measured memory_bytes: 9104
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, k;
  cin >> n >> k;
  unordered_set<int> unos;
  rep(i, 0, k) {
    int d;
    cin >> d;
    unos.insert(d);
  }
  rep(i, n, 100000) {
    int x = i;
    bool flg = true;
    while (x) {
      int b = x % 10;
      if (unos.find(b) != unos.end()) {
        flg = false;
        break;
      }
      x /= 10;
    }
    if (flg) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
S = input()
N = (len(S))
for i in range(N+1):
 S = S[:i-1] + 'x' + S[i:]#i番目の文字をxに変える
 S = S[:N-1] + '' + S[N:]#i番目の文字をxに変える

S = S[:N] + 'x' + S[N+1:]#最後の文字用
S = S[:N] + '' + S[N+1:]#i番目の文字をxに変える
print(S)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
    char S[100001];
    while(scanf("%s",S)!=EOF)
    {
        int i,l1=0,l2=0;
        char s[3]="10",a[3]="01";
        for(i=0;S[i];i++)
        {
            if(S[i]!=s[i%2])
                l1++;
        }
        for(i=0;S[i];i++)
        {
            if(S[i]!=a[i%2])
                l2++;
        }
        cout<<(l1>l2?l2:l1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[200005][2],b[200005],c[200005];
int main()
{
	int n,m,i,j=0,k=0,l=0,flag=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&a[i][0],&a[i][1]);
		if(a[i][0]==1&&a[i][1]!=n)
		{
		     b[j++]=a[i][1];
		}
		if(a[i][1]==n)
		{
             c[k++]=a[i][0];
	    }
	}
	sort(b,b+j);
	sort(c,c+k);
	for(i=0;i<j&&l<k;)
	{
		if(b[i]==c[l]){flag=1;break;}
		else if(b[i]>c[l])l++;
		else if(b[i]<c[l])i++;
	}
	if(flag)printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#define MAX 100
#define INFTY 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dijkstra(void);

int n,M[MAX][MAX];

int main(){
  int i,j,k,c,u,v;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }

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

  dijkstra();
  

  return 0;
}

void dijkstra(){
  int minv,i,v,u;
  int d[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }
  
  d[0]=0;
  color[0]=GRAY;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(d[v]>d[u]+M[u][v]){
	d[v]=d[u]+M[u][v];
	color[v]=GRAY;
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d",i);
    printf(" ");
    if(d[i]==INFTY) printf("-1\n");
    else printf("%d\n",d[i]);
  }
}



Measured memory_bytes: 2112
#include <cstdio>
#include <cstdint>
#include <algorithm>

int main() {
  intmax_t S, C;
  scanf("%jd %jd", &S, &C);

  intmax_t res = 0;
  if (2*S <= C) {
    res += S;
    C -= 2*S;
    res += C/4;
  } else {
    res += C/2;
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 256
//Abhigyan's Code:
             
    //YOU DON'T DARE TO COPY :) 

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef unsigned long long int ull;
    #define checker cout<<"CHECKED" 
    #define modulo 1000000007
    ll dp[100005] ;

    void solvedp(vector<ll> &vec)
    {
      if(vec.size() == 2)
      {
        dp[1] = abs(vec[0] - vec[1]) ;
      }
      else
      {
        dp[0] = 0;
        dp[1] = abs(vec[1] - vec[0]);

        for(ll i =2 ;i <vec.size() ; i++)
        {
          dp[i] = min(  abs(vec[i] - vec[i-1]) + dp[i-1]  , abs( vec[i] - vec[i-2] ) +dp[i-2]  ) ;
        }
      }

    }
    
    int main()
    {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
     
      ll n ;
      cin >> n;

      vector<ll> vec(n);

      for(auto &z : vec)
        cin >> z;

      solvedp(vec) ;

      cout<<dp[n-1] ;


      return 0 ;

    } 

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

const ll mod = 1e9+7;
ll dp[100010][4] = {};

int main(){
    string s;
    cin >> s;
    int len = s.length();


    dp[len][3] = 1;
    rep(i,3) dp[len][i] = 0;

    for(int i = len-1; i >= 0; i--){

        int t1=0,t2=0;
        for(int j = 3; j >= 0; j--){
            dp[i][j] = dp[i+1][j];
            if(s[i] == '?')dp[i][j] = (3 * dp[i+1][j]);

            if(j < 3){
                if(s[i] == '?'){
                    t1 = 3; t2 = 1;
                }else{ 
                    t1 = 1;
                    if(s[i] == "ABC"[j]) t2 = 1;
                    else t2 = 0;
                }
                
                dp[i][j] = t1*dp[i+1][j] + t2*dp[i+1][j+1];
            }

            dp[i][j] = dp[i][j] % mod;
        }
    }

    // rep(j,4){        
    //     rep(i,len+1){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }


    cout << dp[0][0] << endl;
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<pair<int, int>> P(N);
    for(int i = 0; i < N; ++i) {
        int a; cin >> a;
        P[i] = make_pair(a, i);
    }
    sort(P.begin(), P.end(), greater<pair<int, int>>());
    multiset<int> ms;
    ms.insert(-1);
    ms.insert(-1);
    ms.insert(N);
    ms.insert(N);
    int64_t ans = 0;
    for(auto &e : P) {
        int a, i; tie(a, i) = e;
        auto c = ms.lower_bound(i);
        auto v = next(c);
        auto x = prev(c);
        auto z = prev(x);
        ans += (int64_t)(i - *x) * (*v - *c) * a;
        ans += (int64_t)(*x - *z) * (*c - i) * a;
        ms.insert(i);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif




ll n;

int main(){
	cin >> n;
	vector<int> b(n);
	vector<int> d(n);
	vector<int> result;
	
	rep(i,n){
		cin >> b[i];
		b[i]--;
		d[i] = i - b[i]; // 挿入位置からの移動量
	}
	
	while ( d.size() ){
		//rep(i,SZ(b))
		//	cout << d[i] << " ";
		//cout << endl;
		//cout << endl;
		
		int pos = -1;
		rep(i,SZ(d)){
			if ( d[i] == 0 )
				pos = i;
		}
		if ( pos == -1 ){
			cout << -1 << endl;
			return 0;
		}
		result.push_back(pos);
		
		for ( int i = pos; i < SZ(d)-1; i++ ){
			d[i] = d[i+1]-1;
		}
		d.pop_back();
	}
	
	reverse(ALL(result));
	for ( auto it: result )
		cout << it+1 << endl;
	
	return 0;
}




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

import sys
from collections import Counter
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def get_sum(a, b, c):
    """ 等差数列の和：(初項a, 末項b, 項数c) """
    return (a+b) * c // 2

def dfs(N, nodes, src):
    """ DFS(木、再帰、重みなし) """

    def rec(u, prev):
        C = Counter()
        for v in nodes[u]:
            if v != prev:
                C[rec(v, u) + 1] += 1
        if not C:
            return 0
        C = sorted(C.items(), key=itemgetter(0), reverse=1)
        mx = C[0][0]
        add = C[0][1] - 1
        vacant = 0
        for i, (k, v) in enumerate(C[1:], 1):
            k2, _ = C[i-1]
            vacant += k2 - k - 1
            vacant -= v - 1
            if vacant < 0:
                add += abs(vacant)
                vacant = 0
        return mx + add

    return rec(src, -1)

N = INT()
nodes = [[] for i in range(N)]
for a in range(1, N):
    b = INT()
    b -= 1
    nodes[a].append(b)
    nodes[b].append(a)

print(dfs(N, nodes, 0))


Measured memory_bytes: 166252
A,B,C,D,E,F=map(int,input().split())
mizu=[0]*31
mizu[0]=1
satou=[0]*1501
satou[0]=1
noudo=0
for i in range(31):
 if i>=A:
  mizu[i]+=mizu[i-A]
 if i>=B:
  mizu[i]+=mizu[i-B]
for i in range(1501):
 if i>=C:
  satou[i]+=satou[i-C]
 if i>=D:
  satou[i]+=satou[i-D]
for i in range(31):
 for j in range(1501):
  if mizu[i]>0 and satou[j]>0 and (i+j)>0:
   if  j<=E*i and 100*i+j<=F and 100*j/(i+j)>=noudo:
    noudo=100*j/(i+j)
    ans=[100*i+j,j]
print(*ans)

Measured memory_bytes: 41328
class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    # 根ノードの検索
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.size[y] += self.size[x]
        else:
            self.parent[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # グループのサイズ
    def get_size(self, x):
        return self.size[self.find(x)]


N, M = map(int, input().split())
bridges = []

for i in range(M):
    a, b = map(int, input().split())
    bridges.append((a, b,))
bridges = list(reversed(bridges))

ans = [N * (N - 1) // 2]
uf = UnionFind(N)
for i in range(M):
    a, b = bridges[i]
    tmp = 0
    if uf.same_check(a, b):
        tmp = ans[i]
    else:
        tmp = ans[i] - uf.get_size(a) * uf.get_size(b)

    uf.union(a, b)
    ans.append(tmp)

for i in range(M - 1, -1, -1):
    print(ans[i])


Measured memory_bytes: 25176
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

int n;
cin >> n;
vi D(n);
rep(i,n) cin >> D[i];
int m;
cin >> m;
vi T(m);
rep(i,m) cin >> T[i];

map<int , int> mp1, mp2;
rep(i,n) mp1[D[i]]++;
rep(i,m) mp2[T[i]]++;

bool X = false;

for(auto x : mp2){
    mp1[x.first] += 0;
    if(mp1[x.first] < x.second) {
        cout << "NO" << endl;
        return 0;
    }
}

cout << "YES" << endl;

return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ( A + B > C + D) {
    cout << "Left" << endl;
  }

  else if ( A + B == C + D) {
    cout << "Balanced" << endl;
  }

  else {
      cout << "Right" << endl;
  }
}

Measured memory_bytes: 3636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBishop solver = new BBishop();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBishop {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long h = in.nextInt();
            long w = in.nextInt();
            out.println(h == 1 || w == 1 ? 1 : (h * w - 1 + 2) / 2);

        }

    }
}




Measured memory_bytes: 25044
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <limits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using ll = long long;
using namespace std;
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int res = 0;
    rep1(i,n){
        int sum = 0;
        int x = i;
        while(x){
            sum += x % 10 ;
            x /= 10;
        }
        if(sum >= a && sum <= b) res += i;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace killme
{
    public static class Program
    {
        public static void Main()
        {
            Console.ReadLine();

            var anser = Console.ReadLine()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => double.Parse(x))
                .OrderBy(x => x)
                .Aggregate((a, b) => (a + b) / 2.0);

            Console.WriteLine(anser);
        }
    }
}

Measured memory_bytes: 13396
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

vector<vector<P>> t(0,vector<P>(0));
vector<int> c(0);

void dfs(int x,int col){
    if(c[x]<2) return;
    c[x]=col;
    for(auto y:t[x]){
        if(y.second==0) dfs(y.first,col);
        else dfs(y.first,(col+1)%2);
    }
    return;
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    t.resize(n);
    int x,y,z;
    rep(i,n-1){
        cin>>x>>y>>z;
        x --,y --;
        z %=2;
        t[x].emplace_back(y,z);
        t[y].emplace_back(x,z);
    }
    c.resize(n,2);
    dfs(0,0);
    rep(i,n) cout<<c[i]<<endl;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 1000005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;

string s1, s2;
int n, m;
bool solve(int pos, int b, char inc,char dec) {
    int mi = pos;
    int mx = pos;
    f((int)s1.size()) {
        if (s1[i]==dec){
            mi--;
        }
        if (s1[i]==inc){
            mx++;
        }
        //cout << mx <<' '<<mi << '\n';
        if (mi < 1 || mx > b) {
            return 1;
        }
        if (s2[i]==dec){
            mx--;
        }
        if (s2[i]==inc){
            mi++;
        }
        mi = min(mi,b);
        mx = max(mx,1);
    }
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, x, y;
    cin >> n >> m >> k >> x >> y;
    cin >> s1 >> s2;
    if (solve(y,m,'R','L') || solve(x,n,'D','U')) {
        cout << "NO\n";
    }
    else {
        cout << "YES\n";
    }
    
}


Measured memory_bytes: 920
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	N := nextInt(sc)
	A := make([]int, N)
	set := make(map[int]int)
	for i := 0; i < N; i++ {
		v := nextInt(sc)
		set[v]++
		A[i] = v
	}
	// 1個も失われていないときの総和
	tot := 0
	for _, v := range set {
		tot += v * (v - 1) / 2
	}
	// fmt.Println("N", N, "A", A, "set", set, "tot", tot)
	for i := 0; i < N; i++ {
		tt := tot
		v := set[A[i]]
		if v >= 2 {
			tt = tot - (v * (v - 1) / 2) + ((v - 1) * (v - 2) / 2)
		}
		fmt.Println(tt)
	}
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<long long> x(N);
  for(int i=0; i<N; i++) cin >> x[i];
  long long ans = 1e18;
  for (int i=0; i<N-K+1; i++){
    long long tmp;
    if(x[i]*x[i+K-1]<0) tmp = min(abs(x[i]),abs(x[i+K-1]))*2+max(abs(x[i]),abs(x[i+K-1]));
    else tmp = max(abs(x[i]), abs(x[i+K-1]));
    ans = min(tmp, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>

#define ll long long
#define Max 200005

using namespace std;

inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
    ll x=0;char ch=gc();bool positive=1;
    for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
    for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
    return positive?x:-x;
}

inline void write(ll x){
    if(x<0)x=-x,putchar('-');
    if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
    write(x);puts("");
}

ll n,ans,a[Max],sum[Max],num[5];

inline ll work(ll l,ll r,ll x){
    return abs(sum[x]-sum[l-1]-(sum[r]-sum[x]));
}

inline void calc(ll s,ll t,ll x,ll y){
    ll l,r,midl,midr,block;
    l=s;r=t;
    while(l<r){
        block=(r-l)/3;
        midl=l+block;
        midr=r-block;
        if(work(s,t,midl)<work(s,t,midr)){
            r=midr-1;
        }else{
            l=midl+1;
        }
    }
    num[x]=sum[l]-sum[s-1];
    num[y]=sum[t]-sum[l];
}

int main(){
    n=read();
    for(ll i=1;i<=n;i++){
        a[i]=read();
        sum[i]=sum[i-1]+a[i];
    }
    ans=1e18;
    for(ll i=2;i<=n-2;i++){
        calc(1,i,1,2);
        calc(i+1,n,3,4);
        ll minn=1e18,maxn=-1e18;
        for(ll j=1;j<=4;j++){
            minn=min(minn,num[j]);
            maxn=max(maxn,num[j]);
        }
        ans=min(ans,maxn-minn);
    }
    writeln(ans);
    return 0;
}


Measured memory_bytes: 3328
w,h,n=map(int,input().split())
p,q,r,s=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    p=max(p,x)
  elif a==2:
    q=min(q,x)
  elif a==3:
    r=max(r,y)
  elif a==4:
    s=min(s,y)
print(max(0,q-p)*max(0,s-r))


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

#define ll long long
using namespace std;
ll a[200001];
ll mod=1e9+7;
ll js(int k,int i,int flag){
     ll ans=1;
     while(k){
        ans=(ans*(a[i]%mod))%mod;
      if(flag)  i--;
    else i++;
      k--;

    }
    return (ans+mod)%mod;
}
bool cmp(int q,int w){

    return abs(q)<abs(w);
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k1;
    cin>>n>>k1;
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    int k=k1;
    sort(a,a+n,cmp);
    int i=n-1;
    ll ans=1;
    int fneg=-1;int fpos=-1;
    while(k1){

        ans=(ans*a[i])%mod;
    if(a[i]<0)
        {
            fneg=i;
        }
        if(a[i]>0){
            fpos=i;
        }
        i--,k1--;

    }

    // 如果ans为正数  就是最大的数
    // 为负数  就要把已经选择的k个数里面的最大负数与n-k个数中的最大正数交换
    //或者k个数里面的最小正数与n-k个数里面的最大负数交换
    int kneg=-1;int kpos=-1;
    for (int j=0;j<n-k;j++){
        if(a[j]<0){
            kneg=j;
        }
        if(a[j]>0){
            kpos=j;
        }
    }
    //分n-k有没有正数和负数 在根据k 分情况
    if(ans<0&&n!=k){
        if(kpos==-1){
            if(fpos==-1){
                ans=js(k,0,0);
            }
            else{
                swap(a[kneg],a[fpos]);
                ans=js(k,n-1,1);
            }
        }
        else{
            if(fpos==-1){
                swap(a[kpos],a[fneg]);
                ans=js(k,n-1,1);
            }
            else{
                if(kneg==-1){
                    swap(a[kpos],a[fneg]);
                    ans=js(k,n-1,1);
                }
                else{
                     swap(a[kpos],a[fneg]);
                     ans=js(k,n-1,1);
                     swap(a[kpos],a[fneg]);
                    swap(a[kneg],a[fpos]);
                    ll ans2=js(k,n-1,1);
                      swap(a[kneg],a[fpos]);
                    ans=(abs(a[kpos]*a[fpos])>abs(a[kneg]*a[fneg]))?ans:ans2;

                }
            }

        }

    }
    cout<<(ans+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 5180
from collections import Counter

N = int(input())
*D, = map(int, input().split())
mod = 998244353
c = Counter(D)
v = max(D)

if c[0]!=1 or D[0]!=0:
    print(0)
else:
    ans = 1
    for i in range(1, v+1):
        ans *= pow(c[i-1], c[i], mod)
        ans %= mod
    print(ans)

Measured memory_bytes: 19936
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;



int main(){
    while(true){
        int n; cin >> n;
        if(n == 0) break;
        int h = (n+2)/2;

        vector<int> a(26,0);
        vector<bool> p(26,true);

        bool f = true;

        vector<char> s(n);
        rep(i,n) cin >> s[i];

        int mn = 0;
        char mc = 'a';

        rep(i,n){
            int id = s[i]-'A';

            a[id]++;

            if(mn < a[id]) {
                mc = s[i];
                mn = a[id];
            }

            int number = 0;
            rep(j,26){
                if(!p[j]) continue;
                int rv = n - i-1;

                if(a[j] + rv < mn) p[j] = false;
                else number++;
            }

            if(number == 1 and f) {
                cout << mc << " " << i+1 << endl;
                f = false;
            }
        }

        if(f) cout << "TIE" << endl;
    }
}



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

#define INF 1e9
#define PI 3.141592653589793238
typedef long long ll;

int main() {
    int x,y,z;cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl;




    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

int main(){
	string s="ACL",T="";
	int K;
  	cin>>K;
  	for(int i=0;i<K;i++){
      T +=s;
    }
  	cout<<T<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
string s;
bool used[26];
int main()
{
	cin>>s;
	for(int i=0;i<s.length();i++)
		used[s[i]-'a']=1;
	if(s.length()<26)
		for(int i=0;i<26;i++)
			if(!used[i])
			{
				cout<<s<<char(i+'a');
				return 0;
			}
	int id=-1;
	for(int i=s.length()-2;i>=0;i--)
		if(s[i]<s[i+1])
		{
			id=i;
			break;
		}
	if(id==-1)
	{
		puts("-1");
		return 0;
	}
	string t=s.substr(0,id);
	int idx2=id+1;
	for(int i=id+1;i<s.length();i++)
		if(s[i]<s[idx2]&&s[i]>s[id])
			idx2=i;
	t+=s[idx2];
	cout<<t;
	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int main(void){

    int a,b;
    for(int i = 0;i < 7;i++)cin>>a>>b,cout<<a-b<<endl;



    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool comp(const int &a, const int &b)
{
    return a % 10 < b % 10;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;

    vector<int> v;
    int ans = 0;
    if (A % 10 == 0)
    {
        ans += A;
    }
    else
    {
        v.push_back(A);
    }
    if (B % 10 == 0)
    {
        ans += B;
    }
    else
    {
        v.push_back(B);
    }
    if (C % 10 == 0)
    {
        ans += C;
    }
    else
    {
        v.push_back(C);
    }
    if (D % 10 == 0)
    {
        ans += D;
    }
    else
    {
        v.push_back(D);
    }
    if (E % 10 == 0)
    {
        ans += E;
    }
    else
        v.push_back(E);
    sort(v.begin(), v.end(), comp);

    reverse(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i)
    {
        ans += v[i];
        if (i == v.size() - 1)
            break;
        if (ans % 10 != 0)
        {
            ans += (10 - ans % 10);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();

        int[] b = cin.ArrayInt(N, -1);

        List<int> L = new List<int>(b);
        List<int> ans = new List<int>();
        while(L.Count > 0)
        {
            bool flag = false;
            for (int i = L.Count - 1; i >= 0; i--)
            {
                if(L[i] == i)
                {
                    ans.Add(i + 1);
                    L.RemoveAt(i);
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                Console.WriteLine(-1);
                return;
            }
        }
        ans.Reverse();
        Console.WriteLine(string.Join("\n", ans));

    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13268
#include<iostream>
using namespace std;
#include<vector>
#include<cstring>
int memo[3001][3001];
int turn[3001][3001];
int function(char str1[],char str2[],int i,int j)
{
	if(str1[i]=='\0'||str2[j]=='\0')
	  return 0;
	if(memo[i][j]!=-1)
	{
		return memo[i][j];
	}
	else
	{
		if(str1[i]==str2[j])
		{
			int x=1+function(str1,str2,i+1,j+1);
			memo[i][j]=x;
			turn[i][j]=0;
			return memo[i][j];
		}
		else
		{
			int x=function(str1,str2,i+1,j);
			int y=function(str1,str2,i,j+1);
			if(x>y)
			{
				turn[i][j]=1;
				memo[i][j]=x;
			}
			else
			{
				turn[i][j]=2;
				memo[i][j]=y;
			}
			return memo[i][j];
		}
	}
}
int main()
{
    char str1[3001],str2[3001];
    scanf("%s%s",str1,str2);
    int n=strlen(str1);
    int m=strlen(str2);
    int j,i;
	for(i=0;i<=3000;i++)
	{
		for(j=0;j<=3000;j++)
		{
			memo[i][j]=-1;
			turn[i][j]=-1;
		}
	} 
	int l=function(str1,str2,0,0);
	i=0;
	j=0;
	vector<char> v;
	while(i<n&&j<m)
	{
		if(turn[i][j]==0)
		{
			v.push_back(str1[i]);
			i++;
			j++;
		}
		else if(turn[i][j]==1)
		{
			i+=1;
		}
		else
		{
			j+=1;
		}
	}
	for(auto x:v)
	{
		printf("%c",x);
	}
	printf("\n");
}



Measured memory_bytes: 71040
package main
import "fmt"
func main(){
    // Your code here!
    var n, x int
    fmt.Scan(&n)
    
    cnt := 0
    for i:=1; i<=n; i++ {
        fmt.Scan(&x)
        if i != x {
            cnt++
            if cnt > 2 {
                fmt.Println("NO")
                return
            }
        }
    }
    fmt.Println("YES")
}


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

int main()
{
    int x, a, b;
    cin >> x >> a >> b;

    string result;
    if(b - a <= 0)
    {
        result = "delicious";
    }
    else if(b - x - a <= 0)
    {
        result = "safe";
    }
    else
    {
        result = "dangerous";
    }
    cout << result << endl;
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    int k;
    cin >> k >> s;
    string sf;
    if (s.size() > k)
        sf = "...";
    cout << s.substr(0, k) + sf << "\n";
}


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

int main(){
	
	int a1,a2,a3,b1,b2,b3;
	int x[4][4];
	for(int i=1; i<=3; i++){
		for(int j=1; j<=3; j++){
			cin>>x[i][j];
		}
	}
	for(int i=0; i<=x[1][1]; i++){
		a1=i;
		b1=x[1][1]-a1;
		b2=x[1][2]-a1;
		b3=x[1][3]-a1;
		a2=x[2][1]-b1;
		a3=x[3][1]-b1;
		if(a2+b2==x[2][2] && a2+b3==x[2][3] && a3+b2==x[3][2] && a3+b3==x[3][3]){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
 
class DandA {
    static void Main(string[] args) {
        int n = ReadLineInt();
        int[] bList = ReadLineIntArray();
        int[] aList = new int[n];
        for (int i = 0; i < n; i++) {
            if (i == 0) { aList[i] = bList[i]; continue; }
            if (i == n - 1) { aList[i] = bList[i - 1]; continue; }
            aList[i] = Math.Min(bList[i - 1], bList[i]);
        }
        Console.WriteLine(aList.Sum());
    }
 
    static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static string[] strAry = new string[] {"L", "R", "U", "D"}; 
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private long ReadLineLong() {return long.Parse(Console.ReadLine());}
    static private double ReadLineDouble() {return double.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
 
    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int n,ans;
int a[1010],b[1010];
void solve(){
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=1;i<=n;++i)cin>>b[i];
	for(int i=1;i<=n;++i)a[i]+=a[i-1];
	for(int i=n;i;--i)b[i]+=b[i+1];
	for(int i=1;i<=n;++i)
		ans=max(ans,a[i]+b[i]);
	cout<<ans<<endl;
}
int main(){
	solve();
	
	return 0;
}

Measured memory_bytes: 256
//// Journey of Harry Singh from Diploma in Cse to Red Coder of India.///////////////////////////////////////////////////
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
int n,m;cin>>n>>m;
int sum=0;
int a[n+1][m+1];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];

vector<pair<pair<int,int>,pair<int,int> > > vc;
for(int i=1;i<=n;i++)
{
	
	for(int j=1;j<=m;j++)
	{
		if(j + 1 <=m and a[i][j]%2!=0) {
		a[i][j+1]++;
		a[i][j]--;
		vc.push_back({{i,j},{i,j+1}});}
	}
}

for(int i=1;i<=n;i++)
{
	if(i + 1 <=n and a[i][m]%2!=0) {
		a[i+1][m]++;
		a[i][m]--;
		vc.push_back({{i,m},{i+1,m}});}
}
cout<<vc.size()<<"\n";
for(auto sd:vc)
cout<<sd.first.first<<" "<<sd.first.second<<" "<<sd.second.first<<" "<<sd.second.second<<"\n";

}

Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
int x[100];
int main(){
	int n=0,m=0;
	scanf("%d",&n);
	scanf("%d",&m);
	int q=1,s=0;
	while(n>=q){
		q*=m;
		s++;
	}
	q/=m;
	printf("%d",s);
}


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

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(),(n).end()
#define fi first
#define se second

typedef pair<int, int> PII;
typedef long long ll;

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

	int n,k;
	cin >>  n >> k;
	int a[100];
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a,a+n);
	int dp[100005];
	memset(dp,0,sizeof(dp));
	dp[0]=0;
	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (dp[i]) break;
			if (i-a[j]>=0) {dp[i]=max(dp[i],dp[i-a[j]]^1);}
			else dp[i]=0;
		}
	}
	cout << (dp[k] ? "First\n" : "Second\n");
}

Measured memory_bytes: 3996
#include<bits/stdc++.h>
#define ll long long int
//ll a[1000000+9]= {0};
using namespace std;

int main()
{
 ll n,x,r;
 ll i,j;
 cin>>n;
 r=n%500;
x=n/500;
x=x*1000;
x+=((r/5)*5);
cout<<x<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(b - a == c - b)cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
const int mod=998244353;
int n,m,i,j,fac[500005],inv[500005],fi[500005],ans;
int c(int x,int y)
{
	return 1ll*fac[x]*fi[y]%mod*fi[x-y]%mod; 
}
int qp(int x,int y)
{
	int z=1;
	while(y){
		if(y&1){
			z=1ll*z*x%mod;
		}
		x=1ll*x*x%mod;
		y/=2;
	}
	return z;
}
int main()
{
	fac_init(500002);
	read(n);read(m);
	fz0g(i,min(n,m)){
		int tmp=1ll*c(n,i)*c(m,i)%mod*fac[i]%mod*qp(m+1,n-i)%mod*qp(n+1,m-i)%mod;
		if(i&1)dec(ans,tmp) else inc(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9464
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
public class Main {
    private static  BufferedReader  br = null;
 
    static {
        br   = new BufferedReader(new InputStreamReader(System.in));
    }
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int nNum = 0;
        int nTmp = 0;
        int nSum = 0;
        int nMax = 0;
 
        while((nNum = getNum()) != 0) {
            nSum = getNum();
            nMax = nSum;
            for (int n = 1; n < nNum; n++) {
                nTmp = getNum();
                nSum = Math.max(nSum + nTmp, nTmp);
                nMax = Math.max(nSum, nMax);
            }
            System.out.println(nMax);
        }
    }
 
    private static int getNum() {
        return Integer.parseInt(parseStdin());
    }
 
    private static String parseStdin() {
        String  strNum = null;
 
        try {
            String line = br.readLine();
            if (line != null) {
                if (!line.isEmpty()) {
                    strNum = line;
                }
            }
        }
        catch (IOException e) {}
 
        return strNum;
    }
}

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

using namespace std;
typedef long long ll;

const int N = 200005;

int n;
int a[N];

bool f(int c){

    vector<pair<int, int>> s;
    int last = 0;
    for(int i = 0; i < n; i++){
        if(a[i] > last){
            s.emplace_back(1, a[i] - last);
        }
        else{
            int rem = last - a[i];

            while(rem){
                if(s.back().second <= rem){
                    rem -= s.back().second;
                    s.pop_back();
                }
                else{
                    s.back().second -= rem;
                    rem = 0;
                }
            }
            
            int back = 0;
            while(!s.empty() && s.back().first == c){
                back += s.back().second;
                s.pop_back();
            }
            if(s.empty()) return false;
            int tmp = s.back().first + 1;
            s.back().second--;
            if(!s.back().second) s.pop_back();
            s.emplace_back(tmp, 1);
            if(back) s.emplace_back(1, back);
        }

        last = a[i];
    }

    return true;
}

int main(){

    scanf("%d", &n);

    for(int i = 0; i < n; i++) scanf("%d", a+i);

    int L = 1, R = n, ans = n;

    while(L <= R){
        int mid = (L+R)/2;
        if(f(mid)) ans = mid, R = mid - 1;
        else L = mid+1;
    }

    printf("%d\n", ans);


}


Measured memory_bytes: 4692
#include<stdio.h>
#include<math.h>
#define max(a,b)(a>b?a:b)
#define min(a,b)(a<b?a:b)
int main()
{
	int w,h,n,i,s;
	int a[100],b[100],c[100];
	scanf("%d %d %d",&w,&h,&n);
	int x=0,y=w,m=0,p=h;
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
			if(c[i]==1)
			{
				x=max(x,a[i]);
			}
			if(c[i]==2)
			{
				y=min(y,a[i]);
			}
			if(c[i]==3)
			{
				m=max(m,b[i]);
			}
			if(c[i]==4)
			{
				p=min(p,b[i]);
			}
		
	}
	s=(y-x)*(p-m);
	if((x>=y)||(m>=p))
		s=0;
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int main()
{
	string s;
	cin >> s;
	int ans=0;
	int tmp=0;
	for (int i = 0; i < s.length()/2; i++) {
		tmp = s.length() - 1;
		if (s[i] != s[tmp - i]) {
			ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
vector<int>st[N];int n,k,tot;
inline int add(R int x,R int y){return x+y>=k-1?x+y-k+1:x+y;}
int main(){
	k=38,n=k*(k-1)+1,tot=1;
	printf("%d %d\n",n,k);
	fp(i,1,k){
		printf("%d ",1);
		st[i].resize(k-1);
		fp(j,0,k-2)st[i][j]=++tot;
		fp(j,0,k-2)printf("%d ",st[i][j]);
		puts("");
	}
	fp(i,0,k-2){
		fp(s,0,k-2){
			R int p=s;
			printf("%d ",st[1][i]);
			fp(j,2,k)printf("%d ",st[j][p]),p=add(p,i);
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 2816
from collections import deque
n=int(input())
G=[[] for i in range(n)]
dist=[-1]*n
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append([b-1,c])
    G[b-1].append([a-1,c])
Q,k=map(int,input().split())
k-=1

dist[k]=0
q=deque()
q.append(k)
while q:
    cur=q.popleft()
    for nx,nx_dist in G[cur]:
        if dist[nx]==-1:
            dist[nx]=dist[cur]+nx_dist
            q.append(nx)

for i in range(Q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(dist[x]+dist[y])


Measured memory_bytes: 49964
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
  int H, W;
  cin >> H >> W;
  
  string key = "snuke";
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      string temp;
      cin >> temp;
      char tmp = 'A' + j;
      if (temp == key) cout << tmp << i + 1 << endl;;
    }
  }

  return 0;
}


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

int main(){
    int h,w; cin >> h >> w;
    int c[10][10];
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin >> c[i][j];
        }
    }

    int a[202][202];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
        }
    }

    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }

    int ans = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]==-1) continue;
            ans += c[a[i][j]][1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
N = int(input())
A = sorted([int(a) for a in input().split()])
B = [(i+1)//2*2 for i in range(N)] if N % 2 else [i//2*2+1 for i in range(N)]
print(pow(2, N//2, 10**9+7) if A == B else 0)

Measured memory_bytes: 13880
n, m = map(int, input().split())
L = []
R = []

for _ in range(m):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
  
if min(R) - max(L) >= 0:
  print(min(R)-max(L)+1)
else:
  print(0)

Measured memory_bytes: 10996
#include <stdio.h>

int main(){
  int i=0;
  char c[2][105];
  scanf("%s",c[0]);
  while(c[0][i]!=0){
    c[1][i]='x';
    c[1][i+1]=0;
    i++;
  }
  printf("%s",c[1]);
  return 0;
}

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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C;
    D=C-(A-B);
    if(D>=0){
        cout << D << endl;
    }
    if(D<0){
        cout << "0" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,c;
    int i;
    int n = 0;
    scanf("%d %d %d",&a,&b,&c);
    for(i = a;i <= b; i++){
        if(c % i == 0){
            n++;
        }
    }
    printf("%d\n", n);
    return 0;
}



Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
int arr[1000001];
int main()
{
    int n;
    cin>>n;
    int sum=0;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(int i=0; i<n-1; i++)sum+=arr[i];
    int mx=*max_element(arr,arr+n);
    if(mx<sum)cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int C[500],S[500],F[500];
    int n;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++)
        scanf("%d%d%d",C+i,S+i,F+i);
    for(int i=0;i<=n-1;i++)
    {
        int t = 0;
        for(int j = i;j<n-1;j++)
        {
            int temp = S[j]/F[j];
            int m = t/F[j];
            m += ((t%F[j]==0)?0:1);
            if(m<=temp) t = S[j]+C[j];
            else t = m*F[j]+C[j];
        }
        printf("%d\n",t);
    }
    return 0;
}


Measured memory_bytes: 128
//ex3_3
//TKC001
 
#include<stdio.h>
#include<math.h>
 
int main(void){
    double N, K, logKN;
    int digits;
 
    scanf("%lf", &N);
    scanf("%lf", &K);
 
    logKN = log(N) / log(K);
 
    digits = logKN;
 
    printf("%d", digits+1);
 
    return 0;
 
}

Measured memory_bytes: 512
S = str(input())
N =len(S)
flag = False
for i in range(N+1):
    for j in range(i,N+1):
        s = S[:i] + S[j:]
        # print (i, j, s)
        if 'keyence' == s:
            flag = True

if flag:
    print ('YES')
else:
    print ('NO')

Measured memory_bytes: 3060