akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    getLine
    as <- getIntList
    let x1 = (`div` 2) . sum $ zipWith (*) (cycle [1, -1]) as
    let ans = map (2*) $ scanl' (\a b -> b - a) x1 (init as)
    putStrLn . unwords $ map show ans

Measured memory_bytes: 10748
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;
typedef long long LL;

int main(void) {
	int a;
	cin >> a;
	int i = 1, ii;
	while(i <= a) {
		ii = i;
		i *= 2;
	}
	cout << ii << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [] #どこからどこまでがiさんの証言かN×2の配列
tes = []#証言を入れていく
pro_sta = []#過程の状態
tes_count = 0
suc_flag = 1 #矛盾が生じてなければ1
max_honest = 0

# 入力受け取り
for i in range(N):
    a = int(input())
    A.append([tes_count,tes_count + a])
    tes_count += a
    for k in range(a):
        x,y = list(map(int,input().split()))
        tes.append([x,y])

t = (2 ** N)
for p in range(t):
    pro_sta = []
    suc_flag = 1
    t_str = str(format(p,"0"+str(N)+"b"))
    for q in range(N):
        pro_sta.append(t_str[q])

    for q in range(N):
        if pro_sta[q] == "1":
            for r in range(A[q][0],A[q][1]):
                if tes[r][1] != int(pro_sta[tes[r][0] - 1]):
                    suc_flag = 0
    if suc_flag == 1:
        honest_count = pro_sta.count("1")
        max_honest = max(max_honest,honest_count)

print(max_honest)

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

int T[10001];
int n,q,a,b,count=0;

int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>T[i];
    cin>>q;
    for(int j=0;j<q;j++){
        cin >>a;
        T[n]=a;
        for(b=0;T[b]!=a;b++);
            if(b!=n)count++;
        
    }
    cout<< count <<endl;
    return 0;   
}


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

const int INF = 1 << 30;

int w[110], v[110];
int dp[110][100100];

