akhauriyash/Code-Regression huggingface dataset:
a, b = [int(i) for i in input().split()]

e=[]
f=[]

for _ in range(b):
    c, d = [int(i) for i in input().split()]
    e.append(c)
    f.append(d)

if min(f) - max(e) + 1 > 0:
    print(min(f) - max(e) + 1)
else:
    print(0)

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	int h, w, n;
	cin >> h >> w >> n;

	vector<int> a(n);
	vector<vector<int>> ar(h, vector<int>(w, 0));
	rep (i, 0, n)
		cin >> a[i];

	int i = 0, j = 0, k = 0;
	int count = 0;
	while (i < h) {
		ar[i][j] = k + 1;
		if (++count == a[k]) {
			k++;
			count = 0;
		}

		if (i & 1) {
			i += (j > 0) ? 0 : 1;
			j += (j > 0) ? -1 : 0;
		} else {
			i += (j < w - 1) ? 0 : 1;
			j += (j < w - 1) ? 1 : 0;
		}
	}

	rep (i, 0, h) {
		rep (j, 0, w) {
			cout << ar[i][j] << " ";
		}
		cout << "\n";
	}


	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const int INF = 1<<29;
long long GCD(long long a, long long b){
  if (b == 0) return a;
  return GCD(b, a % b);
}

long long lcm(long long a, long long b){
  return a * b / GCD(a, b);
}

