akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int n, v[100005], st, dr, mid, res, k;
int main() {
    DAU
    cin >> n;
    k = n / 2;
    for (int i = 1; i <= n; ++i)
        cin >> v[i];
    sort(v + 1, v + n + 1);
    for (int i = 1; i <= 1e5; ++i)
        if (v[k] <= i && v[k+1] > i)
            ++res;
    cout << res;
    PLEC
}


Measured memory_bytes: 4020
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    q = I()
    lst = collections.deque(list(s))
    state = False

    for _ in range(q):
        query = LS()
        if len(query) == 1:
            state = not state
        else:
            if state:
                if query[1] == "1":
                    lst.append(query[2])
                else:
                    lst.appendleft(query[2])
            else:
                if query[1] == "1":
                    lst.appendleft(query[2])
                else:
                    lst.append(query[2])
    ans = ""
    if state:
        for _ in range(len(lst)):
            ans += lst.pop()
    else:
        ans = "".join(lst)

    print(ans)
main()            


Measured memory_bytes: 15088
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;
int ans[200005]={0};
vector<string> vs,vr;
vector<P> vq,vq2,vq3;
int main(){
  ll n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    string s;
    cin>>s;
    string s2=s;
    s.push_back((char)('a'-1));
    vs.push_back(s);
    reverse(s2.begin(),s2.end());
    s2.push_back((char)('a'-1));
    vr.push_back(s2);
  }
  sort(vs.begin(),vs.end());
  sort(vr.begin(),vr.end());

  for(int i=0;i<m;i++){
    string s;
    cin>>s;
    bool f=false;
    if(s[0]=='*'){
      f=true;
      reverse(s.begin(),s.end());
    }
    bool f_=false;
    int cp=0;
    for(int j=0;j<s.length();j++){
      if(s[j]=='?'){
        f_=true;
        cp=j;
      }
    }
    bool f2=false;
    if(s[s.length()-1]=='*') f2=true;

    if(f){
    //  s.pop_back();
      if(!f_) vq2.push_back(P(s,i));
      else{
        for(int k=0;k<26;k++){
          s[cp]=(char)('a'+k);
          vq2.push_back(P(s,i));
        }
      }
    }
    else{
      if(f2){
      //  s.pop_back();
        if(!f_) vq.push_back(P(s,i));
        else{
          for(int k=0;k<26;k++){
            s[cp]=(char)('a'+k);
            vq.push_back(P(s,i));
          }
        }
      }
      else{
        if(!f_) vq3.push_back(P(s,i));
        else{
          for(int k=0;k<26;k++){
            s[cp]=(char)('a'+k);
            vq3.push_back(P(s,i));
          }
        }
      }
    }
  }
  sort(vq.begin(),vq.end());
  sort(vq2.begin(),vq2.end());
  sort(vq3.begin(),vq3.end());

  for(int i=0;i<vq.size();i++) {
    string s=vq[i].first;
    int sl=s.length();
    int idx=vq[i].second;
    char c=s[sl-2];
    c=(char)(c+1);
    s[sl-2]=(char)(c-2);
    s[sl-1]=(char)('z'+1);
    //cout<<s<<" "<<idx<<" ";
    int lb=upper_bound(vs.begin(),vs.end(),s)-vs.begin();
    s[sl-2]=c;
    s[sl-1]=(char)('a'-1);
    //cout<<s<<" ";
    int rb=lower_bound(vs.begin(),vs.end(),s)-vs.begin();
    ans[idx]+=rb-lb;
    //cout<<rb-lb<<endl;
  }
  for(int i=0;i<vq2.size();i++) {
    string s=vq2[i].first;
    int sl=s.length();
    int idx=vq2[i].second;
    char c=s[sl-2];
    c=(char)(c+1);
    s[sl-2]=(char)(c-2);
    s[sl-1]=(char)('z'+1);
  //  cout<<s<<" "<<idx<<" ";
    int lb=upper_bound(vr.begin(),vr.end(),s)-vr.begin();
    s[sl-2]=c;
    s[sl-1]=(char)('a'-1);
    int rb=lower_bound(vr.begin(),vr.end(),s)-vr.begin();
    ans[idx]+=rb-lb;
  //  cout<<s<<" "<<rb-lb<<endl;
  }
  for(int i=0;i<vq3.size();i++) {
    string s=vq3[i].first;
    int sl=s.length();
    int idx=vq3[i].second;
  //  cout<<s<<" "<<idx<<" ";
    int lb=lower_bound(vs.begin(),vs.end(),s)-vs.begin();
    s.push_back('a');
  //  cout<<s<<" ";
    int rb=lower_bound(vs.begin(),vs.end(),s)-vs.begin();
    ans[idx]+=rb-lb;
  //  cout<<rb<<" "<<lb<<endl;
  }
  for(int i=0;i<m;i++) cout<<ans[i]<<endl;
}