int main() {
    int N, W;
    cin >> N >> W;
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    for (int i = 0; i < 110; i++) {
        for (int j = 0; j < 100100; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= 100100; j++) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
        }
    }

    int ans = 0;
    for (int i = 0; i < 100100; i++) {
        if (dp[N][i] <= W) ans = max(ans, i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 46620
def flpl(): return [float(i) for i in input().split()]
def inpl(): return [int(i) for i in input().split()]
import heapq
def dijkstra(vnum, vs):
    dist = [float('inf') for _ in range(vnum)]
    dist[vs] = 0 
    remain = set(range(vnum))
    Q = []
    heapq.heappush(Q,(0,vs))
    while Q:
        c, vn = heapq.heappop(Q)
        if vn not in remain :
            continue
        remain.remove(vn)
        for j in remain:
            evnj = edge(vn, j)
            if dist[vn] + evnj < dist[j]:
                dist[j] = dist[vn] + evnj 
                heapq.heappush(Q,(dist[j],j)) 
        if not remain:
            break
    return dist
def edge(s, t):
    return max(((X[s] - X[t])**2 + (Y[s] - Y[t])**2)**(1/2) -(R[s]+R[t]), 0)

xs, ys, xt, yt = flpl()
N = int(input())
xyr = [(xs, ys, 0),(xt, yt, 0)] + [inpl() for _ in range(N)]
X, Y, R = list(map(list, zip(*xyr)))
D = dijkstra(N+2, 0)
print(D[1])

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  ll sum=0;
  REP(i,n){
    ll now=i+1;
    if(now%3==0 || now%5==0)
      continue;
    sum+=now;
  }

  cout<<sum<<endl;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define F first
#define S second
#define pb push_back
#define mpp make_pair
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;

const int N=1e4+5;
const int NN=1e6+5;
const ll infi=1e9+5;
const ll mod=1e9+7;
ll n;
ll a[N];
ll hsh[NN];
ll me(ll x,ll p)
{
	ll res=1;

	while(p>0)
	{
		if(p%2==1)
		{
			res=res%mod;
			x=x%mod;
			res=(res*x)%mod;
		}
		p=p/2;
		x=x%mod;
		x=(x*x)%mod;
	}
	return res;
}

int main()
{
	cin>>n;
	ll i,j;
	memset(hsh,0,sizeof(hsh));
	for(i=1;i<=n;i++)
		cin>>a[i];

	ll calc=1;
	for(j=1;j<=n;j++)
	{
		ll val=a[j];

		for(i=2;i*i<=val;i++)
		{
			ll cnt=0;
			while(val%i==0)
			{
				val=val/i;
				cnt++;
			}
			hsh[i]=max(hsh[i],cnt);
		}
		if(val>1)
			hsh[val]=max(hsh[val],calc);
	}
	ll lcm=1;

	for(i=2;i<NN;i++)
	{
		ll val=me(i,hsh[i])%mod;
		lcm=lcm%mod;
		lcm=(lcm*val)%mod;
	}	
	//cout<<lcm<<"\n";
	ll sum=0;
	for(i=1;i<=n;i++)
	{
		ll val=me(a[i],mod-2)%mod;
		ll calc=lcm%mod;
		calc=(calc*val)%mod;
		sum=(sum+calc)%mod;
	}
	cout<<sum<<"\n";
}

Measured memory_bytes: 8192
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

constexpr int MAX_N = 30;

int ans;
int n, m;
int cover[30];
int can[30];
int used;
int ok;
vector<vector<int>> edges;

void dfs(int idx, int sum) {
	if(sum >= ans) return;
	if(used == ok) {
		ans = sum;
		return;
	}
	if(idx == n) return;
	if((used | can[idx]) != ok) return;

	dfs(idx + 1, sum);
	const int tmp = used;
	used |= cover[idx];
	dfs(idx + 1, sum + 1);
	used = tmp;
}

int solve() {
	used = 0;
	int cnt = 0;
	for(int i = 0; i < n; ++i) {
		if(edges[i].size() == 0) {
			used |= (1 << i);
			++cnt;
		}
		else if(edges[i].size() == 1) {
			const int neighbor = edges[i][0];
			if(used & (1 << neighbor)) continue;
			used |= cover[neighbor];
			++cnt;
		}
	}

	can[n - 1] = cover[n - 1];
	for(int i = n - 2; i >= 0; --i) {
		can[i] = (can[i + 1] | cover[i]);
	}

	ok = (1 << n) - 1;
	ans = n - __builtin_popcount(used) + cnt;
	dfs(0, cnt);
	return ans;
}

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

	while(cin >> n >> m && n) {
		memset(cover, 0, sizeof(cover));
		for(int i = 0; i < n; ++i) {
			cover[i] = (1 << i);
		}

		edges.assign(n, vector<int>());
		for(int i = 0; i < m; ++i) {
			int a, b;
			cin >> a >> b;
			cover[a] |= (1 << b);
			cover[b] |= (1 << a);
			edges[a].emplace_back(b);
			edges[b].emplace_back(a);
		}

		cout << solve() << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1220
num = int(input())
ten = int(num/10)
real = ten * 10
ge = num - real
situation = 0
if(ge == 2 or ge == 4 or ge==5 or ge==7 or ge==9):
    situation = 1
elif(ge == 3):
    situation = 3
elif(ge==1 or ge==0 or ge==6 or ge==8):
    situation = 2
if(situation==1):
    print("hon")
elif(situation==2):
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9200
import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n):
    for j in range(n):
        if i<j:
            k=bisect.bisect_left(l,l[i]+l[j])
            ans+=k-j-1
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<queue>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

typedef long long ll;

int N;
ll W,w[200],v[200];
ll base;
ll dp[110][310];

void init() { 
  base = w[0];
  rep(i,N) w[i] -= base;
}

void compute() {
  init();
  ll ans = 0;
  REP(use,1,N+1) {
    ll new_W = W - use * base;
    if( new_W < 0LL ) break;
    ll size = min(new_W+1LL,3LL*use+10LL);
    memset(dp,-1,sizeof dp);
    dp[0][0] = 0;
    rep(i,N) {
      for(int j=use-1;j>=0;--j) {
	rep(k,size+1) {
	  if( dp[j][k] == -1 ) continue;
	  if( k+w[i] <= size ) {
	    dp[j+1][k+w[i]] = max(dp[j+1][k+w[i]],
				  dp[j][k]+v[i]);
	  }
	}
      }
    }
    ll maxi = -1;
    rep(i,size) maxi = max(maxi,dp[use][i]);
    if( maxi != -1 ) ans = max(ans,maxi);
  }
  cout << ans << endl;
}

int main() {
  cin >> N >> W;
  rep(i,N) cin >> w[i] >> v[i];
  compute();
  return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;
public class Main {
	
	static int[] flame;
	static int n = 0;;
	static double ave = 0;
	
	public static void main(String[] args) throws Exception{
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			n = Integer.parseInt(br.readLine());
			flame = new int[n];
			flame = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		}
		
		double sum = 0;
		
		for (int a : flame) {
			sum += a;
		}
		ave = sum / n;
		
		double[] aves = Arrays.stream(flame).mapToDouble(a -> Math.abs(ave - a)).toArray();
		
		int index = 0;
		for (int i=0; i<aves.length; i++) {
			if(aves[i] < aves[index] && aves[i] != aves[index]) index = i; 
		}
		
		System.out.println(index);
	}

}


Measured memory_bytes: 27988
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int[] A = new int[N];
      for(int i = 0; i < N; i++){
        A[i] = sc.nextInt();
      }
      
      // 計算
      long height = 0L;
      for(int i = 1; i < N; i++){
        if(A[i] < A[i-1]){
          height += A[i-1] - A[i];
          A[i] = A[i-1];
        }
      }
      
      // 出力
      System.out.println(height);
    }
    

}

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

int main()
{
    
    int N, x;
    cin >> N;
     
    for(int i=1; i<=9; i++)
    {
    	if(111*i>=N){
    	 cout << 111 * i << endl;
         return 0;
        }
    }

	return 0;
}

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