int main(){
  int A, B; cin >> A >> B;
  cout << lcm(A, B) << endl;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int a[200000],b[200000];
int main() {
	int ans=0;
	int n;
	scanf("%d",&n);
	fup(i,0,n-1,1)scanf("%d",a+i);
	fup(i,0,n-1,1)scanf("%d",b+i);
	fdn(k,28,0,1)
	{
		int K=1<<k;
		fup(i,0,n-1,1)a[i]%=2*K,b[i]%=2*K;
		sort(b,b+n);
		ll cnt=0;
		fup(i,0,n-1,1)
		{
			cnt+=lower_bound(b,b+n,2*K-a[i])-lower_bound(b,b+n,K-a[i]);
			cnt+=lower_bound(b,b+n,4*K-a[i])-lower_bound(b,b+n,3*K-a[i]);
		}
		if(cnt&1)ans|=K;
	}
	printf("%d",ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int maax=0,x=0;
  for (int i=0;i<n;i++) {
    if (s[i]=='I') x++;
    if (s[i]=='D') x--;
    if (maax<x) maax=x;
  }
  cout<<maax<<endl;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int A, B, C, D, E, F;
	cin>>A>>B>>C>>D>>E>>F;
	int sug = -1, wat = -1;
	for(int x1 = 0; ; x1++){
		if(100*A*x1 > F)break;
		for(int x2 = 0; ; x2++){
			if(x1 + x2 == 0)continue;
			if(100*(A*x1 + B*x2) > F)break;
			for(int y1 = 0; ; y1++){
				if(100*(A*x1 + B*x2) + C*y1 > F)break;
				for(int y2 = 0; ; y2++){
					if(100*(A*x1 + B*x2) + C*y1 + D*y2 > F)break;
					if(C*y1 + D*y2 <= E*(A*x1 + B*x2)){
						int ts = C*y1 + D*y2;
						int tw = 100*(A*x1 + B*x2);
						if(sug == -1){
							sug = ts; wat = tw;
						}else if(sug*(tw + ts) < ts*(wat + sug)){
							sug = ts; wat = tw;
						}
					}
				}
			}
		}
	}
	cout<<sug + wat<<" "<<sug<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

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

}


vector<pll> wlist;


bool compare_b(pll a, pll b) {

	if (a.second < b.second) {
		return true;
	}

	return false;

}

int main() {
	ll N, K;

	cin >> N >> K;

	ll hoge = (N - 1) * (N - 2) / 2;
	if (K > (N - 1) * (N - 2) / 2) {
		cout << -1 << endl;
		return 0;
	}


	ll M = hoge - K;


	cout << M + N - 1 << endl;

	for(int i = 1; i < N; i++){
		cout << 1 << " " << i + 1 << endl;
	}

	
	ll ind = 2, kaisuu = 0;
	for(int i = 2; i <= N && kaisuu < M; i++){
		for (int j = i + 1; j <= N && kaisuu < M; j++) {
			cout << i << " " <<  j << endl;
			kaisuu += 1;
		}


	}



	return 0;
}

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

int main(){
  int N;
  double v;
  string s;
  double otoshidama = 0;

  cin >> N;

  for(int i = 0; i < N; i++){
    cin >> v >> s;
    if(s == "JPY")
      otoshidama += v;
    else
      otoshidama += v * 380000.0;

  }
  
  cout << otoshidama << endl;
  return 0;

}
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    double a, b, x;
    cin >> a >> b >> x;
    double water = x / a;
    double s = a * b;
    double rad;
    if ((s / 2) > water)
    {
        double tmp = (b * b) / (water * 2);
        rad = atan(tmp);
    }
    else
    {
        double tmp = 2 * (s - water) / (a * a);
        rad = atan(tmp);
    }
    double ans = rad * (180 / M_PI);
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

Measured memory_bytes: 4044
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(K: int, X: int):
    print(YES if K*500>=X else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(K, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
string s,w="+-*";
int t;
vi a{0,1,2};
ll number(){
	int out=0;
	while(t<s.size()&&isdigit(s[t])){
		out*=10;
		out+=s[t]-'0';
		t++;
	}
	return out;
}
ll expr(){
	vi in;
	vector<char>op;
	while(t<s.size()){
		if(s[t]=='('){
			t++;
			in.pb(expr());
		}else if(s[t]==')'){
			break;
		}else if(isdigit(s[t])){
			in.pb(number());
			t--;
		}else op.pb(s[t]);
		t++;
	}

	rep(i,3)rep(j,op.size())rep(k,3)if(a[k]==i&&op[j]==w[k]){
		char c=w[k];
		if(c=='+')in[j]+=in[j+1];
		if(c=='-')in[j]-=in[j+1];
		if(c=='*')in[j]*=in[j+1];
		in.erase(in.begin()+j+1);
		op.erase(op.begin()+j);
		j--;break;
	}
	return in[0];
}
int main(){
	cin>>s;
	ll out=-9223372036854775807;
	rep(i,3)rep(j,3)rep(k,3){
		t=0;
		a=vi{i,j,k};
		out=max(out,expr());
	}
	cout<<out<<endl;
}









Measured memory_bytes: 3228
<?php
fscanf(STDIN, "%d", $N);
if ($N % 2 !== 0) {
    echo "No";
} else {
    fscanf(STDIN, "%s", $S);
    echo substr($S, 0, $N / 2) === substr($S, $N / 2, $N / 2) ? "Yes" : "No";
}


Measured memory_bytes: 4856
#include <iostream>
#include <vector>
#include <string>
#include <set>

using Bool = bool;
using Int = long long int;
using Char = char;
using String = std::string;
template <class T>
using Vector = std::vector<T>;
template <class T>
using Set = std::set<T>;

int main() {
    String s, t;
    std::cin >> s >> t;

    Vector<Vector<Int>> ssum;
    ssum.reserve(s.length() + 1);

    Vector<Vector<Int>> tsum;
    tsum.reserve(t.length() + 1);

    Vector<Int> acc(26, 0);
    ssum.push_back(acc);
    for (Char c : s) {
        ++acc[c - 'a'];
        ssum.push_back(acc);
    }

    std::fill(acc.begin(), acc.end(), 0);
    tsum.push_back(acc);
    for (Char c : t) {
        ++acc[c - 'a'];
        tsum.push_back(acc);
    }

    Int ans = 0;
    Set<Vector<Int>> ss;
    for (Int l = 0; l <= std::min(s.length(), t.length()); ++l) {
        ss.clear();
        for (Int i = 0; i + l <= s.length(); ++i) {
            for (Int j = 0; j < 26; ++j) {
                acc[j] = ssum[i + l][j] - ssum[i][j];
            }
            ss.insert(acc);
        }

        for (Int i = 0; i + l <= t.length(); ++i) {
            for (Int j = 0; j < 26; ++j) {
                acc[j] = tsum[i + l][j] - tsum[i][j];
            }
            if (ss.count(acc)) ans = l;
        }
    }

    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 6124
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int x2 = 0;
		int count = 1;
		for (int i = 0; i < n; i++) {
			if ((x2 += sc.nextInt()) <= x) {
				++count;
			}
		}
		System.out.println(count);
	}
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;

	for(int i = 0; i < s.size(); i++)
	{
		for(int j = 0; j < i; j++)
		{
			if(s[i] == s[j])
			{
				puts("no");
				return 0;
			}
		}
	}
	puts("yes");
	return 0;
}

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

int main(){
  
  int n,j,i = 0;
  cin >> n;
  
  double A[n];
  
  double Out;
  
  for(i=0;n>i;i++){
    cin >> A[i];
 }
  for(i=0;n>i+1;i++){
    if(A[i]>A[i+1]){
      j = A[i];
      A[i] = A[i+1];
      A[i+1] = j;
      i--;
      i--;
    }
  }
  for(i=0;n>i+1;i++){
    A[i+1] = (A[i]+A[i+1])/2;
  }
  cout << A[n-1];
  
  return 0;
      
}

Measured memory_bytes: 256
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]]
succeed = False
for i in range(6):
    match = True
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
            match = False
            break
        else:
            if x[j] == y[z[i][j]]:
                order[j] = 1
                if x[j] == x[-j-1]:
                    order[j] = 2
    if match:
        if order[0] == 2 or order[1] == 2 or order[2] == 2:
            succeed = True
            break
        if z[i][3] == 0 or z[i][3] == 3:
            if sum(order) % 2:
                succeed = True
                break
        if z[i][3] == 1:
            if not sum(order) % 2:
                succeed = True
                break
if succeed:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 7744
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define VECCIN(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int N;
    cin >> N;
    cout << "ABC" << N << endl;
    return 0;
}

Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc133/tasks/abc133_c
// math
import std.algorithm;
import std.stdio;

void main() {
    long l, r;
    readf("%d %d\n", &l, &r);

    if(r - l >= 2018) {
        0.writeln;
        return;
    }

    long minima = int.max;
    for(long i = l; i < r; i++) {
        for(long j = i + 1; j <= r; j++) {
            minima = min(minima, i*j % 2019);
        }
    }

    minima.writeln;
}



Measured memory_bytes: 2764
#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<#x<<": " <<x<<" ";
#define ll long long
const long long  N=1e5+12,big=1e18,mod=1e9+7;
const double pi=acos(-1);

long long n,k,a[200],dp[103][N],prf[103][N];
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);

    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];

    dp[n+1][0]=1;
    for(int i=n;i>=1;i--)
    {
        for(int j=1;j<=k+1;j++)
            prf[i+1][j]=( (prf[i+1][j-1]%mod)+(dp[i+1][j-1]%mod))%mod;

        for(int j=0;j<=k;j++)
            dp[i][j]=(prf[i+1][j+1]%mod)- (prf[i+1][max(0LL,j-a[i])]%mod) , dp[i][j]+=mod , dp[i][j]%=mod;



    }

