akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1);
    vector<ll> B(N+1);
    vector<ll> C(N);
    vector<ll> D(N+1,0);
    for(ll i = 0;i < N + 1;i++){
        ll a;
        cin >> a;
        A[i] = a;
        B[i] = a;
    }
    for(ll i = 0;i < N;i++){
        ll a;
        cin >> a;
        C[i] = a;
    }
    ll ans = 0;
    for(ll i = 0;i < N;i++){
        if(A[i] > C[i] + D[i]){
            ans += C[i] + D[i];
            
        }else{
            int f = C[i] + D[i] - A[i];
            ans += A[i];
            if(f > C[i]){
                D[i+1] = C[i];
            }else{
                D[i+1] = C[i] + D[i] - A[i];
            }
        }
    }
    if(D[N] >= A[N]){
        ans += A[N];
    }else{
        ans += D[N];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
A, B, C = list(map(int, input().split()))
c = 0
while True:
	if A == B and B == C:
		break
	else:
		ABC = sorted([A, B, C])
		if ABC[2] - ABC[0] == 1:
			ABC[0] += 1
			ABC[1] += 1
		else:
			ABC[0] += 2
		A = ABC[0]
		B = ABC[1]
		C = ABC[2]
		c += 1
print(c)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const int inf = 1e8;

const int N = 801;
string a[N];

int tbl[N][N];

int main(void){
  int h, w, k;
  cin >> h >> w >> k;
  REP(i, 0, h) {
    cin >> a[i];
  }
  // first k steps
  typedef pair<PI, int> PPII;
  int sx = -1, sy = -1;
  REP(i, 0, h) {
    REP(j, 0, w) {
      if (a[i][j] == 'S') {
	sx = i;
	sy = j;
      }
    }
  }
  REP(i, 0, h) {
    REP(j, 0, w) {
      tbl[i][j] = inf;
    }
  }
  queue<PPII> que;
  que.push(PPII(PI(sx, sy), 0));
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  while (not que.empty()) {
    PPII t = que.front(); que.pop();
    int x = t.first.first;
    int y = t.first.second;
    int turn = t.second;
    if (tbl[x][y] <= turn) {
      continue;
    }
    tbl[x][y] = turn;
    if (turn >= k) { continue; }
    REP(d, 0, 4) {
      int nx = x + dx[d];
      int ny = y + dy[d];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) {
	continue;
      }
      if (a[nx][ny] == '#') { continue; }
      que.push(PPII(PI(nx, ny), turn + 1));
    }
  }
  int mi = inf;
  REP(i, 0, h) {
    mi = min(mi, tbl[i][0]);
    mi = min(mi, tbl[i][w - 1]);
  }
  REP(i, 0, w) {
    mi = min(mi, tbl[0][i]);
    mi = min(mi, tbl[h - 1][i]);
  }
  if (mi != inf) {
    cout << (mi + k - 1) / k << endl;
    return 0;
  }
  // bfs without blocks
  REP(i, 0, h) {
    REP(j, 0, w) {
      if (tbl[i][j] != inf) {
	que.push(PPII(PI(i, j), k));
      }
      tbl[i][j] = inf;
    }
  }
  while (not que.empty()) {
    PPII t = que.front(); que.pop();
    int x = t.first.first;
    int y = t.first.second;
    int turn = t.second;
    if (tbl[x][y] <= turn) {
      continue;
    }
    tbl[x][y] = turn;
    REP(d, 0, 4) {
      int nx = x + dx[d];
      int ny = y + dy[d];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) {
	continue;
      }
      que.push(PPII(PI(nx, ny), turn + 1));
    }
  }
  if (0) {
    REP(i, 0, h) {
      cerr << "tbl[" << i << "]:";
      REP(j, 0, w) {
	cerr << " " << tbl[i][j];
      }
      cerr << endl;
    }
  }
  mi = inf;
  REP(i, 0, h) {
    mi = min(mi, tbl[i][0]);
    mi = min(mi, tbl[i][w - 1]);
  }
  REP(i, 0, w) {
    mi = min(mi, tbl[0][i]);
    mi = min(mi, tbl[h - 1][i]);
  }
  assert (mi != inf);
  cout << (mi + k - 1) / k << endl;
}


Measured memory_bytes: 5376
a1,b1=map(int, input().split())
a2,b2=map(int, input().split())
a3,b3=map(int, input().split())
a4,b4=map(int, input().split())
a5,b5=map(int, input().split())
a6,b6=map(int, input().split())
a7,b7=map(int, input().split())

def cal(a,b):
    x=a-b
    return x

