akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    
    int H,W;cin>>H>>W;
    int S[H][W],cnt=0;
    vector<int> A,B,C,D;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>S[i][j];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W-1;j++){
            if(S[i][j]%2==1){
                S[i][j+1]++;
                S[i][j]--;
                cnt++;
                A.push_back(i+1);
                B.push_back(j+1);
                C.push_back(i+1);
                D.push_back(j+2);
            }
            }
        }
    for(int i=0;i<H-1;i++){
        if(S[i][W-1]%2==1){
            S[i+1][W-1]++;
            S[i][W-1]--;
            cnt++;
            A.push_back(i+1);
            B.push_back(W);
            C.push_back(i+2);
            D.push_back(W);
        }
    }
    cout<<cnt<<endl;
    for(int i=0;i<cnt;i++){
        cout<<A[i]<<" "<<B[i]<<" "<<C[i]<<" "<<D[i]<<endl;
    }
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 2e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

int group(int a)
{
    if(a == 2) return 2;
    if(a == 4 || a == 6 || a == 9 || a == 11) return 1;
    return 0;
}

void solve()
{
    int x, y; cin >> x >> y;
    if(group(x) == group(y)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[5][4][11] = {0};
int main () {
	int t, b, f, r, v;
	cin >> t;
	for ( int i = t; i > 0; i-- ) {
		cin >> b >> f >> r >> v; 
		a[b][f][r] = a[b][f][r] + v ;
	} 
	for ( int b = 1 ; b <= 4; b++ ) {
		for ( int f = 1; f <= 3; f++ ) {
			for ( int r = 1; r <= 10; r++ )  
 	  	  		cout << ' ' << a[b][f][r] ; 
			cout << endl;
		}
		if ( b != 4 ) {
	   	 	cout << "####################" << endl; 
        }
	}
	return 0;
}


Measured memory_bytes: 3112
import math

a, b, x = map(int, input().split())

tmp = a*a*b/2

if a < b :
    if x <= tmp:
        ans = (a*b*b)/(2*x)
        print(math.degrees(math.atan(ans)))
    else:
        ans = (2*b)/a - (2*x)/(a*a*a)
        print(math.degrees(math.atan(ans)))
else:
    if x <= tmp:
        ans = (a*b*b)/(2*x)
        print(math.degrees(math.atan(ans)))
    else:
        ans = (2*b)/a - (2*x)/(a*a*a)
        print(math.degrees(math.atan(ans)))


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var str = IO.GetIntList();
            var ans = (str[0] * 3 + str[1]) / 2;

            Console.Write(ans);
        }
    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 11348
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
	int N,A[100],v;
	int j;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	printf("%d",A[0]);
	for(int i=1;i<N;i++){
		printf(" %d",A[i]);
	}
	printf("\n");
	for(int i=1;i<N;i++){
		v=A[i];
		j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
		printf("%d",A[0]);
		for(int k=1;k<N;k++){
			printf(" %d",A[k]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 3204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};

lli gcd(lli a , lli b) {
    if(b == 0) return a;
    a %= b;
    return gcd(b,a);
}

void solve() {
    lli n, d;
    cin >> n >> d;
    lli i = 1, cnt = 0;
    while (i <= n) {
        i += 2 * d + 1;
        cnt++;
    }
    cout << cnt << endl;
}

int main()
{
    IOS;
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
S += "?"

s = 0
t = 0
ans = 0
while t < N:
    while t < N:
        if S[t] in "ATGC":
            t += 1
        else:
            break
    ans = max(ans, t - s)
    s = t + 1
    t = s

print(ans)


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

int main(){
  string B[50];
  int h,w;
  cin >> h >> w;
  
  for(int i=0;i<h;i++) cin >> B[i];
  
  int dx[8] = {1,1,0,-1,-1,-1,0,1};
  int dy[8] = {0,1,1,1,0,-1,-1,-1};
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(B[i][j]=='#')continue;
      int x=0;
      for(int k=0;k<8;k++){
        if(i+dy[k]>=0 && j+dx[k]>=0 && i+dy[k]<h && j+dx[k]<w){
          if(B[i+dy[k]][j+dx[k]]=='#') x++;
        }
      }
      B[i].at(j)=char(x+'0');
    }
  }
  for(int i=0;i<h;i++) cout << B[i] << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    #[inline(always)]
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    #[inline(always)]
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn main() {
    let n = get!(usize);
    let mut aa = util::gets::<u64>();

    aa.sort_by_key(|&a| Rev(a));

    let ans = (0..n)
        .map(|i| unsafe { aa.get_unchecked(i * 2 + 1) })
        .sum::<u64>();

    println!("{}", ans);
}


Measured memory_bytes: 13428
import java.util.Scanner;
class Main{


	static char[][] map;

	static long[][] c;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = (a + b)/2;
		if(ans != (double)(a+b)/2){
			System.out.println("IMPOSSIBLE");
		}else{
			System.out.println(ans);
		}

		
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   end- otherpair.end;
	}








}






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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=1'000'000'007;
const double EPS=1e-14;
const bool DEBUG=false;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////

void answer(){
    string S;
    cin>>S;

    vector<long> mod_2019(S.length());
    long pow10 = 1;
    long number = 0;
    for(int i=S.length()-1; i>=0; i--){
        number = number + pow10 * (S[i] - '0');
        number %= 2019;
        mod_2019[i] = number;
        pow10 = pow10 * 10 % 2019;
    }

    vector<long> count(2019, 0);
    for(int i=0; i<S.length(); i++){
        count[mod_2019[i]]++;
        debug(i, mod_2019[i], count[mod_2019[i]]);
    }

    long ans = 0;
    for(int i=0; i<count.size(); i++){
        ans += count[i] * (count[i] - 1) / 2;
    }
    ans += count[0];

    cout<<ans<<endl;

    return;
}

/////

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(16);

    answer();

    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <cstdlib>
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;
using Graph = vector<vector<ll>>;

ll N, X, Y, ans; 

ll dist(ll i, ll j)
{	
	return min(abs(j - i), abs(X - i) + 1 + abs(Y - j));
}

int main()
{
  cin >> N >> X >> Y;
  vector<ll> K(N, 0);
  for (ll i = 1; i < N; i++) {
  	for (ll j = i + 1; j <= N; j++) {
    	K[dist(i, j)]++;
    }
  }
  for (ll i = 1; i < N; i++) {
  	cout << K[i] << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
queue<pair<int,int>> que;
int H,W;
vector<string> A;
vector<vector<int>> cost;

void bfs(){
  while(!que.empty()){
    pair<int,int> p=que.front();
    que.pop();
    int dy[]={1,0,-1,0}; int dx[]={0,1,0,-1};
    for(int i=0;i<4;i++){
      int ny=p.first+dy[i]; int nx=p.second+dx[i];
      if(ny<0 || nx<0 || ny>=H || nx>=W){continue;}
      if(cost[ny][nx]!=-1)continue;
      cost[ny][nx]=cost[p.first][p.second]+1;
      que.push(make_pair(ny,nx));
    }
  }
}

int main(){
  cin >> H >> W;
  A=vector<string>(H);
  cost=vector<vector<int>> (H,vector<int>(W,-1));
  for(int i=0;i<H;i++)cin >> A[i];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(A[i][j]=='#'){que.push(make_pair(i,j)); cost[i][j]=0;}
    }
  }
  bfs();
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){ans=max(ans,cost[i][j]);}
  }
  cout << ans << endl;
}