//
//    cout<<"DP :"<<endl;
//    for(int i=n+1;i>=1;i--)
//    {
//        for(int j=0;j<=k;j++)
//            cout<<dp[i][j]<<" ";
//        cout<<endl;
//    }
//    cout<<endl<<"prf :"<<endl;
//    for(int i=n+1;i>=1;i--)
//    {
//        for(int j=0;j<=k+1;j++)
//            cout<<prf[i][j]<<" ";
//        cout<<endl;
//    }
    cout<<dp[1][k];


}


Measured memory_bytes: 158464
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	int t[n+1],x[n+1],y[n+1];
	t[0]=0;x[0]=0;y[0]=0;
	for(i=1;i<=n;i++)
		cin>>t[i]>>x[i]>>y[i];
	for(i=1;i<=n;i++)
		if(x[i]+y[i]>t[i] || (x[i]+y[i])%2!=t[i]%2){
			cout<<"No";
			return 0;
		}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1408
n=int(input())
t=[int(input()) for i in range(n)]

from fractions import gcd
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(t))

Measured memory_bytes: 5076
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    ll tmp = 1;
    while(tmp * 2 <= N)
        tmp *= 2;
    cout << tmp << endl;
    return 0;
}


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

int main (){
  string S;
  cin >> S;
  
  string ans = "";
  
  for(int i=0; i<S.size(); i++){
    if(S.at(i) == '0'){
      ans += '0';
    }
    else if(S.at(i) == '1'){
      ans += '1'; 
    }
    else if(S.at(i) == 'B'){
      if(ans.size() != 0){
      ans.erase(ans.size()-1);
      }
    }
  }
    
  cout << ans << endl;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

int n, q;
bool dp[2001];

int main(){
	std::cin >> n;
	dp[0] = true;
	rep(i, n){
		int a;
		std::cin >> a;
		rrep(j, 2000)if (j + a < 2001 && dp[j])dp[j + a] = true;
	}

	std::cin >> q;
	rep(i, q){
		int m;
		std::cin >> m;
		std::cout << (dp[m] ? "yes" : "no") << std::endl;
	}

	return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(string & ns){
    int N = ns.size();
    vector<vector<int>> dp(N+1, vector<int>(2));
    dp[0][0] = 0;
    dp[0][1] = 1;
    rep(i,1,N+1) {
        int digit = ns[i-1] - '0';
        dp[i][0] = min(dp[i-1][0] + digit, dp[i-1][1] + (10 - digit));
        dp[i][1] = min(dp[i-1][0] + (digit+1), dp[i-1][1] + (10 - (digit+1)));
    }
    cout << dp[N][0] << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    string N;
    cin >> N;
    solve(N);
    return 0;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int>a(n), b(n), c(n);
    for(int i=0; i<n; ++i)
        cin>>a[i];
    for(int i=0; i<n; ++i)
        cin>>b[i];
    for(int i=0; i<n-1; ++i)
        cin>>c[i];
    int ans = 0;
    for(int i=0; i<n; ++i) {
        int dish = a[i];
        ans += b[dish-1];
        if(i > 0 && a[i] - a[i-1] == 1)
            ans += c[a[i-1]-1];
    }   
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        public class City : IComparable<City>
        {
            public static bool compare_index = false;

            public City(int p, int y, int ind)
            {
                index = ind;
                prefecture = p;
                year = y;
            }

            public int index { get; private set; }
            public int prefecture { get; private set; }
            public int year { get; private set; }
            public int order { get; set; }

            public int CompareTo(City e)
            {
                if (compare_index)
                {
                    return index.CompareTo(e.index);
                }

                int y = prefecture.CompareTo(e.prefecture);
                if (y == 0)
                {
                    y = year.CompareTo(e.year);
                }

                return y;
            }
        }

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[1]);

            List<City> listC = new List<City>();

            for (int i = 0; i < N; i++)
            {
                s = Console.ReadLine().Split(' ');

                City c = new City(int.Parse(s[0]), int.Parse(s[1]), i);
                listC.Add(c);
            }

            int ord = 1;
            int prev = -1;
            listC.Sort();
            for (int i = 0; i < N; i++)
            {
                City c = listC[i];
                if ( c.prefecture != prev)
                {
                    ord = 0;
                    prev = c.prefecture;
                }

                ord++;

                c.order = ord;
            }

            City.compare_index = true;
            listC.Sort();


            for (int i = 0; i < N; i++)
            {
                City c = listC[i];
                Console.WriteLine("{0:D6}{1:D6}", c.prefecture, c.order);
            }
        }
    }
}


