akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> S;
  ;
}
void solve() {
  bool ans = true;
  rep(i, 0, S.size() - 1) {
    if (i % 2 == 0) {
      if (S[i] == 'L') {
        ans = false;
      }
    } else {
      if (S[i] == 'R') {
        ans = false;
      }
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		int N=nextInt();
		int A=N/1000;
		if(N%1000==0)
			System.out.println(0);
		else
			System.out.println((A+1)*1000-N);
	}
	static boolean isOK(int index,int key,ArrayList<Integer>a){
		if (a.get(index) >= key) return true;
	    else return false;
	}
	static int binary_search(int key,ArrayList<Integer> a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;

	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}



Measured memory_bytes: 32572
#[cfg(test)]
#[macro_use]
extern crate contest;

use std::fmt::Debug;
use std::io::{self, Bytes, Read, Stdin, StdinLock};
use std::str::{self, FromStr};

fn main() {
    let stdin = io::stdin();
    let mut sc = StdinScanner::new(&stdin);
    let n = sc.next();
    println!("{}", solve(sc.vec(n)));
}


fn solve(a: Vec<u32>) -> u32 {
    let max = a.iter().max().unwrap();
    let min = a.iter().min().unwrap();
    max - min
}


#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        assert_eq_in_time!(1000, "", "");
    }
}


struct StdinScanner<'a> {
    buf: Vec<u8>,
    bytes: Bytes<StdinLock<'a>>,
}


#[allow(dead_code)]
impl<'a> StdinScanner<'a> {
    fn new(stdin: &'a Stdin) -> Self {
        StdinScanner {
            buf: Vec::with_capacity(256),
            bytes: stdin.lock().bytes(),
        }
    }

    fn next<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut c = self.bytes.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = self.bytes.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = self.bytes.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug,
              <C as FromStr>::Err: Debug
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


trait PrintYn {
    fn print_yn(self, yes: &str, no: &str);
}

impl PrintYn for bool {
    fn print_yn(self, yes: &str, no: &str) {
        println!("{}", if self { yes } else { no });
    }
}


Measured memory_bytes: 4352
N, M = map(int, input().split())
A = input().split()
list_a = [int(n) for n in A]
count = 0

waru = 4 * M
SUM = sum(list_a)
vote = SUM / waru

for i in range(0, N):
    if list_a[i] >= vote:
        count += 1
    else:
        pass

if count >= M:
    print("Yes")
else:
    print("No")


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

int selectionSort(vector<int> &a, int n) {
  int sw = 0;
  for (int i = 0; i < n - 1; i++) {
    int minj = i;

    for (int j = i + 1; j < n; j++) {
      if (a.at(minj) > a.at(j)) {
        minj = j;
      }
    }
    swap(a.at(minj), a.at(i));
    if (i != minj) sw++;
  }
  return sw;
}

int main() {
  int n, sw;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);

  sw = selectionSort(a, n);

  for (int i = 0; i < n; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << a.at(i);
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}


Measured memory_bytes: 3080
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        if (N % 2 == 0)
        {
            WriteLine(N);
        }
        else
        {
            WriteLine(N * 2);
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}                               

Measured memory_bytes: 13140
N, A, B, K = tuple(map(int, (input().split())))
mod = 998244353

factorial = [1 for i in range(N + 1)]
inverse = [1 for i in range(N + 1)]
for i in range(1, N + 1):
    factorial[i] = (factorial[i - 1] * i) % mod
    inverse[i] = inverse[i - 1] * pow(i, mod - 2, mod) % mod

com = [1 for i in range(N + 1)]
for i in range(1, N + 1):
    com[i] = (factorial[N] * inverse[i] % mod) * inverse[N - i] % mod

ans = 0
for x in range(N + 1):
    d = K - A * x
    if 0 <= d and d % B == 0:
        y = d // B
        if y <= N:
            ans += com[x] * com[y]
print(ans % mod)

Measured memory_bytes: 38852
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;


int res[500][500];
int main(){
    int n;
    cin >> n;
    int i = 0;
    for(; i <= n; i++){
        int j = n - i;
        if(i >= j){
          cout << i - 1;
          return 0;
        }
    }
    cout << i;
}

Measured memory_bytes: 256
#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 n,m; cin >> n >> m;
  vpii p;
  rep(i,n){
    int a,b; cin >> a >> b;
    p.push_back({a,b});
  }
  sort(all(p));
  ll res = 0;
  int idx = 0;
  priority_queue<pair<int,int> > que; //降順
  for(int i = 1;i<=m;i++){ //後ろから考える
    while(1){ 
      if(idx >= n)break;
      if(p[idx].first <= i){
        que.push({p[idx].second,p[idx++].first});
      }
      else break;
    }
    if(que.empty() == false){
      res += que.top().first;
      que.pop();
    }
  }

