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

using namespace std;

int r, c, n;

struct Point
{
	int x, y, id, type;
	Point(){}
	Point(int _x, int _y, int _id, int _type): x(_x), y(_y), id(_id), type(_type) {}
};

vector<Point> a;

bool cmp(const Point &a, const Point &b)
{
	if (a.type != b.type)
		return a.type < b.type;
	if (a.type == 0)
		return a.y < b.y;
	if (a.type == 1)
		return a.x < b.x;
	if (a.type == 2)
		return a.y > b.y;
	if (a.type == 3)
		return a.x > b.x;	
}

int main(int argc, char** argv)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);


	cin >> r >> c >> n;
	for (int i = 1; i <= n; i++)
	{
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if ((x1 == 0 || x1 == r || y1 == 0 || y1 == c) && (x2 == 0 || x2 == r || y2 == 0 || y2 == c))
		{
			if (x1 == 0)
				a.push_back(Point(x1, y1, i, 0));
			else if (y1 == c)
				a.push_back(Point(x1, y1, i, 1));					
			else if (x1 == r)
				a.push_back(Point(x1, y1, i, 2));
			else if (y1 == 0)			
				a.push_back(Point(x1, y1, i, 3));
			if (x2 == 0)
				a.push_back(Point(x2, y2, i, 0));
			else if (y2 == c)
				a.push_back(Point(x2, y2, i, 1));					
			else if (x2 == r)
				a.push_back(Point(x2, y2, i, 2));
			else if (y2 == 0)			
				a.push_back(Point(x2, y2, i, 3));	
		}
	}
	sort(a.begin(), a.end(), cmp);

	stack<int> S;
	for (int i = 0; i < a.size(); i++)	
	{
		if (!S.empty() && S.top() == a[i].id)
			S.pop();
		else
			S.push(a[i].id);
	}

	cout << (S.empty() ? "YES" : "NO");
}

Measured memory_bytes: 7404
#include <stdio.h>