Measured memory_bytes: 25492
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(str(input()))
T = []

for i in t:
  if i == "s":
    T.append(r)
  if i == "p":
    T.append(s)
  if i == "r":
    T.append(p)

ans = 0
for i in range(n):
  if i+k < n:
    if t[i] == t[i+k]:
      T[i+k] = 0
      t[i+k] = "q"
      ans += T[i]
    else:
      ans += T[i]
  else:
    ans += T[i]
print(ans)

Measured memory_bytes: 4792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
#define inf 1<<29
#define nu 4000005
#define maxnum 1000000
int n,k;
string ch="AKIHABARA";
char s[55];
int main()
{
    cin>>s;
    int t=strlen(s);
    if(t>9) cout<<"NO"<<endl;
    else
    {
        int p,q;
        p=q=0;
        int flag=0;
        while(p<t&&q<9){
            if(s[p]==ch[q]) {p++,q++;}
            else if(ch[q]=='A') q++;
            else
                break;
        }
        while(q<9) {
                if(ch[q]=='A') q++;
                else
                    break;
         }
        if(p==t&&q==9) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int H,W;
    cin >> H>> W;
    ll i,j,k,l;
    ll field[H+2][W+2];
    string line;
    string ans[H+2][W+2];
    for(i=0;i<=H+1;i++){
      field[i][0]=0;
      field[i][W+1]=0;
    }
    for(j=0;j<=W+1;j++){
      field[0][j]=0;
      field[H+1][j]=0;
    }
    for(i=1;i<H+1;i++){
      cin >>line;
      for(j=1;j<W+1;j++){
        if(line[j-1] == '.')field[i][j]=0;else field[i][j]=1;
      }
    }
    ll tmp;
    for(i=1;i<H+1;i++){
      for(j=1;j<W+1;j++){
        tmp=0;
        for(k=-1;k<=1;k++){
          for(l=-1;l<=1;l++){
            if(field[i+k][j+l]==1)tmp++;
          }
        }
        ans[i][j]=to_string(tmp);
        if(field[i][j]==1)ans[i][j]="#";
      }
    }
    for(i=1;i<H+1;i++){
      for(j=1;j<W+1;j++){
        cout << ans[i][j];
      }
      cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define MXN 100003

int n,m,ans,
	x,y,
	f[MXN];
bool
	t[MXN];

int main(){

	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		f[i]=1;
	t[1]=1;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		f[x]--;
		f[y]++;
		if(t[x])
			t[y]=1;
		if(f[x]==0)
			t[x]=0;
	}
	for(int i=1;i<=n;i++)
		if(t[i])
			ans++;
	printf("%d\n",ans);
	//system("pause");
	return 0;
}


Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<vector<pair<int,int>>> xs(N);
  F0R(i, N) {
    int a;
    cin >> a;
    F0R(j, a) {
      int x, y;
      cin >> x >> y;
      x--;
      xs[i].emplace_back(x, y);
    }
  }

  int result = 0;
  auto dfs = [&](auto dfs, int v, int score, vector<int> ys)->void {

    if (v >= N) {
      //debug(score);
      //Print(ys);
      chmax(result, score);
      return;
    }

    // 不親切
    if (ys[v] != 1) {
      int temp = ys[v];
      ys[v] = 0;
      dfs(dfs, v + 1, score, ys);
      ys[v] = temp;
    }

    // 正直者
    if (ys[v] != 0) {
      ys[v] = 1;
      F0R(i, xs[v].size()) {
        int p = xs[v][i].first;
        if (ys[p] >= 0 && ys[p] != xs[v][i].second) {
          return;
        }
        ys[p] = xs[v][i].second;
      }
      dfs(dfs, v + 1, score + 1, ys);
    }
  };
  dfs(dfs, 0, 0, vector<int>(N, -1));

  cout << result;
}
#endif


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;


int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }

    auto amitr = max_element(a.begin(), a.end());
    double cr = (*amitr+2)/2.0 - 1;
    int i_ = 0;
    if(amitr == a.begin()) {
        i_ = 1;
    }
    rep(i, n) {
        if(abs(a[i_]-cr) > abs(a[i]-cr)) {
            i_ = i;
        }
    }

    cout << *amitr << ' ' << a[i_] << '\n';
}

Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
for i in range(0,n-2,2):
  s-=a[i]*2