Measured memory_bytes: 103896
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
        k:Chars,
        d:usize,
    }
    //剰余を持つ？

    let n = k.len();
    let mut dp = vec![vec![vec![0i64; 2]; d]; n + 1];

    dp[0][0][1] = 1;
    for (i, &c) in k.iter().enumerate() {
        let num = charconv(c, '0');
        for amari in 0..d {
            dp[i + 1][(amari + num) % d][1] += dp[i][amari][1];
            for j in 0..num {
                dp[i + 1][(amari + j) % d][0] += dp[i][amari][1];
            }
            for j in 0..=9 {
                dp[i + 1][(amari + j) % d][0] += dp[i][amari][0];
            }
            dp[i][amari][0] %= MOD;
            dp[i][amari][1] %= MOD;
            dp[i + 1][amari][0] %= MOD;
            dp[i + 1][amari][1] %= MOD;
        }
    }
    // dbg!(&dp);
    println!("{}", (dp[n][0][0] + dp[n][0][1] - 1 + MOD) % MOD);
}
const MOD: i64 = 1000000007;
pub fn charconv(c: char, base: char) -> usize {
    return (c as u8 - base as u8) as usize;
}


Measured memory_bytes: 57116
import numpy as np
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

A = []
for i in range(N):
    A.append(list(map(int, input().split())))

X = np.array(A).dot(np.array(B)) + C
cnt = np.sum(X > 0)

print(cnt)

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

int main(){
  int N,M,K;
  string S;
  
  cin>>N>>M ;
  if(N<=M)
  
  
  
  cout<<"unsafe"<<endl;
  else cout<<"safe"<<endl;
}

