akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <algorithm>
#include <functional>
#include <utility>
#include <string>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define ceil(x,m) ((x)+(m)-1)/(m)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

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

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
  for (int i = 0; i < len; i++) { s << v[i]; if (i < len - 1) s << " "; }
  s << "]";
  return s;
}

signed main()
{
  string s; cin >> s;
  int n = SZ(s);

  if (s[0] == '0' || s[n-1] == '1') {
    cout << -1 << endl;
    return 0;
  }
  rep(i, 0, n-1) {
    if (s[i] != s[n-2-i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  vec< pair<int,int> > E;
  int cur = 0;
  rep(i, 0, n-1) {
    E.PB(MP(cur, i+1));
    if (s[i] == '1') {
      cur = i+1;
    }
  }

  rep(i, 0, SZ(E)) {
    cout << E[i].first+1 << " " << E[i].second+1 << endl;
  }

  return 0;
}


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

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

    int n = s.size();
    int zero = count(s.begin(), s.end(), '0');

    cout << min(zero, n - zero) * 2 << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
	int car[4][13], i, nu = 0, n, a = 0, b;
	char card[4][13], in;
	
	scanf("%d", &a);
	for (i = 0; i < 4; i++)
	{
		for (n = 0; n < 13; n++)
		{
			car[i][n] = 0;
			switch (i)
			{
			case 0:
				card[i][n] = { 'S' };
				break;
			case 1:
				card[i][n] = { 'H' };
				break;
			case 2:
				card[i][n] = { 'C' };
				break;
			case 3:
				card[i][n] = { 'D' };
          break;
			}
		}
	}
	i = 0;
	for (b = 0; b < a * 2; b++)
	{
		scanf("%c %d", &in,&nu);
		switch (in)
		{
		case 'S':
			car[0][nu - 1] = 1;
			break;
		case 'H':
			car[1][nu - 1] = 1;
			break;
		case 'C':
			car[2][nu - 1] = 1;
			break;
		case 'D':
			car[3][nu - 1] = 1;
			break;
		}
		i++;
	}
	for (i = 0; i < 4; i++)
	{
		for (n = 0; n < 13; n++)
		{
			if (car[i][n] == 0)
			{
				printf("%c %d\n", card[i][n], n + 1);
			}
		}
	}
	
	return 0;
}

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

int main(void){
    int n;
    long long count = 0;
    string s;
    cin >> n >> s;

    for(int i = 0; i < n-2; ++i){
        int red = 0, green = 0, blue = 0, minus = 0;
        for(int j = i + 1; j < n; ++j){
            if(s[j] == 'R') red++;
            else if(s[j] == 'G') green++;
            else if(s[j] == 'B') blue++;
            if(j*2-i < n){
                if(s[i] != s[j] && s[j*2 - i] != s[j] && s[j*2 - i] != s[i]) minus++;
            }
        }
        if(s[i] == 'R') count += green * blue - minus; 
        else if(s[i] == 'G') count += red * blue - minus; 
        else if(s[i] == 'B') count += green * red - minus; 
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

int main() {
  string S;
  cin >> S;
  string answer = "";
  for (char c : S) {
    if (c == 'B') {
      if (answer.length() > 0) {
        answer.pop_back();
      }
    } else {
      answer += c;
    }
  }

  cout << answer << "\n";

  return 0;
}


Measured memory_bytes: 256
//srinivas
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(ll x=in;x<n;x+=r)
#define ifr(x,n) for(ll x=0;x<n;x++)
#define dfr(x,n) for(ll x=n-1;x>=0;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    string s[n];
    ifr(i,n)cin>>s[i];
    ll dp[n][m];
    ifr(i,n)
        ifr(j,m)
            dp[i][j]=0;
    ifr(i,m){
        if(s[0][i]=='.')
            dp[0][i]=1;
        else break;
    }
    ifr(i,n){
        if(s[i][0]=='.')
            dp[i][0]=1;
        else break;
    }
    fr(i,1,n,1){
        fr(j,1,m,1){
            if(s[i][j]=='.')
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
        }
    }
    cout<<dp[n-1][m-1]<<endl;
    return 0;
}

Measured memory_bytes: 9088
using System;

public class p1004
{
	const int mx = 10001;
	
	p1004 ()
	{
		string str;
		int n, cnt;
		bool[] prime = new bool[mx];
		
		for (int i = 0; i < mx; ++i)
			prime [i] = true;
		prime [0] = prime [1] = false;
		
		for (int i = 2; i < mx; ++i)
			if (prime [i])
				for (int j = i+i; j < mx; j+=i)
					prime [j] = false;
		
		while ((str=Console.ReadLine())!= null) {
			n = int.Parse (str);
			cnt = 0;
			for (int i = 1, j = n; i <= n && j >= 1; ++i, --j)
				if (prime [i] && prime [j])
					++cnt;
			Console.WriteLine ("{0}", cnt);
		}
	}
	
	public static int Main (string[] args)
	{
		new p1004 ();
		return 0;
	}
}

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

int main() {
  string s;
  cin >> s;
  
  std::sort(s.begin(), s.end());

  if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
    cout << "Yes";
  } else {
    cout << "No";
  }
    
  return 0;
}

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

int main(){
  int h,n,sum=0;
  cin>>h>>n;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    sum+=a;
  }
  if(sum>=h)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return 0;
}

Measured memory_bytes: 256
package main
import (
	"fmt"
)

type Dice struct{
	/*
	こういう感じ
  		 ___
	____|_1_|_______
	|_4_|_2_|_3_|_5_|
		|_6_|
	*/
	Surface []int
}

func (d *Dice)Move(dir string){
	switch dir{
	case "W":
		d.Surface[0], d.Surface[2], d.Surface[5], d.Surface[3] = d.Surface[2], d.Surface[5], d.Surface[3], d.Surface[0]
	case "E":
		d.Surface[0], d.Surface[2], d.Surface[5], d.Surface[3] = d.Surface[3], d.Surface[0], d.Surface[2], d.Surface[5]
	case "N":
		d.Surface[0], d.Surface[4], d.Surface[5], d.Surface[1] = d.Surface[1], d.Surface[0],d.Surface[4], d.Surface[5]
	case "S":
		d.Surface[5], d.Surface[1], d.Surface[0], d.Surface[4] = d.Surface[1], d.Surface[0],d.Surface[4], d.Surface[5]	
	}
}

func (d *Dice)GetStatus(){
	doc := `              ____
 	 ____|_%02d_|_________
	|_%02d_|_%02d_|_%02d_|_%02d_|
	     |_%02d_|`
	fmt.Printf(doc, d.Surface[0], d.Surface[3], d.Surface[1], d.Surface[2], d.Surface[4], d.Surface[5])
	fmt.Println()
}

func main(){
	d := Dice{
		make([]int, 6),
	}
	for i:=0; i<6; i++{
		var n int
		fmt.Scan(&n)
		d.Surface[i] = n
	}
	var order string
	fmt.Scan(&order)
	for _, o := range []rune(order){
		d.Move(string(o))
		// fmt.Printf("move dir: %s\n", string(o))
		// d.GetStatus()
	}
	fmt.Println(d.Surface[0])
}


Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int d, t, s;
    cin >> d >> t >> s;
    cout << ((t * s >= d) ? "Yes" : "No" ) << endl;
}


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