b=[0]*n
b[n-1]=s
b[0]=2*a[n-1]-b[n-1]
for i in range(1,n):
  b[i]=2*a[i-1]-b[i-1]
print(*b)

Measured memory_bytes: 64484
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int a, b, c, tmp;
    a = sc.nextInt();
    b = sc.nextInt();
    c = sc.nextInt();

    if(a > b){
      tmp = a;
      a = b;
      b = tmp;
    }

    if(b > c){
      tmp = b;
      b = c;
      c = tmp;
    }

    if(a > b){
      tmp = a;
      a = b;
      b = tmp;
    }

    System.out.println(a + " " + b + " " + c);
/*fin*/
    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 17316
function Main(str) {
    str=str.split(/\n/);
    var a = str[0].split(' ')[0];
    var b = str[0].split(' ')[1];
    var total = b-a;
    function cal(a,b,total){
        return total*(total+1)/2-b;
    }
    console.log(cal(a,b,total));
}
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>

using namespace std;

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

	bool flag = false;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == N) {
				flag = true;
				break;
			}
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long ll;
const int maxN = 1e5 + 5;
int a[maxN], b[maxN], c[maxN], N;
ll s1[maxN], s2[maxN], s3[maxN];

void work(int* small, int* big, ll* s, ll* S) {
	ll tmp = 0, tot = 0;
	for(int i = 1; i <= N; ++i) {
		while(tot < N && small[tot + 1] < big[i]) 
		tot++, tmp += s[tot];
		S[i] = tmp;
	}
}

int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i) scanf("%d", &a[i]);
	for(int i = 1; i <= N; ++i) scanf("%d", &b[i]);
	for(int i = 1; i <= N; ++i) scanf("%d", &c[i]);
	sort(a + 1, a + 1 + N);
	sort(b + 1, b + 1 + N);
	sort(c + 1, c + 1 + N);
	for(int i = 1; i <= N; ++i) s1[i] = 1;
	work(a, b, s1, s2);
	work(b, c, s2, s3);
	ll ans = 0;
	for(int i = 1; i <= N; ++i) ans += s3[i];
	printf("%lld\n", ans);
	return 0;
} 