//  cout<<"Yes"<<endl;
//  cout<<" No"<<endl;
//  cout<<" "<<endl;
//  if()  ;


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){

    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        ans += a-1;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
using namespace std;
typedef long long ll;


int main(void) {
	string s; cin >> s;
	int mid = (s.size()) / 2;
	string l, r;
	rep(i, mid) {
		l.push_back(s[i]);
		r.push_back(s[s.size() - 1 - i]);
	}
	if (l != r) {
		cout << "No" << endl;
		return 0;
	}
	rep(i, mid/2) {
		if (l[i] != l[mid -1 - i]) {
			cout << "No" << endl;
			return 0;
		}
		if (r[i] != r[mid - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int n,k;double out=0.0;
	cin>>n>>k;
	REP(i,1,n+1){
		double f=1.0/n;
		int x=i;
		while(x<k){
			x*=2;f/=2;
		}
		out+=f;
	}
	printf("%.12f\n",out);
}


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

int main(void){
  string x[1000];
  int i = 0;
  while(1){
	cin >> x[i];
	if(x[i] == "0"){
	  break;
	}
	i++;
  }
  int sum[i];
  int sumApp = 0;
  int sumSelect = 0;
  for(int k = 0; k < i; k++){
	for(int j = 0; j < x[k].length(); j++){
	  sumSelect = x[k][j] - '0';
	  sumApp += sumSelect;
	}
	sum[k] = sumApp;
	sumApp = 0;
  }

  for(int k = 0; k < i; k++){
	cout << sum[k] << endl;
  }

  return 0;
}
  



Measured memory_bytes: 3164
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1000005
using namespace std;
typedef long long LL;
char s[N];
int dp[N][2];
int main()
{
	scanf("%s",s+1);
	dp[0][1]=1;
	for(int i=1;s[i];i++)
	{
		int d=s[i]-'0';
		dp[i][0]=min(dp[i-1][0]+d,dp[i-1][1]+10-d);
		dp[i][1]=min(dp[i-1][0]+d+1,dp[i-1][1]+9-d);
		if(d==9)dp[i][1]=dp[i-1][1];
	}
	printf("%d\n",dp[strlen(s+1)][0]);
	return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#define rep(i, a, n) for(int i = int(a);i < int(n);++i)
#define repe(i, a, n) for(int i = int(a);i <= int(n);++i)
#define repr(i, a, n) for(int i = int(a);i > int(n);--i)
#define reper(i, a, n) for(int i = int(a);i >= int(n);--i)
#define size(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using namespace std;


int main(){
	int N, M, X;
	int A[110];
	cin >> N >> M >> X;
	rep(i, 0, M) cin >> A[i];

	int a = 0, b = 0;
	rep(i, 0, M)
		if(A[i] < X) a++;
		else b++;

	cout << min(a, b) << endl;

	return 0;
}

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

int main(){
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	double concentration = 0;
	int s_mass = 0;
	int mass =0;
	for(int i = 0; i <= f/(100*a); i++){
		for(int j = 0; j<= f/(100*b); j++){
			if((i*a+j*b)*100>f) break;
			if(i ==0 && j==0) continue;
			for(int k = 0; k<=((e*(i*a+j*b))/c); k++){
				if(((i*a+j*b)*100+k*c) >f) break;
				for(int l=0; l<=((e*(i*a+j*b))/d); l++){
					if((i*a+j*b)*100+ k*c + l*d >f) break;
					if((k*c + l*d)> (i*a+j*b)*e) break;
					double sugar = static_cast<double>(100*(l*d + k*c));
					double v_con = sugar/(l*d + k*c + (i*a+j*b)*100);
					if(concentration < v_con){
						concentration = v_con;
						s_mass = (l*d + k*c);
						mass = (l*d + k*c + (i*a+j*b)*100);
					}
				}
			}
		}
	}
	if(s_mass == 0) mass = 100*a;
	cout << mass << " " << s_mass << endl;
}


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

int main(void) {
  int N, A, B;
  cin >> N >> A >> B;

  if (N * A > B) {
    cout << B << endl;
  } else {
    cout << N * A << endl;
  }
 
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using sc = Scanner;

class Program
{
    static void Main(string[] args)
    {
        var q = new AnswerCollecter<int>();
        while (true)
        {
            int n = sc.NextInt();
            int p = sc.NextInt();
            int yama = p;
            int[] mayers = new int[n];
            if(n == 0)
            {
                q.Answer();
                return;
            }

            for (int i = 0; ; i = (i+1) % n )
            {
                if (yama != 0)
                {
                    yama--;
                    mayers[i]++;
                    if (mayers[i] == p)
                    {
                        q.Enqueue(i);
                        break;
                    }
                }
                else
                {
                    yama = mayers[i];
                    mayers[i] = 0;
                }
            }

        }
    }
}

public class AnswerCollecter<T>
{
    private Queue<T> q;

    public AnswerCollecter()
    {
        q = new Queue<T>();
    }

    public void Enqueue( T item)
    {
        q.Enqueue(item);
    }

    public void Answer()
    {
        while (q.Count != 0)
            Console.WriteLine(q.Dequeue());
    }
}
   
public static class Scanner
{
    public static string[] NextStrArray()
    {
        return Console.ReadLine().Split(' ');
    }

    public static long[] NextLongArray()
    {
        string[] s = NextStrArray();
        long[] a = new long[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = long.Parse(s[i]);
        }
        return a;
    }
    public static int[] NextIntArray()
    {

        string[] s = NextStrArray();
        int[] a = new int[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        return a;
    }
    public static int NextInt()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
        
            tmp += readData;
        }
        return int.Parse(tmp);
    }
    public static double NextDouble()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return double.Parse(tmp);
    }
    public static long NextLong()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return long.Parse(tmp);
    }
    public static double[] NextDoubleArray()
    {

        string[] s = NextStrArray();
        double[] a = new double[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = double.Parse(s[i]);
        }
        return a;
    }
}

Measured memory_bytes: 5964
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    string s,t; cin >> s >> t;
    map<char,char> mps,mpt;
    ll n = s.size();
    rep(i,n){
        if(mps.find(s[i])!=mps.end()){
            if(mps[s[i]] != t[i]){
                puts("No");
                return 0;
            }
        }else{
            mps[s[i]] = t[i];
        }
        if(mpt.find(t[i]) != mpt.end()){
            if(mpt[t[i]] != s[i]){
                puts("No");
                return 0;
            }
        }else{
            mpt[t[i]] = s[i];
        }
    }
    puts("Yes");
}

Measured memory_bytes: 776
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:String = read();

    println!("{}", n.chars().filter(|&x| x=='2').count());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll=long long;

int main(){
    string t;
    int i,j;

    cin>>t;
    for(i=0;i<(int)(t.size());i++){
        if(t[i]=='P'){
            cout<<'P';
            i++;
            if(i<(int)t.size()){
                if(t[i]=='P'){
                    cout<<'P';
                }else{
                    cout<<'D';
                }
            }else{
                return 0;
            }
        }else{
            cout<<'D';
        }
                
    }

    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  int A = a+b;
  int B = c+d;
  if(A>B)cout<<"Left"<<endl;
  else if(A==B)cout<<"Balanced"<<endl;
  else cout<<"Right"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

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

        // 入力
        String s = sc.next();

        // 処理
        String out = "Yes";
        if (s.replace("hi", "").length() != 0){
            out = "No";
        }

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 23124
using System;
using System.Collections.Generic;
using System.Linq;

namespace _2399
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                bool[,] privacy = new bool[n,n + 1];
                for (int i = 0; i < n; i++)
                {
                    int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    for (int j = 1; j <= x[0]; j++)
                    {
                        privacy[i,x[j]] = true;
                    }
                }
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                List<int> ret = new List<int>();
                for (int i = 0; i < n; i++)
                {
                    bool flag = true;
                    for (int j = 1; j <= a[0]; j++)
                    {
                        if (!privacy[i,a[j]]) flag = false;
                    }
                    if (flag) ret.Add(i + 1);
                }
                Console.WriteLine(ret.Count == 1 ? ret[0] : -1);
            }
        }
    }
}


