akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using P = pair<ll, ll>;
const int INF = 1001001001;

int main(void){
  ll n, k;
  cin >> n >> k;
  vector<P> v(n);
  REP(i, n){
    ll a, b;
    cin >> a >> b;
    v[i] = P(a, b);
  }
  sort(ALL(v));
  ll m = 0;
  REP(i, n){
    m += v[i].second;
    if(k <= m){
      cout << v[i].first << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String n = sc.next();
    if (Integer.parseInt(n.substring(0, 3)) % 111 == 0 || Integer.parseInt(n.substring(1, 4)) % 111 == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  } 
}


Measured memory_bytes: 23764
#include <stdio.h>
int main(void){
   long int a;

    scanf("%ld",&a);
   long int before =1;
   long int before2=2;
   long int sum=1;
    if(a>0){
    for(int i=0;i<a-1;i++){

        sum=before+before2;
        before2=before;
        before=sum;
    }
    
    printf("%ld",sum);
}
else
    printf("2");

    }


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    rep(i, s.size()){
        if(s[i]==','){
            cout << " ";
            continue;
        }
        cout << s[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    
    int N, AC=0, WA=0, TLE=0, RE=0;
    scanf("%d", &N);
    
    char S[N][4];
    for(int i=0;i<N;i++){
    	scanf("%s", S[i]);
	}
    for(int k=0;k<N;k++){
    	if(strcmp(S[k], "AC") == 0){
    		AC++;
		} else if(strcmp(S[k], "WA") == 0){
			WA++;
		} else if(strcmp(S[k], "TLE") == 0){
			TLE++;
		} else if(strcmp(S[k], "RE") == 0){
			RE++;
		}
	}
    printf("AC x %d\n", AC);
    printf("WA x %d\n", WA);
    printf("TLE x %d\n", TLE);
    printf("RE x %d\n", RE);
    
    
    return 0;
}

Measured memory_bytes: 2120
#![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());
    fn gcd(a: i64, b: i64) -> i64 {
        if b == 0 {
            a
        } else {
            gcd(b, a % b)
        }
    }
    let n: usize = io.read();
    let a = io.readn::<i64>(n);

    let mut left = vec![1; n];
    let mut right = vec![1; n];
    left[0] = a[0];
    right[n - 1] = a[n - 1];
    for i in 1..n {
        left[i] = gcd(left[i - 1], a[i]);
    }
    for i in (0..n - 1).rev() {
        right[i] = gcd(right[i + 1], a[i]);
    }

    let mut ans = 1;
    for i in 1..n - 1 {
        ans = max(ans, gcd(left[i - 1], right[i + 1]));
    }
    ans = max(left[n - 2], ans);
    ans = max(right[1], ans);
    io.writeln(ans);
}

static MOD: i64 = 1000000007;
// 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 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: 6396
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct edge{
	int to,rev,F;
};
vector<edge>G[1<<17];
int N,M;
int vis[1<<17];
void dfs(int u,int p)
{
	vis[u]=1;
	int cnt=0,par=-1;
	for(int i=0;i<G[u].size();i++)
	{
		if(vis[G[u][i].to]==0)dfs(G[u][i].to,u);
		if(G[u][i].to!=p&&G[u][i].F!=0)
		{
			if(G[u][i].F==-1)
			{
				G[u][i].F=1;
				G[G[u][i].to][G[u][i].rev].F=0;
			}
			cnt++;
		}
		else if(G[u][i].to==p)par=i;
	}
	if(cnt%2==1)
	{
		G[u][par].F=1;
		G[G[u][par].to][G[u][par].rev].F=0;
	}
	return;
}
main()
{
	cin>>N>>M;
	if(M%2==1)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<M;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back((edge){b,(int)G[b].size(),-1});
		G[b].push_back((edge){a,(int)G[a].size()-1,-1});
	}
	dfs(0,-1);
	for(int i=0;i<N;i++)
	{
		for(edge&e:G[i])
		{
			if(e.F==1)cout<<i+1<<" "<<e.to+1<<endl;
		}
	}
}

Measured memory_bytes: 17408
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

cnt = 0
p_cnt = 0
q_cnt = 0
n_list = [i for i in range(1, n+1)]
for P in itertools.permutations(n_list):
    cnt += 1
    if p == list(P):
        p_cnt = cnt
    if q == list(P):
        q_cnt = cnt
    if p_cnt and q_cnt:
        print(abs(q_cnt-p_cnt))
        exit()

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000


int main(){
	int H,W;
	cin>>H>>W;
	
	vector<string> S(H);
	for(int i=0;i<H;i++)cin>>S[i];
	
	queue<pair<int,int>> q;
	q.push(make_pair(0,0));
	
	while(q.size()!=0){
		pair<int,int> P = q.front();
		q.pop();
		S[P.first][P.second] = '.';
		int cnt = 0;
		for(int i=0;i<4;i++){
			int x = P.second;
			int y = P.first;
			switch(i){
				case 0:{
					x++;
					break;
				}
				case 1:{
					x--;
					break;
				}
				case 2:{
					y++;
					break;
				}
				case 3:{
					y--;
					break;
				}
			}
			if(y<0||y>=H||x<0||x>=W)continue;
			if(S[y][x]=='.')continue;
			if(i==1||i==3){
				cout<<"Impossible"<<endl;
				return 0;
			}
			q.push(make_pair(y,x));
			cnt++;
		}
		if(cnt>=2){
			cout<<"Impossible"<<endl;
			return 0;
		}
	}
	
	cout<<"Possible"<<endl;
	
	
	
	
	return 0;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i <= n - 3; i++) {
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
        }
    cout << ans << 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);
		int num1 = sc.nextInt();
		int num2 = sc.nextInt();
		int num3 = sc.nextInt();

		// ??\??????????????°???????????\??????????¬???????????????????????????°????????\??????
		int[][] table = new int[num1][num2];
		int[][] grid = new int[num2][num3];

		for (int cnt1 = 0; cnt1 < num1; cnt1++) {

			for (int cnt2 = 0; cnt2 < num2; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
			}
		}

		for (int cnt1 = 0; cnt1 < num2; cnt1++) {

			for (int cnt2 = 0; cnt2 < num3; cnt2++) {

				grid[cnt1][cnt2] = sc.nextInt();
			}
		}

		// 2??????????¬????????????????????¨????
		long [][] sum = new long[num1][num3];
		int cnt0;
		int cnt1;
		int cnt2;

		for (cnt0 = 0; cnt0 < num1; cnt0++) {

			for (cnt1 = 0; cnt1 < num3; cnt1++) {

				for (cnt2 = 0; cnt2 < num2; cnt2++) {

					sum[cnt0][cnt1] += table[cnt0][cnt2] * grid[cnt2][cnt1];

				}
				if (cnt1 >= num3-1) {

					System.out.println(sum[cnt0][cnt1]);

				} else {

					System.out.print(sum[cnt0][cnt1] + " ");

				}
			}

		}
		sc.close();
	}

}