  out(res);
}

Measured memory_bytes: 2548
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<ull> vul;
typedef vector<pair<ll, ll>> vpl;
typedef pair<ll, ll> pl;
#define For(i, n) for(ll i = 0; i < n; i++)
#define len(n) (ll)(n).size()
#define Sort(a) sort(a.begin(), a.end())
ll dp[100010];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	vl h(n + 2);
	For(i, n) {
		cin >> h[i];
		dp[i] = 1e12;
	}
	h[n] = 0;
	h[n + 1] = 0;
	dp[0] = 0;
	For(i, n) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 4716
#include<iostream>
#include<string>
#include<vector>
using ll = unsigned long long;
using namespace std;


int main(void) {
    int a,b,c,d;
    cin >> a  >>b  >>c  >>d;

    int beg, end;

    if (b < c || d < a) {
            cout << 0 << endl;
            return 0;
    }

    if (a > c) {
        beg = a;
    } else {
        beg = c;
    }

    if (b > d) {
        end =d; 
    } else {
        end = b;
    }

    int out = end - beg;

    cout << out << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
int main(void)
{
    ios::sync_with_stdio(false);
    map<string,int> mp;
    int n;
    char ch[10];
    while(cin>>n)
    {
        for(int i=0;i<n;++i)
        cin>>ch,mp[ch]++;
        printf("AC x %d\n",mp["AC"]);
        printf("WA x %d\n",mp["WA"]);
        printf("TLE x %d\n",mp["TLE"]);    
        printf("RE x %d\n",mp["RE"]);
    }
    return 0;
} 

Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

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

    rep2(i,n,1000)
    {
        int d[3];
        int tmp = i;
        rep(j,3)
        {
            d[j] = tmp/pow(10,2-j);
            tmp = tmp - d[j]*pow(10,2-j);
        }
        if(d[0] == d[1] && d[1] == d[2])
        {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
use proconio::input;
use std::collections::HashMap;

struct Iwashi {
    a:i64,
    b:i64,
}

const MOD:i64 = 1e9 as i64 + 7;
fn main() {
    let (n,iwashi) = {
        input! {
            n:usize,
            ab:[(i64,i64);n],
        }; 
        let iwashi:Vec<Iwashi> = ab.into_iter().map(|(a,b)|Iwashi{a,b}).collect();
        (n,iwashi)
    };
    
    
    let iwashi:Vec<Iwashi> = iwashi.into_iter().filter(|iwa|iwa.a!=0 || iwa.b!=0).collect();
    let zcnt = (n - iwashi.len()) as i64;

    let iwashi:Vec<Iwashi> = iwashi.into_iter().map(|iwa|{
        let g = num::integer::gcd(iwa.a,iwa.b);
        let a = iwa.a/g;
        let b = iwa.b/g;
        Iwashi{a,b}
    }).collect();

    let ps:Vec<(i64,i64)> = iwashi.iter().map(|iwa|(iwa.a,iwa.b)).collect();
    let mut iwadic = HashMap::new();

    iwashi.iter().for_each(|iwa|{
        let count = iwadic.entry((iwa.a,iwa.b)).or_insert(0);
        *count += 1;
    });

    let mut res:i64 = 1;
    let mut pow2:Vec<i64> = vec![1;n+1];
    for i in 0..n {
        pow2[i+1]=pow2[i]*2%MOD;
    }
    for (a,b) in ps {
        let key0 = (a,b);
        let key1 = (-a,-b);
        let key2 = (-b,a);
        let key3 = (b,-a);
        let keys = vec![key0,key1,key2,key3];
        let mut sum0 = 0;
        let mut sum2 = 0;
        for i in 0..4 {
            if let Some(val) = iwadic.get(&keys[i]) {
                if i<2 {
                    sum0+=*val;    
                }
                else {
                    sum2+=*val;
                }
                iwadic.remove(&keys[i]);
            }
        }
        let sum = (pow2[sum0 as usize] + pow2[sum2 as usize] -1)%MOD;
        res*=sum;
        res%=MOD;
    }
    
    res-=1;
    let ans = ((res+zcnt)%MOD+MOD)%MOD;
    println!("{}",ans);
}


Measured memory_bytes: 28552
/*
 * main.c
 *
 *  Created on: 2020/07/27
 *      Author: 113896
 */
#include <stdio.h>

int max(int x, int y) {
	if (x > y) return x;
	else return y;
}

int main() {

	int m, f, r, score;
	while (1) {
		scanf("%d%d%d", &m, &f, &r);
		if (m == -1 && f == -1 && r == -1) break;
		if (m == -1 || f == -1) {
			printf("F\n");
		} else {
			score = max(0, m) + max(0, f);
			if (score >= 80) {
				printf("A\n");
			} else if (score >= 65) {
				printf("B\n");
			} else if (score >= 50) {
				printf("C\n");
			} else if (score >= 30) {
				if (r >= 50) {
					printf("C\n");
				} else {
					printf("D\n");
				}
			} else {
				printf("F\n");
			}
		}
	}

	return 0;
}




Measured memory_bytes: 2124
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MOD 1000000007LL;

int A[100010]={0}, B[200010]={0}, E, flag, N;
long long C, P;

int check1(void) {
	int i;
	if (flag) {
		for (i=0;i<N;i++) if (A[i]%2) return 1;
	} else {
		for (i=0;i<N;i++) if (!(A[i]%2)) return 1;
	}
	return 0;
}

int check2(void) {
	int i;
	for (i=0;i<N;i++) B[A[i]]++;
	if (flag) {
		if (B[0] != 1) return 1;
		else for (i=2;i<N;i+=2) if (B[i] != 2) return 1;
	} else {
		for (i=1;i<N;i+=2) if (B[i] != 2) return 1;
	}

	C = 1LL;
	P = 2LL;
	E = N/2;
	while (E) {
		if (E & 1) {
			C *= P;
			C %= MOD;
		}
		P *= P;
		P %= MOD;
		E >>= 1;
	}
	return 0;
}

int main(void) {
	int i;
	scanf("%d", &N);
	for (i=0;i<N;i++) scanf("%d", &A[i]);
	if (N%2) flag = 1; else flag = 0;
	if (!check1() && !check2()) {
		printf("%lld\n", C);
	} else {
		printf("0\n");
	}

	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
using namespace std;
int maxnum(int x,int y);
int minnum(int x,int y);
int sl(char s[]);
int main(){
    const char code[27] = {"XYZABCDEFGHIJKLMNOPQRSTUVW"};
    char sen[1010] = {0};
    char csen[1010] = {0};
    cin >> sen;
    int len = sl(sen);
    for(int i = 0;i < len;i++){
        csen[i] = code[sen[i]-65];
    }
    cout << csen << endl;
    return 0;
}

int maxnum(int x,int y){
    if(x >= y){
        return x;
    }
    else{
        return y;
    }
}

int minnum(int x,int y){
    if(x <= y){
        return x;
    }
    else{
        return y;
    }
}

int sl(char s[]){
    int len = 0;
    while(1){
        if(s[len] == 0){
            break;
        }
        len++;
    }
    return len;
}

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

using namespace std;

int main(){
    char X, Y; cin >> X >> Y;

    if(X < Y){
        cout << '<' << endl;
    }else if(X > Y){
        cout << '>' << endl;
    }else{
        cout << '=' << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
            if (op.equals("?")) {
                return;
            } else if (op.equals("+")) {
                System.out.println(a + b);
            } else if (op.equals("-")) {
                System.out.println(a - b);
            } else if (op.equals("*")) {
                System.out.println(a * b);
            } else if (op.equals("/")) {
                System.out.println(a / b);
            }
        }
    }
}

Measured memory_bytes: 26260
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main() {
    int r,c;
    int m=1e9+7;
    cin>>r>>c;
    int i,j;
    char a[r][c];
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            cin>>a[i][j];
        }
    }
    int ans[r][c];
    for(i=0;i<r;i++)
    {
        if(a[i][0]!='#')
        {
        ans[i][0]=1;
        }
        else
        break;
    }
    for(i;i<r;i++)
    ans[i][0]=0;
    for(i=0;i<c;i++)
    {
      if(a[0][i]!='#')
      ans[0][i]=1;
      else
      break;
    }
    for(i;i<c;i++)
    ans[0][i]=0;
    for(i=1;i<r;i++)
    {
        for(j=1;j<c;j++)
        {
            if(a[i][j]=='#')
            ans[i][j]=0;
            else
            {
                ans[i][j]=(ans[i-1][j]%m+ans[i][j-1]%m)%m;
            }
        }
    }
    cout<<ans[r-1][c-1];
    
    
    
	return 0;
}

Measured memory_bytes: 8428
#include <stdio.h>
int main(){

  int r,c,sheet[100][100],i,j,frontsum=0,backsum=0,lastsum=0;

  //input
  
  scanf("%d %d",&r,&c);

  for(i = 0; i < r; i++){

    for(j = 0; j < c; j++){

      scanf("%d",&sheet[i][j]);

    }

  }

  //front output

  for(i = 0; i < r; i++){

    for(j = 0; j < c; j++){

      printf("%d ",sheet[i][j]);

      frontsum += sheet[i][j];

    }
    
    printf("%d\n",frontsum);

    frontsum = 0;

  }

  //back output

  for(j = 0; j < c; j++){

    for(i = 0; i < r; i++){

      backsum += sheet[i][j];

    }

    printf("%d ",backsum);

    lastsum += backsum;

    backsum=0;

  }

  //last out put

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

  return 0;

}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int D,A=26;
  scanf("%d",&D);
  vector<int> C(A);
  for(int i=0;i<A;i++){
    scanf("%d",&C[i]);
  }
  vector<vector<int>> S(D,vector<int>(A));
  for(int i=0;i<D;i++){
    for(int j=0;j<A;j++){
      scanf("%d",&S[i][j]);
    }
  }
  vector<int> X(A,0);
  vector<int> XX(A,0);
  vector<vector<pair<int,int>>> Q(D,vector<pair<int,int>>(A));
  for(int i=0;i<D;i++){
    for(int j=0;j<A;j++){
      X[j]+=C[j];
      XX[j]+=X[j];
      Q[i][j]=make_pair(-S[i][j]-X[j],j);
    }
    sort(Q[i].begin(),Q[i].end());
    XX[Q[i][0].second]-=X[Q[i][0].second];
    X[Q[i][0].second]=0;
  }
  vector<vector<int>> P(D,vector<int>(A));
  for(int i=0;i<D;i++){
    for(int j=0;j<A;j++){
      P[i][j]=Q[i][j].second;
    }
  }
  int SC=0,SC2;
  for(int i=0;i<D;i++){
    SC+=S[i][P[i][0]];
  }
  vector<int> Y;
  vector<int> YY;
  int Z;
  int SX,SY;
  int z=-1;
  for(int l=0;l<64;l++){
    for(int k=0;k<25;k++){
      while(k==z){
        k=rand()%25;
      }
      z=k;
      for(int i=0;i<D;i++){
        SC2=SC;
        YY=XX;
        Y=X;
        SC2-=S[i][P[i][0]];
        SC2+=S[i][P[i][k+1]];
        for(int j=0;j<A;j++){
          Y[j]=0;
        }
        YY[P[i][0]]=0;
        YY[P[i][k+1]]=0;
        for(int j=0;j<D;j++){
          if(i==j){
            Z=P[j][k+1];
          }else{
            Z=P[j][0];
          }
          Y[P[i][0]]+=C[P[i][0]];
          Y[P[i][k+1]]+=C[P[i][k+1]];
          Y[Z]=0;
          YY[P[i][0]]+=Y[P[i][0]];
          YY[P[i][k+1]]+=Y[P[i][k+1]];
        }
        SX=0;
        SY=0;
        for(int j=0;j<A;j++){
          SX+=XX[j];
          SY+=YY[j];
        }if((SC2-SY+(rand()%3000))>(SC-SX)){
          P[i].insert(P[i].begin(),P[i][k+1]);
          P[i].erase(P[i].begin()+k+2,P[i].begin()+k+3);
          XX=YY;
          SC=SC2;
        }
      }
    }
  }
  for(int l=0;l<64;l++){
    for(int k=0;k<25;k++){
      while(k==z){
        k=rand()%25;
      }
      z=k;
      for(int i=0;i<D;i++){
        SC2=SC;
        YY=XX;
        Y=X;
        SC2-=S[i][P[i][0]];
        SC2+=S[i][P[i][k+1]];
        for(int j=0;j<A;j++){
          Y[j]=0;
        }
        YY[P[i][0]]=0;
        YY[P[i][k+1]]=0;
        for(int j=0;j<D;j++){
          if(i==j){
            Z=P[j][k+1];
          }else{
            Z=P[j][0];
          }
          Y[P[i][0]]+=C[P[i][0]];
          Y[P[i][k+1]]+=C[P[i][k+1]];
          Y[Z]=0;
          YY[P[i][0]]+=Y[P[i][0]];
          YY[P[i][k+1]]+=Y[P[i][k+1]];
        }
        SX=0;
        SY=0;
        for(int j=0;j<A;j++){
          SX+=XX[j];
          SY+=YY[j];
        }if((SC2-SY+(rand()%3000))>(SC-SX)){
          P[i].insert(P[i].begin(),P[i][k+1]);
          P[i].erase(P[i].begin()+k+2,P[i].begin()+k+3);
          XX=YY;
          SC=SC2;
        }
      }
    }
  }
  /*
  int uku=0;
  for(int i=0;i<A;i++){
    X[i]=0;
  }
  for(int i=0;i<D;i++){
    uku+=S[i][P[i][0]];
    for(int j=0;j<A;j++){
      X[j]+=C[j];
    }
    X[P[i][0]]=0;
    SX=0;
    for(int i=0;i<A;i++){
      SX+=X[i];
    }
    uku-=SX;
  }
  cout<<uku<<endl;
  */
  for(int i=0;i<D;i++){
    cout<<P[i][0]+1<<"\n";
  }
}

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