Measured memory_bytes: 13456
using System;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            int count = int.Parse(Console.ReadLine());
            for(int i=0;i < count;++i){
                Console.WriteLine(Translate(uint.Parse(Console.ReadLine(), System.Globalization.NumberStyles.AllowHexSpecifier)));
            }
        }
        static string Translate(uint value)
        {
            string result = string.Empty;
            if((value & 0x80000000) == 0x80000000){
                result += '-';
            }
            uint num = (value & 0x7FFFFFE0) >> 7;
            uint dec = (value & 0x7F) * (5000000 / 64);
            result += string.Format("{0}.", num);
            if(dec == 0) {
                result += "0";
            }
            else {
                int zero = 7;
                while(dec % 10 == 0) {
                    dec /= 10;
                    --zero;
                }
                result += dec.ToString().PadLeft(zero, '0');
            }
            return result;
        }
    }
}

Measured memory_bytes: 5884
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		WriteLine(Chech(Str) ? "YES" : "NO");
	}
	bool Chech(string S)
	{
		var K = "keyence";
		if (S == K) return true;
		var N = S.Length;
		if (N <= K.Length) return false;
		var c = N - K.Length;
		for (var i = 0; i + c <= S.Length; i++) if (S.Substring(0, i) + S.Substring(i + c, N - i - c) == K) return true;
		return false;
	}
}


