akhauriyash/Code-Regression huggingface dataset:
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=4e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    vi v;
    if(s.front()=='0')v.pb(0);
    int cnt=1;
    loop(n-1,i,0){
        if(s[i+1]!=s[i]){
            v.pb(cnt);
            cnt=1;
        }
        else
            cnt++;
    }
    v.pb(cnt);
    if(s.back()=='0')v.pb(0);
    int m=sz(v);
    vi sum(m+1);
    sum[0]=0;
    loop(m,i,0)sum[i+1]=sum[i]+v[i];
    if(2*k+1>=m+1)
        k=m/2;
    int res=0;
    for(int i=0;i+2*k+1<m+1;i+=2){
        max_self(res,sum[i+2*k+1]-sum[i]);
    }
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 4456
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int x;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>x;
    int s=0;
    s+=(x/500)*1000;
    x-=s/2;
    s+=x/5*5;
    cout<<s;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
 
int main(){
  int n, m; cin >> n >> m;
  vector<vector<int>> s(m);
  rep(i, m) {
    int k; cin >> k;
    rep(j, k) {
      int l; cin >> l; l--;
      s[i].push_back(l);
    }
  }
  vector<int> p(m);
  rep(i, m) cin >> p[i];

  ll res=0;
  rep(bit, (1<<n)) {
    bool fl = true;
    rep(i, m) {
      int count=0;
      for(auto u : s[i]) {
        if(bit & (1<<u)) count++;
      }
      if(count % 2 != p[i]) {
        fl = false;
        break;
      }
    }
    if(fl) res++;
  }
  cout << res << endl;
}


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 2010;

int n;
int K = 42;

vector<int> a[maxn + 5];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	n = K * (K - 1) + 1;
	int cur = 0;
	REP(i, 0, K)
	{
		a[n - 1].pb(cur);
		REP(j, i * (K - 1), (i + 1) * (K - 1))
			a[j].pb(cur);
		++cur;
	}
	REP(i, 0, K - 1)
		REP(j, 0, K - 1)
		{
			REP(k, 0, K - 1)
				a[k * (K - 1) + (j + k * i) % (K - 1)].pb(cur);
			++cur;
		}
	REP(i, 0, K - 1)
		REP(j, 0, K - 1)
			a[(K - 1) * (K - 1) + i].pb(a[j][i + 1]);
	printf("%d %d\n", n, K);
	REP(i, 0, n)
	{
		for (auto u : a[i]) printf("%d ", u + 1);
		printf("\n");
	}
	REP(i, 0, n)
	{
		assert(SZ(a[i]) == K);
	}
	static vector<int> cnt[maxn + 5];
	static bool vis[maxn + 5][maxn + 5];
	REP(i, 0, n) cnt[i].clear();
	memset(vis, 0, sizeof vis);
	REP(i, 0, n) 
	{
		REP(j, 0, K) 
		{
			assert(a[i][j] >= 0 && a[i][j] < n);
			cnt[a[i][j]].pb(i);
		}
	}
	REP(i, 0, n)
	{
		assert(SZ(cnt[i]) == K);
		for (auto u : cnt[i])
			for (auto v : cnt[i]) if (u != v)
			{
				assert(!vis[u][v]);
				vis[u][v] = 1;
			}
	}
	return 0;
}


Measured memory_bytes: 5632
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, C = map(int, input().split())
    D = np.array([list(map(int, input().split())) for i in range(C)])
    board = [list(map(int, input().split())) for i in range(N)]

    # cost[i][j] := mod3==iのグループを色jにする際の違和感の総和
    cost = np.zeros((3, C), dtype=int)
    count = np.zeros((3, C), dtype=int)
    for i in range(N):
        for j in range(N):
            count[(i + j)%3][board[i][j] - 1] += 1
    for i in range(3):
        for j in range(C):
            cost[i] += D[j] * count[i][j]

    ans = int(1e20)
    for i in range(C):
        for j in range(C):
            if i == j:
                continue
            for k in range(C):
                if k==i or k==j:
                    continue
                ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k])
    print(ans)

if __name__ == "__main__":
    main()

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

typedef long long ll;
using namespace std;