Measured memory_bytes: 54220
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <iterator>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

int main(int argc, char *argv[])
{
    int n;
    vector<int> mochi;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        int d;
        scanf("%d", &d);
        mochi.push_back(d);
    }
    sort(mochi.begin(), mochi.end(), greater<int>());
    vector<int>::iterator it = unique(mochi.begin(), mochi.end());
    printf("%d\n", distance(mochi.begin(), it));
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
p = list(map(int, str(input()).split()))

count = 0
for i in range(len(p)-2):
    tmp = [p[i], p[i+1], p[i+2]]
    tmp.sort()
    if tmp[1] == p[i+1]:
        count += 1

print(str(count))

Measured memory_bytes: 3060
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

ll mod = 998244353;
template<typename T> void add(T &a,T b){a=(a+b)%mod;}
template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    int k;
    cin>>s>>k;
    int n = s.size();
    int sum[n+1]={};
    int z = 0;
    int o = 0;
    for(int i=0;i<n;i++){
        if(s[i] == '0'){
            z++;
            sum[z+1] = sum[z];
        }
        else o++;
        sum[z+1] += + (s[i] == '1');
    }
    
    ll dp[z+2][n][n+1]={};
    dp[0][sum[0]][0] = 1;
    for(int i=0;i<z;i++){
        // zero i ko ended
        for(int y=0;y<=min(k,o);y++){
            for(int j=sum[i];j<=min(o,sum[i]+k);j++){
                for(int p=max(j,sum[i+1]);p<=min(sum[i+1]+k,o);p++){
                    ll ret = dp[i][j][y];
                    // if(p>j)add(ret,dp[i+1][p-1]);
                    int cnt = y;
                    int dif = p - j;
                    dif -= sum[i+1] - sum[i];
                    dif = max(0,dif);
                    cnt += dif;
                    // if(p>sum[i+1])cnt = p-sum[i+1];
                    // else{
                    //     // j ni yotte kawaru ?

                    // }
                    if(cnt <= k){
                        add(dp[i+1][p][cnt],ret);
                    }
                }
            }
        }
        // for(int j=sum[i+1];j<=min(o,sum[i+1]+k);j++){
        //     for(int y=0;y<=min(k,o);y++){
        //         cerr << i << " " << j << " " << y << " " << dp[i+1][j][y] << endl;
        //     }
        // }
    }
    ll ans = 0;
    for(int i=sum[z];i<=o;i++){
        //cerr << "ans " << z << " " << i << " " << dp[z][i] << endl;
        
        for(int y=0;y<=min(o,k);y++){
            add(ans,dp[z][i][y]);
            // cerr << z << " " << i << " " << y << " " << dp[z][i][y] << " " << ans << endl;
        }
    }
    cout << ans << endl;

    
}