Measured memory_bytes: 10528
#include <stdio.h>
#include <math.h>

int main() {
    char A, B, C, D;
    int a, b, c, d;
    scanf("%c%c%c%c", &A, &B, &C, &D);
    a = A - '0';
    b = B - '0';
    c = C - '0';
    d = D - '0';
    int ans;
    ans = a+b+c+d;
    if (ans == 7) {
        printf("%d+%d+%d+%d=7\n", a, b, c, d);
        return 0;
    }
    ans = a+b+c-d;
    if (ans == 7) {
        printf("%d+%d+%d-%d=7\n", a, b, c, d);
        return 0;
    }
    ans = a+b-c+d;
    if (ans == 7) {
        printf("%d+%d-%d+%d=7\n", a, b, c, d);
        return 0;
    }
    ans = a+b-c-d;
    if (ans == 7) {
        printf("%d+%d-%d-%d=7\n", a, b, c, d);
        return 0;
    }
    ans = a-b+c+d;
    if (ans == 7) {
        printf("%d-%d+%d+%d=7\n", a, b, c, d);
        return 0;
    }
    ans = a-b+c-d;
    if (ans == 7) {
        printf("%d-%d+%d-%d=7\n", a, b, c, d);
        return 0;
    }
    ans = a-b-c+d;
    if (ans == 7) {
        printf("%d-%d-%d+%d=7\n", a, b, c, d);
        return 0;
    }
    ans = a-b-c-d;
    if (ans == 7) {
        printf("%d-%d-%d-%d=7\n", a, b, c, d);
        return 0;
    }
    return 0;
}


Measured memory_bytes: 128
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    x = ni()

    ans = 100
    for i in range(1, 100000000):
        ans = int(ans * 1.01)
        if ans >= x:
            print(i)
            exit()


if __name__ == '__main__':
    main()

Measured memory_bytes: 9732
//#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n, x;
    cin >> n >> x;
    
    int cnt = 0;
    int d = 0;

    v_int l(n);
    cin >> l;

    irep(i, n+1) {
        if(d > x) {
            break;
        } else {
            cnt++;
        }
        d = d + l[i];
    }
    cout << cnt << endl;
    return 0;
} /*atcoder*/


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  vector<ll> B(N);
  for (int i=0; i<N; i++) B[i] = A[i]-i-1;
  ll b;
  sort(B.begin(), B.end());
  if (N%2!=0) b = B[(N+1)/2-1];
  else if ((B[N/2-1]+B[N/2])%2==0) b = (B[N/2-1]+B[N/2])/2;
  else b= B[N/2-1];
  ll res = 0;
  for (int i=0; i<N; i++) res += abs(B[i]-b);
  cout << res << endl;
  return 0;
}

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