int main()
{
    int l, r;
    scanf("%d %d", &l, &r);

    ll ans = LLONG_MAX;
    for (ll i = l; i <= l + 2019 && i <= r; i++)
        for (ll j = i + 1; j - l <= 2020 && j <= r; j++) {
            //if (ans > i * j % 2019)
              //  printf("%lld %lld %lld\n", i, j, i * j % 2019);
            ans = min(ans, i * j % 2019);
        }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
map<PII,int> memo;
int dfs(int h,int r,int n,vector<PII>& ich,vector<PII>& ji){
  if(memo.find(PII(h,r))!=memo.end()){
    int m = memo[PII(h,r)];
    if(m>=n) return m;
  }
  memo[PII(h,r)] = n;
  int ret=n;
  REP(i,ich.size()){
    if(ich[i].first<h&&ich[i].second<r){
      ret = max(ret,dfs(ich[i].first,ich[i].second,n+1,ich,ji));
      break;
    }
  }
  REP(i,ji.size()){
    if(ji[i].first<h&&ji[i].second<r){
      ret = max(ret,dfs(ji[i].first,ji[i].second,n+1,ich,ji));
      break;
    }
  }
  return ret;
}
int main(void){
  int n,m;
  while(cin>>n,n){
    memo.clear();
    vector<PII> ich;
    vector<PII> ji;
    REP(i,n){
      int h,r;
      cin>>h>>r;
      ich.push_back(PII(h,r));
    } 
    cin>>m;
    REP(i,m){
      int h,r;
      cin>>h>>r;
      ji.push_back(PII(h,r));
    }
    reverse(ich.begin(),ich.end());
    reverse(ji.begin(),ji.end());
    cout<<dfs(INF,INF,0,ich,ji)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
class MyBinaryNode
  attr_accessor :parent, :left, :right, :v
  attr_reader :id

  def initialize(id, v)
    @id = id
    @parent = nil
    @left = nil
    @right = nil
    @v = v
  end

  def to_s
    @v
  end
end

def pre_order(node)
  if node.nil?
    return 
  end
  print ' '
  print node.v
  pre_order(node.left)
  pre_order(node.right)
end

def in_order(node)
  if node.nil?
    return 
  end
  in_order(node.left)
  print ' '
  print node.v
  in_order(node.right)
end

# def post_order(nodes, id)
#   if id.nil?
#     return 
#   end
#   post_order(nodes, nodes[id].left)
#   post_order(nodes, nodes[id].right)
#   print ' '
#   print id
# end

def print_nodes(node)
  in_order(node)
  puts ""
  pre_order(node)
  puts ""
end

def insert(z, root)
  y = nil
  x = root
  while !x.nil? do
    y = x
    if z.v < x.v
      x = x.left
    else
      x = x.right
    end
  end
  
  z.parent = y

  if y.nil?
    # skip
  elsif z.v < y.v
    y.left = z
  else
    y.right = z
  end

end

def find(x, k)
  while !x.nil? && k != x.v do
    if k < x.v
      x = x.left
    else
      x = x.right
    end
  end

  x
end

def delete(z)
  if z.left.nil? && z.right.nil?
    p = z.parent
    if p.left&.v == z.v
      p.left = nil
    else
      p.right = nil
    end
  elsif z.left && z.right
    next_node = get_successor(z)
    z.v = next_node.v
    delete(next_node)
  else
    p = z.parent
    c = z.left || z.right
    if p.left&.v == z.v
      p.left = c
    else
      p.right = c
    end
    c.parent = p
    
  end
end

def get_successor(x)
  if x.right
    return get_minimum(x.right)
  end

  y = x.parent
  while y && x == y.right
    x = y
    y = y.parent
  end
  return y
end

def get_minimum(x)
  while x.left
    x = x.left
  end
  x
end


n = gets.to_i
root = nil
i = 0
n.times do
  order, v = gets.split
  v = v.to_i
  case order
  when "insert"
    node = MyBinaryNode.new(i, v)
    insert(node, root)
    if i == 0
      root = node
    end
    i += 1
  when "print"
    print_nodes(root)
  when "find"
    if find(root, v)
      puts "yes"
    else
      puts "no"
    end
  when "delete"
    target_node = find(root, v)
    delete(target_node)
  end
end


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

int main(void){
    int n, tmp;
    cin >> n;
    tmp = n / 1.08;
    if ((int)(tmp * 1.08) == n){
        cout << tmp << endl;
    } else if ((int)((tmp+1) * 1.08) == n){
        cout << tmp+1 << endl;
    } else{
        cout << ":(" << endl;
    }
    return 0;
}

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

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  ll cnt = 0;
  n -= 1;
  if( n%(k-1) == 0 ){
    cnt = n/(k-1);
  }else{
    cnt = n/(k-1) + 1;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
 
public class Main {
  public static void main (String[] args){
  
   int N,reverse=0,remaind,tmp;
    
   int a,b,c,d;
   int L,R;  

   Scanner sc = new Scanner (System.in);
   a=sc.nextInt();
   b=sc.nextInt();
   c=sc.nextInt();
   d=sc.nextInt();
   
   L=a+b;
   R=c+d;

   if(L>R){
     System.out.println("Left");
   }
   else if(R>L){
     System.out.println("Right");
   }
   else if(L==R){
     System.out.println("Balanced");
   }
  }
}

Measured memory_bytes: 22868
n = int(input())

nl = []
nlnot10 = []
nlmax = 0
for i in range(n):
    k = int(input())
    nl.append(k)
    nlmax = nlmax + k
    if k % 10 != 0:
        nlnot10.append(k)

if nlmax % 10 != 0:
    print(nlmax)
elif nlmax % 10 == 0 and len(nlnot10) > 0:
    print(nlmax - min(nlnot10))
else:
    print(0)

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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=n-1;i>=m;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };

typedef long long ll;
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if (a == b)cout << "Draw" << endl;
	else if ((a < b &&a!=1)||b == 1)cout << "Bob" << endl;
	else cout << "Alice" << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
x1=sum(a)
for i in range(n):
  if i%2!=0:
    x1-=2*a[i]
ans=[x1]
for i in range(n-1):
  ans.append(2*a[i]-ans[i])
print(*ans)

Measured memory_bytes: 95516
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))


N = int(input())

anss = [0 for i in range(N + 1)]
for x in range(1, int(math.sqrt(N))):
    for y in range(1, int(math.sqrt(N))):
        for z in range(1, int(math.sqrt(N))):
            tmp = x ** 2 + y ** 2 + z ** 2 + x*y + x*z + y*z
            if tmp <= N:
                anss[tmp] += 1 

for i in range(1, N + 1):
    print(anss[i])

Measured memory_bytes: 10972
#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 300000000000001
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<pair<ll,ll> > vll;
typedef vector<int> vi;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 1001;
const ll M = log2(N);

struct point {
    ll x, y, i;
    bool operator == (const point b)
    {
        if(this -> x == b.x && this -> y == b.y) return 1;
        return 0;
    }
    bool operator != (const point b) {return !(*this == b);}
    friend bool operator < (const point a, const point b)
    {
        if(a.x != b.x)
            return a.x < b.x;
        return a.y < b.y;
    }
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cerr << word << " = " << a << endl;
    debug(s, args...);
}
bool overflow;
ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    ll ans;
    if(n % 2 == 0)
    {
         ans = fast_exp(x, n / 2);
         if(ans > ans * ans % mod)
                overflow = 1;
         ans = ans * ans % mod;
    }
    else
    {
        ans = fast_exp(x, n - 1);
        if(ans > ans * x % mod)
            overflow = 1;
        ans = ans * x % mod;
    }
    return ans;
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n = 0, m = 0, x = 0, y = 0, ans = 0, k;
        cin >> n >> m >> k;
        char c[n][m];
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                cin >> c[i][j];
            }
        }
        for(int i = 0; i < (1 << n); i++)
        {
            for(int j = 0; j < (1 << m); j++)
            {
                x = 0;
                for(int h = 0; h < n; h++)
                {
                    for(int w = 0; w < m; w++)
                    {
                        if((((1 << h) & i) == 0) && (((1 << w) & j) == 0))
                        {
                            if(c[h][w] == '#')
                                x++;
                        }
                    }
                }
                if(x == k)
                    ans++;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3648
def f(x):
    v = 0
    for i in  range(1,x+1): v ^= i
    return v

def g(x):
    if x%4 == 1:
        return 1
    elif x%4 == 2:
        return x+1
    elif x%4 == 3:
        return 0
    else:
        return x

# for i in range(65): print(i, f(i), g(i))

a,b=map(int,input().split())
print(g(a-1)^g(b))


Measured memory_bytes: 2940
gets
a = gets.split.map(&:to_i).sort + [Float::INFINITY]
gets
b = gets.split.map(&:to_i).sort + [Float::INFINITY]

u = []
until a.empty?
  if a[0] < b[0]
    u << a.shift
  elsif a[0] > b[0]
    u << b.shift
  else
    u << a.shift
    b.shift
  end
end
u[0..-2].each {|x| p x }


Measured memory_bytes: 72108
#include <iostream>
using namespace std;
void ABC80(void);
void ABC81(void);
void ABC83(void);
void ABC85(void);
void ABC86(void);
void ABC87(void);
void ABC88(void);
void ABC89(void);

int main(void){
    ABC80();
}

void ABC80(void){
    int n,a,b;
    cin>>n>>a>>b;
    if(n*a<b)cout<<n*a<<endl;
    else cout<<b<<endl;
}

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

#pragma GCC optimize("O3")

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

bool is_palindrome(string s) {
	string rev_s = s;
	reverse(all(rev_s));
	return s == rev_s;
}

void solve(){
	string s;
	cin >> s;
	bool is;
	is = is_palindrome(s);
	int n = s.size();
	if(is) is = is_palindrome(s.substr(0, (n-1)/2));
	if(is) is = is_palindrome(s.substr((n+3)/2-1, string::npos));
	
	cout << (is ? "Yes" : "No");
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    solve();
    
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}
 
using namespace std;

using P=pair<int,int>;
void solve(){
  int n,q;
  cin>>n>>q;
  int a,b,c;
  vector<pair<int,P>>v;
  set<pair<int,int>>st;
  rep(i,n){
    cin>>a>>b>>c;
    v.eb(c,P{a-c,b-c});
  }
  sort(v.begin(),v.end());
  rep(i,q){
    int d;
    cin>>d;
    st.emplace(d,i);
  }
  vector<int>ans(q,-1);
  rep(i,n){
    auto itr=st.lower_bound(make_pair(v[i].second.first,-1));
    while(itr!=st.end()){
      if(v[i].second.second>itr->first)ans[itr->second]=v[i].first;
      else break;
      st.erase(itr++);
    }
    
  }
  rep(i,q)cout<<ans[i]<<"\n";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 14448
#include <algorithm>
#include <bits/stdc++.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); //cinの高速化
  
  int N;
  IN(N);
  vector<ll> X(N);
  int minus=0;
  ll sum=0;
  ll min;
  REP(i,N){
    IN(X[i]);
    if(X[i]<0){
      ++minus;
      X[i] *=-1; 
    }
    sum += X[i];
    if(i==0) min = X[i];
    if(X[i]< min) min = X[i];    
  }
  if(minus%2 ==1){
    sum -= min *2;
  }
  OUT(sum);
  return 0;
}

Measured memory_bytes: 1024
d,g = map(int,input().split())
p = []
c = []
for i in range(d):
    tp,tc = map(int,input().split())
    p.append(tp)
    c.append(tc)
ans = 1<<50
for i in range(1<<d):#どのコンプリートボーナスを狙うかを決める
    score = 0
    count = 0
    zero_list = []
    for j in range(d):
        if ((i >> j) & 1):
            score += c[j] + p[j]*(j+1)*100 
            count += p[j]
        else:
            zero_list.append(j)
    if score >= g:
        ans = min(ans,count)
    else:#もしまだ点数が届いていないならボーナスを狙わないものから点数が高い問題を解く
        rem = g-score
        if rem <= (p[max(zero_list)]-1)*(max(zero_list)+1)*100:
            for i in range(1,p[max(zero_list)]):
                if rem - i*(max(zero_list)+1)*100 <= 0:
                    count +=  i
                    ans = min(ans,count)
                    break
print(ans)


Measured memory_bytes: 3444
#include<stdio.h>
char sosu[1000001];
int main(void)
{
	int i,j;
	int a,d,n,cnt;
	sosu[0]=0;	sosu[1]=0;
	for(i=2;i<1000000;i++)	{
		sosu[i]=1;
	}
	for(i=2;i<=1000;i++)	{
		if(sosu[i]==1)	{
			for(j=2;i*j<1000000;j++)	{
				sosu[i*j]=0;
			}
		}
	}
	while(1)	{
		scanf("%d %d %d",&a,&d,&n);
		if(a==0 && d==0 && n==0)	break;
		cnt=0;
		for(i=a;i<1000000;i=i+d)	{
			if(sosu[i]==1)	{
				cnt++;
				if(cnt==n)	break;
			}
		}
		printf("%d\n",i);
	}

	return 0;
}


Measured memory_bytes: 1576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string b;
  cin >> b;
  
  string ret;
  if (b == "A") {
    ret = "T";
  } else if (b == "C") {
    ret = "G";
  } else if (b == "G") {
    ret = "C";
  } else if (b == "T") {
    ret = "A";
  }
  
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int rp[100][2];
int rp2[100][100];
int p[100];

int main(){

  int num,i,l,k,j,q,n;

  scanf("%d",&num);

  for(i=1; i<=num; i++)
    scanf("%d %d",&rp[i][0],&rp[i][1]);

  for(i=0; i<num; i++)
    p[i] = rp[i+1][0];

  p[i] = rp[i][1];


  /* for(i=0; i<num+1; i++)
    printf("%d ",p[i]);
  
    printf("\n");*/

  
  //n = sizeof(p)-1;
  for(i=1; i<=num; i++)
    rp2[i][i] = 0;

  for(l=2; l<=num; l++){

    for(i=1; i<=num-l+1; i++){

      j = i+l-1;

      rp2[i][j] = 1000000;

      for(k=i; k<=j-1; k++){

	q = rp2[i][k] + rp2[k+1][j] + p[i-1]*p[k]*p[j];

	if(rp2[i][j] >= q) rp2[i][j] = q;

      }

    }

  }

  
  printf("%d\n",rp2[1][num]);

  return 0;
}

Measured memory_bytes: 636
#include<stdbool.h>
#include<stdio.h>
int main(){
  int n,m,k = 8e6;
  while(scanf("%d%d",&m,&n),n){
    bool b[k]={};
    for(;n!=0;n--){while(b[m])m++;
      for(int j=m;j<k;j+=m)b[j]=true;
    }
    while(b[++m]);
    printf("%d\n",m);
  }
}

Measured memory_bytes: 10544
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  ll c[4]; double n; cin>>c[0]>>c[1]>>c[2]>>c[3]>>n;
  vector<pair<ll,ll> > costs;
  rep(i,4) costs.PB({c[i]*pow(2,(3-i)),i});
  sort(ALL(costs));
  rep(i,4) cerr<<costs[i].first SP costs[i].second<<endl;
  ll ans = 0;
  // while(n>pow(2,costs[now].second)*0.25){
  rep(now,4){
    ll g = (ll)((1.0*n)/(pow(2,costs[now].second)*0.25));
    cerr << "now" SP costs[now].second << endl;
    cerr << g << endl;
    ans += c[costs[now].second] * g;
    n -= 1.0*g*(pow(2,costs[now].second)*0.25);
    cerr << "last" SP n << endl;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 384
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct Point
{
	int x,y;
}blu[105],red[105];
int n;
vector<int> lec[205];
int mat[205];bool vis[205];
bool DFS(int u)
{
	for(int i=0;i<lec[u].size();i++)
	{
		int v=lec[u][i];
		if(vis[v]) continue;
		vis[v]=true;
		if(mat[v]==-1 || DFS(mat[v]))
		{
			mat[v]=u;
			return true;
		}
	}
	return false;
}
int Solve()
{
	int ret=0;
	memset(mat,-1,sizeof mat);
	for(int u=0;u<n;u++)
	{
		memset(vis,false,sizeof vis);
		if(DFS(u)) ret++;
	}
	return ret;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d%d",&red[i].x,&red[i].y);
	for(int i=0;i<n;i++)
		scanf("%d%d",&blu[i].x,&blu[i].y);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			if(blu[i].x>red[j].x && blu[i].y>red[j].y)
				lec[i].push_back(j+n),lec[j+n].push_back(i);
	printf("%d\n",Solve());
	return 0;
}


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

int main(void) {
  int N;
  cin >> N;
  pair<pair<string,int>,int> p[N];
  string s[N];
  int t;
  
  for(int i=0; i<N; i++){
    cin >> s[i] >> t;
    p[i]=make_pair(make_pair(s[i], -t), i);
  }
  
  sort(p, p+N);
  
  for(int i=0; i<N; i++)
    cout << p[i].second+1 << endl;
  
  return 0;
}

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

int main()
{  
   int n;
   cin>>n;
   int a[n];
   double sum=0;
   for(int i=0;i<n;i++){
       cin>>a[i];
       sum+=a[i];
   }
   double ave=sum/n;
   double diff=1000;
   int ans=0;
   for(int i=0;i<n;i++){
       if(abs(a[i]-ave)<diff){
           ans=i;
           diff=abs(a[i]-ave);
       }
   }
   cout<<ans<<endl;

} 


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



int main(){
int n;
cin >> n;
vector<long double> x(n,0);
vector<long double> x2(n,0);
rep(i,n)
{cin >> x.at(i);}

x2=x;
sort(x.begin(),x.end());

pair<long double,long double> Mpair;
Mpair.first=x.at(n/2 - 1);
Mpair.second=x.at(n/2);

float M = (Mpair.first + Mpair.second)/2;

/*
rep(i,x2.size())
{ //cout<< i <<" : "<<x2.at(i)<<":"<<M<<": "<<Mpair.first<<":"<<Mpair.second<<endl;
  if(x2.at(i)>=M)
  {cout << Mpair.first << endl;}
  else{cout << Mpair.second << endl;}
}*/

rep(i,n)
{int ans;
 if(x2.at(i)>=M)
 {ans=Mpair.first;}
 else
 {
   ans=Mpair.second;
 }
 
 cout << ans << endl;
}



return 0;
}
//

Measured memory_bytes: 8448
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();

    ll x, k, d;
    cin >> x >> k >> d;

    ll diff = abs(x);
    ll num1 = diff / d;
    if (num1 >= k) {
        cout << diff - d * k << endl;
        return 0;
    }
    k -= num1;
    diff -= num1 * d;
    DEBUG(k);
    DEBUG(diff);
    if (k % 2 == 0) cout << diff << endl;
    else cout << abs(diff - d) << endl;
}

Measured memory_bytes: 3652
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n, k; cin >> n >> k;
  int ans = 0;
  rep(i, n) {
    int h; cin >> h;
    ans += h >= k;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h> 
int main()
{ 
int t,i=1,p,x=0; 
scanf("%d",&t); 
while(i<=t)
{
scanf("%d",&p); 
if(p!=i)
x++;
i++;
} 
if((x==0)||(x==2))
printf("YES\n");
else
printf("NO\n"); 
return 0; 
} 


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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int X=(A+D-1)/D;
  int Y=(B+C-1)/B;
  if(X>=Y)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3620
n = int(input())
a = [int(item) for item in input().split()]

a.sort()

abs_a = []
minus_num = 0
for i in range(n):
    if a[i] < 0:
        minus_num += 1
    abs_a.append(abs(a[i]))

abs_a.sort()
plus_sum = sum(abs_a)

if minus_num % 2 == 0:
    print(plus_sum)
else:
    print(plus_sum - 2*abs_a[0])

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const LL mod = 1e9 + 7;
int N,M;
bool e[16][16];
LL p1[1<<13] , p2[1<<13];
LL c1[1<<13] , c2[1<<13] , c[1<<13];
bool b1[1<<13] , b2[1<<13];
bool connect[1<<13];

int log2(int x){
	int z = 0;
	for(; x>1 ; x >>= 1) ++z;
	return z;
}

int main(){
	cin >> N >> M;
	repp(i,0,M){
		int a,b;
		cin >> a >> b;
		a = N - a;
		b = N - b;
		e[a][b] = e[b][a] = 1;
	}
	LL ans = 1;
	repp(i,0,M) ans = ans * 2 % mod;
	if(e[N-1][N-2]) return cout << ans << endl , 0;
	
	connect[0] = 1;
	repp(i,1,1<<(N-2)){
		int x = 0;
		while(x<N-2 && (!(i&(1<<x)) || !connect[i-(1<<x)])) ++x;
		if(x==N-2) continue;
		repp(j,0,N-2) if((i&(1<<j)) && e[x][j]) connect[i] = 1;
	}
	
	c[0] = 1;
	repp(i,1,1<<(N-2)){
		int x = i&-i;
		c[i] = c[i^x];
		x = log2(x);
		repp(j,0,N-2) if((i&(1<<j)) && e[x][j]) (c[i] *= 2) %= mod;
	}
	
	p1[0] = c1[0] = 1;
	b1[0] = 1;
	repp(i,1,1<<(N-2)){
		int x = i&-i;
		c1[i] = c1[i^x];
		int y = log2(x);
		repp(j,0,N-2) if((i&(1<<j)) && e[y][j]){
			(c1[i] *= 2) %= mod;
		}
		if(e[y][N-1]){
			(c1[i] *= 2) %= mod;
		}
		int z = 0;
		while(z<N-2 && (!(i&(1<<z)) || !b1[i-(1<<z)])) ++z;
		if(z<N-2){
			repp(j,0,N-2) if((i&(1<<j)) && e[z][j]) b1[i] = 1;
			if(e[z][N-1]) b1[i] = 1;
		}
		if(!b1[i]) continue;
		p1[i] = c1[i];
		for(int k = (i-1) & i ; k >= 0 ; --k){
			k &= i;
			(p1[i] -= p1[k] * c[i^k]) %= mod;
		}
	}
	
	p2[0] = c2[0] = 1;
	b2[0] = 1;
	repp(i,1,1<<(N-2)){
		int x = i&-i;
		c2[i] = c2[i^x];
		int y = log2(x);
		repp(j,0,N-2) if((i&(1<<j)) && e[y][j]){
			(c2[i] *= 2) %= mod;
		}
		if(e[y][N-2]){
			(c2[i] *= 2) %= mod;
		}
		int z = 0;
		while(z<N-2 && (!(i&(1<<z)) || !b2[i-(1<<z)])) ++z;
		if(z<N-2){
			repp(j,0,N-2) if((i&(1<<j)) && e[z][j]) b2[i] = 1;
			if(e[z][N-2]) b2[i] = 1;
		}
		if(!b2[i]) continue;
		p2[i] = c2[i];
		for(int k = (i-1) & i ; k >= 0 ; --k){
			k &= i;
			(p2[i] -= p2[k] * c[i^k]) %= mod;
		}
	}
	
	repp(i,0,1<<(N-2)){
		if(!b1[i]) continue;
		for(int j = ((1<<(N-2))-1)^i ; j >= 0 ; --j){
			j &= ((1<<(N-2))-1)^i;
			if(!b2[j]) continue;
			bool b = 1;
			repp(k,0,N-2){
				if((j&(1<<k)) && e[k][N-1]) b = 0;
				if((i&(1<<k)) && e[k][N-2]) b = 0;
				repp(l,k+1,N-2){
					if((i&(1<<k)) && (j&(1<<l)) && e[k][l]) b = 0;
					if((i&(1<<l)) && (j&(1<<k)) && e[k][l]) b = 0;
				}
			}
			if(b) (ans -= p1[i] * p2[j] % mod * c[((1<<(N-2))-1)^i^j]) %= mod;
	//		if(b) cout << i << ' ' << j << ' ' << p1[i] << ' ' << p2[j] << ' ' << c[((1<<(N-2))-1)^i^j] << ' ' << ans << endl;
		}
	}
	if(ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define dl double long
const int INF=0x3fffffff;
const ll MOD=1000000007;
const ll MODD=998244353;
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }

int main()
{
  string S;
  cin >> S;
  if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) cout << "Bad" << "\n";
  else cout << "Good" << "\n";
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> P(N);
	REP(i, N) cin >> P[i];

	vector<ll> DP(N+1, 0);
	REP(i, N){
		ll p = P[i];
		DP[p] = DP[p-1] + 1;
	}
	ll ma = -1;
	REP(i, N+1) if(ma<DP[i]) ma = DP[i];

	cout << N-ma << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define M_PI 3.1415926
int main()
{
LL a,b;
while(cin>>a>>b){
    LL ans=0;
    ans+=min(a,b/2);
    b-=ans*2;
    ans+=b/4;
    cout<<ans<<endl;
}
    return 0;
}


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

int N;
int ans = 0;

void calc(long long n, bool f3, bool f5, bool f7)
{
	if(n > N)
		return;

	if(f3==true && f5==true && f7==true)
		ans++;
	
	long long a = 10 * n;
	calc(a+3, true, f5, f7);
	calc(a+5, f3, true, f7);
	calc(a+7, f3, f5, true);

}

int main(void)
{
	cin >> N;

	calc(0, false, false, false);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import Control.Monad                                                                                                       
main :: IO ()                                                                                                              
main = do                                                                                                                  
  [n,m] <- map read . words <$> getLine                                                                                    
  ab <- replicateM n (map read . words <$> getLine)                                                                        
  cd <- zip [1..m] <$> replicateM m (map read . words <$> getLine)                                                         
  forM_ ab $ \x -> do                                                                                                      
    print . fst . foldr1 (f x) $ cd                                                                                        
                                                                                                                           
f :: [Int] -> (Int,[Int]) -> (Int,[Int]) -> (Int,[Int])                                                                    
f [a,b] (n1,[c1,d1]) (n2,[c2,d2]) = if abs(a-c1)+abs(b-d1) <= abs(a-c2)+abs(b-d2) then (n1,[c1,d1]) else (n2,[c2,d2])

Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(void){
	int i,j,n,now,x[15][15];

	while(cin>>n && n){
		memset(x,0,sizeof(x));

		j = n / 2;
		i = j + 1;
		x[i][j] = 1;

		for(now=2;now<=n*n;now++){
			i++; j++;
			while(1){
				if(n <= j) j = 0;
				if(j < 0) j = n - 1;
				if(n <= i) i = 0;

				if(x[i][j] == 0) break;
				else{
					i++; j--;
				}
			}
			x[i][j] = now;
		}

		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				printf("%4d",x[i][j]);
			}
			cout<<endl;
		}
	}

	return 0;
}

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

int main(){
  long long n;
  cin>>n;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
  }sort(num.begin(),num.end());
  if(n==1&&num[0]==0){
    cout<<1<<endl; return 0;
  }
  if(num[0]==0){
    if(n%2==0){
      cout<<0<<endl; return 0;
    }
    for(int i=1;i<n;i++){
      if(num[i]%2==0 && num[i+1]==num[i]&&num[i-1]!=num[i]){
        i++;
        continue;
      }
      cout<<0<<endl; return 0;
    }
  }else{
    if(n%2==1){
      cout<<0<<endl; return 0;
    }
    for(int i=0;i<n;i++){
      if(num[i]%2==1 && num[i+1]==num[i] &&num[i-1]!=num[i]){
        i++;
        continue;
      }
      cout<<0<<endl; return 0;
    }
  }long long ans=1;
  for(int i=0;i<n/2;i++){
    ans*=2;
    ans%=1000000007;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<map>
#include<cctype>
#include<sstream>
using namespace std;
int main()
{
	int n, k;
	int ans;
	cin >> n >> k;
	if (n%k==0)
		ans = 0;
	else
		ans = 1;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
input_angle = int(input())
input_length = input()

_length = input_length.split(' ')
length = [int(l) for l in _length]
length.sort()
sum = 0

for i in range(input_angle-1):
  sum += int(length[i])
  
if int(length[-1]) < sum:
  print('Yes')
else:
  print('No')

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int n,m,R;
    cin >> n >> m >> R;
    VL r(R);
    VVL cost(n,VL(n,INT32_MAX));
    for (int i = 0; i < R; i++) {
        int a;
        cin >> a;
        a--;
        r[i] = a;
    }
    SORT(r);
    for (int i = 0; i < n; i++) {
        cost[i][i] = 0;
    }
    for (int i = 0; i < m; i++) {
        int a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        cost[a][b] = c;
        cost[b][a] = c;
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cost[i][j] = min(cost[i][j],cost[i][k] + cost[k][j]);
            }
        }
    }

    LL ans = INT64_MAX;
    do {
        LL tmp = 0;
        for (int i = 0; i < R - 1; i++) {
            tmp += cost[r[i]][r[i+1]];
        }
        ans = min(ans,tmp);
    } while (next_permutation(r.begin(), r.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip> //do setprecision
#include <ctime>
#include <complex>
using namespace std;

int main(void){
	int i,n,temp;
	
	cin >> n;
	map<int,int> numberof;
	for(i=0;i<n;i++){
		cin >> temp;
		numberof[temp]++;
	}
	auto itrf=numberof.begin();
	auto nextitr=next(itrf,1);
	if(numberof.size()==1){
		if((itrf->first==1) || (itrf->first+1==n) || (2*itrf->first<=n)){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else if(numberof.size()==2){
		if((itrf->first+1)==nextitr->first){
			if((n-itrf->second)/2+itrf->second>=(itrf->first+1) && (itrf->second+1<=itrf->first+1)){
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
		}else{
			cout << "No" << endl;
		}
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, K, A, S[200001];
ll res;
map<int, ll>mp;
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A;
		S[i + 1] = ((S[i] + A) % K - 1 + K) % K;
	}
	for (int i = 0; i <= min(N, K - 1); i++) {
		mp[S[i]]++;
	}
	for (pair<int, ll>p : mp) {
		res += p.second*(p.second - 1) / 2;
	}
	for (int i = 0; i <= N; i++) {
		mp[S[i]]--;
		if (i + K <= N) {
			res += mp[S[i + K]];
			mp[S[i + K]]++;
		}
	}
	cout << res << endl;
}

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

int compute(string &s,int len){

	if(len&1) return compute(s,len-1);

	else{

		int mid=len>>1;

		string a,b;

		for(int i=0;i<mid;++i) a+=s[i];

		for(int i=mid;i<len;++i) b+=s[i];

		if(a==b) return len;

		else return compute(s,len-1);
	}

}




int main(){

		string s;

		cin>>s;

		cout<<compute(s,s.size()-1)<<'\n';

}

Measured memory_bytes: 256
sx, sy, tx, ty = list(map(int, input().split()))

diff_x = tx - sx
diff_y = ty - sy

print('R'*diff_x + 'U'*diff_y + 'L'*diff_x + 'D'*diff_y
      + 'D' + 'R'*(diff_x+1) + 'U'*(diff_y+1) + 'L'
      + 'U' + 'L'*(diff_x+1) + 'D'*(diff_y+1) + 'R')


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

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = (0..3 * n).map(|_| read()).collect();

    a.sort_by(|a, b| b.cmp(a));

    println!(
        "{}",
        a[..2 * n]
            .iter()
            .enumerate()
            .filter(|x| x.0 % 2 == 1)
            .map(|x| x.1)
            .sum::<i64>()
    );
}

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


Measured memory_bytes: 8444