Measured memory_bytes: 3712
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 205000;

int len, n;
int a[MAXN];
long long sum[MAXN];

int main() {

    scanf("%d %d", &len, &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    long long ans = 1e9;
    for (int i = 0; i < n; i++) {
        long long cur = a[n - 1] - a[i];
        if (i > 0) {
            cur += a[i - 1] + len - a[n - 1];
        }
        ans = min(ans, cur);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  auto bsearch = [&]() {
    bool fin = false;
    string s0;

    auto query = [&](int k) {
      cout << k << endl;
      string s;
      cin >> s;
      return s;
    };
    auto test = [&](int k) {
      string s = query(k);
      if(s == "Vacant") {
        return fin = true;
      } else if((k%2==1 && s!=s0) || (k%2==0 && s==s0)) {
        return true;
      } else {
        return false;
      }
    };

    int ok = 0, ng = N;
    s0 = query(0);
    while(abs(ok-ng)>1) {
      int mid = (ok+ng)/2;
      if(test(mid)) {
        if(fin) return;
        ok = mid;
      } else {
        ng = mid;
      }
    }
  };
  bsearch();
  return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli n;
	cin>>n;
	lli a[n],i;
	fr(i,n)
	{
		cin>>a[i];
	}
	lli j=1,count=0;
	fr(i,n)
	{
		if(a[i]!=j)
			count++;
		else
			j++;
	}
	if(count==n)
	{
		cout<<"-1";
		return 0;
	}
	cout<<count<<"\n";
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に

int main() {
  ll a,b,c;
  cin>>a>>b>>c;
  ll d = c - a - b;
  cout << (0 < d && 4 * a * b < d * d ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int ans[100];
int query[100];
int Ms[1000001];
int Ds[1000001];
int Cs[1000001];
long MCs[1000001];
void Calc(){
	int N = rei();
	string S = res();
	int Q = rei();
	for(int i=0;i<Q;i++){
		query[i] = rei(); 
	}
	for(int i=0;i<N;i++){
		if(S[i] == 'D'){
			Ds[i]++;
		}
		if(S[i] == 'M'){
			Ms[i]++;
		}
		if(S[i] == 'C'){
			Cs[i]++;
		}
	}
	for(int i=0;i<N-1;i++){
		Ds[i+1] += Ds[i];
		Ms[i+1] += Ms[i];
		Cs[i+1] += Cs[i];
	}
	for(int i=0;i<N;i++){
		if(S[i] == 'C'){
			MCs[i] = Ms[i];
		}
	}
	for(int i=0;i<N-1;i++){
		MCs[i+1] += MCs[i];
	}
	for(int q=0;q<Q;q++){
		long ans = 0;
		for(int i=0;i<N;i++){
			if(S[i] == 'D'){
				long c = MCs[min(N-1,i+query[q]-1)] - MCs[i];
				c -= ((long)(Cs[min(N-1,i+query[q]-1)] - Cs[i]))*Ms[i];
				ans += c;
			}
		}
		cout << ans << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

int main() {
    int n;cin>>n;
    ll h[n];
    rep(i,n)cin>>h[i];
    ll maxh = h[0];
    if(n==1)cout<<"Yes"<<endl;
    else{
        repd(i,1,n){
            if(h[i]<max(maxh,h[i-1])-1){
                cout<<"No"<<endl;
                return 0;
            }
            maxh = max(maxh,h[i]);
        }
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair <long long,long long> ii;
// typedef complex<long double> point;
 
ll n;
const ll s = 700;
 
struct querie{
	ll l,r,id;
	bool operator < (const querie& rhs) const{
       if (l / s != rhs.l / s)
        return make_pair(l,r) < make_pair(rhs.l,rhs.r);
      return (l / s & 1) ? (r < rhs.r) : (r > rhs.r);
	}
};
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin >> n;
   ll q;
   cin >> q;
	vector <ll> arr(n);
	for (int z=0;z<n;z++){
		cin >> arr[z];
	}
	
	vector <querie> que(q);
	for (int z=0;z<q;z++){
		cin >> que[z].l >> que[z].r;
		que[z].l--;que[z].r--;
		que[z].id = z;
	}
	sort(que.begin(),que.end());
	ll l = 0;
	ll r = 0;
	ll count = 1;
	vector <ll> mapp(n+1);
	mapp[arr[0]]++;
	vector <ll> ans(q);
	for (int z=0;z<q;z++){
		while (que[z].l < l){
			l--;
			mapp[arr[l]]++;
			if (mapp[arr[l]] == 1) count++;
		}
		while (que[z].l > l){
			mapp[arr[l]]--;
			if (mapp[arr[l]] == 0) count--;
			l++;
		}
		while (que[z].r < r){
			mapp[arr[r]]--;
			if (mapp[arr[r]] == 0) count--;
			r--;
		}
		while (que[z].r > r){
			r++;
			mapp[arr[r]]++;
			if (mapp[arr[r]] == 1) count++;
		}
		ans[que[z].id] = count;
	}
	for (ll i : ans){
		cout << i  << endl;
	}
}
 

Measured memory_bytes: 27168
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long H, W, A, B;
  cin >> H >> W >> A >> B;
  if (A * 2 > W) {
    cout << "No" << endl;
    return;
  }
  if (B * 2 > H) {
    cout << "No" << endl;
    return;
  }
  rep (h, H) {
    rep (w, W) {
      if ((h < B) ^ (w < A)) cout << 0;
      else cout << 1;
    }
    cout << endl;
  }
}

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


Measured memory_bytes: 1280
N=int(input())
A = [int(j) for j in input().split()]
ans=0
min_A=10**5

A_count= len([a for a in A if a <0])
if A_count%2==0:
    for a in A:
        if a <0:
            ans+= -1*a
        else:
            ans+=a


elif A_count%2!=0:
    for a in A:
        ans+=abs(a)
        min_A=min(min_A,abs(a))
    ans=ans-2*min_A
print(ans)

Measured memory_bytes: 14224
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

int f(const vector<int>& a, int b){
    int x = 0;
    rep(i, (int)a.size()){
        x += abs(a[i] - (b + i+1));
    }
    return x;
}

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

    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
        a[i] -= i+1;
    }
    sort(a.begin(), a.end());

    int b = a[n / 2];
    int s = 0;
    rep(i, n){
        s += abs(a[i] - b);
    }
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 1792
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [True for i in range(N)]
for i in range(M) :
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    if(H[a] <= H[b]) :
        A[a] = False
    if(H[b] <= H[a]) :
        A[b] = False

ans = 0
for i in range(N) :
    if(A[i]) :
        ans += 1
print(ans)

Measured memory_bytes: 19972
/* competitive programming circle traP */
/* template */
#include <stdio.h>
#include <stdlib.h>
#include <queue>
using namespace std;

int h,w;
int vert[30][30];
int hori[30][30];
bool used[30][30];
int dy[4] = {1,0,-1,0};
int dx[4] = {0,1,0,-1};

bool cango(int sy,int sx,int ty,int tx){
  if(sy==ty && abs(sx-tx)==1){
    int x = min(sx,tx);
    return (vert[sy][x]==0);
  }else if(sx==tx && abs(sy-ty)==1){
    int y = min(sy,ty);
    return (hori[y][sx]==0);
  }
  return false;
}

int bfs(int sy,int sx,int gy,int gx){
  for(int i=0;i<h;i++)for(int j=0;j<w;j++){
    used[i][j] = false;
  }
  queue<int> qy,qx,qd;
  used[sy][sx] = true;
  qy.push(sy); qx.push(sx); qd.push(0);
  while(!qy.empty()){
    int y,x,d;
    y = qy.front(); qy.pop();
    x = qx.front(); qx.pop();
    d = qd.front(); qd.pop();
    if(y==gy && x==gx)return d;
    for(int i=0;i<4;i++){
      int ny = y+dy[i];
      int nx = x+dx[i];
      int nd = d+1;
      if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
      if(used[ny][nx])continue;
      if(!cango(y,x,ny,nx))continue;
      used[ny][nx] = true;
      qy.push(ny); qx.push(nx); qd.push(nd);
    }
  }
  return -1;
}

int main(){
  while(true){
    scanf("%d%d",&w,&h);
    if(h==0 && w==0)break;
    for(int k=0;k<2*h-1;k++){
      int i = k/2;
      if(k%2==0){
        // vert
        for(int j=0;j<w-1;j++){
          scanf("%d",&vert[i][j]);
        }
      }else{
        // hori
        for(int j=0;j<w;j++){
          scanf("%d",&hori[i][j]);
        }
      }
    }
    int ans = bfs(0,0,h-1,w-1)+1;
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1060
n,m=map(int,input().split())
adj=[[]for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    adj[a].append(b)
    adj[b].append(a)
for i in adj[0]:
    if n-1 in adj[i]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Measured memory_bytes: 41684
s = input()
n = len(s)
# indごとの、次のLまでの距離
next_L = [0] * n
next_R = [0] * n
dist = 0
for i in range(n-1,-1,-1):
    if s[i] == 'R':
        dist += 1
        next_L[i] = dist
    else:
        dist = 0
dist = 0
for i in range(n):
    if s[i] == 'L':
        dist += 1
        next_R[i] = dist
    else:
        dist = 0
ans_ls = [0] * n
for i in range(n):
    if s[i] == 'R':
        if next_L[i] % 2 == 0:
            ans_ls[i+next_L[i]] += 1
        else:
            ans_ls[i+next_L[i]-1] += 1
for i in range(n-1,-1,-1):
    if s[i] == 'L':
        if next_R[i] % 2 == 0:
            ans_ls[i-next_R[i]] += 1
        else:
            ans_ls[i-next_R[i]+1] += 1
ans_ls = list(map(str,ans_ls))
print(' '.join(ans_ls))




Measured memory_bytes: 77396
/*https://atcoder.jp/contests/abc118/tasks/abc118_b*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	int n, m, k, a[30][30], b[30];
	cin >> n >> m;
	for (int i = 0; i < m + 1; i++)
		b[i] = 0;
	int l = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> a[l][j];
			b[a[l][j]]++;
		}
		l++;
	}
	int count = 0;
	for (int i = 1; i < m + 1; i++)
	{

		if (b[i] == n)
			count++;
	}
	cout << count;

}

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	k := nextInt()

	i := 0
	for {
		// takahashi
		if i >= k {
			break
		}
		if a%2 == 0 {
		} else {
			a--
		}
		tmp := a / 2
		a -= tmp
		b += tmp
		i++

		// aoki
		if i >= k {
			break
		}
		if b%2 == 0 {
		} else {
			b--
		}
		tmp = b / 2
		b -= tmp
		a += tmp
		i++
	}
	fmt.Println(a, b)

}


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

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

  int n; cin >> n;
  vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  int b = a[1];
  for (int i = 2; i < n; i++)
    if (min(b, a[0] - b) < min(a[i], a[0] - a[i]))
      b = a[i];
  cout << a[0] << " " << b << "\n";
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i];
    }
    int k = lower_bound(A.begin(), A.end(), X) - A.begin();
    cout << min(k, M - k) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<cstdio>
#include<string.h>
#include<set>
#include<algorithm>

using namespace std;
#define inf 0x3f3f3f3f;
set<int>s;
int gh[1000][1000],w[2000],dis[1000][1000],pre[2000];
bool vis[20000]={0}; 
        

int main()
{
    int i,j,k,l,n,m,r,a,b,c;
    int sum;
    int sx[10000];
    cin>>n>>m>>r;
    for (i=0;i<r;i++)
       cin>>sx[i];
       
    for (i=1;i<=n;i++)
      for (j=1;j<=n;j++)
      {
        gh[i][j]=inf;
        dis[i][j]=inf;
      }
     
    for (i=1;i<=n;i++)
    {
       gh[i][i]=0;     
       dis[i][i]=0;
    } 
       
    for (i=1;i<=m;i++)
    {
        cin>>j>>k>>l;
        if (gh[j][k]>l || gh[k][j]>l)
        {
          gh[j][k]=l;
          gh[k][j]=l;
        }
    }
  for (k=1;k<=n;k++)
    for (i=1;i<=n;i++)
      for (j=1;j<=n;j++)
        
           if (gh[i][j]>gh[i][k]+gh[k][j])
             gh[i][j]=gh[i][k]+gh[k][j];
    sort(sx,sx+r);
    int ans=inf;
    do 
    { 
       sum=0;
       for (i=0;i<r-1;i++)
           sum=sum+gh[sx[i]][sx[i+1]];
       ans=min(ans,sum);
    }while (next_permutation(sx,sx+r));    
   
    cout<<ans<<endl;

    return 0;
}
        
    
    


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main()
{
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;

  rep(i, n) {
    cout << s[i] << t[i];
  }

  cout << endl;

  return 0;
}


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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define delete

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

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

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

    int xor_all = 0;
    rep(i, n) xor_all = A[i]^xor_all;

    rep(i, n) cout << (xor_all^A[i]) << ' ';
    cout << endl;

    return 0;
}

Measured memory_bytes: 3968