cnt = 0
while True:
  flag = True
  for i in range(n):
    if a[i] % 2 == 0:
      a[i] //= 2
    else:
      flag = False
  if flag:
    cnt += 1
  else:
    break
      
print(cnt)
      

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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;
}
int main() {
  cout << fixed << setprecision(10);
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(ALL(a));
  int ans = 0;
  rep(i,k){
    ans+=a[i];
  }
  cout << ans << endl;
}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);	
	int n;
	string s;
	cin >> n;
	map<string, int> m;
	for (int i = 0; i < n; ++i){
		cin >> s;
		++m[s];
	}
	cout << "AC x " << m["AC"] << "\n";
	cout << "WA x " << m["WA"] << "\n";
	cout << "TLE x " << m["TLE"] << "\n";
	cout << "RE x " << m["RE"] << "\n";
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

int f(int n) {
  if (n%2 == 0) {
    return n/2;
  } else { 
    return 3*n+1;
  }
}
int main() {
  cin.tie(0); ios::sync_with_stdio(false);

  int s;
  cin >> s;
  set<int> ss;
  ss.insert(s);
  int cnt = 1;
  while (1) {
    cnt++;
    s = f(s);
    if (ss.find(s) != ss.end()) {
      cout << cnt << endl;
      return 0;
    }
    ss.insert(s);
  }
}


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

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

  int n, k;
  cin >> n >> k;

  int ans = 0;

  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;

    int a = x;
    int b = k - x;

    int c = min(a, b);
    ans += 2 * c;
  }

  cout << ans << '\n';

  return (0);
}