int main() {
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  if(H%h==0&&W%w==0)cout<<"No"<<endl;
  else{
    cout<<"Yes"<<endl;
    if(H%h!=0){
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          if(i%h==h-1)cout<<-1-1000*(h-1);
          else cout<<1000;
          if(j!=W-1)cout<<' ';
          else cout<<endl;
        }
      }
    }
    else{
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          if(j%w==w-1)cout<<-1-1000*(w-1);
          else cout<<1000;
          if(j!=W-1)cout<<' ';
          else cout<<endl;
        }
      }
    }
  }
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  int A, B;
  std::cin >> A >> B;
  if (A > 12) {
    std::cout << B << '\n';
  } else if (A > 5) {
    std::cout << B / 2 << '\n';
  } else {
    std::cout << 0 << '\n';
  }
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <cmath>

using namespace std;

int main(){
	int n;
	double x[100] = {0},y[100] = {0},p_1 = 0,p_2 = 0,p_3 = 0,p_infinity = -1;
	scanf("%d",&n);
	for(int i = 0; i < n; i++) scanf("%lf",&x[i]);
	for(int i = 0; i < n; i++) scanf("%lf",&y[i]);

	for(int i = 0; i < n; i++){
		p_1 += abs(x[i] - y[i]);
		p_2 += (x[i] - y[i])*(x[i] - y[i]);
		p_3 += abs((x[i] - y[i])*(x[i] - y[i])*(x[i] - y[i]));
		p_infinity = (p_infinity >= abs(x[i] - y[i]))? p_infinity:abs(x[i] - y[i]);
 	}
	printf("%.6lf\n",p_1);
	printf("%.6lf\n",sqrt(p_2));
	printf("%.6f\n",cbrt(p_3));
	printf("%.6lf\n",p_infinity);

}



Measured memory_bytes: 2864
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <deque>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i) = 0; (i) <= (n); (i)++)
using namespace std;

int K;
int flg[100000];

signed main()
{
	cin >> K;

	deque<int> q;

	q.push_front(1);
	flg[1] = 1;

	REP(i, K) flg[i] = INT_MAX;

	int len = 1;

	while (q.size() > 0)
	{
		int count = q.size();
		queue<int> qq;
		for (int i = 0; i < count; i++)
		{
			int a = q.front();
			q.pop_front();

			int next = (a * 10) % K;
			if (len < flg[next])
			{
				flg[next] = len;
				q.push_front(next);
				i--;
			}

			if ((a % 10) < 9)
			{
				int next = (a + 1) % K;
				if ((len + 1) < flg[next])
				{
					flg[next] = len + 1;
					q.push_back(next);
				}
			}
		}

		len++;
	}

	cout << flg[0] << endl;
}

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

typedef long long ll;
#define pii pair<ll , ll>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 200005