Measured memory_bytes: 214524
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> a;
int main() {
  cin >> n;
  read_n(a, n);
  vector<i64> cnt(n);
  for (i64 x : a) cnt[x]++;

  for (i64 d = 1; d < n; ++d) {
    i64 r = (d + 1) / 2;
    bool ok = true;
    if (d % 2 == 0) {
      if (cnt[r] != 1) ok = false;
    } else {
      if (cnt[r] != 2) ok = false;
    }
    for (i64 i = 1; i < r; ++i) {
      if (cnt[i] != 0) ok = false;
    }
    for (i64 i = r + 1; i <= d; ++i) {
      if (cnt[i] < 2) ok = false;
    }
    for (i64 i = d + 1; i < n; ++i) {
      if (cnt[i] != 0) ok = false;
    }
    if (ok) {
      cout << "Possible\n";
      return 0;
    }
  }
  cout << "Impossible\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
vector<int> generate_primes(int n) {
    vector<bool> is_prime(n+1);
    vector<int> primes;
    fill(is_prime.begin(), is_prime.end(), true);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= n; i++) {
        if(is_prime[i]) {
            primes.push_back(i);
            for(int j = 2 * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return primes;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> primes = generate_primes(100'000);
    set<int> pset(primes.begin(), primes.end());
    vector<int> sim(100'001);
    for(int i = 1; i <= 100'000; i++) {
        sim[i] = pset.count(i) and pset.count((i + 1) / 2);
    }
    vector<int> rsq(100'001);
    partial_sum(sim.begin(), sim.end(), rsq.begin());
    int q;
    cin >> q;
    while(q--) {
        int L, R;
        cin >> L >> R;
        cout << rsq[R] - rsq[L - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}
int main() {
   int N, X;
   cin >> N >> X;
   vector<int> x(N);
   vector<int> dis(N);
   for(int i = 0; i < N; i++) cin >> x[i];
   sort(x.begin(), x.end());
    ll res = 10000000000;
    
   for(int i = 0; i < N - 1; i++) {
       dis[i] =  x[i + 1] - x[i]; 
   }
    int gc = 0;
    gc = gcd(dis[0], dis[1]);
   for(int i = 2; i < N - 1; i++) {
       gc = gcd(gc, dis[i]);
   }
    ll ans = 0;
    vector<int> d(N);
    for(int i = 0; i < N; i++) {
         d[i] = abs(x[i] - X);
         ans = gcd(gc, d[i]);
    }


    cout << ans;


    return 0;

}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main() 
{
  int n,w,t,i,m,sum;
  string s;
  while(true)
  {
    cin>>i;
    n=2,w=3,t=1;
    sum=1;
    if(i==0)break;
    for(int j=0;j<i;j++)
     {
      cin>>s;
      if(s=="South")m=n,n=t,t=7-m;
      if(s=="North")m=t,t=n,n=7-m;
      if(s=="East")m=t,t=7-w,w=m;
      if(s=="West")m=t,t=w,w=7-m;
      if(s=="Left")m=w,w=n,n=7-m;
      if(s=="Right")m=n,n=w,w=7-m;
      sum+=t;
    }
    cout<<sum<<endl;
  }
}

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

int main()
{
    int P,Q,R;

    cin >>P>>Q>>R;

    if(P>=Q && P>=R) cout << (Q+R);
    else if(Q>=P && Q>=R) cout << (P+R);
    else cout << (P + Q);

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline


def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))

# mod=10**9+7
# rstrip().decode('utf-8')

import numpy as np
from itertools import combinations

def main():
	n,k=MI()
	ans=10**18

	A=LI()
	A=[A[0]-1]+A
	A=np.array(A)

	for t in combinations(range(n),k):
		B=A.copy()
		tmp=0
		for i in t:
			i+=1
			B[i]=max(B[:i].max()+1,A[i])
			tmp+=B[i]-A[i]
		ans=min(ans,tmp)
	print(ans)

if __name__ == "__main__":
	main()


Measured memory_bytes: 12524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,x;
    cin >> n >> x;
    int grm = x;
    int ans = n;
    vector<int> m(n);
    for(int i=0;i<n;i++){
        cin >> m[i];
        grm -= m[i];
    }
    sort(m.begin(),m.end());
    ans += grm/m[0];
    cout << ans << endl;
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 3e5 + 10;
ll bestPref[maxN], bestSuf[maxN];
int a[maxN];
const ll INF = 1e18;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    priority_queue < int > q;
    ll sum = 0;
    for (int i = 1; i <= 3 * n; i++) {
        cin >> a[i];
        sum += a[i];
        q.push(-a[i]);
        while (q.size() > n) {
            sum -= (-q.top());
            q.pop();
        }
        if (q.size() < n) bestPref[i] = -INF;
        else bestPref[i] = sum;
    }
    sum = 0;
    while (!q.empty()) q.pop();
    for (int i = 3 * n; i >= 1; i--) {
        sum += a[i];
        q.push(a[i]);
        while (q.size() > n) {
            sum -= q.top();
            q.pop();
        }
        if (q.size() < n) bestSuf[i] = INF;
        else bestSuf[i] = sum;
    }
    ll ans = -INF;
    for (int i = 1; i <= 3 * n - 1; i++) {
        ans = max(ans, bestPref[i] - bestSuf[i + 1]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6648
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int x, n; cin >> x >> n;
	set<int> s;
	REP(i, 102) s.insert(i);
	REP(i, n ) {
		cin >> tmp;
		s.erase((int) tmp);
	}
	auto it = s.lower_bound(x);
	auto mim = s.lower_bound(x);
	mim--;
	if(abs(*it - x) >= abs(*mim - x)) cout << *mim << endl;
	else cout << *it << endl;
}

Measured memory_bytes: 3624
H,W,M=map(int,input().split())
l = [ list(map(int,input().split(" "))) for i in range(M)]
h=[0]*H
w=[0]*W
for i in range(M):
    h[l[i][0]-1]+=1
    w[l[i][1]-1]+=1
maxh=max(h)
maxw=max(w)
hlist=[]
wlist=[]
for i in range(H):
    if h[i]==maxh:
        hlist.append(i)
for i in range(W):
    if w[i]==maxw:
        wlist.append(i)
c=0
for i in range(M):
  if h[l[i][0]-1]==maxh and w[l[i][1]-1]==maxw:
    c+=1
if len(hlist)*len(wlist)==c:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Measured memory_bytes: 92108
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10


N, K = MAP()
A = LIST()

g = A[0]

for x in A:
	g = gcd(g, x)


if K%g == 0 and K <= max(A):
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Measured memory_bytes: 21536
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    h = list(map(int,ipti().split()))
    dp = [0] * n
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])

    for i in range(2, n):
        dp[i] = min(abs(h[i] - h[i-2]) + dp[i-2], abs(h[i] - h[i-1]) + dp[i-1] )

    print(dp[n-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 13716
n, m = input().split()
n = int(n)
m = int(m)
ans = 0
if min(m, n) != 1:
    ans = max(n * m - (2 * n + 2 * m - 4), 0)
else:
    ans = max(max(n, m) - 2, 1)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N, std::vector<long long> A, std::vector<long long> B) {
  LL ans = 0;
  for (auto elem : A) ans += elem;

  vector<LL> data;
  for (int i = 0; i < N; i++) {
    data.push_back(A[i] + B[i]);
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
  for (int i = 0; i < N; i++) {
    if (i % 2 == 1) ans -= data[i];
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  std::vector<long long> B(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, std::move(A), std::move(B));
  return 0;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
 
#define fr(i,a,b) for(int (i)=(int) a;(i)<=(int)(b);++(i))
#define li list<int>
#define ll long long
#define mp make_pair
#define mod 1000000007
#define pb push_back
#define pi pair<ll,ll>
#define pr printf
#define vi vector<ll>
#define vpi vector< pi > 
int main()
{
	int n;
	cin>>n;
	if(n%10==9||n/10==9)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a,b,c,d,e;
    scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  scanf("%d",&e);
    if (a == 0){
        printf("1");
    }
    else if (b == 0){
        printf("2");
    }
    else if (c == 0){
        printf("3");
    }
    else if (d == 0){
        printf("4");
    }
    else{
        printf("5");
    }

    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  int count = 0;
  for(int i = 0; i < s.size() - 1; i++) {
    for(int j = i + 1; j < s.size(); j++) {
      if(s[i] == s[j]) {
        count++;
      }
    }
  }
  if(count == 2) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
int s[305][305];
P pos[90005];
int x[90005], y[90005];
int H, W, D, Q;
int pw[90005];
int main()
{

   scanf("%d%d%d", &H, &W, &D);
   //cin >> H >> W >> D)
   {
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            //cin >> s[i][j];
            scanf("%d", &s[i][j]);
            x[s[i][j]] = i;
            y[s[i][j]] = j;

            //pos[s[i][j]] = make_pair(i, j);
         }
      }
     // cout << "haha" << endl;

      int L, R;
      for(int i = 1; i <= D;  i++){
            int curx = x[i];
            int cury = y[i];
            pw[i] = 0;
            for(int j = i + D; j <= H*W; j+=D){
               pw[j] += pw[j - D] + abs(x[j] - curx) + abs(y[j] - cury);
               curx = x[j], cury = y[j];
               //cout << j << ' ' << pw[j] << endl;
            }

      }

      //cin >> Q;
      scanf("%d", &Q);
      for (int k = 0; k < Q; k++) {

         //cin >> L >> R;
         scanf("%d%d", &L, &R);
         int ans = pw[R] - pw[L];
         cout <<  ans << endl;
      }

   }


}
/*
5 5 4
13 25 7 15 17
16 22 20 2 9
14 11 12 1 19
10 6 23 8 18
3 21 5 24 4
3
2 10
6 10
10 10
*/


Measured memory_bytes: 2560
# https://atcoder.jp/contests/abc082/tasks/arc087_a
COUNT = Hash.new(0)

n = gets.to_i
nums = gets.split.map(&:to_i)

res = 0

real_size = nums.size
nums.each do |i|
  COUNT[i] += 1
end

COUNT.each_key do |i|
  diff = COUNT[i] - i
  if diff < 0
    res += COUNT[i]
  else
    res += diff
  end
end

puts res

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

using namespace std;

int main(void) {
  int X;
  cin >> X;
  int kyu;
  if (X<=599) {
    kyu = 8;
  } else if (X <= 799) {
    kyu = 7;
  } else if (X <= 999) {
    kyu = 6;
  } else if (X <= 1199) {
    kyu = 5;
  } else if (X <= 1399) {
    kyu = 4;
  } else if (X <= 1599) {
    kyu = 3;
  } else if (X <= 1799) {
    kyu = 2;
  } else  {
    kyu = 1;
  }

  cout << kyu << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 2006, M = N << 1;

int n, m, k;
int tot, head[N], ver[M], nxt[M];
int dist[N];
bool st[N];
int ton[N];
int x, y;

inline void add(int u, int v) 
{
    ver[++tot] = v, nxt[tot] = head[u], head[u] = tot;
}

inline void Dij(int s)
{
    priority_queue <PII> q;
    q.push(make_pair(0, s));
    memset(dist, 0x3f, sizeof dist);
    dist[s] = 0;
    memset(st, false, sizeof st);
    while (!q.empty())
    {
        int u = q.top().second; q.pop();
        if (st[u]) continue;
        st[u] = true;
        for (int i = head[u]; i; i = nxt[i])
        {
            int v = ver[i];
            if (dist[v] > dist[u] + 1)
            {
                dist[v] = dist[u] + 1;
                q.push(make_pair(-dist[v], v));
            }
        }
    }
    for (int i = s + 1; i <= n; i+=1) ++ton[dist[i]];
}

int main()
{
	//File("");
	cin >> n >> x >> y;
	for (int i = 1; i < n; i+=1) add(i, i + 1), add(i + 1, i);
	add(x, y), add(y, x);
	for (int i = 1; i <= n; i+=1)
	    Dij(i);
	for (int i = 1; i < n; i+=1)
	    cout << ton[i] << endl;
	return 0;
}


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

int main() {
	int K, S;
	cin >> K >> S;

	int cnt = 0;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			int n = S - (i + j);
			if ((n >= 0) && (n <= K)) cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <iterator>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector <int> v(n+1);
    for (int i=0; i<n; i++){
        cin >> v[i];
    }
    int kol = 0;
    v[n] = 10000;
    sort(v.begin(), v.end());
    for (int i=0; i<n-2; i++){
        for (int j=i+1; j<n-1; j++){
            auto up = upper_bound(v.begin(), v.end(), v[i]+v[j]-1);
//            cout << up-v.begin() << ' ' <<   v[i]+v[j]-1 << ' ' << v[up-v.begin()] << ' ' << i << ' ' << j << '\n';
            kol += ((up-v.begin())-j-1);
        }
    }
    cout << kol;
    return 0;
}

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

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

fn main() {
    let n: usize = input();
    let s: Vec<i64> = (0..n).map(|_| input()).collect();

    let sum: i64 = s.iter().sum();
    let mut ans = 0;
    if sum % 10 != 0 {
        ans = sum;
    } else {
        for i in s {
            if (sum - i) % 10 != 0 {
                ans = std::cmp::max(ans, sum - i);
            }
        }
    }

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
 
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)
 
#define sl(a) scanf("%I64d", &a)
#define sll(a, b) scanf("%I64d %I64d", &a, &b)
#define slll(a, b, c) scanf("%I64d %I64d %I64d", &a, &b, &c)
 
#define outi(a) printf("%d\n", a)
#define outii(a, b) printf("%d %d\n", a, b)
#define outiii(a, b, c) printf("%d %d %d\n", a, b, c)
 
#define outl(a) printf("%I64d\n", a)
#define outll(a, b) printf("%I64d %I64d\n", a, b)
#define outlll(a, b, c) printf("%I64d %I64d %I64d\n", a, b, c)
 
#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
 
 
#define fr(i, n) for(ll i=0; i<n;i++)
#define fr1(i, n) for(ll i=1; i<=n;i++) 
 
#define readf(f) freopen(f, "r", stdin)
#define writef(f) freopen(f, "w", stdout)
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
 
template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
 
typedef long long ll;
typedef pair<int,int> pii;
 
const int N = 105;
 
int main()
{
 
	int n;

	char s[N],t[N];

	si(n);

	scanf("%s %s",s,t);

	fr(i,n){
		printf("%c%c", s[i],t[i]);
	}
	printf("\n");
 
 
    return 0;
}

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

using namespace std;

char str[200100];
vector<char> vec;

int main() {
    int i, n;
    scanf("%s",str);
    n = strlen(str);
    for (i=0;i<n;i++) {
        if(vec.size()>=1&&vec.back()=='S'&&str[i]=='T') {
            vec.pop_back();
        }
        else vec.push_back(str[i]);
    }
    printf("%d\n",vec.size());
    return 0;
}


Measured memory_bytes: 768
#include<cstdio>
int h,w,d;
int main()
{
	scanf("%d%d%d",&h,&w,&d);
	for(int i=0;i<h;i++,puts(""))
		for(int j=0;j<w;j++)putchar("RGBY"[(i+j)/d%2*2+(i>=j?(i-j)/d%2:(j-i+d-1)/d%2)]);
	return 0;
}


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

int arr[101] = {0};

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while(a>0 || c>0)
	{
		c -= b;
		if(c<=0)
		{
			cout << "Yes";
			return 0;
		}
		a -= d;
		if(a <= 0)
		{
			cout << "No";
			return 0;
		}
	}
}



Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
s = [int(x) for x in input()]
l1 = [i % 2 for i in range(len(s))]
l2 = [1] + l1[:len(l1) - 1]
d1 = len([sv for sv, lv in zip(s, l1) if sv != lv])
d2 = len([sv for sv, lv in zip(s, l2) if sv != lv])
print(d1 if d1 < d2 else d2)


Measured memory_bytes: 6300
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}

vec<ll> g[100100];
ll depth[100100];
ll par[100100][20];

void dfs(ll v,ll p,ll d){
    par[v][0]=p;
    depth[v]=d;
    rep(i,g[v].size()){
        if(g[v][i]!=p) dfs(g[v][i],v,d+1);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s,t;
    cin>>s>>t;
    if(s.size()<t.size()){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    
    for(ll i=s.size()-t.size();i>=0;i--){
        string check=s.substr(i,t.size());
        ll d=0;
        rep(j,t.size()){
            if(check[j]=='?' || check[j]==t[j]) d++;
        }
        if(d==t.size()){
            rep(k,t.size()){
                s[i+k]=t[k];
            }
            rep(k,s.size()){
                if(s[k]=='?') s[k]='a';
            }
            cout<<s<<endl;
            return 0;
        }
    }
    cout<<"UNRESTORABLE"<<endl;
    return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  string s, t;
  cin >> s >> t;
  int size = s.size();

  int ans = 0;
  for(int i = 0; i < size; i++){
    if(s[i] != t[i]) ans ++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3916
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll d,n;
    cin>>d>>n;
    if(n==100)
    {
        cout<<pow(100,d)*101;
    }
    else
    cout<<pow(100,d)*n;}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  int minus_count = 0;
  int min_value = INT_MAX;
  ll sum = 0;
  REP(i, n) {
    int x;
    cin >> x;
    if (x < 0) {
      minus_count++;
    }
    min_value = min(min_value, abs(x));
    sum += abs(x);
  }
  if (minus_count % 2 == 1) {
    sum -= 2 * min_value;
  }
  cout << sum << endl;
}

Measured memory_bytes: 384
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

def wf(d):
    n=len(d)
    for k in range(n):#       // 経由する頂点
        for i in range(n):#    // 始点
            for j in range(n):#  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


n,m,l=MI()
d=[[inf]*n for _ in range(n)]
for i in range(m):
    a,b,c=LI_()
    d[a][b]=c+1
    d[b][a]=c+1

d=wf(d)
g=[[inf]*n for i in range(n)]

for i in range(n):
    for j in range(i+1,n):
        if d[i][j]<=l:
            g[i][j]=1
            g[j][i]=1
g=wf(g)

q=I()
for _ in range(q):
    s,t=LI_()
    if g[s][t]==inf:
        ans=-1
    else:
        ans=g[s][t]-1
    print(ans)
    


Measured memory_bytes: 127196
#include<stdio.h>
int main(){
  int a,b,i;
  scanf("%d%d",&a,&b);
  if(a<b){
    for(i=1; i<=b; i++){
      printf("%d",a);
    }
    printf("\n");
  }
  else{
    for(i=1; i<=a; i++){
      printf("%d",b);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	static class MultiTreeSet {
		private TreeMap<Long, Integer> map = new TreeMap<>();

		int count(long x) {
			return map.getOrDefault(x, 0);
		}

		void add(long x) {
			map.put(x, count(x) + 1);
		}

		void remove(long x) {
			int prev = count(x);
			if (prev == 1) {
				map.remove(x);
			} else {
				map.put(x, prev - 1);
			}
		}

		long getMax() {
			return map.lastKey();
		}

		long getMin() {
			return map.firstKey();
		}

		@Override
		public String toString() {
			return map.toString();
		}

		boolean isEmpty() {
			return map.isEmpty();
		}
	}

	void solve() throws IOException {
		int n = nextInt();
		int[] ls = new int[n];
		int[] rs = new int[n];

		for (int i = 0; i < n; i++) {
			ls[i] = nextInt();
			rs[i] = nextInt();
		}

		int[] minDiff = new int[n - 1];
		int[] maxDiff = new int[n - 1];
		for (int i = 0; i < n - 1; i++) {
			minDiff[i] = ls[i] - rs[i + 1];
			maxDiff[i] = rs[i] - ls[i + 1];
		}

		MultiTreeSet low = new MultiTreeSet();
		MultiTreeSet high = new MultiTreeSet();

		low.add(0);
		high.add(0);

		long deltaLow = 0;
		long deltaHigh = 0;

		long valMin = 0;

		for (int i = 0; i < n - 1; i++) {
			
			deltaLow += minDiff[i];
			deltaHigh += maxDiff[i];

			long lowMax = low.getMax() + deltaLow;
			long highMin = high.getMin() + deltaHigh;

			if (lowMax >= 0) {
				low.add(-deltaLow);
				low.add(-deltaLow);

				long newLowMax = low.getMax() + deltaLow;

				low.remove(newLowMax - deltaLow);
				high.add(newLowMax - deltaHigh);
			} else {
				high.add(-deltaHigh);
				high.add(-deltaHigh);

				long newHighMin = high.getMin() + deltaHigh;

				high.remove(newHighMin - deltaHigh);
				low.add(newHighMin - deltaLow);
			}

			if (lowMax > 0) {
				valMin += lowMax;
			} else if (highMin < 0) {
				valMin -= highMin;
			}
		}

		long lowMax = low.getMax() + deltaLow;
		long highMin = high.getMin() + deltaHigh;

		out.println(valMin);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

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

int main() {
  int H,W;
  cin>>H>>W;
  int C[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>C[i][j];
    }
  }

  for(int k=0;k<10;k++){
    for(int j=0;j<10;j++){
      for(int i=0;i<10;i++){
        if(C[i][j]>C[i][k]+C[k][j]) C[i][j]=C[i][k]+C[k][j];
      }
    }
  }   
  
  int temp;
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>temp;
      if(temp != -1) ans+=C[temp][1];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)

vector<vector<int> > A;
int main(){
    int N,M;
    cin >> N >> M;
    A.resize(N);
    vector<int> B(M);
    int res=0;
    rep(i,0,M) B[i] = N;
    rep(i,0,N){
        int k;
        cin >> k;
        A[i].resize(k);
        rep(j,0,k){
            cin >> A[i][j];
            B[A[i][j] - 1]--;
        }
    }
    rep(i,0,M){
        if(B[i]==0) res++;
    }
    cout << res << endl;

}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<sstream>
#include<numeric>
#include<iostream>
#include<algorithm>
#include<functional>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> Vi;
typedef pair<int,int> pii;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=5e5+19;

int A[N],B[N];
int n,l,r,res;

int check(int mid){
	int x=(n+1)/2,pre=-1,suf=-1;
	For(i,1,n+1) B[i]=(A[i]>=mid);
	if (B[x]==B[x-1]||B[x]==B[x+1]) return B[x]==1;
	for (int i=x-1;i>=1;i--) if (B[i]==B[i+1]) {pre=i;break;}
	for (int i=x+1;i<=n;i++) if (B[i]==B[i-1]) {suf=i;break;}
	if (pre==-1&&suf==-1) return (B[x]+x-1)%2;
	if (pre==-1) return B[suf];
	if (suf==-1) return B[pre];
	return x-pre<suf-x?B[pre]:B[suf];
}

int main(){
	n=IN()*2-1;
	For(i,1,n+1) A[i]=IN();
	l=1,r=n;
	while (l<=r){
		int mid=(l+r>>1);
		if (check(mid)) res=mid,l=mid+1;else r=mid-1;
	}
	printf("%d\n",res);
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007

bool prime_judge(int A)
{
  for (int i = 2; i <= sqrt(A); i++)
  {
    if(A%i == 0) return true;
  }

  return false;
  
  
}


void solve(void)
{ 
  int N,K;
  cin>>N>>K;

  int ANS = K;
  for (int i = 0; i < N-1; i++)
  {
    ANS *= K-1;
  }

  cout<<ANS<<endl;
  
  return;  
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 256
n,a,b=map(int,raw_input().split())
if a+b-1>n or a*b<n :
    print -1
else :
    t=0
    for i in range(a-1,-1,-1) :
        #mx=min((i+1)*b,n)
        #for j in range(min(b,n-i*b)) :
        #    print mx-j,
        sz=min(n-i,b)
        for j in range(sz) :
            print t+sz-j,
        t+=sz
        n-=sz


Measured memory_bytes: 13060