Measured memory_bytes: 3580
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] arr = Console.ReadLine().Split(' ');
        long H = long.Parse(arr[0]);
        long h = 1;
        long cnt = 0;
        long sum = 0;

        while(0 < H)
        {
            cnt++;
            H /= 2;
            sum += (long)Math.Pow(2, cnt - 1);
        }

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long int
#define pair <ll, ll> pi
#define vector <ll> vi
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define SQ(a) (a) * (a)
#define ordered_set tree<ll, null_type, greater_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen('input.txt', 'r', stdin);
    //freopen('output.txt', 'w', stdout);
    ll i, j, k, n, m, b, d, t, ans = 0,a,x,y;
    cin>>a>>b;
    if((a>=1&&a<=9) &&(b>=1&&b<=9)){
        cout<<a*b<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#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 all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

int main(void){
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin>>a[i];
    }
    int res = 1e9;
    for(int k = -100; k<=100; k++){
        int sum = 0;
        for(int i = 0; i < n; i++){
            sum += (a[i]-k)*(a[i]-k);
        }
        res = min(res, sum);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
 
typedef long long ll;
ll n,c,s,ans;
int main(){
  ll i,N;
  cin>>N>>c;
ll x[N],cal[N],mx[N+1]={0},mx2[N+1]={0};
 
  for(i=0;i<N;i++){
    scanf("%lld %lld",&x[i],&cal[i]);
  }  
  for(i=N-1;i>=0;i--){
    s+=cal[i];
    mx[i] = max(mx[i+1],s-(c-x[i]));
    mx2[i] = max(mx2[i+1],s-(c-x[i])*2);
  }
  ans = max(mx[0],mx2[0]);
  s=0;
  for(i=0;i<N;i++){
    s+=cal[i];
    ans = max(ans, s-x[i]*2 + mx[i+1]);
    ans = max(ans, s-x[i] + mx2[i+1]);
  }
    cout << ans;
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define ll              long long int
#define ld              long double
#define F               first
#define S               second
#define pb              push_back
#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpi             vector <pii>
#define vpp             vector <pair<int, pii>>
#define mii             map <int, int>
#define mpi             map <pii, int>
#define spi             set <pii>
#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl
#define fast            ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

inline ll power(ll a, ll b)
{
     ll x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}
////// Variables //////
int tc;

//////////////////////////////

void solve(){
    ll n;
    cin >> n;
    ll a[n+5];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans = 0;//23
    sort(a,a+n);
    for(int i=0;i<n-2;i++){
        int k = i+2;
        for(int j=i+1;j<n;j++){
            while(k < n && a[k]<a[i]+a[j])
                k++;
            if(k > j)
                ans += (k-j-1);
        }
    }
    cout<<ans;
}
int32_t main(){
    fast
    cout<< setprecision(10) << fixed;
    tc=1;
    clock_t z = clock();
    //cin >> tc;
    while(tc--){
        solve();
    }
   // cerr << "Runtime: "<<((double)(clock()-z)/CLOCKS_PER_SEC);
    return 0;
}

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


using namespace std;


// Powered by caide (code generator, tester, and library code inliner)


class Solution {
public:
  void solve(std::istream& in, std::ostream& out)
  {
    int n;
    in >> n;
    vector<long long> a(n);
    for(auto&& i : a) {
      in >> i;
    }
    vector<long long> b(n + 1);
    partial_sum(a.begin(), a.end(), b.begin() + 1);
    long long ans = LLONG_MAX;
    for(int i = 1; i < n; i++) {
      ans = min(ans, abs(b[i] - (b[n] - b[i])));
    }
    out << ans << "\n";
  }
};

void solve(std::istream& in, std::ostream& out)
{
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


  istream& in = cin;


  ostream& out = cout;

  solve(in, out);
  return 0;
}




Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll = long long;
#define pb push_back
#define F first
#define S second
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,b) for(int i=a; i<=b; i++)
#define drep2(i,a,b) for(int i=a; i>=b; i--)

int main()
{
    string input;
	cin >> input;
	if ( (input == "101") || (input == "110") || (input == "011")) {
		cout << "2" << endl;
	} else if(input == "000") {
		cout << "0" << endl;
	} else if(input == "111") {
		cout << "3" << endl;
	} else {
        cout << "1" << endl;
    }

    return 0;
}




Measured memory_bytes: 256
L, R = map(int, input().split())

p, q = L%2019, R%2019
z = R - L

if (p == 0) or (q == 0) or (z > 2019) or (p >= q):
    print(0)
else:
    answer = []
    for i in range(z):#669
        for j in range(z-i):#669-i
            k1 = p + i#3
            k2 = j + k1 + 1
            X = k1 * k2 % 2019
            answer.append(X)
    A = min(answer, key=int)
    print(A)

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

using namespace std;

string a[3];
const int N = int(1e4 + 10);
bool poss[3][3][N];
int f[3];

bool solve(int i, int j, int k){
	for(int d = k ; d < a[i].length() && (d - k < a[j].length()) ; d++){
		if(a[i][d] != a[j][d - k] && a[i][d] != '?' && a[j][d - k] != '?'){
			return false;
		}
	}

	return true;
}

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

	cin >> a[0] >> a[1] >> a[2];

	for(int i = 0 ; i < 3 ; i++){
		f[i] = i;

		for(int j = 0 ; j < 3 ; j++){
			if(i == j){
				continue;
			}

			for(int k = 0 ; k <= a[i].length() ; k++){
				poss[i][j][k] = solve(i, j, k);
			}
		}
	}

	int ans = int(1e9);

	do{
		for(int d = 0 ; d <= a[f[0]].length() ; d++){
			if(poss[f[0]][f[1]][d]){
				for(int j = 0 ; j <= max(a[f[1]].length(), a[f[0]].length()) ; j++){
					if(d + j > a[f[0]].length() || poss[f[0]][f[2]][d + j]){
						if(j > a[f[1]].length() || poss[f[1]][f[2]][j]){
							ans = min(ans, max({j + d + int(a[f[2]].length()), 
								d + int(a[f[1]].length()), int(a[f[0]].length())}));
						}
					}
				}
			}
		}
	}while(next_permutation(f, f + 3));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 10; //乗車券の枚数
const int MAX_M = 40; // 町の数
const int INF = 1e9;
int t[MAX_N];
int d[MAX_M][MAX_M];
double dp[1<<MAX_N][MAX_M];

int N,M,P,a,b;

void chmin(double &a, double b){ if( a > b){ swap(a,b);} return ;}

void solve(){
  for(int i = 0; i < (1<<MAX_N); i++){ 
    for(int j = 0; j < MAX_M; j++){ 
      dp[i][j] = INF;}}
  dp[(1<<N)-1][a] = 0;
  //スタート地点にいて、かつチケットを全部持っている状態に達するまでのコストは0
  double res = INF;
  for(int  S = (1<<N)-1; S >= 0; S--){
    chmin(res, dp[S][b]);
    for(int u = 0; u < M; u++){
      for(int i = 0; i < N; i++){
        if( S >> i & 1){ 
          for(int v = 0; v < M; v++){ 
            if( d[u][v] != -1){
              chmin(dp[S & ~(1<<i)][v],dp[S][u]+(double)d[u][v]/t[i]);}
          }
        }
      }
    }
  }
  if( res == INF){ cout << "Impossible" << endl;}
  else{
    cout << fixed << setprecision(10) << res << endl;}
  return;
}

int main(){
  while(true){
    cin >> N >> M >> P >> a >> b;
    if( N == 0 && M == 0 && P == 0 && a == 0 && b == 0){
      break;}
    
    a--; b--;
    
    for(int i = 0; i < MAX_M; i++){
      for(int j = 0; j < MAX_M; j++){ 
        d[i][j] = -1;}}
    
    for(int i = 0; i < N; i++){ cin >> t[i];}
    
    for(int i = 0; i < P; i++){
      int x,y,dist ; cin >> x >> y >> dist ;
      x--; y--;
      d[x][y] = dist; d[y][x] = dist;
    }
    solve();
  }
  
  return 0;}
                
               
    
  
             


Measured memory_bytes: 3564
n = gets.chomp.to_i
a = gets.split.map(&:to_i)
min = 10**12
count = 0
sum = 0
n.times do |i|
  v = a[i]
  if v < 0
    count += 1
    v = -v
  end
  min = v if min > v
  sum += v
end
sum -= min * 2 if count.odd?
puts sum


Measured memory_bytes: 10628
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
ans = 0
N = int(input())
for n in range(1, N+1):
    if n%2 != 0:
        if len(make_divisors(n)) == 8:
            ans += 1

print(ans)

Measured memory_bytes: 61988
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
ll dp[100][2][2];
int main(){
  ll n,k;
  cin>>n>>k;
  for(int i=0;i<100;i++)for(int j=0;j<2;j++)dp[i][j][1]=-inf;
  V<ll> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=60;i>=0;i--){
    int d=(k&(1ll<<i)?1:0);
    ll cnt=0;
    for(int j=0;j<n;j++)if(a[j]&(1ll<<i))cnt++;
    for(int j=0;j<2;j++){
      for(int l=0;l<2;l++){
      for(int r=0;r<=(j?1:d);r++){
          if(r&&k<(1ll<<i))continue;
          chmax(dp[i][r][(j||r!=d)],dp[i+1][l][j]+(r?n-cnt:cnt)*(1ll<<i));
      }
      }
    }
  }
  cout<<max({dp[0][0][0],dp[0][0][1],dp[0][1][0],dp[0][1][1]})<<"\n";
}


Measured memory_bytes: 3964
N = int(input())
A = [int(x) for x in input().split()]
tmp = list()
for n in range(len(A)):
  tmp.append([n+1, A[n]])
tmp = sorted(tmp, key=lambda x: x[1])
res = []
for x in tmp:
  res.append(x[0])
print(*res)

Measured memory_bytes: 23612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long int ll;
int main()
{
	int n;
	ll a, b, x, d, op = 0 ;
	cin >> n >> x;
	cin >> a >> b;
	if( a + b > x )
	{
		d = a + b - x;
		if( d <= b ){
	    	b -= d;
        }
	    else
        {
	    	b = 0;
        }
          op += d;
	}
	a = b;
	rep(i,2,n)
	{
	    cin >> b;
	    if( a + b > x )
		{
			d = a + b - x;
			if( d <= b ){
		    	b -= d;
            }
		    else
            {
              b = 0;
            }  
			op += d;
		}
		a = b;
	}
	cout << op<< endl;
	return 0;
}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

VI c;
vector<VI> g;

struct uftree
{
	VI parent, rank;

	uftree(int max_n) : parent(VI(max_n)), rank(VI(max_n)) 
	{
		init(max_n);
	};

	void init(int n) {
		REP(i, n)
		{
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x) {
		return parent[x] == x ? x : parent[x] = find(parent[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank[x] < rank[y]) parent[x] = y;
		else {
			parent[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};

void dfs(int v, int d)
{
	c[v] = d;
	REP(i, g[v].size())
	{
		if (c[g[v][i]] == -1) dfs(g[v][i], d);
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	VI p(n);
	g = vector<VI>(n);
	c = VI(n);
	REP(i, n) cin >> p[i];
	REP(i, m)
	{
		int x, y;
		cin >> x >> y;
		g[x-1].push_back(y-1);
		g[y-1].push_back(x-1);
	}

	REP(i, n) c[i] = -1;
	REP(i, n) if(c[i] == -1) dfs(i, i);
	
	auto uft = uftree(n);
	REP(i, n) uft.unite(i, c[i]);

	int count = 0;
	REP(i, n)
	{
		if (uft.same(i, p[i] - 1)) count++;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 9344
import java.util.*;
import java.util.Arrays;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int[] num=new int[1001];
		int l=1;
		int ans=0;
		num[0]=1;
		
		for(int i=2;i<32;i++){
			int tmp=i;
			for(int j=2;j<10;j++){
				tmp*=i;
				if(tmp<=1000){
					num[l]=tmp;
					l++;
				}
			}
		}

		Arrays.sort(num);

		if(X<1000){
			for(int k=0;k<num.length;k++){
				if(num[k]!=0 && num[k]<=X && X<num[k+1]){ 
					ans=num[k];
				}
			}
		}else{
			ans=1000;
		}


		System.out.println(ans);
		
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

const long MOD = 998244353;
int n, m;
map<P, bool> mp;

long DP[100000][16];

bool valid(int i, int s) {
  for (int x = 0; x < 3; ++x) {
    for (int y = 0; y < 3; ++y) {
      P p(i + x, i + y);
      if (!mp.count(p)) continue;
      if (mp[p] != ((s >> (x * 3 + y)) & 1)) return false;
    } 
  }
  return true;
}

long dog() {
  if (n == 2) {
    if (m == 4) {
      int sum = 0;
      for (auto&& p : mp) {
        sum += p.second;
      }
      return !(sum % 2);
    }
    return 1 << (3 - m);
  }
  
  for (int s = 0; s < (1 << 4); ++s) {
    DP[0][s] = __builtin_popcount(s) % 2 == 0;
  }
  
  for (int i = 0; i < n - 2; ++i) {
    int mask = 0;
    int val = 0;
    for (int x = 0; x < 3; ++x) {
      for (int y = 0; y < 3; ++y) {
        P p(i + x, i + y);
        int k = x * 3 + y;
        if (mp.count(p)) {
          mask |= 1 << k;
          val |= mp[p] << k;
        }
      } 
    }
    
    for (int s = 0; s < (1 << 9); ++s) {
      if ((s & mask) != val) continue;
      if (__builtin_popcount(s) % 2 != 0) continue;
      if (__builtin_popcount(s & 0b000011011) % 2 != 0) continue;
      if (__builtin_popcount(s & 0b110110000) % 2 != 0) continue;
      
      int t = ((s & 0b000011000) >> 1) | (s & 0b000000011);
      int u = ((s & 0b110000000) >> 5) | ((s & 0b000110000) >> 4);
      DP[i + 1][u] += DP[i][t];
      DP[i + 1][u] %= MOD;
    }
  }
  
  long sum = 0;
  for (int s = 0; s < (1 << 4); ++s) {
    sum += DP[n - 2][s];
    sum %= MOD;
  }
  return sum;
}

long mpow(long n) {
  if (n == 0) return 1;
  if (n % 2 == 1) return mpow(n - 1) * 2 % MOD;
  long tmp = mpow(n / 2);
  return tmp * tmp % MOD;
}

long cat() {
  set<P> st;
  for (auto&& q : mp) {
    P a = q.first;
    if (abs(a.second - a.first) < 3) continue;
    P b(a.second, a.first);
    if (mp.count(b) && mp[a] != mp[b]) return 0;
    st.insert(a);
    st.insert(b);
  }
  
  return mpow((long(n - 2) * (n - 3) - st.size()) / 2);
}

long sub() {
  cin >> n >> m;
  for (int j = 0; j < m; ++j) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    mp[P(a, b)] = c;
  }
  return cat() * dog() % MOD;
}

int main() {
  cout << sub() << endl;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

vector<ll> num, pnum;

ll f(ll n, ll x){
    if (n == 0) return 1;
    if (x == 1) return 0;
    else if (1 < x && x <= num[n-1]+1) return f(n-1, x-1);
    else if (x == num[n-1]+2) return pnum[n-1]+1;
    else if (num[n-1]+2 < x && x < 2*num[n-1]+2) return pnum[n-1] + 1 + f(n-1, x-num[n-1]-2);
    else if (x == 2 * num[n-1] + 3) return 2 * pnum[n-1] + 1;
}

int main(){
    ll n, x;
    cin >> n >> x;
    num = vector<ll>(n+1);
    pnum = vector<ll>(n+1);
    num[0] = 1, pnum[0] = 1;
    for(int i = 1; i <= n; i++){
        num[i] = num[i-1]  * 2 + 3;
        pnum[i] = pnum[i-1] * 2 + 1;
    }
    f(n, x);
    ll ans = f(n, x);
    cout << ans << endl;
}

Measured memory_bytes: 3624
w,h,n=map(int,input().split())
s=0
W=[i for i in range(1,w+1)]
H=[i for i in range(1,h+1)]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        W=[j for j in W if j>x]
    elif a==2:
        W = [j for j in W if j <= x]
    elif a==3:
        H=[j for j in H if j>y]
    elif a==4:
        H = [j for j in H if j <= y]
print(len(W)*len(H))


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

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD=1e9+7;
const ll LINF=1e18;
const int INF=0x3f3f3f3f;
const int MAXN=100050;

void solve(int T){
	ll s,x1,x2,y1,y2;
	scanf("%lld",&s);
	if(s<=1e9){
		printf("0 0 1 0 0 %lld\n",s);
		return;
	}
	if(s==1e18){
		printf("0 0 0 1000000000 1000000000 0\n");
		return;
	}
	x1=1000000000;
	y2=s/1000000000+1;
	ll sy=s-s/1000000000*1000000000;
	x2=1000000000-sy;
	y1=1;
	printf("0 0 %lld %lld %lld %lld\n",x1,y1,x2,y2);
}
signed main(){
	int t=1;
	//scanf("%d",&t); 
	for(int i=1;i<=t;i++){
		solve(i);
	}
}

Measured memory_bytes: 3760
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int q;cin>>q;
    set<int> st;
    rep(i,0,q){
        int a,b;cin>>a>>b;
        if(a==0){
            st.insert(b);
            cout<<st.size()<<endl;
        }else {
            cout<<((st.find(b)==st.end())?0:1)<<endl;
        }
    }
    
    
}



/*

*/



Measured memory_bytes: 12460
N=int(input())
x=input()


def popcount(X,ones,count): 
    #print(count,bin(X),X,ones)
    if ones==0:
        return count
    else:
      
        X=X%ones
        
        count+=1
 
        ones=str(bin(X)).count("1")
        
        return popcount(X,ones,count)
 

    
GroundOnes=x.count("1")
GroundX=int(x,2)

if GroundOnes>1:
    CaseOne= GroundX%(GroundOnes-1)
else:
    CaseOne=2

CaseZero= GroundX%(GroundOnes+1)

TwoPowerCaseOne=[]
TwoPowerCaseZero=[]

if GroundOnes>1:
    for j in range(N):
      TwoPowerCaseOne.append(pow(2,(N-j-1) , (GroundOnes-1)))
      TwoPowerCaseZero.append(pow(2,(N-j-1), (GroundOnes+1)))
else:
    for j in range(N):
      TwoPowerCaseZero.append(pow(2,(N-j-1), (GroundOnes+1)))
  
    
for i in range(N):
    
    #CaseOne
    if x[i]=="1":
        ones=GroundOnes-1
        if ones>0:
            X=CaseOne-pow(2,N-i-1,ones)
        else:
            X=0
    #CaseZero
    else:
        ones=GroundOnes+1
        X=CaseZero+pow(2,N-i-1,ones)
            
 
    # print("for loop",i)
    # print("ones",ones)
    # print("new2bit",new2bit)
    #print(" ------ return --- ",popcount(X,ones,0))
    print(popcount(X,ones,0))

Measured memory_bytes: 100148
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	long long w=0,cnt=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='W')
			w++;
		else if(s[i]=='B')
			cnt+=w;
	}
	cout<<cnt<<"\n";
	return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  if(s[k-1]=='A'){
    s[k-1]='a';
  }else if(s[k-1]=='B'){
    s[k-1]='b';
  }else{
    s[k-1]='c';
  }
  cout << s;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = scanner.nextInt();
        }

        int[] minA = new int[n];
        minA[0] = 0;
        minA[1] = Math.abs(arr[1] - arr[0]);
        for(int i = 2; i < n; i++){
            minA[i] = Math.min(Math.abs(arr[i] - arr[i - 1]) + minA[i - 1], Math.abs(arr[i] - arr[i - 2]) + minA[i - 2]);
        }

        System.out.println(minA[n - 1]);

    }
}


Measured memory_bytes: 52444
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var K = int.Parse(Console.ReadLine());
            var ans = 1;

            for (var i = 0; i < N; i++)
            {
                ans = Math.Min(ans * 2, ans + K);
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cmath>


using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

tuple<double, double, double, double> cross_point(double cx, double cy, double r, double lx1, double ly1, double lx2, double ly2) {
	double a = ly2 - ly1;
	double b = lx1 - lx2;
	double c = -(a * lx1 + b * ly1);
	double l = sqrt(pow(lx2 - lx1, 2.0) + pow(ly2 - ly1, 2.0));
	double ex = (lx2 - lx1) / l;
	double ey = (ly2 - ly1) / l;
	double vx = -ey;
	double vy = ex;
	double k = -(a * cx + b * cy + c) / (a * vx + b * vy);
	double xp = cx + k * vx;
	double yp = cy + k * vy;
	double s = sqrt(r * r - k * k);
	double x1  = xp - s * ex;
	double y1  = yp - s * ey;
	double x2  = xp + s * ex;
	double y2  = yp + s * ey;
	return make_tuple(x1, y1, x2, y2);
}

int main()
{
	double cx, cy, r;
	int q;
	double lx1, lx2, ly1, ly2;
	cin >> cx >> cy >> r >> q;
	rep (i, q) {
		cin >> lx1 >> ly1 >> lx2 >> ly2;
		if (lx1 > lx2 || (lx1 == lx2 && ly1 > ly2) ) {
			swap(lx1, lx2);
			swap(ly1, ly2);
		}
		auto ret = cross_point(cx, cy, r, lx1, ly1, lx2, ly2);
		double ans[4];
		ans[0] = get<0>(ret);
		ans[1] = get<1>(ret);
		ans[2] = get<2>(ret);
		ans[3] = get<3>(ret);
		string space = "";
		rep (i, 4) {
			cout << fixed << setprecision(8) << space << ans[i];
			space = " ";
		}
		cout << endl;
	}
}



Measured memory_bytes: 3272
#include<stdio.h>


int main(void)
{	int n,i,a,max=-1000000,min=1000000;
	double sum=0;
	scanf("%d\n",&n);
	for(i = 0;i < n;i++){
	scanf("%d",&a);
	if(min>a)min=a;
	if(max<a)max=a;
	sum = sum + a;
	}
	
	printf("%d %d %.f\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
const int N = 1e6;
const int inf = 0x3f3f3f3f;
vector<ll>v;
int main()
{
	ll a,b;
	cin>>a>>b;
	ll x,y;
	x=a%b;
	y=b-x;
	cout<<min(x,y);
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    vector<long long> cum_sum(N + 1);
    for (int i = 0; i < N; i++) {
        cum_sum[i + 1] = cum_sum[i] + A[i];
    }
    unordered_map<long long, long long> hash;
    for (long long n : cum_sum) hash[n]++;


    long long res = 0;
    for (pair<long long, long long> p : hash) {
        res += p.second * (p.second - 1LL) / 2LL;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 11592
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
dic = defaultdict(int)
for i in range(n):
    dic[i+1] = 0
for a in A:
    dic[a] += 1
for i in range(n):
    print(dic[i+1])


Measured memory_bytes: 41640
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;

int tot=0,h[100005];
int n,x,y,siz[100005],f[100005];
struct Edge{
	int x,next;
}e[200005];

inline void add_edge(int x,int y){
	e[++tot].x=y;
	e[tot].next=h[x],h[x]=tot;
}

bool dfs(int x,int fa){
	siz[x]=1;
	int cnt=0;
	for(int i=h[x];i;i=e[i].next){
		if(e[i].x==fa)continue;
		if(dfs(e[i].x,x))return true;
		if(siz[e[i].x]){
			cnt++,siz[x]=0;
			if(cnt==2)return true;
		}
	}
	return false;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add_edge(x,y);
		add_edge(y,x);
	}
	printf(dfs(1,0)||siz[1]?"First":"Second");
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>

using namespace std;

typedef long long int LL;
typedef long double LD;
typedef pair<int, int> PII;

int main(void){
  LL n, k;
  cin >> n >> k;

  LL max_times = ceil(log2(k));
  LL denom = n;
  LL num = 0;
  for (int i = 0; i < max_times; i++) {
    denom *= 2;
  }

  for (LL i = 1; i <= n; i++) {
    int val = 1;
    LL times = ceil(log2(k / (LD)i));
    LL diff;
    if (times <= 0) diff = max_times;
    else diff = max_times - times;

    for (int j = 0; j < diff; j++) {
      val *= 2;
    }
    num += val;
  }

  // cout << num << endl;
  // cout << denom << endl;
  LD result = (LD)num / (LD)denom;

  cout << setprecision(15) << result << endl;

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    int A[11];
    for(int i = 0;i < N;++i) cin >> A[i];
    sort(A ,A + N);
    reverse(A, A + N);
    int answer = A[0]/2;
    for(int i = 1;i < N;++i){
        answer += A[i];
    }
    cout << answer << endl;
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	if(n%1000==0) cout<<0<<endl;
	else cout<<1000-n%1000<<endl;
}

Measured memory_bytes: 3520
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll,ll,ll> tl3;
// https://atcoder.jp/contests/abc177/tasks/abc177_e
ll gcd(ll x, ll y){
    if(x < y) swap(x,y);
    if(y == 0) return x;
    else return gcd(y, x%y);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string ans[] ={"pairwise coprime","setwise coprime","not coprime"};
    ll n;
    cin >> n;
    vector<ll> v(1010101);
    vector<ll> num(1010101);
    ll g = 0;
    for(int i = 0;i<n;i++){
        cin >> v[i];
        g = gcd(g,v[i]);
        num[v[i]]++;
    }
    ll val = -1;
    int i;
    for(i = 2;i<=1000000;i++){
        ll x = 0;
        for(int j = i;j<=1000000;j+=i){
            x += num[j];
        }
        if(x >= 2)
            break;
    }
    if(i == 1000001) val = 0;
    else if(g == 1) val = 1;
    else val = 2;
    cout << ans[val];
    
    return 0;
}

Measured memory_bytes: 19028
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

class BIT {
private:
	int size;
	vector<int> bit;
	
public:
	BIT(int n = 0):size(n), bit(n + 1, 0) {}
	
	void add(int i, int x) {
		while(i <= size) {
			bit[i] += x;
			i += i & -i;
		}
	}

	int sum(int i) const {
		int s = 0;
		while(i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
};

void input(BIT& bit, int size) {
	for(int i = 1; i <= size; ++i) {
		int in;
		cin >> in;
		bit.add(i, in);
	}
}

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

	for(int n, m; cin >> n >> m, n;) {
		BIT ver(n), hor(m);
		input(ver, n);
		input(hor, m);

		map<int, int> cnt;
		for(int i = 0; i < n; ++i)
			for(int j = i + 1; j <= n; ++j)
				++cnt[ver.sum(j) - ver.sum(i)];

		int ans = 0;
		for(int i = 0; i < m; ++i)
			for(int j = i + 1; j <= m; ++j)
				ans += cnt[(hor.sum(j) - hor.sum(i))];

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 19052
#include <bits/stdc++.h>
#include<iostream>
#include <math.h>//pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm>//sort(a.begin(), a.end());reverse(a.begin(), a.end());
#define rep(init,i,n) for (int i=init; i <(n);i++)
#define ll long long
#define rev(s) reverse(s.begin(),s.end())
#define sor(v) sort(v.begin(),v.end())
#define PI 3.14159265358979323846264338327950L
//コード自動整形 Shift + Option + F @vscode
using namespace std;

ll facctorialMethod(ll k);//階乗を出力する
/////main/////
int main() {
ll N;
cin>>N;
vector<ll> D1(N),D2(N),jadge(N);
string output = "No";
rep(0,i,N){
    cin>>D1.at(i)>>D2.at(i);
    if(D1.at(i)==D2.at(i)){jadge.at(i)=1;}
    else{jadge.at(i)=0;}
}
rep(0,i,N-2){
    if(jadge.at(i)==1 && jadge.at(i+1)==1 && jadge.at(i+2)==1){output = "Yes";}
}
cout<<output<<endl;
}
/////main/////

/////function/////
ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

Measured memory_bytes: 3628
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Program
{
    public class ABC079D
    {
        static class Console_
        {
            private static Queue<string> param = new Queue<string>();
            public static int NextInt() => int.Parse(NextString());
            public static long NextLong() => long.Parse(NextString());
            public static string NextString()
            {
                if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item);
                return param.Dequeue();
            }
        }
        static public void Main(string[] args)
        {
            var H = Console_.NextInt();
            var W = Console_.NextInt();

            var costTable = new int[10][];
            for (int i = 0; i < 10; ++i)
            {
                costTable[i] = new int[10];
                for (int j = 0; j < 10; ++j)
                {
                    costTable[i][j] = Console_.NextInt();
                }
            }

            for (int k = 0; k < 10; ++k)
            {
                for (int i = 0; i < 10; ++i)
                {
                    for (int j = 0; j < 10; ++j)
                    {
                        costTable[i][j] = Math.Min(costTable[i][j], costTable[i][k] + costTable[k][j]);
                    }
                }
            }

            var ans = 0;
            for (int i = 0; i < H; ++i)
            {
                for (int j = 0; j < W; ++j)
                {
                    var val = Console_.NextInt();
                    if (val == -1) continue;
                    ans += costTable[val][1];
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}

int main()
{
     int N,W;
     cin>>N>>W;
     int w[N],val[N];
     for(int i=0;i<N;i++)
     {
          cin>>w[i]>>val[i];
     }
     ll dp[N][W+1];
     for(int i=0;i<N;i++)
     {
          for(int j=0;j<=W;j++)
               dp[i][j]=0;
     }
     for(int j=1;j<=W;j++)
     {
          if(j>=w[0])
          dp[0][j]=val[0];
     }
     for(int i=1;i<N;i++)
     {
          for(int j=1;j<=W;j++)
          {
               if(j>=w[i])
               dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+val[i]);
               else
               dp[i][j]=dp[i-1][j];
          }
     }
     cout<<dp[N-1][W];
}


Measured memory_bytes: 78336