int main()
{
    _FastIO;
    int n , k;
    cin >> n >> k;
    if(n * 500 >= k)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdlib.h>
#include<stdio.h>
int main()
{ 
  int n;
  scanf("%d",&n);
  char a[n],b[n],c[n];
  scanf("%s",a);
  scanf("%s",b);
  scanf("%s",c);
  int count=0;
  for(int i=0;i<n;i++)
  {
    if(a[i]==b[i] && b[i]==c[i])
      continue;
    else if(a[i]==b[i] ||b[i]==c[i] || a[i]==c[i])
      count++;
    else
      count = count + 2;
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    int dpl[n + 1], dpr[n + 1];
    dpl[0] = 0;
    dpr[0] = 0;
    int last = -10000000;
    for (int i = 1; i <= n; ++i) {
        if (s[i - 1] == 'x') dpl[i] = dpl[i - 1];
        else if (last + c < i) {
            last = i;
            dpl[i] = dpl[i - 1] + 1;
        }
        else dpl[i] = dpl[i - 1];
    }
    last = -10000000;
    for (int i = 1; i <= n; ++i) {
        if (s[n - i] == 'x') dpr[i] = dpr[i - 1];
        else if (last + c < i) {
            last = i;
            dpr[i] = dpr[i - 1] + 1;
        }
        else dpr[i] = dpr[i - 1];
    }
    //for (int i = 0; i <= n; ++i) cout << dpr[i] << " ";
    for (int i = 0; i < n; ++i) {
        int left = i;
        int right = n - i - 1;
        if (s[i] == 'o' && dpl[left] + dpr[right] < k && dpl[left] + dpr[right] + 1 >= k) cout << i + 1 << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<pair<long long, long long>> vec(N);
  for (int i = 0; i < N; i++)
  {
    long long A, B;
    cin >> A >> B;
    vec[i] = {A, B};
  }
  sort(vec.begin(), vec.end());
  long long ans = 0, sum = 0, m = 0;
  for (int i = 0; i < N; i++)
  {
    m = min(m, sum - vec[i].first);
    sum += vec[i].second;
    ans = max(ans, sum - vec[i].first - m);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 10760
import math

A, B, N= (int(x) for x in input().split())
#x = B * math.floor(N/B) - 1
x =  B - 1
if N < B:
    x = N
a = math.floor(A * x / B) - A * math.floor(x / B)
# b = math.floor(A * N / B) - A * math.floor(N / B)
print(a)

Measured memory_bytes: 9160
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
	srand((unsigned int)time(NULL));
	while(1)
	{
		int n,m,h,k;
		int sum=0,gen=0;
		int p[1005];
		int pos[1005],rev[1005];
		vector<int>edge[1005];
		vector<int>le,ri;
		scanf("%d %d %d %d",&n,&m,&h,&k);
		if(!n) return 0;
		for(int i=1;i<=n;i++)
		{
			pos[i]=i;
			scanf("%d",&p[i]);
		}
		for(int i=0;i<m;i++)
		{
			int a,b; scanf("%d%d",&a,&b);
			edge[b].pb(a);
		}
		for(int i=1;i<=h-1;i++)
		{
			for(int j=0;j<edge[i].size();j++)
			{
				le.pb(pos[edge[i][j]]);
				ri.pb(pos[edge[i][j]+1]);
				swap(pos[edge[i][j]],pos[edge[i][j]+1]);
			}
		}
		for(int i=1;i<=n;i++)
		{
			rev[pos[i]]=i;
		}
		for(int i=1;i<=k;i++)
		{
			sum+=p[rev[i]];
		}
		for(int i=0;i<le.size();i++)
		{
			int id1=le[i];
			int id2=ri[i];
			if(id1<=k&&id2>k)
			{
				gen=max(gen,p[rev[id1]]-p[rev[id2]]);
			}
			if(id2<=k&&id1>k)
			{
				gen=max(gen,p[rev[id2]]-p[rev[id1]]);
			}
		}
		printf("%d\n",sum-gen);
	}
}

Measured memory_bytes: 2760
#include<stdio.h>

int main(){
   int x[100];
   int n;
   scanf("%d", &n);
   
   for(int i = 0; i < n; i++){
      scanf("%d", &x[i]);
   }
   for(int i = 0; i < n; i++){
      if(x[i] % 2 == 0 && x[i] % 3 != 0 && x[i] % 5 != 0){
         printf("DENIED\n");
         return 0;
      }
   }
   printf("APPROVED\n");

   return 0;
}


Measured memory_bytes: 1616
N = int(input())
S = [sorted(str(input())) for _ in range(N)]
S.sort()

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

L = []
c = 1
for i in range(N):
    if i == 0:
        pass
    else:
        if S[i-1]==S[i]:
            c += 1
            if i == N-1:
                L.append(c)
        else:
            if c >= 2:
                L.append(c)
            c = 1
res = 0
for x in L:
    res += cmb(x,2)
print(res)

Measured memory_bytes: 102232
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

int ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}

const int N=100100;
ll cnt=0,all,sc;
ll a[N],b[N],s[N];

int main()
{
	int n;
	read(n);
	for (int i=1;i<=n;i++) read(a[i]),sc+=a[i];
	for (int i=1;i<=n;i++) read(b[i]),sc-=b[i];
	if (sc<0) return puts("-1"),0;
	for (int i=1;i<=n;i++)
	{
		if (a[i]<b[i]) all+=b[i]-a[i],ans++;
		if (a[i]>b[i]) s[++cnt]=a[i]-b[i];
	}
	sort(s+1,s+cnt+1);
	while (cnt&&all)
	{
		if (s[cnt]<all) all-=s[cnt],ans++,cnt--;
		else ans++,all=0;
	}
	cout<<ans;
	return 0;
}









Measured memory_bytes: 6784
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

l = list(itertools.permutations(range(1,N+1)))
tp = tuple(P)
tq = tuple(Q)
tpi = l.index(tp)
tqi = l.index(tq)
print(abs(tpi-tqi))

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

void solve(){
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  string ans="Yes";
  if(s[a]!='-') ans = "No";
  rep(i,a){
      char c = s[i];
      int tmp = c-'0';
      if(!(0<=tmp&&tmp<=9)) ans = "No"; 
  }
  rep(i,b){
      char c = s[a+1+i];
      int tmp = c-'0';
      if(!(0<=tmp&&tmp<=9)) ans = "No"; 
  }

  cout << ans << endl;
}

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

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int r = sc.nextInt();
        int D = sc.nextInt();
        int x = sc.nextInt();

        for(int i = 0;i<10;i++){
          x = r*x -D;
          System.out.println(x);
        }

    }
}


Measured memory_bytes: 23124
/*
   О НЕТ! ОНИ ДОГОНЯЮТ!!!
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 300 + 1;

int d[N][N];
int pr[N];

int get(int v)
{
    if (v == pr[v])
    {
        return v;
    }
    else
    {
        return pr[v] = get(pr[v]);
    }
}

void uni(int u, int v)
{
    pr[get(u)] = get(v);
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int x;
            scanf("%d", &x);
            d[i][j] = x;
        }
    }
    vector <pair <int, pair <int, int> > > e;
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            int best = 2e9 + 7;
            for (int k = 0; k < n; k++)
            {
                if (k != i && k != j)
                {
                    best = min(best, d[i][k] + d[k][j]);
                }
            }
            if (d[i][j] == best)
            {
                e.push_back({d[i][j], {i, j}});
            }
            else if (d[i][j] < best)
            {
                uni(i, j);
                ans += d[i][j];
            }
            else
            {
                cout << -1 << '\n';
                return 0;
            }
        }
    }
    sort(e.begin(), e.end());
    for (auto c : e)
    {
        int u = c.second.first, v = c.second.second;
        if (get(u) != get(v))
        {
            ans += c.first;
        }
    }
    printf("%lld\n", ans);
}


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

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

#define fr first
#define sc second

ll S(ll n){
	ll ret=0;
	while(n>0){
		ret+=n%10;
		n/=10;
	}
	return ret;
}

int main(){
	ll k;
	cin>>k;
	
	ll POW[16];
	POW[0]=1;
	for(int i=1;i<16;i++){
		POW[i]=POW[i-1]*10;
	}
	
	vector<ll> ret;
	for(int d=0;d<=15;d++){
		ll B=9*d-1;
		if(d==0)B=0;
		for(int a=0;a<=min(9*(ll)d+200,POW[15-d]);a++){
			if(a%10==9)continue;
			if(a-S(a)<=B)ret.push_back(a*POW[d]+POW[d]-1);
		}
	}
	//cout<<ret.size()<<endl;
	sort(ret.begin(),ret.end());
	for(int i=1;i<=k;i++){
		printf("%lld\n",ret[i]);
		//cout<<ret[i]<<" "<<S(ret[i])/(ld)(ret[i])<<endl;
	}
}



Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int n;
  cin >> n;
  vector<int64_t> sum(n+1, 0);
  reps(i,1,n+1) {
    int64_t a;
    cin >> a;
    sum[i] = sum[i-1] + a;
  }

  int64_t res = inf64;
  reps(i,1,n) {
    res = min(res, abs(sum[n]-sum[i]-sum[i]));
  }
  cout << res << endl;
  return 0;
}

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

int main() {
	int c[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++)cin >> c[i][j];
	}

	int a[3] = {}, b[3] = {};
	a[0] = 0;
	for (int i = 0; i < 3; i++) {
		if(i)a[i] = c[i][0] - b[0];
		b[i] = c[i][i] - a[i];
	}

	bool match = true;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (c[i][j] != a[i] + b[j])match = false;
		}
	}
	cout << (match ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  ll x, y; cin >> x >> y;
  int cnt = abs(abs(x) - abs(y));

  if (x==0 || y==0) {
    if (y<x) {
      cnt++;
    }
    cout << cnt << endl;
    return 0;
  }

  if (x*y>0) {
    if (y<x) {
      cnt+=2;
    }
  } else {
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#累積和　都度sum（O(n)）を取っていると，O(n^2)になってしまう
import itertools
 
n, k = map(int, input().split())
p = list(map(int, input().split()))
acc = [0] + list(itertools.accumulate([(x+1)/2 for x in p])) 
 
ans = max(acc[i+k]-acc[i] for i in range(n-k+1)) 
print(ans)

Measured memory_bytes: 25148
import Data.List

main = do
    getLine
    s <- getLine
    print . minimum $ zipWith (\p q -> snd p + fst q) (scanl ew (0,0) s) (tail (scanr (flip ew) (0,0) s))
    
ew (e,w) h | h == 'E' = (e+1,w)
           | h == 'W' = (e,w+1)

Measured memory_bytes: 84348
from collections import deque

H, W = 2, 2
N = 3
ARR = [2, 1, 1]

H, W = 3, 5
N = 5
ARR = [1, 2, 3, 4, 5]

H, W = 1, 1
N = 1
ARR = [1]

H, W = map(int, input().split())
N = int(input())
ARR = list(map(int,input().split()))

def calculate(h, w, n, arr):
    resources = deque()

    for index, ar in enumerate(arr):
        for m in range(ar):
            resources.append((index + 1))

    nodeStatus = [[False for i in range(w)] for j in range(h)]
    for j in range(h):
        if j % 2 == 0:
            startIndex = 0
            for i in range(startIndex, w, 1):
                nodeStatus[j][i] = str(resources.popleft())
        else:
            startIndex = w - 1
            for i in range(startIndex, -1, -1):
                nodeStatus[j][i] = str(resources.popleft())

    for j in range(h):
        print(" ".join(nodeStatus[j]))


calculate(H, W, N, ARR)


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
    ll res_suwa = 0,res_su = 0;
    double rate = 0.0;
    rep(i,31){ //100*a*i
        rep(j,31){ //100*b*j
            for(int k=0;k<= f/c;k++){ //c*k
                for(int l=0;l<=f/d;l++){ //d*l
                    ll wa = 100*(a*i+b*j);
                    ll su = c*k + d*l;
                    if(wa+su > f)continue;
                    if(su*1.0/(wa+su) > e*1.0/(100+e))continue;
                    if(rate > su*1.0/(wa+su))continue;
                    rate = su*1.0/(wa+su);
                    res_suwa = su+wa;
                    res_su = su;
                }
            }
        }
    }
    if(rate == 0.0){
        cout << 100*a << " " << 0 << endl;
        return 0;
    }
    cout << res_suwa << " " << res_su << endl;
}



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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

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; }

int main()
{
    ll n, k;
    cin >> n >> k;
    vector <ll> a(n), ans(n+k, inf);
    for (int i = 0; i < n; i++) cin >> a[i];

    ans[0] = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            chmin(ans[i+j], ans[i] + abs(a[i] - a[i+j]));
        }
    }
    cout << ans[n-1] << endl;
    return 0;
}



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

int main(){
  int N, K;
  cin >> N >> K;
/*
  vector<char> S(N);
  for(int i = 0; i < N; i++)
    cin >> S.at(i);
*/


  
  cout << N-K+1 << endl;
}

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

#define INF 1000000000

bool isbingo(vector<vector<int>> r){
    if(r[0][0]*r[0][1]*r[0][2] == 1) return true;
    if(r[1][0]*r[1][1]*r[1][2] == 1) return true;
    if(r[2][0]*r[2][1]*r[2][2] == 1) return true;
    if(r[0][0]*r[1][0]*r[2][0] == 1) return true;
    if(r[0][1]*r[1][1]*r[2][1] == 1) return true;
    if(r[0][2]*r[1][2]*r[2][2] == 1) return true;
    if(r[0][0]*r[1][1]*r[2][2] == 1) return true;
    if(r[2][0]*r[1][1]*r[0][2] == 1) return true;
    return false;
}

int main(){
    vector<vector<int>> A(3,vector<int>(3));
    vector<vector<int>> result(3,vector<int>(3,0));
    for(int i=0;i<3;i++){for(int j=0;j<3;j++) cin >> A[i][j];}
    int N; cin >> N;

    for(int n=0;n<N;n++){
        int b; cin >> b;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(b == A[i][j]){result[i][j] = 1;}
            }
        }
    }

    //for(int i=0;i<3;i++){for(int j=0;j<3;j++){cout << result[i][j] << endl;}}
    if(isbingo(result)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256