Measured memory_bytes: 13140
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
NN = (M + 10).bit_length()
BIT=[0]*(2**NN+1)

def addrange(l0, r0, x=1):
    l, r = l0, r0
    while l <= 2**NN:
        BIT[l] += x
        l += l & (-l)
    while r <= 2**NN:
        BIT[r] -= x
        r += r & (-r)
def getvalue(r):
    a = 0
    while r != 0:
        a += BIT[r]
        r -= r&(-r)
    return a

X = []
for _ in range(N):
    l, r = map(int, input().split())
    X.append((l, r+1))

X = sorted(X, key = lambda x: -(x[1]-x[0]))
for d in range(1, M+1):
    while X and X[-1][1] - X[-1][0] < d:
        l, r = X.pop()
        addrange(l, r)
    ans = len(X)
    for i in range(d, M+1, d):
        ans += getvalue(i)
    print(ans)


Measured memory_bytes: 100312
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        int min = -1;
        int result = 0;
        for (int i =0; i<S.length()-2; i++) {
            Integer target = Integer.parseInt(S.substring(i, i+3));
            if (min < 0 || min > Math.abs(753 - target)){
                min = Math.abs(753 - target);
                result = target;
            }
        }

        System.out.println(min);

    }

}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.second == b.second) {
        return a.first.compare(b.first) < 0;
    }
    return a.second > b.second;
}
 