#define dbg(a)	cerr << __LINE__ << ": " << #a << " = " << a << '\n'

int main(){
	string s;	cin >> s;
	if(s[0]=='7' or s[1]=='7' or s[2]=='7')	puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define int long long 
using namespace std;
 
int32_t main()
{
	string a;
	cin>>a;

	if (a[0]==a[1] && a[1]==a[2]){
		cout<<"No\n";
	}
	else{
		cout<<"Yes\n";
	}

}


Measured memory_bytes: 256
S=input()
l=len(S)
for i in range(l-1):
    if S[i]==S[i+1]:
        print(i+1,i+2)
        exit()
for i in range((l+1)//2-1):
    if S[i*2]==S[i*2+2]:
        print(i*2+1,i*2+3)
        exit()
for i in range(l//2-1):
    if S[i*2+1]==S[i*2+3]:
        print(i*2+2,i*2+4)
        exit()
print(-1,-1)


Measured memory_bytes: 3188
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e3+69, INF=2e9+6969;

int qq,ile[R];
vector <int> v[R];

int main()
{
	int n,x,y;
	scanf("%d%d%d", &n, &x, &y);
	for(int i=1;i<n;++i)
	{
		v[i].pb(i+1);
		v[i+1].pb(i);
	}
	v[x].pb(y);
	v[y].pb(x);
	for(int i=1;i<=n;++i)
	{
		queue <pair<int,int>> q {};
		bitset <R> vis;
		vis.reset();
		q.push(mp(i,0));
		vis[i]=1;
		while(!q.empty())
		{
			int cur = q.front().fi;
			int d = q.front().se;
			q.pop();
			for(int  i=0;i<v[cur].size();++i)
			{
				if(!vis[v[cur][i]])
				{
					vis[v[cur][i]]=1;
					ile[d+1]++;
					q.push(mp(v[cur][i],d+1));
				}
			}
		}
	}
	for(int i=1;i<n;++i)
	{
		printf("%d\n", ile[i]/2);
	}
	return 0;
}


Measured memory_bytes: 3980
# abc164_b.py
A,B,C,D = map(int,input().split())
for i in range(10000):
    if i%2 == 1:
        A = A - D
    else:
        C = C - B
    if C <= 0 or A <= 0:
        if A > C:
            print('Yes')
            break
        else:
            print('No')
            break


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int tc; cin>>tc; while(tc--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, l;
    cin>> n>> l;
    bool zero= 0;

    if( l<=0 && l+n>0)
    {
        zero =1;

        if( (-2*l)+1 <n)
        {
            n+= 2*l -1;
            l= 1-l;
        }
    }

    int ans=  l* n+ (n*(n-1))/2;

    if(!zero)
        ans-= (l>=0? l: l+n-1);


    cout << ans<< "\n";

    return 0;
}




Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int max=0;
	int len=LEN(s);
	rep(i,len){
		int tmp=0;
		rep(j,len-i){
			if(s.at(i+j)!='A')
			if(s.at(i+j)!='G')
			if(s.at(i+j)!='C')
			if(s.at(i+j)!='T')break;
			tmp++;
		}
		chmax(max,tmp);
	}
	cout<<max<<endl;
}

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

using namespace std;

#define pb              push_back
#define endl            "\n"
#define sz(x)          (int) (x.size())
#define all(v)          v.begin(), v.end()
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool can(int a, int b, int c){
    vector<int> v = {a, b, c};
    sort(all(v));
    if(v[0] == v[2] || v[0] == v[1] || v[1] == v[2]) return 0;
    return v[0] + v[1] > v[2];
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n; cin >> n;
    int a[n];
    ll c = 0;
    for(auto &i: a) cin >> i;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            for(int k = j + 1; k < n; k++){
                if(can(a[i], a[j], a[k])){
                    c++;
                }
            }
        }
    }
    cout << c;
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
main(){
  int go[3],to[3],gos,tos;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>go[j];
    }
    gos=go[0]*3600+go[1]*60+go[2];
    for(int j=0;j<3;j++){
      cin>>to[j];
    }
    tos=to[0]*3600+to[1]*60+to[2];
    int a,b;
    a=tos-gos;
    b=a/3600;
    cout<<b<<" ";
    a=a-(b*3600);
    b=a/60;
    cout<<b<<" ";
    a=a-(b*60);
    cout<<a<<endl;
  }  
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int x;
    cin >> x;
    cout << x / 3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int w[10], k[10], i, j, stock;

  for(i = 0; i < 10; i++){
    scanf("%d",&w[i]);
  }

  for(i = 0; i < 10; i++){
    scanf("%d",&k[i]);
  }
  

  for(i = 0; i < 3; i++){
    for(j = i; j < 10; j++){
      if(w[i] < w[j]){
	stock = w[i];
	w[i] = w[j];
	w[j] = stock;
      }
    }
  }


  for(i = 0; i < 3; i++){
    for(j = i; j < 10; j++){
      if(k[i] < k[j]){
	stock = k[i];
	k[i] = k[j];
	k[j] = stock;
      }
    }
  }

  printf("%d %d\n",w[0]+w[1]+w[2],k[0]+k[1]+k[2]);


  return 0;

}

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