int main() {
    int w, a, b;
    cin >> w >> a >> b;
    if (a+w<b) cout << b-a-w << endl;
    else if (b+w<a) cout << a-b-w << endl;
    else cout << "0\n";
}

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

using namespace std;

const int N = 100005;
int tree[4*N + 5];

struct record{
  int a, b;
};

record arr[N];

void update(int node, int start, int end, int idx, int val){
  if (start == end){
    tree[node] += val;
  }
  else{
    int mid = (start + end) / 2;
    if (start <= idx && idx <= mid){
      update(node * 2, start, mid, idx, val);
    }
    else{
      update(node * 2 + 1, mid + 1, end, idx, val);
    }
    tree[node] = tree[node * 2] + tree[node * 2 + 1];
  }
}

int query(int node, int start, int end, int l, int r){
  if (l > end || r < start) return 0;
  if (l <= start && end <= r) return tree[node];
  int mid = (start + end) / 2;
  int t1 = query(node * 2, start, mid, l, r);
  int t2 = query(node * 2 + 1, mid + 1, end, l, r);
  return t1 + t2;
}

int find_l(int start, int end){
  int a = start, m = end;
  int result = - 1;

  while(start <= end){
    int mid = (start + end) / 2;
    int slot = query(1, 1, m, a, mid);
    if (slot < mid - a + 1){
      result = mid;
      end = mid - 1;
    }
    else{
      start = mid + 1;
    }

  }
  return result;
}