int main() {
    int N;
    cin >> N;
    map<string, int> m;
    string S;
    for (int i = 0; i < N; i++) {
        cin >> S;
        if (m.count(S)) {
            m[S]++;
        } else {
            m[S] = 1;
        }
    }
    vector<pair<string, int>> v;
    for (auto it = m.begin(); it != m.end(); it++) {
        v.push_back(make_pair(it->first, it->second));
    }
    sort(v.begin(), v.end(), my_compare);
    int t = v[0].second;
    for (int i = 0; i < v.size(); i++) {
        if (v[i].second == t) {
            cout << v[i].first << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 29296
n = int(input())
s = input()

w_series = [0]
e_series = [0]
for c in s:
    if c == "W":
        w_series.append(w_series[-1]+1)
    else:
        w_series.append(w_series[-1])
for c in s[::-1]:
    if c == "E":
        e_series.append(e_series[-1]+1)
    else:
        e_series.append(e_series[-1])
e_series = e_series[::-1]

ans = n
for x in zip(w_series[1:], e_series[:-1]):
    ans = min(sum(x)-1, ans)
print(ans)

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

using ll = long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; k < (n); k++)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define repr(i, a, b) for (auto i = (a); i < (b); i++)
#define repv(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = max((t), (v)))
#define updatemin(t, v) (t = min((t), (v)))
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}
template <typename T>
class segtree {
 private:
  int n;
  vector<T> data, lazy;

 public:
  segtree(int n_) {
    n = pow(2, ceil(log2(n_)));
    data.resize(n);
    lazy.resize(n);
    auto __x = data[0];
    repi(n) {
      data[i] = __vmin(__x);
      lazy[i] = 0;
    }
  }
};

int main() {
  ll l, r;
  cin >> l >> r;
  ll re = LLONG_MAX;
  repr(i, l, min(r + 1, l + 2019)) {
    repr(j, i + 1, min(r + 1, i + 2020))
        updatemin(re, ((i % 2019) * (j % 2019)) % 2019);
  }
  cout << re << endl;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
MOD = 998244353

class Segtree:
    def __init__(self, A, intv, initialize = True, segf = max):
        self.N = len(A)
        self.N0 = 2**(self.N-1).bit_length()
        self.intv = intv
        self.segf = segf
        if initialize:
            self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
            for i in range(self.N0-1, 0, -1):
                self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
        else:
            self.data = [intv]*(2*self.N0)
        
    def update(self, k, x):
        k += self.N0
        self.data[k] = x
        while k > 0 :
            k = k >> 1
            self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])
    
    def query(self, l, r):
        L, R = l+self.N0, r+self.N0
        s = self.intv
        while L < R:
            if R & 1:
                R -= 1
                s = self.segf(s, self.data[R])
            if L & 1:
                s = self.segf(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s
    
    def binsearch(self, l, r, check, reverse = False):
        L, R = l+self.N0, r+self.N0
        SL, SR = [], []
        while L < R:
            if R & 1:
                R -= 1
                SR.append(R)
            if L & 1:
                SL.append(L)
                L += 1
            L >>= 1
            R >>= 1
        
        if reverse:
            for idx in (SR + SL[::-1]):
                if check(self.data[idx]):
                    break
            else:
                return -1
            while idx < self.N0:
                if check(self.data[2*idx+1]):
                    idx = 2*idx + 1
                else:
                    idx = 2*idx
            return idx - self.N0
        else:
            for idx in (SL + SR[::-1]):
                if check(self.data[idx]):
                    break
            else:
                return -1
            while idx < self.N0:
                if check(self.data[2*idx]):
                    idx = 2*idx
                else:
                    idx = 2*idx + 1
            return idx - self.N0

N = int(readline())
XD = [tuple(map(int, readline().split())) for _ in range(N)]
XD.sort(key = lambda x: (x[0], -x[1]))

sXD = []
seen = set()
for x, d in XD:
    if x not in seen:
        sXD.append((x, d))
        seen.add(x)

N = len(sXD)
table = list(range(N))
T = Segtree(table, -1, initialize = True, segf = max)
X, D = map(list, zip(*sXD))
for i in range(N-1, -1, -1):
    ok = i
    ng = N
    gi = X[i] + D[i]
    while abs(ok-ng) > 1:
        med = (ok+ng)//2
        if X[med] < gi:
            ok = med
        else:
            ng = med
    table[i] = T.query(i, ok+1)
    T.update(i, table[i])

dp = [0]*(N+1)
dp[N] = 1
Dp = dp[:]
for i in range(N-1, -1, -1):
    dp[i] = Dp[table[i]+1]
    Dp[i] = (Dp[i+1] + dp[i])%MOD
print(Dp[0])

Measured memory_bytes: 129568
#include <stdio.h>

int main(void) {
  int N,A,B,seki;

  scanf("%d",&N); scanf("%d",&A); scanf("%d",&B);

  seki=A*N;

  if(seki>=B)
    printf("%d",B);
  else 
    printf("%d",seki);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) (v.begin(),v.end())
#define MP make_pair
#define pb(n) push_back(n)


int main(){
    int N;
    cin>>N;
    rep(i,N){
        int K,P;
        cin>>K>>P;cout<<(K%P?K%P:P)<<endl;
    }
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	int n,a,b;
	cin >> n;
	if(n==1) cout << "Hello World" << endl;
	else{
		cin >> a >> b;
		cout << a+b << endl;

	}
}

Measured memory_bytes: 256
N = int(input())
S = input()

mod = 10 ** 9 + 7

if S[0] == 'W' or S[-1] == 'W' :
    print(0)

else :
    ret = 1
    l = 1
    pre = 0
    for i in range(1, 2 * N) :
        if S[i-1] == S[i] :
            if pre == 0 :
                ret *= l
                ret %= mod
                l -= 1
                pre ^= 1
            else :
                l += 1
                pre ^= 1
        else :
            if pre == 0 :
                l += 1
            else :
                ret *= l
                ret %= mod
                l -= 1
                
    if l != 0 :
        print(0)
    else :
        for i in range(1, N + 1) :
            ret *= i
            ret %= mod
            
        print(ret)

Measured memory_bytes: 41052
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

long long A[200000];
long long cnt = 0;

void merge(long long A[], int left, int mid, int right) {
    long L[100001], R[100001];
    int n1 = mid - left;
    int n2 = right - mid;

    int inverse = n1;
    
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];

    L[n1] = 100000000000;
    R[n2] = 100000000000;

    int li = 0, rj = 0;
    for (int ak = left; ak < right; ak++ ) {
        if (L[li] <= R[rj]) {
            A[ak] = L[li];
            li++;
            inverse--;
        } else {
            A[ak] = R[rj];
            rj++;
            cnt += inverse;
        }
    }
}

void mergeSort(long long A[], int left, int right) {
    if (left + 1 == right) return;

    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
}