int main(){
  int n;
  char a[100], b[100];
  char answer[200];
  
  scanf("%d", &n);
  scanf("%s", a);
  scanf("%s", b);
  
  for(int i = 0; i < n; i++){
    answer[2 * i] = a[i];
    answer[2 * i + 1] = b[i];
  }
  
  for(int i = 0; i < n * 2; i++){
    printf("%c", answer[i]);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<pair<ll, ll>> b(n);
    REP(i, n) {
        cin >> a.at(i);
        b.at(i) = make_pair(a.at(i), i);
    }
    sort(b.begin(), b.end());
    if(b.back().first == 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    ll num = 1;
    vector<bool> is_sink(n, false);
    REP(i, b.size()){
        const ll j = b.at(i).second;
        if(j == 0 && j + 1 < n && is_sink.at(j + 1)){
            num--;
        }
        if(j == n - 1 && j > 0 && is_sink.at(j - 1)){
            num--;
        }
        if(0 < j && j + 1 < n){
            if(is_sink.at(j - 1) && is_sink.at(j + 1)){
                num--;
            }else if(!is_sink.at(j - 1) && !is_sink.at(j + 1)){
                num++;
            }
        }
        is_sink.at(j) = true;

        if(i + 1 == n || b.at(i).first != b.at(i + 1).first){
            ans = max(ans, num);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5228
using System;
class c
{
    static void Main()
    {
        var s = Console.ReadLine();
        bool judge = false;
        for (int i = 0; i <= 7; i++)
        {
            if (s.Substring(0, i) + s.Substring(s.Length - (7 - i), 7 - i) == "keyence") judge = true;
        }
        Console.WriteLine(judge ? "YES" : "NO");
    }
}

Measured memory_bytes: 11092
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val q = readInteger()

    val table = primeTable(100000)
    val sums = IntArray(100001)
    for (i in 0 until 100000) {
        sums[i + 1] = sums[i] + if (table[i] && table[(i + 1) / 2]) 1 else 0
    }

    repeat(q) {
        val (l, r) = readIntegerList()
        out.println(sums[r + 1] - sums[l])
    }
}

/** O(nlog(logn)) // n * n <= Int.MAX_VALUE, n <= 10^6 */
fun primeTable(n: Int): BooleanArray {
    val table = BooleanArray(n + 1) { true }
    if (n >= 0) table[0] = false
    if (n >= 1) table[1] = false
    var i = 2
    while (i * i <= n) {
        if (table[i]) {
            for (j in (i + i)..n step i) { table[j] = false }
        }
        i++
    }
    return table
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 60240
#include<stdio.h>

#define UP 0
#define FRONT 1
#define RIGHT 2
#define LEFT 3
#define BACK 4
#define BOTTOM 5

typedef struct{
	int label[6];		// label, what do each tiles have.
	int direction[6];	// direction, what direction is dice. [0]-[5]:up, front, right, left, back, bottom.
}dice;

int DiceRoll(dice* p, char c);

int main(void){
	dice a;
	int i=0;
	char command = 'a';
	char line[101] ={0};

	for(i=0;i<6;i++) a.direction[i]=i;	// dice direction setup

	scanf("%d %d %d %d %d %d", &a.label[0], &a.label[1],
		&a.label[2], &a.label[3], &a.label[4], &a.label[5]);	// dice label setup
	
	scanf("%s", line);

	for(i=0;line[i]!='\0';i++){
		DiceRoll(&a, line[i]);
	}

	printf("%d\n", a.label[a.direction[UP]]);

	return 0;
}

int DiceRoll(dice* p, char c){
	int tmp = -1;
	
	switch(c){
	case 'E':
		tmp = p->direction[UP];
		p->direction[UP] = p->direction[LEFT];		// up <- left
		p->direction[LEFT] = p->direction[BOTTOM];	// left <- bottom
		p->direction[BOTTOM] = p->direction[RIGHT];	// bottom <- right
		p->direction[RIGHT] = tmp;					// right <- up
		break;
	case 'N':
		tmp = p->direction[UP];
		p->direction[UP] = p->direction[FRONT];		// up <- front
		p->direction[FRONT] = p->direction[BOTTOM];	// front <- bottom
		p->direction[BOTTOM] = p->direction[BACK];	// bottom <- back
		p->direction[BACK] = tmp;					// back <- up
		break;
	case 'S':
		tmp = p->direction[UP];
		p->direction[UP] = p->direction[BACK];		// up <- back
		p->direction[BACK] = p->direction[BOTTOM];	// back <- bottom
		p->direction[BOTTOM] = p->direction[FRONT];	// bottom <- front
		p->direction[FRONT] = tmp;					// front <- up
		break;
	case 'W':
		tmp = p->direction[UP];
		p->direction[UP] = p->direction[RIGHT];		// up <- right
		p->direction[RIGHT] = p->direction[BOTTOM];	// right <- bottom
		p->direction[BOTTOM] = p->direction[LEFT];	// bottom <- left
		p->direction[LEFT] = tmp;					// left <- up
		break;
	default:
		break;
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int s[110];
int main() {
	
	int n, x; scanf("%d%d", &n, &x);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &s[i]);
	sort(s + 1, s + n + 1);
	int Ans = 0;
	for (int i = 1; i <= n; ++i)
		if (x >= s[i]) {
			Ans ++;
			x -= s[i];
		}
	if (x && Ans == n) Ans --;
	cout << Ans << endl;

}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    cout << "2018";
    for(int i = 4; i < s.size(); i++) cout << s[i];
    cout << "\n";
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1e18;

int main(){
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int x,y;
  cin>>x>>y;
  int ans=0;
  if(x==1)ans+=300000;
  if(x==2)ans+=200000;
  if(x==3)ans+=100000;
  if(y==1)ans+=300000;
  if(y==2)ans+=200000;
  if(y==3)ans+=100000;
  if(x==1&&y==1)ans+=400000;
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
  ll K, A, B;
  cin >> K >> A >> B;
  
  auto ans = (A%K==0 || (A/K+1)*K <= B) ? "OK" : "NG";
 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3104
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int[] A = nextIntArray(N);

		int t1 = -1,t2 = -1;
		for(int i=0;i<N-1;i++) {
			if(A[i] > A[i+1]) {
				t1 = i;
				for(int j=i+1;j<N-1;j++) {
					if(A[j] > A[j+1]) {
						t2 = j+1;
					}
				}
				break;
			}
		}
		if(t1 != -1&&t2 != -1) {
			int tmp = A[t1];
			A[t1] = A[t2];
			A[t2] = tmp;
		}
		for(int i=0;i<N-1;i++) {
			if(A[i]>A[i+1]) {
				out.println("NO");
				return;
			}
		}
		out.println("YES");
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}


}

Measured memory_bytes: 21844
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    assert_eq!(!0usize, std::usize::MAX); //🙊
    assert!(0 == 0); //😇
    let w = io.read::<i64>();
    let mut a = io.read::<i64>();
    let mut b = io.read::<i64>();

    if a > b {
        swap(&mut a, &mut b);
    }
    let mut ans = INF;
    if a + w <= b {
        ans = b - a - w;
    } else {
        ans = 0;
    }
    io.writeln(ans);
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


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

int N, A[10010];

long long int max(){
    long long int max = A[0];
    for (int i = 1; i < N; i++){
        if (A[i] > max){
            max = A[i];
        }
    }
    return max;
}

long long int sum(){
    long long int sum = 0;
    for (int i = 0; i < N; i++){
        sum += A[i];
    }
    return sum;
}

long long int min(){
    long long int min = A[0];
    for (int i = 1; i < N; i++){
        if (A[i] < min){
            min = A[i];
        }
    }
    return min;
}

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    cout << min() << ' ' << max() << ' ' << sum() << endl;
}

Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
  int n;
  cin >> n;
  int c = 0;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    if(a != i+1) c++;
  }
  if(c <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long ans = 0;
        for(int b = K+1;b <= N;b++){
            ans += (N/b)*(b-K)+Math.max(0, N%b-K+1);
        }
        if(K == 0)  ans -= N;
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
d1=list(map(int,input().split()))
d2=list(map(int,input().split()))

class dice(object):
	def __init__(self, d):
		self.d = d

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

dice1=dice(d1)
dice2=dice(d2)

if sorted(d1)!=sorted(d2):
	print("No")
else:
	c=["E","W","S","N"]
	import random
	n=0
	while n<10**5:
		if dice1.d==dice2.d:
			break 
		else:
			dice1.roll(c[random.randint(1,2)])
		n+=1
	if n==10**5:
		print("No")
	else:
		print("Yes")

Measured memory_bytes: 11700
#include <stdio.h>

int main(){
  char str[20];
  for(int i = 0; i < (5+1+7+1+5); i++){
    scanf("%c", &str[i]);
    if(str[i] == ','){
      str[i] = ' ';
    }
  }
  str[19] = '\0';
  printf("%s\n", str);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int n,a[110001];
void MRoy(){
    scanf("%d",&n);
    for (register int i = 0; i < n; i++){
        scanf("%d",a+i);
    }
    int Ans = 0, cnt = 0;
    for(register int i=n-2;i>=0;i--){
        if(a[i]>=a[i+1]) cnt++;
        else cnt = 0;
        Ans = Ans<cnt?cnt:Ans;
    }
    printf("%d\n",Ans);
}
int main(){
    MRoy();
    return 0;
}

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

int main(){
  int N, K;
  string S;
  cin >> N >> S >> K;
  char C=S.at(K-1);
  for(int i=0; i<N; i++){
    if(S.at(i)!=C) S.at(i)='*';
  }
  cout << S << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n, k = MAP()
    h = [x for x in LIST()if x>=k]

    print(len(h))

if  __name__=='__main__':
    main()


Measured memory_bytes: 14084
#include <bits/stdc++.h>
using namespace std;
int main()
{
	vector<int> vec;
	int a, b, c, d, e;
	int s,m;
	cin >> a >> b >> c >> d >> e;

	vec = { a % 10,b % 10,c % 10,d % 10,e % 10 };
	sort(vec.begin(), vec.end());
	if (vec.at(0) != 0)m = vec.at(0);
	else if (vec.at(1) != 0)m = vec.at(1);
	else if (vec.at(2) != 0)m = vec.at(2);
	else if (vec.at(3) != 0)m = vec.at(3);
	else m = vec.at(4);

	if (m == a % 10)
	{
		//if (a % 10 == 0)s += a/10;
		//else s += a/10 + 1;
		if (b % 10 == 0)s += b / 10;
		else s += b/10 + 1;
		if (c % 10 == 0)s += c/10;
		else s += c/10 + 1;
		if (d % 10 == 0)s += d/10;
		else s += d/10 + 1;
		if (e % 10 == 0)s += e/10;
		else s += e/10 + 1;

		s = s * 10;

		s += a;
	}
	else if (m == b % 10)
	{
		if (a % 10 == 0)s += a / 10;
		else s += a / 10 + 1;
		//if (b % 10 == 0)s += b / 10;
		//else s += b / 10 + 1;
		if (c % 10 == 0)s += c / 10;
		else s += c / 10 + 1;
		if (d % 10 == 0)s += d / 10;
		else s += d / 10 + 1;
		if (e % 10 == 0)s += e / 10;
		else s += e / 10 + 1;

		s = s * 10;

		s += b;
	}
	else if (m == c % 10)
	{
		if (a % 10 == 0)s += a / 10;
		else s += a / 10 + 1;
		if (b % 10 == 0)s += b / 10;
		else s += b / 10 + 1;
		//if (c % 10 == 0)s += c / 10;
		//else s += c / 10 + 1;
		if (d % 10 == 0)s += d / 10;
		else s += d / 10 + 1;
		if (e % 10 == 0)s += e / 10;
		else s += e / 10 + 1;

		s = s * 10;

		s += c;
	}
	else if (m == d % 10)
	{
		if (a % 10 == 0)s += a / 10;
		else s += a / 10 + 1;
		if (b % 10 == 0)s += b / 10;
		else s += b / 10 + 1;
		if (c % 10 == 0)s += c / 10;
		else s += c / 10 + 1;
		//if (d % 10 == 0)s += d / 10;
		//else s += d / 10 + 1;
		if (e % 10 == 0)s += e / 10;
		else s += e / 10 + 1;

		s = s * 10;

		s += d;
	}
	else if (m == e % 10)
	{
		if (a % 10 == 0)s += a / 10;
		else s += a / 10 + 1;
		if (b % 10 == 0)s += b / 10;
		else s += b / 10 + 1;
		if (c % 10 == 0)s += c / 10;
		else s += c / 10 + 1;
		if (d % 10 == 0)s += d / 10;
		else s += d / 10 + 1;
		//if (e % 10 == 0)s += e / 10;
		//else s += e / 10 + 1;

		s = s * 10;

		s += e;
	}
	cout << s << endl;
	//return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);
//const int INF=(1<<29);

int main(){
  string s;
  cin >> s;
  int ans=0;
  REP(i,s.size()-1){
    if(s[i]!=s[i+1])ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 512
#include<stdio.h>

int main(){
    int c=0;
    char s[3];
    scanf("%c",&s[0]);
    scanf("%c",&s[1]);
    scanf("%c",&s[2]);
    if(s[0]=='1')c++;
    if(s[1]=='1')c++;
    if(s[2]=='1')c++;
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;
 
 ll mod=1e9 +7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    // Sieve();
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
      
      char c;
      cin>>c;
      if((int)(c)>90) cout<<"a";
      else cout<<"A";
    }
    return 0;
   }

Measured memory_bytes: 14152
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;
 
struct RMQandRUQ{
  vector<int> data;
  int sq;
  vector<int> lazy;
  vector<int> lazymin;
  void boot(const int &n){
    data.resize(n);
    sq = round(sqrt((double)n));
    lazy.resize(n/sq+1);
    lazymin.resize(n/sq+1);
    for(int i = 0;i < lazy.size();i++)lazy[i] = -2147483647;
  }
  int fin(const int &s){
    if(lazy[s/sq] != -2147483647){
      for(int i = s/sq*sq;i < min((s/sq+1)*sq,(int)data.size());i++)data[i] = lazy[s/sq];
      lazy[s/sq] = -2147483647;
    }
    return data[s];
  }
  void update(int s,const int &t,const int &num){
    int S = s,T = t;
    if(lazy[s/sq] != -2147483647){
      for(int i = s/sq*sq;i < min((s/sq+1)*sq,(int)data.size());i++)data[i] = lazy[s/sq];
      lazy[s/sq] = -2147483647;
    }
    if(lazy[t/sq] != -2147483647){
      for(int i = t/sq*sq;i < min((t/sq+1)*sq,(int)data.size());i++)data[i] = lazy[t/sq];
      lazy[t/sq] = -2147483647;
    }
    while(s%sq && s<=t){
      data[s] = num;
      s++;
    }
    while((t-s)/sq){
      lazy[s/sq] = num;
      lazymin[s/sq] = num;
      s += sq;
    }
    while(s <= t){
      data[s] = num;
      s++;
    }
    lazymin[S/sq] = 2147483647;
    for(int i = S/sq*sq;i < min((S/sq+1)*sq,(int)data.size());i++)lazymin[S/sq] = min(lazymin[S/sq],fin(i));
    lazymin[T/sq] = 2147483647;
    for(int i = T/sq*sq;i < min((T/sq+1)*sq,(int)data.size());i++)lazymin[T/sq] = min(lazymin[T/sq],fin(i));
    return;
  }
  int find(int s,const int &t){
    int ans = 2147483647;
    while(s%sq && s<=t){
      ans = min(ans,fin(s));
      s++;
    }
    while((t-s)/sq){
      ans = min(ans,lazymin[s/sq]);
      s += sq;
    }
    while(s <= t){
      ans = min(ans,fin(s));
      s++;
    }
    return ans;
  }
};
 
signed main(){
  RMQandRUQ RMUQ;
  int n,q;
  scanf("%d%d",&n,&q);
  int query,s,t,x;
  RMUQ.boot(n);
  RMUQ.update(0,n-1,2147483647);
  FOR(i,0,q){
    scanf("%d",&query);
    if(query == 0){
      scanf("%d%d%d",&s,&t,&x);
      RMUQ.update(s,t,x);
    }
    else{
      scanf("%d%d",&s,&t);
      printf("%lld\n",RMUQ.find(s,t));
    }
  }
}


Measured memory_bytes: 3420
import sys
def main():
    input = sys.stdin.readline
    H,W=map(int, input().split())
    c=[list(map(int, input().split())) for _ in range(10)]
    A=[tuple(map(int, input().split())) for _ in range(H)]

    for k in range(10):
        for i in range(10):
            for j in range(10):
                c[i][j] = min(c[i][j], c[i][k] + c[k][j])

    ans = 0
    for i in range(H):
        for j in range(W):
            if A[i][j] >= 0:
                ans += c[A[i][j]][1]
    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 8080;

#define p(n) (8000 + n)

bool dpX[MAX_N][2 * MAX_N];
bool dpY[MAX_N][2 * MAX_N];

string S;
int X, Y;

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

  cin >> S;
  cin >> X >> Y;

  int cnt = 0;
  // true:X / false:Y
  bool dist = true;
  
  REP(si, S.size()) {
    if (S[si] != 'F') break;
    cnt++;
  }
  // debug(cnt);
  
  dpX[cnt][p(cnt)] = dpY[cnt][p(0)] = true;
  if (cnt == 0)
    dist = !dist;

  int tmp = max(cnt, 1);
  cnt = 0;
  
  FOR(si, tmp, S.size() + 1) {
    if (S[si] == 'T' or si == S.size()) {
      if (dist) {
	// X方向
	REP(i, 2 * MAX_N) {
	  if (dpX[si - cnt - 1][i]) {
	    dpX[si][i + cnt] = true;
	    dpX[si][i - cnt] = true;
	  }
	  if (dpY[si - cnt - 1][i]) dpY[si][i] = true;
	}
      } else {
	// Y方向
	REP(i, 2 * MAX_N) {
	  if (dpY[si - cnt - 1][i]) {
	    dpY[si][i + cnt] = true;
	    dpY[si][i - cnt] = true;
	  }
	  if (dpX[si - cnt - 1][i]) dpX[si][i] = true;
	}
      }
      dist = !dist;
      cnt = 0;
    } else {
      // F
      cnt++;
    }
  }

  bool ok = false;
  if (dpX[S.size()][p(X)] && dpY[S.size()][p(Y)])
    ok = true;

  OK(ok);

  /*
  FOR(i, -5, 6) {
    debug(i);
    OK(dpX[S.size()][p(i)]);
  }

  FOR(i, -5, 6) {
    debug(i);
    OK(dpY[S.size()][p(i)]);
  }
  */
  
  return 0;
}



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

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

using namespace std;
using ll = long long;

const pair<double, double> operator+(const pair<double, double> p1, const pair<double, double> p2) {
    pair<double, double> q;
    q.first = p1.first + p2.first;
    q.second = p1.second + p2.second;
    return q;
}
const pair<double, double> operator-(const pair<double, double> p1, const pair<double, double> p2) {
    pair<double, double> q;
    q.first = p1.first - p2.first;
    q.second = p1.second - p2.second;
    return q;
}
const pair<double, double> operator*(const pair<double, double> p, const double k) {
    pair<double, double> q;
    q.first = p.first * k;
    q.second = p.second * k;
    return q;
}
const pair<double, double> operator/(const pair<double, double> p, const double k) {
    pair<double, double> q;
    q.first = p.first / k;
    q.second = p.second / k;
    return q;
}

void koch_curve(int depth, pair<double, double> p1, pair<double, double> p2) {
    if(depth == 0) return;

    pair<double, double> q1, q2, q3, rot;
    q1 = (p1 * 2 + p2) / 3;
    q3 = (p1 + p2 * 2) / 3;
    rot.first = -((q3 - q1) * sqrt(3) / 2).second;
    rot.second = ((q3 - q1) * sqrt(3) / 2).first;
    q2 = (q1 + q3) / 2 + rot;

    koch_curve(depth - 1, p1, q1);
    printf("%.8lf %.8lf\n", q1.first, q1.second);
    koch_curve(depth - 1, q1, q2);
    printf("%.8lf %.8lf\n", q2.first, q2.second);
    koch_curve(depth - 1, q2, q3);
    printf("%.8lf %.8lf\n", q3.first, q3.second);
    koch_curve(depth - 1, q3, p2);
}

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

    int n;
    cin >> n;

    pair<double, double> p1(0, 0), p2(100, 0);
    printf("%.8lf %.8lf\n", p1.first, p1.second);
    koch_curve(n, p1, p2);
    printf("%.8lf %.8lf\n", p2.first, p2.second);

    return 0;
}


Measured memory_bytes: 3236
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#define f first
#define s second
using namespace std;
typedef long long ll;
const ll limit=1e6+2;
const ll maxN=1e9+2;
string s,st,st1;
bool f[limit];
long long t,n,x,test,d=0,tp=0,mp=0,temp=2,l,r,m,res=1;
long long b[limit],mi[limit],a[limit];

int main()
{
    cin>>s;
    if(s[1]=='B') cout<<"ARC";
    else cout<<"ABC";
}


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
int cntDiv(int n){
	int ans = 0;
	for (int i= 1;i<=n;i+=2){
		if(n%i==0)ans++;
	}
	return ans;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	scanf("%d", &n);
	int ans = 0;
	for (int i = 1;i<= n;i+=2){
		if(cntDiv(i) == 8)ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string colour1, colour2, throw_away;
    int colour1_number, colour2_number;
    cin >> colour1 >> colour2;
    cin >> colour1_number >> colour2_number;
    cin >> throw_away;
    if(throw_away == colour1){
        colour1_number = colour1_number - 1;
    }
    else if (throw_away == colour2){
        colour2_number = colour2_number - 1;
    }
    cout<< colour1_number <<' '<<colour2_number;
}

Measured memory_bytes: 256
name1,a1,b1 = input().split()
a1 = int(a1)
b1 = int(b1)
name2,a2,b2 = input().split()
a2 = int(a2)
b2 = int(b2)
name3,a3,b3 = input().split()
a3 = int(a3)
b3 = int(b3)
name4,a4,b4 = input().split()
a4 = int(a4)
b4 = int(b4)
name5,a5,b5 = input().split()
a5 = int(a5)
b5 = int(b5)
name6,a6,b6 = input().split()
a6 = int(a6)
b6 = int(b6)
name7,a7,b7 = input().split()
a7 = int(a7)
b7 = int(b7)
name8,a8,b8 = input().split()
a8 = int(a8)
b8 = int(b8)
name9,a9,b9 = input().split()
a9 = int(a9)
b9 = int(b9)


print(name1,a1 + b1,a1 * 200 + b1 * 300)
print(name2,a2 + b2,a2 * 200 + b2 * 300)
print(name3,a3 + b3,a3 * 200 + b3 * 300)
print(name4,a4 + b4,a4 * 200 + b4 * 300)
print(name5,a5 + b5,a5 * 200 + b5 * 300)
print(name6,a6 + b6,a6 * 200 + b6 * 300)
print(name7,a7 + b7,a7 * 200 + b7 * 300)
print(name8,a8 + b8,a8 * 200 + b8 * 300)
print(name9,a9 + b9,a9 * 200 + b9 * 300)


Measured memory_bytes: 5604
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<_> = (0..n).map(|i| (i, read::<usize>() - 1)).collect();
    let mut now = a[0];
    let mut count = 1;

    for _ in 0..n {
        if now.1 == 1 {
            println!("{}", count);
            return;;
        }
        now = a[now.1];
        count += 1;
    }
    println!("-1");
}

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


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const lint INF = mod;
const int MAX = 610;

int n, m;
vector<int> G[MAX];
double p[MAX], E[MAX];

double dfs(int v){
    if(E[v]>=0) return E[v];
    E[v]=1;
    for(int nv: G[v]) E[v]+=dfs(nv)/(double)G[v].size();
    return E[v];
}

int main(){
    scanf("%d%d", &n, &m);
    rep(i, m){
        int s, t;
        scanf("%d%d", &s, &t);
        G[s-1].push_back(t-1);
    }

    p[0]=1;
    rep(i, n)for(int j: G[i]) p[j]+=p[i]/(double)G[i].size();
    rep(i, n) E[i]=-1;
    E[n-1]=0;
    rep(i, n) dfs(i);

    double ans=E[0];
    rep(i, n)if(G[i].size()>1)for(int j: G[i]){
        double tmp=(E[i]*G[i].size()-(1+E[j])) / (G[i].size()-1);
        tmp=(E[i]-tmp)*p[i];
        chmin(ans, E[0]-tmp);
    }
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 1408
n,k = map(int, input().split())
p = list(map(int, input().split()))

# 値ごとの期待値を取得
s = [0]*n
for i in range(n):
  s[i] = (p[i]+1)/2

# 期待値を累積していく
p = [0]*(n+1)
for i in range(1, n+1):
  p[i] = p[i-1] + s[i-1]

# 下記の方法で隣接する期待値合計を取得し、比較を行う。
# 隣接する期待値の合計　= 対象とする範囲の最大累積和　- 対象外範囲の最大累積和
ans = 0
for i in range(n-k+1):
  ans = max(ans, p[i+k] - p[i])

print(ans)

Measured memory_bytes: 32120
#include <iostream>


using namespace std;


int main()
{
  int a, b, c, d, e, f, water[1000000], sugar[1000000];
  int w, s, sw;
  int idx_w=0, idx_s=0;

  cin >> a >> b >> c >> d >> e >> f;
  for (int i=0; i<f+1; i++){
    for (int j=0; j<f+1; j++){
      w = 100*a*i + 100*b*j;
      s = c*i + d*j;
      if (w <= f){
	water[idx_w] = w;
	idx_w++;
      }
      if (s <= f){
	sugar[idx_s] = s;
	idx_s++;
      }
    }
  }

  double max_r = -1;
  int max_sw, max_s;
  for (int i=0; i<idx_w; i++){
    for (int j=0; j<idx_s; j++){
      sw = water[i]+sugar[j];
      if (sw <= f && 100*sugar[j] <= water[i]*e && sugar[j] > sw*max_r){
	max_sw = sw;
	max_s = sugar[j];
	max_r = (double)sugar[j]/sw;
      }
    }
  }
  cout << max_sw << ' ' << max_s << endl;
  
  return 0;
}


Measured memory_bytes: 2304
x = int(input())
if 400<=x<=599:
    print(8)
elif 600<=x<=799:
    print(7)
elif 800<=x<=999:
    print(6)
elif 1000<=x<=1199:
    print(5)
elif 1200<=x<=1399:
    print(4)
elif 1400<=x<=1599:
    print(3)
elif 1600<=x<=1799:
    print(2)
elif 1800<=x<=1999:
    print(1)

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

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

//---main---------------------------------------------
int main(){
    //main
    int N;
    cin >> N;

    /* 
    vector<int> d(N+1);
    for(int i=1; i<=N ; i++){
        for(int j=i; j<=N; j+=i) d[j]++;
    }
    ll ans2 = 0;
    rep(i,N+1) ans2 += ll(i)*d[i];
    cout << ans2 << endl;
    */


    //int M[N+1];
    int *M;
    M = new int[N+1];

    rep(i,N+1) M[i] = 2;
    M[0]=0; M[1]=1;
    for(int i=2; i<=N ; ++i){
        int idx = i*2;
        while(idx <= N){
            M[idx]++;
            idx += i;
        }
    }

    //rep(i,N) cout << M[i] << " ";
    //cout << M[N] << endl;

    ll ans=0;
    rep(i,N+1) ans += ll(i)*M[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 42696
from sys import stdin


def main() -> int:
    n = next_int()
    m = 10 ** 9 + 7

    ans = 1

    for i in range(1, n + 1):
        j = i % m
        ans = (ans * j) % m

    print(ans)
    return 0


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int dp[1001][1000];
int a[1001][1000];
int ainv[1001][1001];
signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    cin.tie(0);
    cout.tie(0);
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n;
        cin>>n;
        rep(i,1,n+1){
        	rep(j,1,n) cin>>a[i][j];
        }
        int cur[n+1];
        rep(i,1,n+1) cur[i] = 1;
        int ans=0;
       	while(1){
       		int cnt = 0;
       		ans++;
       		int mark[n+1]={};
       		rep(i,1,n+1){
       			if(cur[i]==n||mark[i]) continue;
       			if(a[a[i][cur[i]]][cur[a[i][cur[i]]]] == i && mark[a[i][cur[i]]] ==0){
       				cnt++;
       				mark[i] = 1;
       				mark[a[i][cur[i]]] = 1;
       				// trace(i,a[i][cur[i]],ans);
       				cur[a[i][cur[i]]]++;
       				cur[i]++;
       			}
       		}
       		if(cnt==0){
       			bool yes = 1;
       			rep(i,1,n+1) if(cur[i]!=n) yes = 0;
       			if(yes==0) cout<<-1;
       			else{
       				cout<<ans-1;
       			}
       			r0;
       		}
       	}
    }   
}     


Measured memory_bytes: 6400
from math import sqrt
n,d=map(int,input().split())
x=[]
for i in range(n):
  a=list(map(int,input().split()))
  x.append(a)
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k])
    if sqrt(dis)%1==0:
      ans+=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int selectionSort(vector<int> &a, int n){
	int minj, count = 0;
	for (int i = 0; i < n; i++){
		minj = i;
		for (int j = i; j < n; j++){
			if (a[j] < a[minj]) minj = j;
		}
		if (i != minj){
			swap(a[i], a[minj]);
			count++;
		}
	}
	return count;
}

int main(){
	int n, count;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	count = selectionSort(a, n);
	for (int i = 0; i < n; i++){
		cout << a[i];
		if (i != n - 1) cout << " ";
	}
	cout << endl << count << endl;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll N,ans,sum,left,right;
  vi W;
  cin >> N;
  sum = 0;
  REP(i,N){
		int x;
		cin >> x;
    sum = sum+x;
		W.push_back(x);
	}
  left = 0;
  right = sum;
  ans = sum;
  REP(i,N){
    left = left + W[i];
    right = right - W[i];
    ans = min(abs(left-right),ans);
  }
  cout << ans<< endl;
  return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,res=0;
	cin>>N;
	set<P>a,b;
	for(int i=0;i<N;i++)
	{
		int x,y;
		cin>>x>>y;
		a.insert(make_pair(x,y));
	}
	for(int i=0;i<N;i++)
	{
		int x,y;
		cin>>x>>y;
		b.insert(make_pair(x,y));
	}
	for(set<P>::iterator it=b.begin();it!=b.end();it++)
	{
		set<P>::iterator jt=a.begin(),x;
		x=a.end();
		for(;jt!=a.end()&&jt->first<it->first;jt++)
		{
			if(jt->first<it->first&&jt->second<it->second)
			{
				if(x==a.end()||x->second<jt->second)
				{
					x=jt;
				}
			}
		}
		if(x!=a.end())
		{
			res++;
			a.erase(x);
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
	int n, i=1;
	scanf(" %d", &n);
	
	while(i <= n){
		int x=i;
		
		if(x%3==0) {
			printf(" %d", i);
		}
		else {
			while(x){
				if(x%10==3){
					printf(" %d", i);
					break;
				}
				else x/=10;
			}
		}
		
		++i;
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int main()
{
	int n;
	int a[200005];
	set<int>s;
	cin>>n;
	REP(i,n)
	{cin>>a[i];
	s.insert(a[i]);
		}	
	if(s.size()==n)
		cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <deque>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

ll a[2000];
vector<ll> tori;//取り出される可能性のある数字
deque<ll> part[2000];//部分列

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

	//a[i]を最小値として取り出せるかを調べる
	for(int i=0;i<n;i++)
	{
		int index=0;
		for(int j=0;j<n;j++)
			part[j].clear();
		tori.clear();
		for(int j=0;j<n;j++)
		{
			if(a[i]>a[j])
				index++;
			else
				part[index].push_back(a[j]);
		}

		for(int j=0;j<index+1;j++)
		{
			sort(part[j].begin(),part[j].end());
			while(part[j].size()>=k)
			{
				tori.push_back(part[j][0]);
				part[j].pop_front();
			}
		}

		sort(tori.begin(),tori.end());
		/*
		cerr<<a[i]<<endl;
		for(int j=0;j<tori.size();j++)
			cerr<<tori[j]<<" ";
		cerr<<endl;*/
		if(tori.size()>=q)
		{
			ll temp=tori[q-1]-tori[0];
			ans=min(temp,ans);
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2304
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    t = S()
    l = len(s)
    d = collections.defaultdict(lambda: None)
    e = collections.defaultdict(lambda: None)
    for i in range(l):
        si = s[i]
        ti = t[i]
        if not d[si] is None:
            if ti != d[si]:
                return 'No'
        if not e[ti] is None:
            if si != e[ti]:
                return 'No'
        d[si] = ti
        e[ti] = si

    return 'Yes'


print(main())


Measured memory_bytes: 6592
#include <iostream>
#include <bits/stdc++.h>
#define t97 1000000007

using namespace std;
typedef long long ll;

void dm(vector<vector<ll> >& m) {
    for(ll i = 0; i < m.size(); i++) {
        for(ll j = 0; j < m[i].size(); j++) {
            if(j != m[i].size()-1) {
                cout << m[i][j] << " ";
            } 
            else {
                cout << m[i][j] << endl;
            }
        }
    }
}

void dv(vector<ll>& v) {
    for(ll i = 0; i < v.size()-1; i++) {
        cout << v[i]<<" ";
    }
    cout << v[v.size()-1]<<endl;
}

void swap(ll& a, ll& b) {
    ll temp = a;
    a = b;
    b = temp;
}

ll minval(ll a, ll b) {
    if(a < b) {
        return a;
    }
    return b;
}

ll ans(vector<ll>& v, ll index, vector<ll>& dp) {
    if(dp[index] != -1) {
        return dp[index];
    }
    if(index == 0) {
        dp[index] = 0;
        return 0;
    }
    else if(index == 1) {
        dp[index] = abs(v[1]-v[0]);
        return abs(v[1]-v[0]);
    }
    else {
        dp[index] = minval(abs(v[index-1]-v[index])+ans(v, index-1, dp), abs(v[index-2]-v[index])+ans(v, index-2, dp));
        return dp[index];
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    scanf("%lld", &n);
    vector<ll> v(n), dp(n, -1);
    for(ll i= 0; i < n; i++) {
        scanf("%lld", &v[i]);
    }
    cout << ans(v, n-1, dp)<<endl;
    
    return 0;
}


Measured memory_bytes: 4992
N,W = map(int,input().split())
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1,N+1):
    v,w = map(int,input().split())
    for j in range(1,W+1):
        if j-w >=0:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[-1][-1])


Measured memory_bytes: 25496
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	long long ans = 0;
	int arr[n + 1] = { 0 };
	for (int i = 0; i < n ; i++) {
		if (s[i] == '<') {
			arr[i + 1] = max(arr[i] + 1, arr[i + 1]);
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '>') {
			arr[i] = max(arr[i], arr[i + 1] + 1);
		}
	}

	for (int i = 0 ; i <= n ; i++) ans += arr[i];
	printf("%lld\n", ans);
}



Measured memory_bytes: 5768
// 他の人の回答を参考に、より本質的にDPを書き直したもの

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll H, N;
vector<ll> As;
vector<ll> Bs;


ll solve_later(ll N, vector<ll>& As, vector<ll>& Bs) {

    // 両方ともin-place DPで実装可能

    // DP1: dp[何番目の魔法まで使うか][体力]
    //          = ちょうどその体力を削るのに必要な魔力の最小値
    // 本番中考えていたのはこちら
    // (削れる体力=10000, 魔力=1)という魔法のためにテーブルは長くとる
    // 参考: http://kmjp.hatenablog.jp/entry/2020/01/27/0900
    vector<ll> dp1(H + 10010, 1e18);

    // DP2: dp[何番目の魔法まで使うか][体力]
    //          = その体力を削るのに必要な魔力の最小値
    //            （その体力以上を削る場合も含む）
    // 参考: https://atcoder.jp/contests/abc153/submissions/9730947
    vector<ll> dp2(10001, 1e18);

    dp1[0] = 0;
    dp2[0] = 0;

    REP(i, N) {
        ll a = As[i];
        ll b = Bs[i];
        REP(j, H + 10000) {
            if (j - a >= 0) {
                dp1[j] = min(dp1[j],
                             dp1[j - a] + b);
            }
        }

        // 魔法(a, b)を1回撃つと魔力bで体力aが削れる
        // ということは魔力bで体力1, 2, ..., a-1も当然削れる
        FOR(j, 1, a) dp2[j] = min(dp2[j], b);
        FOR(j, a, H + 1) {
            dp2[j] = min(dp2[j],
                         dp2[j - a] + b);
        }
    }

    ll ans1 = 1e18;
    FOR(j, H, H + 10000) {
        ans1 = min(ans1, dp1[j]);
    }

    ll ans2 = dp2[H];

    assert(ans1 == ans2);

    return ans1;
}

int main(void)
{
    cin.sync_with_stdio(false);
    cin >> H >> N;
    As.resize(N);
    Bs.resize(N);
    REP(n, N) {
        cin >> As[n] >> Bs[n];
    }
    cout << solve_later(N, As, Bs) << endl;

    return 0;
}


Measured memory_bytes: 512