bool compare(record x, record y){
    if (x.b == y.b){
      return x.a < y.a;
    }
    return x.b > y.b;
}

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

  for (int i = 1; i <=n; ++i){
    cin >> arr[i].a >> arr[i].b;
  }

  sort(arr + 1, arr + 1 + n, compare);
  /*
  cout << endl;
  for(int i = 1; i <=n; ++i){
    cout << arr[i].b << " " << arr[i].a << endl;
  }
  */
  int result = 0;

  for (int i = 1; i <=n; ++i){
    int a = arr[i].a;
    int b = arr[i].b;
    if(a > m) continue;
    int slot = query(1, 1, m, a, m);

    if (slot < m - a + 1){
      result += b;
      int l = find_l(a,m);
      update(1, 1, m, l, 1);
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 2048
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H,W = map(int,read().split())

def F(H,W):
    opt = H * W + 100
    for a in range(1,W):
        x = H * a
        y = (W-a) * (H//2)
        z = (W-a) * (H-H//2)
        d = max(x,y,z) - min(x,y,z)
        if opt > d:
            opt = d
    if W >= 3:
        a = W//3
        b = (W-a)//2
        c = W-a-b
        d = (max(a,b,c) - min(a,b,c)) * H
        if opt > d:
            opt = d
    return opt

answer = min(F(H,W),F(W,H))
print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define N 55
int n,m;
string s[N],r[N];

bool che(int i,int j){
	for(int a=0;a<m;a++){
		for(int b=0;b<m;b++){
			if(s[a+i][b+j]!=r[a][b])
				return 0;
		}
	}
	return 1;
}

bool solve(){
	for(int i=0;i<=n-m;i++)
		for(int j=0;j<=n-m;j++)
			if(che(i,j))
				return 1;
	return 0;		 
}

int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)
			cin>>s[i];
	for(int i=0;i<m;i++)
			cin>>r[i];
	if(solve())cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 256
N = input()
k = len(N)
if k == 1:
    print(int(N))
elif k == 2:
    print(9)
elif k == 3:
    print(int(N)-90)
elif k == 4:
    print(909)
elif k == 5:
    print(int(N)-9090)
else:
    print(90909)


Measured memory_bytes: 2940
n, k=map(int, input().split())
a=list(map(int, input().split()))

for i in range(n):
    a[i]-=1

rec=[-1]*n
turn=0
current=0

while True:
    if k<=0:
        print(current+1)
        break
    if rec[current]==-1:
        rec[current]=turn
        turn+=1
        current=a[current]
        k-=1
    else:
        loop=turn-rec[current]
        k%=loop
        rec=[-1]*n


Measured memory_bytes: 32296
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! {
        s: chars
    }
    if s[0] == s[1] || s[1] == s[2] || s[2] == s[3] {
        println!("Bad");
    } else {
        println!("Good");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	char a[100000+10];
	cin>>n;
	cin>>a;
	int sum=1;
	for(int i=1;i<n;i++)
	{
		if(a[i]!=a[i-1])
		sum++;
	}
	cout<<sum;
} 

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

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

    int m[1010];
    int total = 0;
    for ( int i = 0; i < n; i++){
        cin >> m[i];
        total += m[i];
    }

    int ans;
    sort(m, m + n);
    ans = (x - total) / m[0] + n;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,r;
    scanf("%d%d",&n,&r);
    if(n>=10)
    {
        printf("%d\n",r);
    }
    else
    {
        int s=r+100*(10-n);

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


Measured memory_bytes: 1704
N = int(input())
S = input()
s = []
cnt = 0
for i in range(N):
    if S[i] == "W":
        s.append(-1)
    elif S[i] == "E":
        s.append(1)
        if i != 0:
            cnt += 1
        
DP = [cnt]

for i in range(1, N):
    cnt = 0
    if s[i - 1] == -1:
        cnt += 1
    if s[i] == 1:
        cnt -= 1
    DP.append(DP[i - 1] + cnt)

print(min(DP))

Measured memory_bytes: 17872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FASTIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N = 200005, M = 1000000007, BIG = 0x3f3f3f3f;

int ct = 0;

struct Mint {
  int value;
  Mint(int _value = 0) : value(_value) {}
  operator int() { return value; }
  Mint operator - (const Mint& _a) { int ans = value - _a.value; return ans < 0 ? M + ans : ans; }
  Mint operator + (const Mint& _a) { int ans = value + _a.value; return ans - (ans >= M) * M; }
  Mint operator * (const Mint& _a) { return (ll)value * _a.value % M; }
  Mint& operator += (const Mint& _a) { return *this = this->value + _a.value; }
  Mint& operator -= (const Mint& _a) { return *this = this->value - _a.value; }
  Mint& operator *= (const Mint& _a) { return *this = this->value * _a.value; }
  bool operator == (const Mint& _a) { return value == _a.value; }
  bool operator != (const Mint& _a) { return value != _a.value; }
};
istream& operator >> (istream& is, Mint& _a) { is >> _a.value; return is; }
ostream& operator << (ostream& os, Mint& _a) { os << _a.value; return os; }
Mint n, a, b;

Mint ModPow(Mint _a, ll _b) {
  Mint ans = 1;
  while (_b > 0) {
    if (_b & 1) 
      ans = ans * _a;
    _a = _a * _a;
    _b >>= 1;
  }
  return ans;
}

Mint MMI(Mint _a) {
  int ax = _a, bx = M, sx = 1, tx = 0;
  while (bx) {
    int qx = ax / bx;
    ax -= qx * bx;
    sx -= qx * tx;
    swap(ax, bx);
    swap(sx, tx);
  }
  return sx >= 0 ? sx : sx + M;
}

Mint C(int _a, int _b) {
  Mint ans = 1;
  for (int i = 0; i < _b; i++) {
    ans = (ans * Mint(_a - i));
    ans = (ans * MMI(i + 1));
  }
  return ans;
}

bool Read() {
  cin >> n;
  if (cin.eof())
    return 0;
  cin >> a >> b;

  return 1;
}

void Process() {
  cout << ModPow(2, n) - Mint(1) - C(n, a) - C(n, b) << "\n";
}

int main() {
  FASTIO();

  while (Read())
    Process();

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll x[200000], s[200000];
ll sum_l[200000], sum_r[200000];
ll sum[200000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> s[i];
        if(i >= 1){
            sum[i] = sum[i-1]+s[i]; 
        }else{
            sum[i] = s[i];
        }
        sum_l[i] = sum[i]-s[i]-x[i];
        sum_r[i] = sum[i]-x[i];
    }
    ll ans = 0;
    ll sum_r_max = -1e18;
    for(int i = N-1; i >= 0; i--){
        sum_r_max = max(sum_r[i], sum_r_max);
        ans = max(ans, sum_r_max-sum_l[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11456
// D - Triangles

// 尺取り法を利用

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

int N;
int L[2000];

// 一番短い辺がL[i]（Lは昇順ソート済）のときの成立する数を尺取り法でカウント
int count_ok (int i) {
	int count = 0;
	int left = i + 1;
	int right = i + 1;

	while(right < N) {
		//cout << "i=" << i << "(" << L[i] << ")" << " left=" << left << "(" << L[left] << ")"<< " right=" << right << "(" << L[right] << ")"<< endl;

		if (L[right + 1]  < L[i] + L[left] && right + 1 < N) {
			right++;
		} else {
			count += right - left;
			//cout << "+" << count << endl; // **** debug ****
			left++;
			if (left > right) right++;
		}
	}

	return count;
}

int main(){
	cin >> N;

	for (int i=0; i<N; i++) {
		cin >> L[i];
	}

	sort(L, L+N);

	// **** debug ****
	/*
	for (int i=0; i<N; i++) {
		cout << L[i] << " ";
	}
	cout << endl;
	*/

	int ans = 0;

	for (int i=0; i<N-2; i++) {
		ans += count_ok(i);
	}

	cout << ans << endl;

	return 0;
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    unordered_map<int, int> p5;
    for(int i = -1000; i <= 1000; i++) {
        int a = i * i * i * i * i;
        p5[a] = i;
    }
    for(auto x: p5) {
        for(auto y: p5) {
            if(x.first - y.first == n) {
                cout << x.second << " " << y.second << endl;
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3752
#include <stdio.h>
int main(void){
  int sum[1000],a[1000],b[1000],i,n,count[1000];
  i=0;
  while(scanf("%d %d",&a[i],&b[i])!=EOF){    
    sum[i]=a[i]+b[i];
    i++;
  }
  for(n=0;n<i;n++){
    count[n]=0;
    while(sum[n]>0){
      count[n]++;
      sum[n]=sum[n]/10;
    }
  }
  for(n=0;n<i;n++){
    printf("%d\n",count[n]);
  }
  return(0);
}

Measured memory_bytes: 616
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
const int N = 100005;
using namespace std;
typedef long long ll;
int x[N],y[N],t[N];

int main()
{
   int n,c,flag=0;
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
    scanf("%d%d%d",&t[i],&x[i],&y[i]);
   for(int i=1;i<=n;i++){
      if(i==1){
         c=x[1]+y[1];//c是距离
         if(t[i]%c!=0||t[i]<c||t[i]/c%2!=1){
            flag=1;
            break;
         }
      }

      else{
          c=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
          int mid=t[i]-t[i-1];
          if(mid%c!=0||mid<c||mid/c%2!=1){
            flag=1;
            break;
          }
      }

   }
   if(flag)
    printf("No\n");
   else
    printf("Yes\n");
}


Measured memory_bytes: 1408
n = int(input())
b = list(map(int,input().split()))
a = 0

for i in range(n - 2):
    if b[i] <= b[i + 1]:
        a += b[i]
    else:
        a += b[i + 1]
        
a += b[0] + b[n - 2]

print(a)


Measured memory_bytes: 3060
a,b,m = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
mlist = [list(map(int,input().split())) for s in range(m)]
ans = []
for m in mlist:
	tmp = alist[m[0]-1] + blist[m[1]-1] -m[2]
	ans.append(tmp)
x = min(alist) + min(blist)
ans.append(x)
print(min(ans))

Measured memory_bytes: 42412
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1000000000 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, l, q;
vector<int> x(100000 + 5, 1e10);
vector<vector<int>> step(100000+ 5, vector<int>(25, 1e10));

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) cin >> x[i];
    cin >> l;
    rep(i, n - 1) {
        int nx = lower_bound(all(x), x[i] + l + 1) -1 - x.begin();
        step[i][0] = nx;
    }
    rep(j, 20)rep(i, n) {
        step[i][j + 1] = step[min(n - 1, step[i][j])][j];
    }
    cin >> q;
    rep(i, q) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);
        int ans = 0;
        int now = a;
        rrep2(j, 20, -1) {
            if (step[now][j] < b) {
                ans += 1<<j;
                now = step[now][j];
            }
        }
        cout << ans + 1 << endl;
    }
}


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

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

#pragma GCC optimize("Ofast")



using namespace std;

bool is_integer( float x ){
    return floor(x) == x;
}
bool is_integer(double x){
    return floor(x) == x;
}


int main() {

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

    int a[3]; cin >> a[0] >> a[1] >> a[2];
    int n; cin >> n;
    int ans = 0;
    sort(a,a+3);

    rep(i,3001){
        rep(j,3001){
            if((n-i*a[0]-j*a[1])/a[2] >= 0 && (n-i*a[0]-j*a[1])%a[2] == 0){
                ans ++;
            }
        }
    }

    cout << ans;

    return 0;
}











Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  int ans=0;
  int c[N];
  for(int i=0; i<N; i++) cin>>c[i];
  sort(c,c+N);
  for(int i=0; i<K; i++) ans+=c[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
use std::io;
use std::io::prelude::*;

fn main() {
    let mut abc: [u32; 26] = [0; 26];
    let scan = io::stdin();
    for line in scan.lock().lines() {
        let uline = line.unwrap();
        for e in uline.chars() {
            if e as u8 >= 65 && e as u8 <= 90 {
                abc[(e as u8 - 65) as usize] += 1;
            } else if e as u8 >= 97 && e as u8 <= 122 {
                abc[(e as u8 - 97) as usize] += 1;
            }
        }
    }
    for i in 0..26 {
        println!("{} : {}", ((i as u8) + 97) as char, abc[i]);
    }
}



Measured memory_bytes: 5024
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	int a[100000];
	for (int i = 0;i < n;i++)cin >> a[i];
	int ans = 0;
	for (int i = 0;i < n;i++) {
		if (a[a[i] - 1] == i + 1)ans++;
	}
	cout << ans / 2 << endl;
}

Measured memory_bytes: 640
def dist(a, b, d):
    s = 0
    for i in range(d):
        s += (a[i] - b[i])**2
    
    return s

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

square_list = set([i*i for i in range(40*40*10+1)])

cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        if dist(X[i], X[j], D) in square_list:
            cnt += 1

print(cnt)

Measured memory_bytes: 67100
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n;
	vector<int>v(n); rep(i, 0, n)cin >> v[i];
	vector<vector<int> >dp(n, vector<int>(21));
	dp[0][v[0]] = 1;
	rep(i, 0, n - 2) {
		rep(j, 0, 21) {
			if (dp[i][j] > 0) {
				int plus = j + v[i+1], minus = j - v[i+1];
				if (plus < 21)dp[i + 1][plus] += dp[i][j];
				if (0 <= minus)dp[i + 1][minus] += dp[i][j];
			}
		}
	}
	cout << dp[n - 2][v[n - 1]] << endl;
	return 0;
}

Measured memory_bytes: 3160
/*input
4
3 6 28 9


*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
// #define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

const int N = 2e5 + 5;

bool vis[N];
ll label[N];
vector <int> adj[N];

void dfs(int s) {
  vis[s] = true;
  for (auto it : adj[s]) {
    if (!vis[it]) {
      label[it] += label[s];
      dfs(it);
    }
  }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, q;
  cin >> n >> q;
  int u, v;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  while (q--) {
    int p, v;
    cin >> p >> v;
    label[p] += v;
  }
  dfs(1);
  for (int i = 1; i <= n; i++) {
    cout << label[i] << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 21376
import sys

input = sys.stdin.readline
N = int(input())

pre = int(input())
if pre != 0:
    print(-1)
    sys.exit()
ans = 0
for _ in range(N-1):
    x = int(input())
    if pre + 1 < x:
        print(-1)
        sys.exit()
    elif pre + 1 == x:
        ans += 1
    else:
        ans += x
    pre = x

print(ans)

Measured memory_bytes: 9128
#include <iostream>
#include <vector>

using namespace std;

#define INF 1e9

int main() {
	int n; cin >> n;
	int m[100][100]; fill(&m[0][0], &m[0][0]+100*100, INF);
	for (int i = 0; i < n; ++i) m[i][i] = 0;
	for (int i = 0; i < n; ++i) {
		int r, k; cin >> r >> k; --r;
		for (int j = 0; j < k; ++j) {
			int t; cin >> t; --t;
			m[r][t] = 1;
		}
	}
	for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
		m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
	}
	int p; cin >> p;
	for (int k = 0; k < p; ++k) {
		int s, t; cin >> s >> t; --s, --t;
		int th; cin >> th;
		if (m[s][t] < th) cout << m[s][t]+1 << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 1204
[n,k] = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
dic = {}
iter = 0
for i in range(10):
    try:
        if i != d[iter]:
            dic[str(i)] = 1
        else:
            dic[str(i)] = 0
            iter += 1
    except:
        dic[str(i)] = 1
        pass

for i in range(n,10 ** 5):
    tmp = 1
    cand = str(i)
    for j in range(len(cand)):
        tmp *= dic[cand[j]]
    if tmp == 1:
        print(cand)
        break


Measured memory_bytes: 3064
/*
And, when you want something, all the universe conspires in helping you to achieve it.
-The Alchemist, Paulo Coelho
*/
 
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <algorithm>
#include <math.h>
#include <map>
#include <cstdlib>
 
#define INF 1e9
 
using namespace std;
 
 
int main(){
 
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t, n, m;

    cin >> t >> n >> m;

    int k = t - (n%t);

    if(k == t)k = 0;

    if(m-n >= k)cout << "OK\n";
    else cout << "NG\n";

    return 0;
}

Measured memory_bytes: 3676
N, M = map(int, input().split(' '))

broken_list = []
if M > 0:
    for i in range(M):
        broken_list.append(int(input()))
        
broken_set =set(broken_list)
nums = [0] * (N + 1)
nums[0] = 1

if 1 not in broken_set:
    nums[1] = 1

for i in range(2, N + 1):
    nums[i] = nums[i - 1] + nums[i - 2]
    if i in broken_set:
        nums[i] = 0

print(nums[N] % 1000000007)

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

const int MOD = 998244353;
static const int MAX = 2e5;
ll f[MAX];

ll power(ll a, ll x){
    if(x == 0) return 1;
    if(x & 1) return a * power(a, x-1) % MOD;
    return power(a*a % MOD, x/2);
}

ll fact(ll n){
    if(f[n]) return f[n];
    if(n == 0) return f[n] = 1;
    return f[n] = n * fact(n-1) % MOD;
}

ll combi(ll n, ll r){
    ll res = fact(n) * power(fact(r), MOD-2) % MOD;
    res = res * power(fact(n-r), MOD-2) % MOD;
    return res;
}

int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    for(ll i = 0; i <= k; i++){
        ll temp = m * combi(n-1, i) % MOD;
        temp = temp * power(m-1, n-1-i) % MOD;
        ans =  (ans + temp) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8280
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back

map<char, int> m;
struct CH {
	int rev;
	bool mirror;
};
CH ch[4] = {
	{0, true},
	{1, true},
	{3, false},
	{2, false}
};

int main() {
	char name[16];
	scanf(" %s", name);
	m.insert(mp('i', 0));
	m.insert(mp('w', 1));
	m.insert(mp('(', 2));
	m.insert(mp(')', 3));
	int length = strlen(name);
	int ans = 0;
	if(length % 2 == 1) {
		int t = length / 2;
		if(ch[m[name[t]]].mirror == false)
			ans++;
	}
	rep(i,length / 2) {
		int t = m[name[i]];
		int u = m[name[length - i - 1]];
		if(ch[t].rev != u) {
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 2010
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll dp[2][MAXN][2],ans;
int sum[MAXN],now;
int n,m,k;
int main(){
	SF("%d%d%d",&n,&m,&k);
	m--;
	k--;
	dp[0][0][0]=1;
	now=1;
	for(int i=1;i<=max(n,m)*2;i++){
		for(int j=0;j<=n;j++)
			sum[j+1]=(sum[j-1+1]+dp[now^1][j][0]+dp[now^1][j][1])%MOD;//+1 to prevent overflow
		for(int j=0;j<=n;j++){
			dp[now][j][0]=(sum[j+1]-sum[j-1+1]+MOD)%MOD;	
			dp[now][j][1]=(sum[j-1+1]-sum[max(0,j-k)-1+1]+MOD)%MOD;
		}
		for(int j=0;j<=n;j++)
			if(j%k==n%k&&(i*k-j)%k==m%k&&(i*k-j)<=m)
				ans=(ans+dp[now][j][1])%MOD;
		now^=1;
	}
	PF("%lld",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int H, N;
  cin >> H >> N;
  vi A(N); vi B(N);
  rep(i, N) {
    cin >> A[i] >> B[i];
  }
  
  vll dp(H+1, LLINF);
  dp[0] = 0;
  for(int i=1; i<=H; i++) {
    ll minv = LLINF;
    rep(j, N) {
      chmin(minv, (i - A[j] >= 0 ? dp[i - A[j]] : 0) + (ll)B[j]);
    }
    
    dp[i] = minv;
  }
  
  fin(dp[H]); 
}

Measured memory_bytes: 384
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll H,W,h,w;
    cin >> H >> W >> h >> w;
    if(H % h == 0 && W % w == 0){
        print("No");
        return 0;
    }
    ll res[510][510] = {};
    rep(i,0,H){
        rep(j,0,W){
            res[i][j] = 1000;
        }
    }
    for(ll hi = h-1; hi < H; hi += h){
        for(ll wi = w-1; wi < W; wi += w){
            res[hi][wi] = -1000 * (h*w - 1) - 1;
        }
    }
    print("Yes");
    rep(i,0,H){
        rep(j,0,W){
            cout << res[i][j] << " \n"[j==W-1];
        }
    }
    
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int n, k;
long long a[100010][3];
long long dp[100010][3];

int main(void){
	cin >> n;
	for(int i=0; i<n; i++) for(int j=0; j<3; j++) cin >> a[i][j];

	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1; i<n; i++){
		for(int j=0; j<3; j++){
			for(int k=0; k<3; k++){
				if(j!=k) chmax(dp[i][k], dp[i-1][j]+a[i][k]);
			}
		}
	}
	long long res;
	for(int i=0; i<3; i++) chmax(res, dp[n-1][i]);
	cout << res << endl;
}

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

int main()
{
	string S, a("Sunny"),b("Cloudy"),c("Rainy");
	while(cin>>S){
		if(S.compare(a)==0){
			cout<<b<<endl;
		}
		else if(S.compare(b)==0){
			cout<<c<<endl;
		}
		else if(S.compare(c)==0){
			cout<<a<<endl;
		}
	}
}

Measured memory_bytes: 256
import math
n,x= map(int,input().split())
a = [int(_) for _ in input().split()]
ru = [0]*(n+1)
for i in range(1,n+1):
  ru[i] = ru[i-1]+a[i-1]
ans = float("inf")
for i in range(1,n+1):
  tmp = 0
  l = math.ceil(n/i)
  for j in range(1,l+1):
    if j == 1:
        m = -i*(j+1)-1
        if m < -n:
          m = -n-1
        tmp += (ru[n]-ru[m])*5
    else:
        m = -i*(j+1)-1
        if m < -n:
          m = -n-1
        if -i*j-1 < -n:
          break
        tmp += (ru[-i*j-1]-ru[m])*(2*j+3)
  tmp += x*i
  ans = min(ans,tmp)
print(ans+n*x)

Measured memory_bytes: 89168
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, K: int, h: "List[int]"):

    h.sort()
    ans = INF

    for i in range(K-1, N):
        ans = min(ans, h[i]-h[i-K+1])

    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7484
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using vl = vector<ll>;                   //   | grep -v ' .* '  1300111 ~2^20.31
using vvl = vector<vl>;                  //                    10300777 ~2^23.30
using pll = pair<ll,ll>;                 //                   100400999 ~2^26.58
using vb = vector<bool>;                 //                  1300400999 ~2^30.28
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //                 10200500333 ~2^33.25
const double eps = 1e-9;                 //                100200400777 ~2^36.54
#define sz(c) ll((c).size())             //               1200300700111 ~2^40.13
#define all(c) begin(c),end(c)           //              10200300500777 ~2^43.21
#define mp make_pair                     //             100200300400777 ~2^46.51
#define mt make_tuple                    //            1200300400600999 ~2^50.09
#define pb push_back                     //           10200300400600111 ~2^53.18
#define eb emplace_back                  //          100200300400600333 ~2^56.48
#define xx first                         //         1200300400500800999 ~2^60.06
#define yy second                       
#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(ll)(b); i++)       
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
/// ({ ... }) avoids some problems: http://kernelnewbies.org/FAQ/DoWhile0
/// In non-contest code it is probably better to use: do { ... } while(0)
#define TR(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {

    int a;
    cin >> a;
    string s;
    cin >> s;
    if(!(a < 3200 )){
        cout << s;
    } else {
        cout << "red";
    }
}


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

#define ll long long int

using namespace std;

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

	vector<ll> x(n + 1);
    for (ll i = 2; i <= n; ++i) {
        ll num = i;
    	for (ll j = 2; j <= num; ++j) {
	    	while (num%j == 0) {
		    	x.at(j)++;
			    num /= j;
    		}
    	}
    }

    ll res = 0;
    for (ll i = 2; i <= n; ++i) {
        if (x[i] >= 74) ++res;
        for (ll j = i + 1; j <= n; ++j) {
            if (x[i] >= 14 && x[j] >= 4) ++res;
            if (x[i] >= 4 && x[j] >= 14) ++res;
            if (x[i] >= 24 && x[j] >= 2) ++res;
            if (x[i] >= 2 && x[j] >= 24) ++res;
            for (ll k = j + 1; k <= n; ++k) {
                if (x[i] >= 4 && x[j] >= 4 && x[k] >= 2) ++res;
                if (x[i] >= 4 && x[j] >= 2 && x[k] >= 4) ++res;
                if (x[i] >= 2 && x[j] >= 4 && x[k] >= 4) ++res;
            }
        }
    }
    cout << res << endl;
}


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

using namespace std;

#define NMAX 1000
#define MMAX 1000

int M,N;
int K;
int JOI[3][NMAX+1][MMAX+1];
int a,b,c,d;
string in;

int main(){

    cin>>M>>N;
    cin>>K;

    for(int i=1;i<=M;i++){
        cin>>in;
        for(int j=0;j<N;j++){
            if(in[j]=='J') JOI[0][i][j+1]=1;
            else if(in[j]=='O') JOI[1][i][j+1]=1;
            else if(in[j]=='I') JOI[2][i][j+1]=1;
        }
    }

    for(int i=1;i<=M;i++){
        for(int j=1;j<=N;j++){
	  for(int k=0;k<3;k++){
            JOI[k][i][j]+=JOI[k][i][j-1];
	  }
        }
    }

    for(int i=1;i<=N;i++){
         for(int j=1;j<=M;j++){
	   for(int k=0;k<3;k++){
	     JOI[k][j][i]+=JOI[k][j-1][i];
	   }
        }
    }

    for(int i=0;i<K;i++){
        cin>>a>>b>>c>>d;
	for(int j=0;j<3;j++){
	  cout<<JOI[j][c][d]-JOI[j][c][b-1]-JOI[j][a-1][d]+JOI[j][a-1][b-1];
	  if(j!=2) cout<<" ";
	  else cout<<endl;
	}
    }

    return 0;
}

Measured memory_bytes: 12912
n = int(input())

def prime_decomposition(n):
    # 素因数分解
    if n < 2:
        return []
    prime_factors = []
    while n % 2 == 0:
        prime_factors.append(2)
        n >>= 1

    while n % 3 == 0:
        prime_factors.append(3)
        n //= 3

    a = 5
    b = 7
    while a ** 2 <= n:
        if n % a == 0:
            prime_factors.append(a)
            n //= a
        elif n % b == 0:
            prime_factors.append(b)
            n //= b
        else:
            a += 6
            b += 6
    if n > 1:
        prime_factors.append(n)
    return prime_factors

pfs = prime_decomposition(n)
pfs.reverse()

def ds(n):

    ret = 1
    while 10**ret <= n:
        ret += 1
    return ret

ln = len(pfs)
size = 2**ln

min_v = 100
for i in range(size):
    p = 1
    for j in range(ln):
        if 1<<j & i:
            p *= pfs[j]
    min_v = min(min_v, max(ds(p), ds(n//p)))
print(min_v)

Measured memory_bytes: 42348
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


ll n;
ll s[100100];
int main(){
	cin>>n;
	REP(i,n)cin>>s[i];
	ll ans=0;
	for(ll c=1;c<n;c++){
		ll f=0;
		for(ll k=1;k<((n-1)%c==0?((n-1)/c+1)/2:(n-1)/c);k++){
			
			f=f+s[(n-1)-(k)*c]+s[(k)*c];
			ans=max(ans,f);
		}
		
	}
	cout<<ans<<endl;
	return 0;
}

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

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

int main() {
    int n, r;
    cin >> n >> r;
    if (n >= 10) {
        cout << r << endl;
    } else {
        cout << r + (100 * (10 - n)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256