int main(void) {

    int n;
    cnt = 0;

    cin >> n;
    for (int i = 0; i < n; i++ ) cin >> A[i];

    mergeSort(A, 0, n);

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 6224
N,C,K = map(int,input().split())

cnt = 0
ans = 0
lst = [int(input()) for _ in range(N)]
lst = sorted(lst)
next_t = 10**10
for t in lst:
  next_t = min(t+K,next_t)
  if (t > next_t):
    ans += 1
    cnt = 0
    next_t = t+K
    
  cnt += 1
  if (cnt == C):
    ans += 1
    cnt = 0
    next_t = 10**10
    
if (cnt > 0):
  ans += 1
print(ans)

Measured memory_bytes: 51288
n, k = map(int, input().split())
p = [int(s) for s in input().split()]

for i in range(n):
    p[i] = (1 + p[i]) / 2

value = sum(p[0:k])
ans = value
for i in range(k, n):
    value = value + p[i] - p[i - k]
    ans = max(ans, value)

print(ans)


Measured memory_bytes: 24548
#include<iostream>
#include<cmath>

using namespace std;

bool Isprime(int x);

int main() {
	
	int n;
	
	while( cin >> n) {
		
		int a;
		int count = 0;
		
		for(int i=0;i<n;i++) {
			
			cin >> a;
			count += Isprime(a);
				
	}
		cout << count << "\n";
}
	return 0;
}

bool Isprime(int x) {
	
	if( x == 2 )
	return true;
	
	if( x < 2 || x % 2 == 0 )
	return false;
	
	int i = 3;
	
	while( i <= sqrt(x) ) {
		
		if( x % i == 0)
		return false;
		
		i += 2;
	}
	return true;
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int n1 = a + b;
  int n2 = a + c;
  int n3 = b + c;
  cout << min({n1, n2, n3}) << endl;
  return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int A[20];
int m[200];
int n;
int q;
bool solve(int i,int m){
	bool res;
	if (m == 0){ return true; }
	if (i >= n){ return false; }
	res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}
int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> A[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++){
		cin >> m[i];
		if (solve(0, m[i]) == true){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

	int K, T; cin >> K >> T;
	vector<int> A(T);
	rep(i, T) cin >> A[i];

	sort(all(A));
	// 全部のケーキ
	int total = accumulate(all(A), 0);
	// 一番多いケーキ
	int top = A.back();
	// 全部から1番を抜いた残りのケーキ
	int rest = total - top;
	// 一番多いケーキの数 <= 残りのケーキ+1までなら連続しない
	// それ以上の場合、連続する日数が1つずつ増えていく
	int ans = top - (rest+1);

	if (ans < 0) ans = 0;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int i,j,k,X,Y;

int main()
{
  cin>>X>>Y;
  
  if(Y%2==1)
  {
    cout<<"No";
    return 0;
  }
  else
  {
    i=Y/2-X;
    j=X-i;
    if(i>=0 && j>=0)
    {
      cout<<"Yes";
      return 0;
    }
  }
  
  cout<<"No";
  
  
}

Measured memory_bytes: 3624
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


n = int(sys.stdin.buffer.readline())
if n <= 999:
    print('ABC')
else:
    print('ABD')


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    vi a(n + 1, 0);
    rep(i, 1, n + 1) { cin >> a[i]; }

    vi ans(n + 1, 0);

    // O(n * log(n))
    rrep(i, 1, n + 1) {
        int c = a[i];
        for (int j = 2 * i; j < n + 1; j += i) { c ^= ans[j]; }
        ans[i] = c;
    }

    int cnt = 0, last = -1;
    rep(i, 1, n + 1) {
        if (ans[i] == 1) {
            ++cnt;
            last = i;
        }
    }

    cout << cnt << endl;
    rep(i, 1, n + 1) {
        if (ans[i] == 1) {
            cout << i;
            if (i == last) {
                cout << endl;
            } else {
                cout << " ";
            }
        }
    }

    return 0;
}

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

int main() {
  int x=0,n,max_x=0;
  cin >> n;
  string s;
  cin >> s;
  
  for (int i=0;i<n;i++) {
    if (s.at(i)=='I') x++;
    else x--;
    if (x>max_x) max_x=x;
  }
  cout << max_x << endl;
}

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

using namespace std;

int main(){
	ll n, m, i;
	bool b[2020]={0};
	
	cin>>n;
	
	vector < ll > x(n+1);
	
	for(i=1; i<=n; i++){
		cin>>x[i];
		b[x[i]]=1;
	}
	
	cin>>m;
	
	ll a;
	
	for(i=1; i<=m; i++){
		cin>>a;
		if(x[a]<2019 && b[x[a]+1]==0){
			b[x[a]]=0;
			b[x[a]+1]=1;
			x[a]++;
		}
	}
	
	for(i=1; i<=n; i++){
		cout<<x[i]<<"\n";	
	}
	
	return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>

int main()
{
    int H, W, x, y, r;
    
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    
    if (x - r >= 0 && y - r >= 0 && W >= x  + r && H >= y + r ){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
    
}


Measured memory_bytes: 2140
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include<unordered_map>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	deque<int>b1;
	unordered_map<int, int>a2;
	rep(i, m) {
		int a, b;
		scanf("%d %d",&a,&b);
		if (a == 1) {
			b1.push_back(b);
		}
		if (b == n) {
			a2[a] = i + 1;
		}
	}
	bool flag = false;
	rep(i, b1.size()) {
		if (a2[b1[i]]>0) {
			flag = true;
			break;
		}
    }
	
	if (flag) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 8904
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

#define DEBUG_MSG_off

static int N;
static vector<double> v_list;

int main() {
  cin >> N;
  v_list.resize(N);
  double res_per = 0.0;
  for(int i=0;i<N;++i) {
    cin >> v_list[i];
    double tmp = (1.0 / v_list[i]);
    res_per += tmp;
#ifdef DEBUG_MSG
    cerr << "v_list[i]=" << v_list[i] << "\n";
    cerr << "1/v_list[i]=" << tmp << "\n";
    cerr << "res_per=" << res_per << "\n";
#endif
  }
  cout << (1.0/res_per) << "\n";

#ifdef DEBUG_MSG
  cerr << N << "\n";
  for(auto s: v_list) cerr << s << "\n"; 
#endif
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int x;
  char *day[] = { "thu", "fri", "sat", "sun", "mon", "tue", "wed" };
  
  scanf("%d", &x);
  
  x %= 7;
  printf("%s\n", day[x]);

  return 0;
}
  



Measured memory_bytes: 2092
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<LL,LL>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn];
int main(){
	int n , m;cin >> n >> m;
	int sum = 0 , cnt = 0;
	fo(i,1,n){
		cin >> a[i];
		sum += a[i];
	}
	fo(i,1,n){
		if(a[i] * 4 * m >= sum)cnt++;
	}
	puts(cnt >= m?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;

int N, d;
int V[2][50];
int E[2][50][50];

struct Node
{
	int n;
	int mt;
	int h;
	bool sel[50];
	bool operator< (const Node & node) const
	{
		return h < node.h;
	}
	Node() : n(0), mt(0x0FFFFFFF), h(0)
	{
	}
	Node(const Node & node) : n(node.n), mt(node.mt), h(node.h)
	{
		if(n > 0)
			memcpy(sel, &node.sel, sizeof(bool) * n);
	}
};

int tdiff(int t1, int t2)
{
	int diff = abs(t1 - t2);
	return min(diff, 24 - diff);
}

int bnb(int minedge)
{
	priority_queue <Node> pq;
	pq.push(Node());
	int bnd = 0;
	while (!pq.empty())
	{
		Node node = pq.top();
		pq.pop();
		if (node.h < bnd)
			continue;
		if (node.n == N)
		{
			bnd = max(bnd, node.mt);
			if (minedge <= bnd)
				break;
			continue;
		}
		for (int s = 0; s < 2; ++s)
		{
			node.sel[node.n] = s;

			// compute new minimum tdiff
			// between new vertex and others.
			int backup = node.mt;
			for (int m = 0; m < node.n; ++m)
				node.mt = min(node.mt, tdiff(V[node.sel[m]][m], V[s][node.n]));
			
			// compute heuristic
			// select others having always best edges
			node.h = node.mt;
			for (int m = node.n + 1; m < N; ++m)
				node.h = min(node.h, E[1][node.n][m]);

			++node.n;
			pq.push(node);
			node.mt = backup;
			--node.n;
		}
	}
	return min(bnd, minedge);
}

int main(void)
{
	//freopen("input.txt", "r", stdin);
	scanf("%d", &N);
	int minedge = 0x0FFFFFFF;
	int dupchk[13] = { 0, };
	for (int n = 0; n < N; ++n)
	{
		scanf("%d", &d);
		++dupchk[d];
		V[0][n] = min(d, 24 - d);
		V[1][n] = max(d, 24 - d);
		minedge = min(minedge, V[0][n]);
	}

	// pigeon's hole
	if (dupchk[0] >= 1)
	{
		printf("0");
		return 0;
	}
	for (int h = 1; h < 12; ++h)
		if (dupchk[h] >= 3)
		{
			printf("0");
			return 0;
		}
	if (dupchk[12] >= 2)
	{
		printf("0");
		return 0;
	}

	for (int n = 0; n < N; ++n)
		for (int m = n + 1; m < N; ++m)
		{
			E[0][n][m] = 0x0FFFFFFF;
			E[1][n][m] = 0;
			for (int i = 0; i < 2; ++i)
				for (int j = 0; j < 2; ++j)
				{
					int td = tdiff(V[i][n], V[j][m]);
					E[0][n][m] = min(E[0][n][m], td);
					E[1][n][m] = max(E[1][n][m], td);
				}
		}
	printf("%d", bnb(minedge));
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int myhas(string s, int ptr, int a, int b, int c, int d){
  if(s[ptr] == 'a'){ return a; }
  else if(s[ptr] == 'b'){ return b; }
  else if(s[ptr] == 'c'){ return c; }
  else if(s[ptr] == 'd'){ return d; }
  else if(s[ptr] == '['){
    int p = 0;
    if(s[ptr+2] == '['){
      int cnt = 1;
      while(cnt != 0){
	p++;
	if(s[ptr+2+p] == ']'){cnt--;}
	else if(s[ptr+2+p] == '['){cnt++;}
      }
    }
    // cout << "p = " << p << endl;
    // cout << "X now gaze " << "s[" << ptr+2 << "] == " << s[ptr+2] << endl;
    int X = myhas(s, ptr+2, a, b, c, d);
    // cout << "Y now gaze " << "s[" << ptr+2+p+1 << "] == " << s[ptr+2+p+1] << endl;
    int Y = myhas(s, ptr+2+p+1, a, b, c, d);
    if(s[ptr+1] == '+'){
      return (X | Y) & 15;
    }else if(s[ptr+1] == '*'){
      return (X & Y) & 15;
    }else if(s[ptr+1] == '^'){
      return (X ^ Y) & 15;
    }
  }
  // cout << "something wrong" << endl;
  return 0;
}

int main(void){
  for(;;){
    string S;
    cin >> S;
    if(S == "."){return 0;}
    string P;
    cin >> P;
    int mypassword = stoi(P);
    int md = mypassword % 10;
    int mc = (mypassword / 10) % 10;
    int mb = (mypassword / 100) % 10;
    int ma = (mypassword / 1000);
    int ans = myhas(S,0,ma,mb,mc,md);
    int cnt = 0;
    for(int a = 0 ; a <= 9 ; a++){
      for(int b = 0 ; b <= 9 ; b++){
	for(int c = 0 ; c <= 9 ; c++){
	  for(int d = 0 ; d <= 9 ; d++){
	    if(ans == myhas(S,0,a,b,c,d)){
	      cnt++;
	    }
	  }
	}	
      }
      }
    cout << ans << " " << cnt << endl;
  }
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<(n); i++)
#define int long long
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
signed main(void){
    int n;cin>>n;
    int sum=0;
    vector<int>W(n);rep(i,n){cin>>W[i];sum+=W[i];}
    int ans=INF;int com=0;
    rep(i,n-1){
        com+=W[i];
        ans=min(ans,abs(sum-com*2));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n=int(input())
D=[list(map(int,input().split())) for _ in range(n)]
num=0
dnum=0
for i in range(n):
    if D[i][0]==D[i][1]:
        num+=1
        if num==3:
            dnum=1
    else:
        num=0

print("Yes" if dnum==1 else "No")

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n;
string str;
vector<int> e[2000];
int par[2000];
int dist[2000];
int cnt[2000];
int dp[2000];

void dfs(int v) {
    cnt[v] = 0;
    dist[v] = 0;
    int max_d = -1, max_i;
    int ccnt = 0;
    rep(i,e[v].size()) {
        if (e[v][i] == par[v]) continue;
        ccnt++;
        par[e[v][i]] = v;
        dfs(e[v][i]);
        cnt[v] += cnt[e[v][i]];
        dist[v] += dist[e[v][i]] + cnt[e[v][i]];
        if (max_d < dist[e[v][i]] + cnt[e[v][i]]) {
            max_d = dist[e[v][i]] + cnt[e[v][i]];
            max_i = e[v][i];
        }
    }
    if (str[v] == '1') cnt[v]++;
    if (ccnt == 0) {
        dp[v] = 0;
        return;
    }
    int oth_d = dist[v] - max_d;
    if (max_d > oth_d) {
        dp[v] = oth_d + min((max_d-oth_d)/2, dp[max_i]);
    } else {
        dp[v] = dist[v] / 2;
    }
}

int main() {
    cin >> n >> str;
    rep(i,n-1) {
        int a, b; cin >> a >> b; a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    int ans = inf;
    rep(i,n) {
        par[i] = i;
        dfs(i);
        /*
        if (i == 0) {
            rep(j,n) {
                cout << j << " " << dist[j] << " " << cnt[j] << " " << dp[j] << endl;
            }
            cout << endl;
        }
        */
        if (dp[i]*2 == dist[i]) {
            ans = min(ans, dp[i]);
        }
    }
    if (ans == inf) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long n,m,t;
int main(){
	cin>>n;
	m=sqrt(n);
	if(m*m==n){
		cout<<2*m-2<<endl;
		return 0;
	}else{
		for(int i=m;i>=1;i--){
			t=n/i;
			if(t*i==n){
				cout<<i+t-2<<endl;
				break;
			}
		}
	}
	return 0;
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
	int n,m;
	string s,s2;
cin>>n>>m;
int le=0,ri=1;
for(int i=1;i<999;i++){
le+=i;ri+=(i+1);
if(le-n==ri-m){
cout<<le-n<<endl;
}
}
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    ll q = (N+1000-1)/1000;
    cout << 1000*q-N << endl;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();    
    int C = sc.nextInt();    
    int K = sc.nextInt();
    int max = Math.max(Math.max(A,B),Math.max(B,C));
    int res = A + B + C - max;
    System.out.println(res + max * (int)Math.pow(2,K));
  }
}

Measured memory_bytes: 22868
ans=0
n=input()
s=input()
flag="0"

for i in s:
    if i=="A":
        flag="a"
    elif i=="B" and flag=="a":
        flag="b"
    elif i=="C" and flag=="b":
        flag="0"
        ans+=1
    else:
        flag="0"
        
print(ans)

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string line2 = Console.ReadLine();
            if (line2.IndexOf(line) == 0 && line2.Length == line.Length+1)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 26176
N = int(input())
S = int(input())


def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n // b) + n % b


if N == S:
    print(N + 1)
    exit()
elif N < S:
    print(-1)
    exit()

num = -1
for i in range(2, int(N ** 0.5) + 1):
    if f(i, N) == S:
        num = i
        break


if num == -1:
    for i in range(int(N ** 0.5) + 1, 0, -1):
        if (N - S) % i == 0:
            b = (N - S) // i + 1
            if f(b, N) == S:
                num = b
                break

print(num)

Measured memory_bytes: 41968
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define mod 1000000007
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inp_vecN for(int i=0;i<n;i++)cin>>v[i]; 
vector<int> get_Factors(ll n)
{
      vector <int> v;
      for(ll i=2; i<=sqrt(n)+1; i++)
      {
            if(n%i==0)
            {
                  v.push_back(i);
                  v.push_back(n/i);
            }
      }

      v.push_back(1);

      return v;
}
string get_bin(ll n)
{
    string s = "";
    while(n > 0)
    {
        s += ('0' + n%2);
        n /= 2;
    }
    reverse(s.begin(), s.end());
    return s;
}

ll bin_to_dec(string s)
{
    ll ans = 0;
    for(auto ch: s)
    {
        ans *= 2;
        ans += (ch - '0');
    }
    return ans;
}
void PrintVector(vector<int> v,int n)
{

    for(int i=0;i<n;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
int no_of_primeFactors(int n)  
{ 
    int count=0;
    while (n % 2 == 0)  
    {  
        count++;
        n = n/2;  
    }  
   
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    { 
        while (n % i == 0)  
        {  
           count++;
            n = n/i;  
        }  
        
    }  
    if (n > 2)  
        count++;
    return count;
} 
 ll gcd(int a, int b)
{ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
} 
   
  ll lcm(int a, int b)  
{  
    return (a/gcd(a, b)*b);  
}  



ll pwr(ll base,ll expo,ll m)
{
    if(base==0) return 0LL;
    if(expo==0) return (1LL%m);
    if((expo&1)==0) {ll temp=pwr(base,expo>>1,m); return (temp*temp)%m;}
    return ((base%m)*pwr(base,expo-1,m))%m;
}

int main(int argc, char const *argv[])
{
    ios;

    ll x;
    cin>>x;

    for(ll i=-150;i<=150;i++)
    {
      for(ll j=-150;j<=150;j++)
      {
            if(pow(i,5)-pow(j,5)==x)
            {
                  cout<<i<<" "<<j;
                  return 0;
            }
      }
    }





    



    return 0;
}

Measured memory_bytes: 4060