x1=cal(a1,b1)
x2=cal(a2,b2)
x3=cal(a3,b3)
x4=cal(a4,b4)
x5=cal(a5,b5)
x6=cal(a6,b6)
x7=cal(a7,b7)

print(x1)
print(x2)
print(x3)
print(x4)
print(x5)
print(x6)
print(x7)



Measured memory_bytes: 5604
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: String,
        k: usize,
    }

    let ans = match s.chars().take(k).find(|&c| c != '1') {
        Some(c) => c,
        None => '1',
    };

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


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
    int n, a;
    scanf("%d", &n);
    long long int max = 0, min = 1000000, cont = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a);
        if (a >= max)
        {
            max = a;
        }
        if (a <= min)
        {
            min = a;
        }
        cont += a;
    }
    if (n == 1)
    {
        min = a;
        max = a;
    }
    printf ("%lli %lli %lli\n", min, max, cont);
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef complex <double> cp;
#define debug(a) cout<<#a<<":"<<a<<endl;
#define fr freopen("in.txt","r",stdin);
#define Fill(x,a) memset(x,a,sizeof(x))
#define cpy(a,b) memcpy(a,b,sizeof(a))
const double PI = acos(-1);
const int INF=0x3f3f3f3f;
const int N=1e6+7;
const int mod=1e9+7;
int maxn,minn;
int T,n,m,q;
int a[N], b[N], c[N];
int n1[200006],n2[200006];
int main(){
	cin >> n;
	for(int i = 1; i <= n; i ++ ){
		scanf("%d", a + i);
		n1[a[i]]++;
	}
	for(int i = 1;i <= n; i ++ ){
		scanf("%d", b + i);
		n2[b[i]]++;
	}
	reverse(b + 1, b + n + 1);
	int l, r, flag, num;
	l = r = flag = num = 0;
	for(int i = 1; i <= n; i ++ ){
		if(a[i] == b[i] && l == 0){
			l = i;
			r = i;
			flag = a[i];
		}
		else if(a[i] == b[i] && l){
			r = i;
		}		
	}
	if(l==0){
	cout<<"Yes\n"<<b[1];
	for(int i=2;i<=n;++i){cout<<' '<<b[i];}
	cout<<'\n';
	return 0;
	}
	if(n-n2[a[l]]<r-l+1){cout<<"No\n";return 0;}
	if(l){
		for(int i = 1; i <= n && num <= r - l; i ++ ){
			if(b[i] != flag && a[i] != flag){
				b[l + num] = b[i];
				b[i] = flag;
				num ++ ;
			}
		} 
	}
	if(l == 0 || num == r - l + 1){
		puts("Yes");
		for(int i = 1;i <= n; i ++ ){
			cout << b[i] << " ";
		}
		cout << endl;
	}
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 6760
import sys
from collections import deque

input = sys.stdin.readline

N, M = map(int, input().split())
T = [set() for _ in range(N)]
for _ in range(M):
    l, r, d = map(int, input().split())
    T[l - 1].add((r - 1, d))
    T[r - 1].add((l - 1, -d))

Nvisited = set(range(N))
pos = dict()


def dfs(v):
    D = deque()
    D.append(v)
    pos[v] = 0
    while D:
        x = D.pop()
        for y, d in T[x]:
            if y in Nvisited:
                pos[y] = pos[x] + d
                Nvisited.remove(y)
                D.append(y)
            elif pos[y] - pos[x] != d:
                print('No')
                sys.exit()


while Nvisited:
    dfs(Nvisited.pop())

print('Yes')


Measured memory_bytes: 101276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n;
  cin >> n;
  int tx;
  pair<int,int> x[n];
  rep(i,n){
    cin >> tx;
    x[i]=mp(--tx, i+1);
  }
  sort(x,x+n);
  deque<int> mar;
  deque<pair<int, int> > Rque;
  int ans[n*n];
  rep(i,n*n) ans[i]=-1;
  int pre=0;
  rep(i,n){
    int pos=x[i].first;
    int ind=x[i].second;
    for(int j=pre; j<pos; j++) mar.pb(j);
    ans[pos]=ind;
    int c=ind-1;
    while(!mar.empty()){
      if(c==0) break;
      ans[mar.front()]=ind;
      c--;
      mar.pop_front();
    }
    if(c>0){
      cout << "No" << endl;
      return 0;
    }
    rep(j,n-ind) Rque.push_front(mp(pos+1, ind));
    pre=pos+1;
  }
  for(int j=pre; j<n*n; j++) mar.pb(j);
  //  rep(i,n*n) cout << ans[i] << " ";
  //  cout << ""<<endl;
  for(int i=mar.size()-1;i>=0;i--){
    pair<int,int> pu=Rque.front();Rque.pop_front();
    if(pu.first>mar[i]){
      cout << "No" << endl;
      return 0;
    }
    //    cout << mar[i] << " ni "  << pu.second << " wo " <<endl;
    ans[mar[i]]=pu.second;
  }
  cout << "Yes" << endl;
  rep(i,n*n) cout << ans[i] << " ";
  cout << "" << endl;
  return 0;
    
  
}