int main(){
  int D;
  cin>>D;

  vector<int64_t> c(27,0);
  for(int i=1;i<=26;++i) cin>>c[i];

  vector<vector<int64_t>> s(D+1,vector<int64_t>(27,0));
  for(int i=1;i<=D;++i){
    for(int j=1;j<=26;++j){
      cin>>s[i][j];
    }
  }

  vector<int> t(D+1);
  for(int i=1;i<=D;++i) cin>>t[i];

  int64_t score=0;
  vector<vector<int>> last(D+1,vector<int>(27,0));

  for(int i=1;i<=D;++i){
    score += s[i][t[i]];
    for(int j=1;j<=26;++j){
      if(j!=t[i]) last[i][j]=last[i-1][j];
      else last[i][j]=i;
      score -= c[j]*(i-last[i][j]);
    }
    cout<<score<<endl;
  }

}

Measured memory_bytes: 3696
#include<stdio.h>
#include<string.h>
#define min(x, y) ((x) < (y) ? (x) : (y));
int main(){
  int n, i, j, max, field[1004][1004];
  char c;
  while(1){
    memset(field, 0, sizeof(field));
    scanf("%d", &n);
    if(n == 0)return 0;
    for(i = 1; i <= n;i++){
      for(j = 1;j <= n;j++){
	scanf(" %c", &c);
	field[i][j] = field[i - 1][j] + field[i][j - 1] - field[i - 1][j - 1];
	if(c == '*')field[i][j]++;
      }
    }
    max = 0;
    for(i = 0;i < n;i++){
      for(j = 0;j < n;j++){
	int top = min(n - i, n - j);
	int bottom = 0;
	while(top - bottom > 1){
	  int k = (top + bottom) / 2;
	  if(field[i + k][j + k] + field[i][j] - field[i][j + k] - field[i + k][j] == 0)
	    bottom = k;
	  else
	    top = k;
	}
	if(field[i + top][j + top] + field[i][j] - field[i][j + top] - field[i + top][j] == 0)bottom = top;
	if(max < bottom)max = bottom;

      }
    }
    printf("%d\n", max);
  }
}