Measured memory_bytes: 3840
#include<cstdio>

using namespace std;

int main(){
    int n,a,b;
    int ans = 0;
    scanf("%d %d %d", &n, &a, &b);
    for(int i = 1; i <= n; i++){
        int num = i;
        int sm = 0;
        // printf("%d\n", num);
        while(num != 0){
            sm += num % 10;
            num /= 10;
        }
        // printf("%d\n", sm);
        if (a <= sm && sm <= b){
            ans += i;
            // printf("%d", ans);
        }
    }
    printf("%d\n", ans);
    

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    string ans="";
    for(int i=0;i<tx-sx;i++)ans+='R';
    for(int i=0;i<ty-sy;i++)ans+='U';
    for(int i=0;i<tx-sx;i++)ans+='L';
    for(int i=0;i<ty-sy;i++)ans+='D';
    ans+='D';
    for(int i=0;i<tx-sx+1;i++)ans+='R';
    for(int i=0;i<ty-sy+1;i++)ans+='U';
    ans+="LU";
    for(int i=0;i<tx-sx+1;i++)ans+='L';
    for(int i=0;i<ty-sy+1;i++)ans+='D';
    ans+="R";
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//BUGSBUNNY
//IIT ROORKEE

#include<bits/stdc++.h>
using namespace std; 
#define int long long
#define ll long long
#define double long double
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define gcd __gcd
#define mp make_pair
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
// #define mod 1000000007
#define mod 1000000000 
// #define mod 998244353
#define rep(i,n) for (ll i = 0; i < n; i++)
#define repp(i,a,b) for(ll i = a ; i<b ; i++)
#define reppr(i,a,b) for(ll i = a-1 ; i>=b ; i--)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " << 
#define setprec(x) cout << fixed << setprecision(x);
#define reve(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()

//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }

//modInverse
    int modInverse(int a) 
    { 
       return powmod(a,mod-2); 
    }

//Binomial Coefficients
    // int fact[200010], factinv[200010];
    // int nCr(int n , int r)
    // {
    //     return ((fact[n] * modInverse(fact[n-r]) % mod * modInverse(fact[r]))%mod) ;
    // }


void solve();

signed main()
{
    //-------------------------------------------------------------------------------
        
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        clock_t clk = clock();

    //-------------------------------------------------------------------------------

        // fact[0] = 1 , factinv[0] = 1;
        // repp(i,1,200010)
        // {
        //     fact[i] = (fact[i-1] * i)%mod;
        //     factinv[i] = (factinv[i-1] * modInverse(i))%mod;
        // }
        
    //-------------------------------------------------------------------------------
        int t = 1;
        // cin >> t;
        while(t--)
            solve();
        clk = clock() - clk;
        cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;
    //-------------------------------------------------------------------------------
}

void solve()
{
    int n , k ;
    cin >> n >> k;
    int a = n - (n/k)*k;
    int b = abs(k-a);
    cout << min(a,b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i<=i##end;++i)
#define DREP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i>=i##end;--i)
template<typename T>bool chkmin(T &x,const T &y){return x>y?x=y,1:0;}
template<typename T>bool chkmax(T &x,const T &y){return x<y?x=y,1:0;}
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
template<typename T>T read(){
	T x=0,f=1;
	char c=getchar();
	while((c<'0')||(c>'9')){if(c=='-')f=-1;c=getchar();}
	while((c>='0')&&(c<='9'))x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define read() read<int>()
template<typename T>void write(T x,char c){
	static char t[25];
	static int tlen;
	t[tlen=1]=c;
	if(x<0)putchar('-'),x=-x;
	do t[++tlen]=(x%10)^48;
	while(x/=10);
	while(tlen)putchar(t[tlen--]);
}
typedef long long ll;
ll a,b;
int main(){
	int ans=0;
	a=read<ll>(),b=read<ll>()/a;
	while(b)b/=2,++ans;
	write(ans,'\n');
	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
# define MOD 1000000007
typedef long long ll;
class interval{
public:
    int left,right;
    ll val;
    interval(int left, int right, ll val){
        this->left = left;
        this->right = right;
        this->val = val;
    }
};
void update(ll tree[], ll lazy[], int i, int l, int r, int x, int y, ll val){
    if(l > r) return;
    if(lazy[i]){
        tree[i] += lazy[i];
        if(l != r){
            lazy[2*i+1] += lazy[i];
            lazy[2*i+2] += lazy[i];
        }
        lazy[i] = 0;
    }
    if(x > r or l > y){
        return;
    }
    else if(x <= l and r <= y){
        tree[i] += val;
        if(l != r){
            lazy[2*i+1] += val;
            lazy[2*i+2] += val;
        }
        return;
    }
    int mid = l + (r-l)/2;
    update(tree, lazy, 2*i+1, l, mid, x, y, val);
    update(tree, lazy, 2*i+2, mid+1, r, x, y, val);
    tree[i] = max(tree[2*i+1], tree[2*i+2]);
}
// returns maximum value in range x-y
ll query(ll tree[], ll lazy[], int i, int l, int r, int x, int y){
    if(l > r) return 0;
    if(lazy[i]){
        tree[i] += lazy[i];
        if(l != r){
            lazy[2*i+1] += lazy[i];
            lazy[2*i+2] += lazy[i];
        }
        lazy[i] = 0;
    }
    if(x > r or l > y){
        return 0;
    }
    else if(x <= l and r <= y){
        return tree[i];
    }
    int mid = l + (r-l)/2;
    ll left = query(tree, lazy, 2*i+1, l, mid, x, y);
    ll right = query(tree, lazy, 2*i+2, mid+1, r, x, y);
    return max(left, right);
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	ll tree[4*n] = {};
	ll lazy[4*n] = {};
	unordered_map<int, vector<interval>> intervals;
	for(int i=0;i<m;i++){
	    int l, r;
	    ll v;
	    cin>>l>>r>>v;
	    intervals[r-1].push_back(interval(l-1, r-1, v));
	}
	for(int i=0;i<n;i++){
	    ll prev_max = query(tree, lazy, 0, 0, n-1, 0, i-1);
	    update(tree, lazy, 0, 0, n-1, i, i, prev_max);
	    for(int j=0;j<intervals[i].size();j++){
	        interval curr = intervals[i][j];
	        update(tree, lazy, 0, 0, n-1, curr.left, curr.right, curr.val);
	    }
	}
	ll ans = max(ll(0), query(tree, lazy, 0, 0, n-1, 0, n-1));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 30408
#include<iostream>

using namespace std;

int main()
{
	int a;
    int b;
    cin >> a;
    cin >> b;
    
  if(a*b%2==0)
   {
	cout << "Even" << endl;
   }
   else
   {
   cout <<  "Odd" << endl;
   }
   
  
    return 0;
}
  
    
  
    
      
      
      

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  bool ans=false;
  
  for(int i=1;i<1000;i++){
    if((i*a%b)==(c%b)){
      ans = true;
      break;
    }
  }
  
  if(ans) cout << "YES" <<endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >>N;
  int s=0;
  int i=N;
  
  while(i>0){
    s+=i%10;
    i/=10;
  }
  
  
  if(N%s==0)
    cout <<"Yes"<<endl;
  else
    cout <<"No"<<endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, K;
    cin >> N >> K;
    if (K == 1) cout << 0 << "\n";
    else cout << N-K << "\n";
}

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

using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


int main() {
  int N;
  cin>>N; 
  bool ans=false;
  vector<char>a(N);
  rep(i,N){
    cin>>a.at(i);
    if(a.at(i)=='Y'){
      ans=true;
      break;
    }
  }
  if(ans){
    cout << "Four"<< endl;
  }
  else{
    cout<<"Three"<<endl;
  }
  
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll X,K,D;
    cin >> X >> K >> D;
    ll t=abs(X)/D;
    ll z=min(K,t);
    K-=z;
    X-=(abs(X)/X)*z*D;
    if(K==0){
        cout << abs(X) << endl;
    }
    else if(K%2==0){
        cout << abs(X) << endl;
    }
    else{
        cout << D-abs(X) << endl;
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

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

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

int main(){
int n;
cin>>n;
vector<ll> a,b,c;
rep(i,n){
  ll s;
  cin>>s;
  a.push_back(s);
}
rep(i,n){
  ll s;
  cin>>s;
  b.push_back(s);
}
rep(i,n){
  ll s;
  cin>>s;
  c.push_back(s);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
sort(c.begin(),c.end());

ll ans=0;
rep(i,n){
  auto itr=lower_bound(a.begin(),a.end(),b[i]);
  auto itr2=upper_bound(c.begin(),c.end(),b[i]);
  auto count1=itr-a.begin(),count2=c.end()-itr2;
  ans+=count1*count2;
//cout<<"ans=="<<ans<<" "<<"count1=="<<count1<<" "<<"count2=="<<count2<<endl;
}

cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3316
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

/*bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}*/

int N, H, W;
double arr[3000];
double dp[3000][3000];
vector<int> v1, v2;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(12);
    cin >> N;
    int A, B;
    cin >> A >> B;
    int t1 = 0, t2 = 0, t3 = 0;
    for (int i = 0; i < N; ++i)
    {
        int a;
        cin >> a;
        if (a <= A)
            t1++;
        else if (a >= A + 1 && a <= B)
            t2++;
        else
            t3++;
    }
    cout << min({t1, t2, t3}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    rep(i, 3)
    {
        if (s[i] == s[i + 1])
        {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
using namespace std;
const int N=1e6+5;
int arr[N],have[N],mark[N];
int n;

void solve()
{
    for(int i=1;i<N;i++)
    {
        if(have[i])
        {
            if(have[i]>=2) mark[i]=1;
            for(int j=2;i*j<N;j++) mark[i*j]=1;
        }
    }
}

int32_t main()
{
    IOS;
    cin>>n;
    for(int i=1;i<=n;i++) 
    {
        cin>>arr[i];
        have[arr[i]]++;
    }
    solve();
    int ans=0;
    for(int i=1;i<=n;i++) ans+=!mark[arr[i]];
    cout<<ans;
    return 0;
}

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

int main(){
  int a, b, x;
  cin >> a >> b >> x;
  string ans = "YES";
  if(a < x && a+b < x || a > x) {
    ans = "NO";
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine()
                .Select(x => int.Parse(x.ToString()))
                .ToArray();
            var count = str.Length;
            var bits = CreateBits(3);
            foreach (var item in bits)
            {
                var num = str[0];
                for (int i = 0; i < count - 1; i++)
                {
                    if (item[i])
                        num += str[i + 1];
                    else
                        num -= str[i + 1];
                }
                if (num == 7)
                {
                    var sb = new StringBuilder();
                    sb.Append(str[0]);
                    for (int j = 0; j < 3; j++)
                    {
                        sb.Append(item[j] ? "+" : "-");
                        sb.Append(str[j + 1]);
                    }
                    sb.Append("=7");
                    Console.WriteLine(sb.ToString());
                    Console.ReadLine();
                    return;
                }
            }
            Console.ReadLine();

        }

        /// <summary>
        /// Bit全探索用のライブラリ
        /// </summary>
        /// <param name="len">作る配列の長さ(lenが0以下だと（ｒｙ)</param>
        /// <returns>できた配列</returns>
        public static List<List<bool>> CreateBits(int len)
        {
            return CreateBitsPri(new List<List<bool>>(), len, 0);
        }

        private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len, int count)
        {
            if (count == 0)
            {
                var lss = new List<bool>();
                lss.Add(true);
                bits.Add(lss);
                var lx = new List<bool>();
                lx.Add(false);
                bits.Add(lx);
                count++;
                return CreateBitsPri(bits, len, count);
            }
            if (len - count == 0)
                return bits;
            count++;
            var ls = new List<List<bool>>();
            foreach (var item in bits)
            {
                var x = item.ToList();
                x.Add(true);
                item.Add(false);
                ls.Add(item);
                ls.Add(x);
            }
            return CreateBitsPri(ls, len, count);
        }
    }
}



Measured memory_bytes: 13396
def getlist():
	return map(int, input().split())

L = []

H, W = getlist()
for i in range(H):
	S = list(input())
	L.append(S)

ans1 = [[0 for i in range(W)] for j in range(H)]
ans2 = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
	val = 0
	l = []
	for j in range(W):
		if L[i][j] == "#":
			for k in l:
				ans1[i][k] = val
			val = 0
			l = []
		else:
			val += 1
			l.append(j)
	for k in l:
		ans1[i][k] = val

for i in range(W):
	val = 0
	l = []
	for j in range(H):
		if L[j][i] == "#":
			for k in l:
				ans2[k][i] = val
			val = 0
			l = []
		else:
			val += 1
			l.append(j)
	for k in l:
		ans2[k][i] = val


ans = -1
for i in range(H):
	for j in range(W):
		x = ans1[i][j] + ans2[i][j] - 1
		if x > ans:
			ans = x

print(ans)

Measured memory_bytes: 249992
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    int n;
    cin >> n;
    int c=0;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        if(x%2==1){
            c++;
        }
    }
    if(c%2==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

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

using namespace std;

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

  map<string, int> count;
  int N, mx = 0;
  cin >> N;
  string s;
  while (N--) {
    cin >> s;
    count[s]++;
    if (count[s] > mx) mx = count[s];
  }

  vector<string> res;
  for (auto &x: count) {
    if (x.second == mx) 
      res.push_back(x.first);
  }
  sort(res.begin(), res.end());
  for (auto &x: res) 
    cout << x << endl;

	return 0;
}



Measured memory_bytes: 25584
#include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;
template <class T> T Next() { T buf; cin >> buf; return buf; }

int n;
int a[200001];
int f[200001];
int g[200001];
int cnt;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = n; i >= 1; --i) {
    int sum = 0;
    for (int k = i; k <= n; k += i) {
      sum += f[k];
    }
    sum %= 2;
    if (sum != a[i]) {
      f[i] = 1;
      ++cnt;
    }
  }
  
  cout << cnt << endl;
  for (int i = 1; i <= n; ++i) {
    if (f[i]) cout << i << ' ';
  }
  cout << endl;
}

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

int main(){
	vector<int> a;
	int x;
	for(int i=0; i<3; i++){
		cin >> x;
		a.push_back(x);
	}
	sort(a.begin(), a.end(), greater<int>());
	cout << (a[0]-a[1]) + (a[1]-a[2]) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

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

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
const int mod = 1'000'000'007, maxn = 100100;
int f[4][maxn], pf[4][maxn];
long long s[maxn], a, b;
int main(){
	int n; cin >> n >> a >> b;
       	for(int i = 1; i <= n; i++) cin >> s[i];
	for(int j = 0; j < 4; j++) f[j][0] = pf[j][0] = 1;
	sort(s + 1, s + 1 + n); s[n + 1] = s[n] + b + a;
	int pta = 0, ptb = 0, upa = 0, upb = 0, pt2a = 0, pt2b = 0;
	for(int i = 1; i <= n; i++){
		while(pta + 1 < i && s[pta + 1] + a <= s[i]) pta++;
		while(ptb + 1 < i && s[ptb + 1] + b <= s[i]) ptb++;
		if(pta == i - 1){
			f[0][i] = f[0][i - 1];
		}
		if(ptb == i - 1){
			f[1][i] = f[1][i - 1];
		}
		if(i > 2 && s[i - 2] + a > s[i - 1]) upa = i - 2;
		if(i > 2 && s[i - 2] + b > s[i - 1]) upb = i - 2;
		auto getSum = [&](int v, int l, int r){
			if(l > r) return 0;
			int rr = pf[v][r];
			if(l) rr += mod - pf[v][l - 1];
			if(rr >= mod) rr -= mod;
			return rr;
		};
		while(pt2a + 1 < i && s[pt2a + 1] + a <= s[i + 1]) pt2a++;
		while(pt2b + 1 < i && s[pt2b + 1] + b <= s[i + 1]) pt2b++;
		if(upa <= pt2b && pta == i - 1) f[2][i] = f[0][min(pt2b + 1, i - 1)];
		if(upb <= pt2a && ptb == i - 1) f[3][i] = f[1][min(pt2a + 1, i - 1)];
		{
			if(upb <= i - 2){
				f[0][i] += getSum(2, upb, min(i - 2, pta));
				if(i > 1 && i < n && s[i - 1] + b <= s[i + 1]) f[2][i] += getSum(2, upb, min(i - 2, pta));
			}
		}
		{
			if(upa <= i - 2){
				f[1][i] += getSum(3, upa, min(i - 2, ptb));
				if(i > 1 && i < n && s[i - 1] + a <= s[i + 1]) f[3][i] += getSum(3, upa, min(i - 2, ptb));
			}
		}
		for(int j = 0; j < 4; j++){
			if(f[j][i] >= mod) f[j][i] -= mod;
			pf[j][i] = pf[j][i - 1] + f[j][i];
			if(pf[j][i] >= mod) pf[j][i] -= mod;
		}
	}	
	int ans = f[1][n] + f[0][n];
	if(ans >= mod) ans -= mod;
	cout << ans << endl;
	return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

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

    int n;
    cin >> n;
    vector<int> vec(n);

    rep (i, n)
        cin >> vec[i];

    ll ans = 0;
    rep (i, n)
        ans += vec[i] - 1;

    print(ans);

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    repall (i, vec)
        cout << i << ' ';
    cout << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}





ll K;
ll maxi = 1e12;
ll mdep = 12;
ll cnt = -1;
void dfs(ll v = 0,int dep = 0) {
    if (v > maxi) return;
    if (dep==mdep) {
        cnt++;
        if(cnt == K) {
            cout << v << endl;
            exit(0);
        }
        return;
    }

    if (v == 0) {
        REP(i,10) dfs(i,dep+1);
        return;
    }

    auto lk = v % 10;
    if (lk != 0) dfs(v*10+lk-1,dep+1);
    dfs(v*10+lk,dep+1);
    if (lk != 9) dfs(v*10+lk+1,dep+1);
}

void solve() {
    cin >> K;
    dfs();
    cerr << cnt << endl;
}

int main() {
    solve();
    return 0;
}


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

vector<ll> ans;

void dfs(ll x){
    if(x > 3234566667){
        return;
    }
    ans.push_back(x);
    ll d = x % 10;
    ll res = 10*x + d;
    dfs(res);
    if(d != 9){
        dfs(res + 1);
    }
    if(d != 0){
        dfs(res - 1);
    }
}

int main() {

    int k;
    cin >> k;

    REP(i, 1, 10){
        dfs(i);
    }
    
    sort(all(ans));

    cout << ans[k-1] << endl;

    return 0;
}

Measured memory_bytes: 1400
#define DBG 0//submit 0
#define ll long long
#if DBG
    #include <algorithm>
    #include <array>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <unordered_map>
    #include <iostream>
    #include <cmath>
    #include <queue>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif
 
using namespace std;
 
 
int main(){
    int n=0,ans;
    char s[15];
    for(int i = 0;i<10;i++){
        cin >> s[i];
    }
    
    s[3] = '8';
    //cout << (!flag ? "Yes" : "No") << endl;
    cout << s << endl;
 
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void) {

	int num, get, i;
	scanf ("%d", &num);
	int out[num];

	for (i=0; i<num; i++){
		scanf ("%d", &get);
		out[i] = get;
	}

	for (i=num-1; 0<=i; i--) {
		printf("%d", out[i]);
		if (i != 0) {
			printf(" ");
		} else {
			printf("\n");
		}
	}

	return 0;
}

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

int main() {
    //エラトステネスの篩にかける
    int MAX = 100010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for(int i = 2; i < MAX; ++i) {
        if(!is_prime[i]) continue;
        for(int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }
    
    vector<int> a(MAX, 0);
    for(int i = 0; i < MAX; ++i) {
        if(i % 2 == 0) continue;
        //iが2017に似た数ならば
        if(is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }
    
    //累積和
    vector<int> s(MAX+1, 0);
    for(int i = 0; i < MAX; ++i) s[i+1] = s[i] + a[i];
    
    //クエリ処理
    int Q; cin >> Q;
    for(int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;
        ++r;
        
        cout << s[r] - s[l] << endl;
    }
}


Measured memory_bytes: 1792
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def get(a,x):
    if a<0:
        return 0
    return a//x + 1

def solve():
    a,b,x = f()

    print(get(b, x) - get(a-1,x))



solve()


Measured memory_bytes: 2940
package main

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

var mod int = 998244353

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n, k := io.NextInt(), io.NextInt()
	l, r := make([]int, k), make([]int, k)
	for i := 0; i < k; i++ {
		l[i], r[i] = io.NextInt(), io.NextInt()
	}
	// lib.Log(n, k)
	// lib.Log(l, r)
	cnt := make([]int, n+1)
	csum := 1
	for i := 0; i < n; i++ {
		cnt[i] %= mod
		csum += cnt[i]
		for j := 0; j < k; j++ {
			begin, end := i+l[j], i+r[j]+1
			if begin < n {
				cnt[begin] += csum
				if end <= n {
					cnt[end] -= csum
				} else {
					cnt[n] -= csum
				}
			}
		}
	}
	// lib.Log(cnt, csum)
	io.Println(cnt[n-1])
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 3408
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val A = nextIntList()
    println(A.distinct().size)
}

Measured memory_bytes: 37836
s = int(input())
def an(n):
    if n == 1:
        return s
    else:
        return f(an(n-1))

def f(n):
    if n % 2 == 0:
        return n//2
    else:
        return 3 * n + 1

se = set()
n = 1
while True:
    a = an(n)
    #print(n,a)
    if a in se:
        print(n)
        exit()
    se.add(a)
    n += 1

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))

minus_num = 0
minimum_abs = int(1e20)
total_sum = 0
for v in A:
    minimum_abs = min(abs(v), minimum_abs)
    total_sum += abs(v)
    if v < 0:
        minus_num += 1
if minus_num % 2 == 0:
    print(total_sum)
else:
    print(total_sum-minimum_abs*2)


Measured memory_bytes: 14412
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

// Priority Queue
type Item struct {
	priority, value, index int
}

type PQ []*Item

func (pq PQ) Len() int {
	return len(pq)
}

func (pq PQ) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

func (pq PQ) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PQ) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PQ) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1
	*pq = old[0 : n-1]
	return item
}

// End Priority Queue
// Path
type Edge struct {
	to, cost int
}

type Path struct {
	edges []Edge
}

// Dijkstra
type Route struct {
	path []int
}

func Dijkstra(N, S int, path []Path) ([]int, []Route) {
	pq := make(PQ, 0)
	heap.Init(&pq)
	d := make([]int, N+1)
	r := make([]Route, N+1)
	// init
	for i := 0; i <= N; i++ {
		d[i] = math.MaxInt32
	}
	d[S] = 0
	r[S].path = []int{S}
	heap.Push(&pq, &Item{0, S, 0})
	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		v := item.value
		if d[v] < item.priority {
			continue
		}
		for _, e := range path[v].edges {
			if d[e.to] > d[v]+e.cost {
				d[e.to] = d[v] + e.cost
				r[e.to].path = append(r[v].path, e.to)
				heap.Push(&pq, &Item{d[e.to], e.to, 0})
			}
		}
	}
	return d, r

}

func main() {
	sc.Split(bufio.ScanWords)

	H, W := getInt(), getInt()
	s := make([]string, H)
	for i := 0; i < H; i++ {
		s[i] = getString()
	}

	path := make([]Path, W*H)
	cnt := 0
	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			if s[y][x] == '#' {
				cnt++
				continue
			}
			f := y*W + x
			if x != 0 && s[y][x-1] != '#' {
				t := f - 1
				path[f].edges = append(path[f].edges, Edge{t, 1})
			}
			if x != W-1 && s[y][x+1] != '#' {
				t := f + 1
				path[f].edges = append(path[f].edges, Edge{t, 1})
			}
			if y != 0 && s[y-1][x] != '#' {
				t := f - W
				path[f].edges = append(path[f].edges, Edge{t, 1})
			}
			if y != H-1 && s[y+1][x] != '#' {
				t := f + W
				path[f].edges = append(path[f].edges, Edge{t, 1})
			}
		}
	}
	d, _ := Dijkstra(W*H, 0, path)
	pos := W*H - 1

	if d[pos] == math.MaxInt32 {
		out(-1)
	} else {
		out(W*H - cnt - d[pos] - 1)
	}
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, w;
    cin >> n >> w;
    vi wi(n), v(n);
    rep(i, n) cin >> wi[i] >> v[i];
    vector<vll> dp(n+1, vll(w+1));
    rep(i, n) rep(j, w+1) {
        if (j-wi[i]>=0) dp[i+1][j] = max(dp[i][j], dp[i][j-wi[i]]+v[i]);
        else dp[i+1][j] = dp[i][j];
    }
    cout << dp[n][w] << endl;
    return 0;
}


Measured memory_bytes: 83156
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  ll N;
  cin >> N;
  ll A, B, C, D;
  cin >> A >> B >> C >> D;

  for(ll m = 0; m < N; m++){
    if(-D * m + C * (N - 1 - m) <= B - A && B - A <= -C * m + (N - 1 - m) * D){
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

if a.count(a[0])==n:
    print(n//2)
    exit()


x=a[::2]
y=a[1::2]

xx=Counter(x)
yy=Counter(y)

xxx=xx.most_common()
yyy=yy.most_common()

if xxx[0][0]!=yyy[0][0]:
    print(n-xxx[0][1]-yyy[0][1])

else:
    print(min(n-xxx[1][1]-yyy[0][1],n-xxx[0][1]-yyy[1][1]))


Measured memory_bytes: 102112
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
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
from fractions import gcd
from heapq import heappush, heappop, heapify
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

N, M, R = MAP()
r = LIST()
ABC = [LIST() for _ in range(M)]

dist_matrix = [[0]*N for _ in range(N)]
for A, B, C in ABC:
	dist_matrix[A-1][B-1] = C
	dist_matrix[B-1][A-1] = C

#for i in range(N):
#	print(dist_matrix[i])

#ワーシャルフロイド法  注意 PyPy非対応!!!!
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
 
graph = csr_matrix(dist_matrix) #隣接行列からcsr行列をつくる
dist_matrix = floyd_warshall(graph, directed=False) #無向の場合directed=False
#dist_matrixの中身はfloatになっているので注意！

#for i in range(N):
#	print(dist_matrix[i])

ans = INF
for x in permutations(r):
	dis = 0
	for i in range(1, R):
		dis += dist_matrix[x[i-1]-1][x[i]-1]
	ans = min(ans, dis)

print(int(ans))


	


Measured memory_bytes: 23876
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int t,x;
    cin>>t>>x;
    double ans = (double)t/x;

    cout << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 256