Measured memory_bytes: 4544
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ll=long long;
ll a[100010];
int main(){ _;
  int n;cin>>n;
  a[0]=0;
  a[n+1]=0;
  ll sum=0;
  REP(i,n){
    cin>>a[i+1];
    sum+=abs(a[i+1]-a[i]);
  }
  sum+=abs(a[n+1]-a[n]);
  REP(i,n){
    if((a[i]<a[i+1]&&a[i+1]<a[i+2])||
       (a[i]>a[i+1]&&a[i+1]>a[i+2]))
      cout<<sum<<endl;
    else
      cout<<sum+abs(a[i]-a[i+2])-abs(a[i]-a[i+1])-abs(a[i+1]-a[i+2])<<endl;
  }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int N; cin >> N;
  vi32 a(N); cin >> a;
  sort(all(a)), reverse(all(a));
  map<int, int> se;
  rep(i, N) se[a[i]]++;
  int ans = 0;
  rep(i, N) {
    if (se[a[i]] <= 0) continue;
    se[a[i]]--;
    int x = 1;
    while (x <= a[i]) x <<= 1;
    int y = x - a[i];
    if (se[y] > 0) {
      ans++;
      se[y]--;
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 19840
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	cin>>s;
	char c1=s[0],c2='0';
	int b1=1,b2=0;
	for(int i=1;i<=3;i++){
		if(s[i]!=c1){
			if(c2=='0')
				c2=s[i];
			else if(s[i]!=c2){
				printf("No\n");
				return 0;
			}
			b2++;
		}
		else if(s[i]==c1)
			b1++;
	}
	if(b1==2&&b2==2){
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
  	long N,M;
  	cin >> N >> M;
  	vector<long> L(M);
  	vector<long> R(M);
  	
  	int idx = 0;
  	int lowwer=0, upper=N;
  	while(cin >> L[idx] >> R[idx])
    {
      if(lowwer <= L[idx]) lowwer = L[idx];
      if(R[idx] <= upper) upper = R[idx];
      idx++;
    }
  	if(upper >= lowwer) cout << upper - lowwer + 1 << endl;
  	else cout << 0 << endl;
  	return 0;
}


Measured memory_bytes: 1792
N,K=map(int,input().split())
V=list(map(int,input().split()))
R=min(N,K)
M=0
for a in range(0,R+1):
    for b in range(0,R-a+1):
        left=V[0:a]
        right=V[N-b:N]
        getV=sorted(left+right)
        for k in range(K-(a+b)):
            if getV!=[] and getV[0]<0:
                getV=getV[1:]
        sumGetV=sum(getV)
        if sumGetV>M:
            M=sumGetV
print(M)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#define MAXN 100500
using namespace std;

int s[MAXN];
int ans[MAXN];
int n;
int main(){
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> s[i];
    }
    ans[0] = 0;
    ans[1] = abs(s[1] - s[0]);
    for (int i = 2; i < n; i++){
        ans[i] = min(ans[i - 1] + abs(s[i - 1] - s[i]), ans[i - 2] + abs(s[i] - s[i - 2]));
    }
    cout << ans[n - 1] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
        int x,y;
	while(1){
         scanf("%d %d",&x,&y);
         if(x==0 && y==0){
          break;
         }
         if(x<=y){
          printf("%d %d\n",x,y);
         }
         else{
          printf("%d %d\n",y,x);
         }

        }
	return 0;
}

Measured memory_bytes: 1760
input()
p1=complex(*list(map(float,input().split())))
p2=complex(*list(map(float,input().split())))
ans=0
def area(p,q,r):
    return ((p-r).conjugate()*(q-r)).imag/2
try:
    while True:
        p3=complex(*list(map(float,input().split())))
        ans+=area(p1,p2,p3)
        p2=p3
except EOFError: print(abs(ans))


Measured memory_bytes: 5596
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

int main(void){
    int n,k;
    std::cin >> n >> k;

    std::vector<int> x_add;
    std::vector<int> x_resuce;
    int base = k/2;
    for(int i = 0; i < n; i++){
       int x; 
       std::cin >> x;

       if(base < x){
           x_resuce.push_back(x);
       }
       else if(base >= x){
           x_add.push_back(x);
       }
    }


    int sum = 0;
    for(int i = 0; i < x_add.size(); i++){
        sum += x_add[i]*2;
    }

    for(int i = 0; i < x_resuce.size(); i++){
        sum += (k-x_resuce[i])*2;
    }

    std::cout << sum;
    return 0;


    


}




Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c\n",c)
int z(int a){
  if(a<0)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int main(void){
  int n,sum=0;
  scanf("%d",&n);
  int a[n];
  FOR(n){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  int ans=sum,r=0;
  FOR(n-1){
    r+=a[i];
    ans=min(ans,z(sum-2*r));
  }
  PRN(ans);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{  int i;
  int a[10];

    for(i=0;i<3;i++)
        scanf("%d",&a[i]);
    sort(a,a+3);
    if(a[0]==5&&a[1]==5&&a[2]==7)
        printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	int n,x; cin >> n >> x;
	int count = 0;
	vector<int> hash(n+1,0);
	for(int i = 1 ; i < n+1 ; i++){
		int y;
		cin >> y;
		hash[i] = hash[i-1]+y;
		if(hash[i] <= x)
			count++;
	}
	cout<<count+1<<"\n";
	
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll qw(ll x,ll y){ll res = 1;while(y){if(y & 1) res *= x;x = x * x;y >>= 1;}return res;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int n,m,u,v;
vector<int> g[maxn];
int ans[maxn];
bool vis[maxn];
void solve(){
	queue<int> q;
	q.push(1);
	while(!q.empty()){
		int u = q.front(); q.pop();
		for(int i = 0;i < g[u].size();i++){
			int v = g[u][i];
			if(!vis[v]){
				ans[v] = u;
				vis[v] = 1;
				q.push(v);
			}
		}
	}
	bool ok = 0;
	for(int i = 2;i <= n;i++){
		if(ans[i] == 0) ok = 1;
	}
	if(ok){
		cout << "No" << endl;
		return;
	}
	cout << "Yes" << endl;
	for(int i = 2;i <= n;i++) cout << ans[i] << endl;
	return;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	while(m--){
		cin >> u >> v;
		g[u].pb(v); g[v].pb(u);
	}	
	solve();
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 12916
N,C = map(int,input().split())
cum = [0]*(10**5+1)
st = [[] for _ in range(C)]
for _ in range(N):
    s,t,c = map(int,input().split())
    st[c-1].append([s,t])
for c in range(C):
    st[c].sort()

st_concat = [[] for _ in range(C)]
for c in range(C):
    if len(st[c]) != 0:
        s0,t0 = st[c].pop()
        while st[c]:
            s,t = st[c].pop()
            if t != s0:
                st_concat[c].append([s0,t0])
                s0,t0 = s,t
            else:
                s0 = s
        st_concat[c].append([s0,t0])

for c in range(C):
    for s,t in st_concat[c]:
        cum[s-1] += 1
        cum[t] -= 1

for i in range(10**5):
    cum[i+1] += cum[i]
print(max(cum))

Measured memory_bytes: 21376
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    string s;
    cin >> s;
    for(int i=0;i<(1<<3);i++){
        int total=s[0]-'0';
        for(int j=0;j<3;j++){
            if(i&(1<<j)){
                total+=s[j+1]-'0';
            }else{
                total-=s[j+1]-'0';    
            }
        }
        if(total==7){
            cout << s[0];
            for(int j=0;j<3;j++){
                if(i&(1<<j)){
                    cout << '+';
                    cout << s[j+1];
                }else{
                    cout << '-';
                    cout << s[j+1];
                }
            }
            break;
        }
    }
    
    cout << "=7" << endl;

    return 0;
}











Measured memory_bytes: 256
class Car
  num = 1
  
  define_method(:initialize) do |time|
    @num = num
    num += 1
    @time = time
  end
  attr_accessor :num, :time
  
  define_singleton_method(:clear) {num = 1}
end

class ParkingLot
  Space = Struct.new(:upper, :lower)
  
  def initialize(num)
    @spaces = num.times.map {|i| Space.new}
  end
  
  def add_car(waiting_time)
    idx = @spaces.index {|sp| sp.lower.nil?}
    if idx
      @spaces[idx].lower = Car.new(waiting_time)   #下のスペースが空いている
    else
      return false if @spaces.all?(&:upper)        #満車
      
      #下は空いていないが満車でない場合
      idxs = @spaces.map.with_index {|sp, i| i unless sp.upper}.compact
      idx = idxs.map do |i|
        diff = @spaces[i].lower.time - waiting_time
        diff >= 0 ? [diff, i] : nil
      end.compact.sort_by(&:itself).first&.last
      unless idx
        idx = idxs.map {|i| [waiting_time - @spaces[i].lower.time, i]}
                  .sort_by(&:itself).first.last
      end
      
      @spaces[idx].upper = @spaces[idx].lower.dup
      @spaces[idx].lower = Car.new(waiting_time)
    end
    true
  end
  
  def next
    @spaces.each do |sp|
      if sp.lower
        sp.lower.time -= 1
        sp.upper.time -= 1 if sp.upper
      end
    end
    
    result = []
    @spaces.each do |sp|
      if sp.lower and sp.lower.time <= 0
        result << sp.lower.num
        sp.lower = sp.upper.dup
        sp.upper = nil
      end
    end
    @spaces.each do |sp|
      if sp.lower and sp.lower.time <= 0
        result << sp.lower.num
        sp.lower = nil
      end
    end
    
    result
  end
  
  #車庫が空か
  def empty?
    @spaces.all? {|sp| sp.lower.nil?}
  end
end


until (given = gets.split.map(&:to_i)) == [0, 0]
  m, n = given
  parking_time = n.times.map {gets.to_i}
  pl = ParkingLot.new(m)
  result = []
  wait = []
  Car.clear
  t = 0
  
  loop do
    result += pl.next
    
    wait << parking_time.shift if (t % 10).zero?
    t += 1
    while (waiting = wait.shift)
      unless pl.add_car(waiting)
        wait.unshift(waiting)    #満車の場合
        break
      end
    end
    
    break if pl.empty?
  end
  
  puts result.join(" ")
end


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

using namespace std;
int a[510][510];
vector<int> b,c,d,e;
int main(){
	int i,j,h,w;
	cin >> h >> w;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin >> a[i][j];
		}
	}
	
	for(i=0;i<h-1;i++){
		for(j=0;j<w;j++){
			if(a[i][j]%2==1 && j!=w-1){
				b.push_back(i+1);
				c.push_back(j+1);
				d.push_back(i+1);
				e.push_back(j+2);
				a[i][j+1]++;
			}
			if(j==w-1 && a[i][j]%2==1){
				b.push_back(i+1);
				c.push_back(j+1);
				d.push_back(i+2);
				e.push_back(j+1);
				a[i+1][j]++;
			}
		}
	}
	for(j=0;j<w-1;j++){
		if(a[i][j]%2==1){
			b.push_back(h);
			c.push_back(j+1);
			d.push_back(h);
			e.push_back(j+2);
			a[h-1][j+1]++;
		}
	}
	cout << b.size() << endl;
	for(i=0;i<b.size();i++){
		cout << b[i] << " " << c[i] << " " << d[i] << " " << e[i] << endl;
	}
}

Measured memory_bytes: 5220