akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )
#define space ' '
#define enter '\n'
#define RE cout << "Passing [" << __FUNCTION__ << "] on " << __LINE__ << enter
#define DEBUG(...) for( auto &i: __VA_ARGS__ ) cout << i << " "; cout << enter
using std::make_pair;

template < typename T >
inline T read( )
{
 T x = 0;
 char ch = gc( );
 bool f = 0;
 while( !std::isdigit( ch ) )
 {
  f = ( ch == '-' );
  ch = gc( );
 }
 while( std::isdigit( ch ) )
 {
  x = x * 10 + ( ch - '0' );
  ch = gc( );
 }
 return f ? -x : x;
}

template < typename T >
void print( T x )
{
 if( x < 0 )
 {
  x = -x;
  pc( '-' );
 }
 if( x < 10 )
 {
  pc( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 pc( x % 10 + 48 );
 return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( space )
#define ptl( i ) print < long long > ( i ), putchar( space )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
 using std::cin;
 using std::cout;
 using std::endl;
 using std::vector;
 using std::map;
 using std::queue;
 using std::deque;
 using std::set;
 using std::pair;
 const int N = 204001, mod = 1e9 + 7;
 int n;
 long long dp[ N ];
 void Fakemain( )
 {
  cin >> n;
  for( int i = 3; i <= n; ++i )
  {
   dp[ i ] = 1;
   for( int j = 3; j <= i - 3; ++j )
    dp[ i ] = ( dp[ i ] + dp[ i - j ] ) % mod;
  }
  cout << dp[ n ];
  return;
 }

} // namespace Solution

int main( int argc, char* argv[] )
{
 Solution::Fakemain( );
 return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  bool A = a == 5 || a == 7;
  bool B = b == 5 || b == 7;
  bool C = c == 5 || c == 7;
  if(A && B && C && a + b + c == 17) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

int main() {

	int N, M;

	cin >> N >> M;

	cout << (1900 * M + 100 * (N - M))*pow(2, M) << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
const ll oo = 1000000000000000000;
const ll mod = 1e9 + 7;
typedef pair <ll , ll> ii;
typedef vector<ii> vii;
typedef vector <ll> vi;
#define x first
#define y second

ll a , b , c;

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

//#ifndef ONLINE_JUDGE

    //freopen("c.inp"  , "r" , stdin);
    //freopen(".OUT" , "w" , stdout);

//#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> a >> b >> c;

    cout << c << " " << a << " " << b;


    return 0;
}






Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

ll gcd(ll aa, ll bb){
	return (bb > 0)? gcd( bb , aa%bb ) : aa ;
}

ll lcm(ll aa, ll bb){
	return aa / gcd(aa,bb) * bb;
}

int main() {
	 ll a, b, c, d, e, f;

	while (cin >> a >> b >> c >> d >> e >> f) {
		ll x = 1, y = 1, z = 1;
		ll xcnt = 0, ycnt = 0, zcnt = 0;
		if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)break;
		while (1) {
			x = (a * x) % b;
			xcnt++;
			if (x == 1)
				break;
		}
		while (1) {
			y = (c * y) % d;
			ycnt++;
			if (y == 1)
				break;
		}
		while (1) {
			z = (e * z) % f;
			zcnt++;
			if (z == 1)
				break;
		}
		ll ans = lcm( lcm(xcnt,ycnt) , zcnt);
				cout << ans << endl;

	}
}

Measured memory_bytes: 3064
package main

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

var dm map[int]map[int]int
var colors []int

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	dm = make(map[int]map[int]int, n)
	for i := 1; i <= n; i++ {
		dm[i] = make(map[int]int)
	}

	colors = make([]int, n)
	for i := 0; i < n-1; i++ {
		sc.Scan()
		v, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		w, _ := strconv.Atoi(sc.Text())
		dm[v][u] = w
		dm[u][v] = w
	}

	color(1, 0)

	for _, c := range colors {
		fmt.Println(c - 2)
	}
}

func color(v, d int) {
	if colors[v-1] > 0 {
		return
	}
	colors[v-1] = d + 2
	for u, w := range dm[v] {
		if w > 0 {
			color(u, (d+w)%2)
		}
	}
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

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

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

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

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

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

int main(){

    long long N;
    scanf("%lld",&N);

    ll sum = 0;

    for(ll i = 1; i <= N; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3764
#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;

int a[100];

int main(){
	int n,k,sum = 0;
	cin >> n >> k;
	for(int i = 1;i <= n;i++) cin >> a[i];
	sort(a + 1,a + 1 + n);
	for(int i = n;i >= n - k + 1;i--) sum += a[i];
	cout << sum;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
        	
const int ppr = 257;
const ll INF = 2e18;
const int inf = 998244353;
const int mod = 1e9 + 7;
const int N = 1e5 + 123;
const ld pi = 3.1741592653589793238462643;
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int n, a[N], dp[N];

main() {             	
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);

//	srand(time(NULL));

	scanf("%d", &n);

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

		if(i == 1) continue;

		dp[i] = inf;
		dp[i] = min(dp[i], dp[i - 1] + abs(a[i] - a[i - 1]));
		if(i > 2) dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2])); 
	}

	cout << dp[n];
             
    return 0;                                        
}

Measured memory_bytes: 1024
import math
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
v.reverse()
if a==n:
  print(sum(v)/n)
  print(1)
elif v[a-1]!=v[a]:
  print(sum(v[0:a])/a)
  print(1)
elif v[0]!=v[a-1]:
  print(sum(v[0:a])/a)
  ct1=0;ct2=0
  for i in range(n):
    if v[i]==v[a-1]:
      ct1+=1
      if i<a:
        ct2+=1
  print(math.factorial(ct1)//(math.factorial(ct1-ct2)*math.factorial(ct2)))
else:
  print(sum(v[0:a])/a)
  ct1=0;ans=0
  for i in range(n):
    if v[i]==v[a-1]:
      ct1+=1
  for i in range(a,min(ct1+1,b+1)):
    ans+=math.factorial(ct1)//(math.factorial(ct1-i)*math.factorial(i))
  print(ans)

Measured memory_bytes: 3064
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

import numpy as np

ans = np.sum(B)

D = np.zeros(N-1)

for i in range(N-1):
  D[i] = A[i+1] - A[i]
  
for i in range(N-1):
  if D[i] == 1:
    x = A[i] - 1
    ans += C[x]
    
print(ans)

Measured memory_bytes: 21404
//ALL GLORY TO JESUS CHRIST 
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n-1); i>=0; --i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

const int MOD = (int)1e9+7;

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD; 
}
//modular inverse
//inv(a,m) - inverse of a mod m
template <class T>
inline T inv(T a, T m){
 return 1<a ? m - inv(m%a, a)*m/a : 1;
}
//const int NAX = (int)3e5+5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int n; cin >> n;
    double res = n/2+n%2;
    res = res/n;
    cout << res << "\n";
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
N = int(input())
As = []
for i in range(N):
  A = int(input())
  A = A-1
  As.append(A)
r = 0
c = 0
M = [-1]*N
M[c] = 0
while True:
  n = As[c]
  if not(M[n] < 0):
    break
  r += 1
  M[n] = r
  c = n
#print(M)
if M[1] < 0:
  print(-1)
else:
  print(M[1])


Measured memory_bytes: 11052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> light(m);
  for(int i = 0;i < m;i++){
    int k = 0;
    cin >> k;
    for(int j = 0;j < k;j++){
      int num = 0;
      cin >> num;
      num--;
      light[i].push_back(num);
    }
  }
  vector<int> mod(m);
  for(int i = 0;i < m;i++)cin >> mod[i];
  int res = 0;
  for(int i = 0; i < (1<<n); i++){//2のa乗回繰り返す(0 ~ 2^a- 1)
    bool now = true;
    for(int j = 0;j < m;j++){
      int nowmod = 0;
      for(int k = 0;k < light[j].size();k++){
        if(i & (1<<light[j][k]))nowmod++;
      }
      if(nowmod % 2 != mod[j])now = false;
    }
    if(now)res++;
  }
  cout << res << endl;
}

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

int main(void)
{
  int n;
  cin>>n;
  int b=n/100;
  int c=b*100+b*10+b;
  int d=(b+1)*100+(b+1)*10+b+1;
  if(n>c)
    cout<<d<<endl;
  else if(n<d)
    cout<<c<<endl;
  else
    cout<<n<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k; cin >> n >> k;
  set<int> s;
  while (k--) {
    int d; cin >> d;
    while (d--) {
      int a; cin >> a;
      s.insert(a);
    }
  }
  cout << n-s.size();
  return 0;
}

Measured memory_bytes: 3568
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int deg[5];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  for (int rep = 1; rep < 4; ++rep) {
    int u, v;
    scanf("%d%d", &u, &v);
    ++deg[u];
    ++deg[v];
  }
  puts(count(deg + 1, deg + 5, 3) ? "NO" : "YES");

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = s; n > i; i++)
#define REP(i,n) rep(i,0,n)
#define MODU 33
#define Range(x,a,b) ((a) <= (x) && (x) <= (b))
#define POWT(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;

int main() {
	int h, w;
	scanf("%d %d", &h, &w);
	REP(i, h) {
		scanf("%*c");
		int las = -1;
		REP(j, w) {
			char state;
			scanf("%c", &state);
			if (state == 'c') {
				las = j;
			}
			printf("%d", las == -1 ? -1 : j-las);
			if (j != w - 1)
				printf(" ");
		}
		printf("\n");
	}
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	int n,t[10000];
	cin >> n;
	rep(i,0,n-1) cin >> t[i];

	static int dp[2][2][6000];
	fill_n((int*)dp,2*2*6000,INF);
	dp[0][0][1]=dp[0][1][0]=0;
	rep(i,0,n-1){
		rep(j,0,n/2+100){
			if(j-1>=0) dp[1][0][j]=min(dp[0][0][j-1],dp[0][1][j-1]+t[i]);
			dp[1][1][j]=min(dp[0][1][j],dp[0][0][j]+t[i]);
		}
		swap(dp[0],dp[1]);
	}

	cout << min(dp[0][0][n/2],dp[0][1][n/2]) << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 1324
import itertools

mod=10**9+7
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*(2**n) for _ in range(n+1)]
dp[0][0]=1
for i in range(n):
  for bit in range(2**n):
    if dp[i][bit]!=0:
      for j in range(n):
        if bit&(2**j)==0 and arr[i][j]==1:
          dp[i+1][bit^(2**j)]+=dp[i][bit]
          dp[i+1][bit^(2**j)]%=mod
print(dp[n][2**n-1])

Measured memory_bytes: 435256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;

long long MOD = 1e9 + 7;

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

    double n;
    cin >> n;

    int c = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % 2 == 1) {
            c++;
        }
    }
    cout << c / n << endl;
    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

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

  int n, m, c; cin >> n >> m >> c;
  vi b(m);
  for(int i=0;i<m;++i) {
    cin >> b[i];
  }
  int cnt = 0;
  for(int i=0;i<n;++i) {
    int su = c;
    for(int j=0;j<m;++j) {
      int a; cin >> a;
      su += a * b[j];
    }
    cnt += su > 0;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a <= c && c <= b || b <= c && c <= a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3680
n, x, y = map(int, input().split())

answer = [0 for _ in range(n-1)]
for i in range(1, n+1):
    for j in range(i+1, n+1):
        tmp = abs(i-x) + abs(j-y) + 1
        _id = min(j-i, tmp)
        answer[_id-1] += 1
for a in answer:
    print(a)

Measured memory_bytes: 3444
def do(level,x):
    if x<=0:
        return 0
    elif x>=j[level]:
        return k[level]
    res=0
    x-=1
    if x>=j[level-1]+1:
        x-=j[level-1]+1
        res+=k[level-1]+1
    return res+do(level-1,x)

n,x=map(int,input().split())
j=[1]+[0]*50
k=[1]+[0]*50
for i in range(1,n+1):
    j[i]=j[i-1]*2+3
    k[i]=k[i-1]*2+1
res=0
print(do(n,x))

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

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> l(N);
  for (int i = 0; i < N; i++){
    cin >> l.at(i);
  }
  sort(l.begin(), l.end(), greater<int>());
  
  int sum = 0;
  for (int i = 0; i < K; i++){
    sum += l.at(i);
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
string a;
bool q=true;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>a;
	for (int i=0;i<a.size();i++){
		if (i&1){
			if (a[i]=='R')
				q=false;
		}
		else {
			if (a[i]=='L')
				q=false;
		}
	}
	cout<<(q?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<(n);++i)
#define repeq(i,a,n) for(int i=a,i<=(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
/*
int main(){
    int n,q;
    cin >> n;
    vector<int> a(n);
    rep(i,0,n){
        cin >> a.at(i);
    }
    
    cin >> q;
    vector<int> b(q);
    vector<int> c(q);
    vector<ll> s(q);
    int ans=0;

    rep(i,0,q){
        cin >> b.at(i) >> c.at(i);
    }

    int count=0;
    rep(i,0,q){
        ans=0;
        count=0;
        rep(j,0,n){
            if(a.at(j)==b.at(i)){

                a.at(j)=c.at(i);
            }
            ans+=a.at(j);
        }
        cout << ans << endl;
    }
    return 0;
}
*/
const int MX =100005;

int main(){
    int n;
    //Nの読み込み
    cin >> n;
    //それぞれの値が何個ずつ入っているかの配列
    vector<ll> cnt(MX);
    //aの入力を受けたらaの個数を+1していく
    rep(i,0,n){
        int a;
        cin >> a;
        cnt[a]++;
    }

    ll total=0;
    rep(i,0,MX){
        total+=i*cnt[i];
    }

    int q;
    cin >> q;
    rep(i,0,q){
        int b,c;
        cin >> b >> c;
        total-=b*cnt[b];
        total-=c*cnt[c];
        cnt[c]+=cnt[b];
        cnt[b]=0;
        total+=b*cnt[b];
        total+=c*cnt[c];
        cout << total << endl;
    }

    return 0;
}


Measured memory_bytes: 4036
#include <stdio.h>
static double q, h, s, d, n;
double f(double cost, double size) {
    return cost / size;
}
int main(void) {
    long sum = 0;
    scanf("%lf%lf%lf%lf%lf", &q, &h, &s, &d, &n);
    if (f(s, 1) <= f(d, 2))
        d = 2 * s;
    if (f(h, 0.5) <= f(s, 1))
        s = 2 * h;
    if (f(h, 0.5) <= f(d, 2))
        d = 4 * h;
    if (f(q, 0.25) <= f(h, 0.5))
        h = 2 * q;
    if (f(q, 0.25) <= f(s, 1))
        s = 4 * q;
    if (f(q, 0.25) <= f(d, 2))
        d = 8 * q;
    while (n >= 2) {
        sum += (long)d;
        n -= 2;
    }
    while (n >= 1) {
        sum += (long)s;
        n -= 1;
    }
    while (n >= 0.5) {
        sum += (long)h;
        n -= 0.5;
    }
    while (n >= 0.25) {
        sum += (long)q;
        n -= 0.25;
    }
    printf("%ld\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//#define float double
int main(){
	int n;
	cin>>n;
	cout<<fixed<<setprecision(10);
	double p[n];
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	vector<vector<double>> dp(n+1 ,vector<double>(n+1,0.0));//dp[i][j] = probabilty of getting j heads with i coins
	for(int i=0;i<=n;i++){
		for(int j=0;j<=i;j++){
			if(i==0 && j==0)
				dp[i][j]=1;
			else if(j==0)
				dp[i][j]=dp[i-1][j]*(1-p[i-1]);
			else
			//probabilty of getting j heads 
			// if there are already j heads, toss tail
			// else if j-1 heads, heads
				dp[i][j]=p[i-1]*dp[i-1][j-1] + (1-p[i-1])*dp[i-1][j];	
		}
	}
	double ans=0.0;
	/*for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++)
		cout<<dp[i][j]<<" ";
		cout<<"\n";
	}*/
	for(int i=0;i<=n;i++){
		if(i>n/2)
		ans+=dp[n][i];
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 73784
#include <iostream>
using namespace std;
int main(){
	double W;
	while(cin >> W){
		if(W>91.00) cout << "heavy\n" ;
		else if(W>81.00) cout << "light heavy\n" ;
		else if(W>75.00) cout << "middle\n" ;
		else if(W>69.00) cout << "light middle\n" ;
		else if(W>64.00) cout << "welter\n" ;
		else if(W>60.00) cout << "light welter\n" ;
		else if(W>57.00) cout << "light\n" ;
		else if(W>54.00) cout << "feather\n" ;
		else if(W>51.00) cout << "bantam\n" ;
		else if(W>48.00) cout << "fly\n" ;
		else cout << "light fly\n" ;
	};
}

Measured memory_bytes: 1192
#include<stdio.h>

int main(){
	int n,a,b,c,i;
	while(scanf("%d",&n)!=EOF){
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d%d%d",&a,&b,&c);
			if(a==100 || b==100 || c==100)printf("A\n");
			else if((a+b)/2>=90)printf("A\n");
			else if((a+b+c)/3>=80)printf("A\n");
			else if((a+b+c)/3>=70)printf("B\n");
			else if((a+b+c)/3>=50 && (a>=80 || b>=80))printf("B\n");
			else printf("C\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define gc getchar()
#define ll long long
#define int long long
#define ri register int
#define rc register char
#define rb register bool
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
using namespace std;
    
il int read()
{
    rc ch=gc;ri x=0;rb y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
ll min1[1000001], min2[1000001], adds[1000001];
inline void down(int tree) 
{
    if (!adds[tree])return;
    ll c = adds[tree];
    adds[tree] = 0;
    adds[ls(tree)] += c;
    adds[rs(tree)] += c;
    min1[ls(tree)] += c;
    min2[ls(tree)] += c;
    min1[rs(tree)] += c;
    min2[rs(tree)] += c;
}
inline void up(int tree) 
{
    min1[tree] = min(min1[ls(tree)], min1[rs(tree)]);
    min2[tree] = min(min2[ls(tree)], min2[rs(tree)]);
}
void setpt(int l, int r, int tree, int pt, ll num) 
{
    if (l == r) 
	{
        min1[tree] = min(min1[tree], num - l);
        min2[tree] = min(min2[tree], num + l);
        return;
    }
    int mid = (l + r) >> 1;down(tree);
    if (pt <= mid)setpt(l, mid, ls(tree), pt, num);
    else setpt(mid + 1, r, rs(tree), pt, num);
    up(tree);
}
ll query1(int rl, int rr, int l, int r, int tree) 
{
    if (rl == l && rr == r)return (min1[tree]);
    int mid = (l + r) >> 1;down(tree);
    if (rl > mid)return (query1(rl, rr, mid + 1, r, rs(tree)));
    if (rr <= mid)return (query1(rl, rr, l, mid, ls(tree)));
    return (min(query1(rl, mid, l, mid, ls(tree)), query1(mid + 1, rr, mid + 1, r, rs(tree))));
}
ll query2(int rl, int rr, int l, int r, int tree) 
{
    if (rl == l && rr == r)return (min2[tree]);
    int mid = (l + r) >> 1;down(tree);
    if (rl > mid)return (query2(rl, rr, mid + 1, r, rs(tree)));
    if (rr <= mid)return (query2(rl, rr, l, mid, ls(tree)));
    return (min(query2(rl, mid, l, mid, ls(tree)), query2(mid + 1, rr, mid + 1, r, rs(tree))));
}
ll query(int l, int r, int tree) 
{
    if (l == r)return (min1[tree] + l);
    int mid = (l + r) >> 1;down(tree);return (min(query(l, mid, ls(tree)), query(mid + 1, r, rs(tree))));
}
signed main() 
{
//	freopen("2558.in","r",stdin);
    int n = read(), q = read(), pre = read();
    memset(min1, 0x3f, sizeof(min1));memset(min2, 0x3f, sizeof(min2));setpt(1, n, 1, read(), 0);
    for (register int i = 1; i <= q; i++) 
	{
        int nw = read();
        ll cjr = min(query1(1, nw, 1, n, 1) + nw, query2(nw, n, 1, n, 1) - nw);
        adds[1] += abs(nw - pre);
        min1[1] += abs(nw - pre);
        min2[1] += abs(nw - pre);
        setpt(1, n, 1, pre, cjr);
        pre=nw;
    }
    printf("%lld\n",query(1,n,1));
    return (0);
}

Measured memory_bytes: 23680
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;

int main(void) {
	map<string, vector<int> > dic;
	string str;
	int page;
	int i;

	while(!cin.eof()) {
		cin >> str >> page;
		if(!cin.eof()) { dic[str].push_back( page ); }
	}

	map<string, vector<int> >::iterator it = dic.begin();
	while(it != dic.end() ) {
		cout << (*it).first << endl;
		sort((*it).second.begin(), (*it).second.end());
		for(i = 0; i < (int)(*it).second.size(); i++) {
			cout << (*it).second[i];
			if(i < (int)(*it).second.size()-1) { cout << " "; }
		}
		cout << endl;
		++it;
	}

	return 0;
}

Measured memory_bytes: 0
import itertools
n, m, q = map(int, input().split())
abcds = [list(map(int, input().split())) for _ in range(q)]
aaa = range(1, m + 1)
ans = 0
for a in itertools.combinations_with_replacement(aaa, n):
    list(a).sort()
    tmp = 0
    for abcd in abcds:
        if a[abcd[1] - 1] - a[abcd[0] - 1] == abcd[2]:
            tmp += abcd[3]
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 9204
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <typename T> vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template <typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

struct Mod {
    static ll BASE;
    ll value = 0;
    static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
    Mod(ll value) : value(residue(value)) {}
    Mod operator+(const Mod &rhs) const { return Mod(value + rhs.value); }
    void operator+=(const Mod &rhs) { *this = *this + rhs; }
    Mod operator-(const Mod &rhs) const { return Mod(value - rhs.value); }
    void operator-=(const Mod &rhs) { *this = *this - rhs; }
    Mod operator*(const Mod &rhs) const { return Mod(value * rhs.value); }
    void operator*=(const Mod &rhs) { *this = *this * rhs; }
};
ll Mod::BASE = 1000000007;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> ais;
    for (ll i = 0; i < N; i++) {
        ll ai;
        cin >> ai;
        ais.push_back(ai);
    }
    auto dp = make_vec_nd((Mod)0, N, K + 1);
    auto dp_sum = make_vec_nd((Mod)0, N, K + 1);
    for (ll i = 0; i < N; i++) {
        for (ll k = 0; k <= K; k++) {
            if (i == 0) {
                if (k <= ais[0]) {
                    dp[i][k] = 1;
                } else {
                    dp[i][k] = 0;
                }
            } else {
                ll l = min(ais[i], k);
                if (k - l >= 1) {
                    dp[i][k] = dp_sum[i - 1][k] - dp_sum[i - 1][k - l - 1];
                } else {
                    dp[i][k] = dp_sum[i - 1][k];
                }
            }
            if (k >= 1) {
                dp_sum[i][k] += dp_sum[i][k-1] + dp[i][k];
            } else {
                dp_sum[i][k] = dp[i][k];
            }
        }
    }
    cout << dp[N-1][K].value << endl;
}


Measured memory_bytes: 157680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean bl = true;
		char s[] = sc.next().toCharArray();
		char t[] = sc.next().toCharArray();
		for(int i = 0; i < s.length; i++) {
			if(s[i] != t[i])
				bl = false;
		}
		if(bl && s.length < t.length)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}


Measured memory_bytes: 35496
#include <cstdio>
#include <algorithm>
using namespace std;
int N,T,S;
int A[3010],B[3010];
int dp[3010][3010];
int main()
{
	scanf("%d %d %d",&N,&T,&S);
	for(int i=0;i<N;i++)scanf("%d %d",&A[i],&B[i]);
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<=T;j++)
		{
			if(j>0)dp[i+1][j]=dp[i+1][j-1];
			if(j-B[i]<S&&S<j)dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			else if(j-B[i]<0)dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			else dp[i+1][j]=max(dp[i+1][j],max(dp[i][j],dp[i][j-B[i]]+A[i]));
			//printf("%d ",dp[i+1][j]);
		}
		//puts("");
	}
	printf("%d\n",dp[N][T]);
	return 0;
}

Measured memory_bytes: 36332
H,W = map(int,input().split())
a = [list(input()) for _ in range(H)]

tate,yoko = set(),set()
for i in range(H):
    t = True
    for j in range(W):
        if a[i][j] == "#":
            t = False
            break
    if t:
        tate.add(i)
for j in range(W):
    y = True
    for i in range(H):
        if a[i][j] == "#":
            y = False
            break
    if y:
        yoko.add(j)

ct = 0
for t in tate:
    a = a[:t-ct] + a[t+1-ct:]
    ct += 1

cy = 0
for y in yoko:
    for i in range(H-len(tate)):
        a[i] = a[i][:y-cy] + a[i][y+1-cy:]
    cy += 1

for i in range(H-len(tate)):
    print("".join(a[i]))


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<end
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll N,K;
  cin>>N>>K;

  ll x=N/K;

  if(K%2==0){
    cout<<x*x*x+(N/(K/2)-x)*(N/(K/2)-x)*(N/(K/2)-x)<<endl;
  }
  else cout<<x*x*x<<endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

// utils
func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func abs(a, b int) int {
	return int(math.Abs(float64(a) - float64(b)))
}

//data types

type set map[int]struct{}

type pair struct {
	first  int
	second int
}

func main() {
	sc.Split(bufio.ScanWords)
	h := nextInt()
	m := make(map[int]int)
	fmt.Print(f(h, m))
}

func f(h int, m map[int]int) int {
	if h == 1 {
		return 1
	}
	if _, ok := m[h/2]; !ok {
		m[h/2] = 1 + f(h/2, m)*2
	}
	return m[h/2]
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) {
    cin >> a[i];
    if(n%2==a[i]%2 || a[i]>=n) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(ALL(a));
  if(a[0]!=0 && n%2==1){
    cout << 0 << endl;
    return 0;
  }
  rep(i,n-2){
    if(i==0 && n%2==1){
      if(a[i]==a[i+1]){
        cout << 0 << endl;
        return 0;
      }
    }
    if(a[i]==a[i+2]){
      cout << 0 << endl;
      return 0;
    }
  }
  
  ll ans = 1;
  rep(i,n/2){
    ans*=2;
    ans%=mod;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  while(cin >> n >> m && n) {
    int x;
    map<int,int> m1,m2;
    m1.clear();m2.clear();
    for(int i=0; i<n; i++) {
      cin >> x;
      m1[x]++;
    }
    for(int i=0; i<m; i++) {
      cin >> x;
      m2[x]++;
    }
    int ans=0;
    for(int i=1; i<=20; i++) ans+=i*max(m1[i],m2[i]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1196
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	ll n, m;
	cin >> n >> m;
	pll p[N];
	rep(i, n) cin >> p[i].first >> p[i].second;
	sort(p, p + n);
	ll ans = 0;
	rep(i, n) {
		if (m >= p[i].second) {
			ans += p[i].first * p[i].second;
			m -= p[i].second;
		}
		else {
			ans += p[i].first * m;
			break;
		}
	}
	cout << ans << endl;
}


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

int main() {
  char c;
  char aiueo[] = {'a', 'i', 'u', 'e', 'o'};
  bool flag = false;

  cin >> c;

  for (int i = 0; i < 5 ; i++) {
    if (aiueo[i] == c) {
      flag = true;
    }
  }

  if (flag) {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
vector<ll>bit(1000010);
ll n;
ll sum(ll i){
    ll s=0;
    while(i>0){
        s+=bit[i];
        i-=(i&(-i));
    }
    return s;
}
void add(ll i,ll a){
    while(i<=n){
        bit[i]+=a;
        i+=(i&(-i));
    }
}
int main(){
    cin>>n;
    vector<ll>a(n),b(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll ans=inf;
    bool f=1;
    rep(i,(1<<n)){
        priority_queue<pll,vector<pll>,greater<pll> >c,d;
        rep(j,n){
            if(i&(1<<j)){
                if(j%2)c.push(mp(b[j],j));
                else d.push(mp(b[j],j));
            }else{
                if(j%2)d.push(mp(a[j],j));
                else c.push(mp(a[j],j));
            }
        }
        ll ma=0;
        vector<ll>e(0);
        bool f=1;
        rep(j,n){
            if(j%2){
                if(d.empty()){
                    f=0;
                    break;
                }else{
                    pll k=d.top();
                    if(k.first<ma){
                        f=0;
                        break;
                    }
                    ma=k.first;
                    e.pb(k.second+1);
                    d.pop();
                }
            }else{
                if(c.empty()){
                    f=0;
                    break;
                }else{
                    pll k=c.top();
                    if(k.first<ma){
                        f=0;
                        break;
                    }
                    ma=k.first;
                    e.pb(k.second+1);
                    c.pop();
                }
            }
        }
        if(!f)continue;
        rep(j,n+1)bit[j]=0;
        ll cnt=0;
        //cout<<i<<endl;
        rep(j,n){
            ll k=e[j];
            cnt+=j-sum(k);
            add(k,1);
            //cout<<j<<' '<<e[j]<<' '<<cnt<<endl;
        }
        ans=min(ans,cnt);
    }
    if(ans==inf)ans=-1;
    cout<<ans<<endl;
}

Measured memory_bytes: 8064
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = a * b;
    if(c % 2 == 0){
      System.out.println("Even");
    }else{
      System.out.println("Odd");
    }
  sc.close();
  }
}


Measured memory_bytes: 35580
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double old;

const int N = 200;

int a[N][N];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            string s(n, '0');
            s[i] = s[j] = '1';
            cout << "? " << s << endl;
            int x;
            cin >> x;
            if (x) {
                a[i][j] = 1;
            }
        }
    }
    cout << '!';
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (a[i][j]) {
                cout << " (" << i << ',' << j << ')';
            }
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 980
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    ll n, a[100009], sum = 0;
    cin >> n;
    rep(i, n) cin >> a[i], sum += a[i];
    ll ans[100009] = {};
    rep(i, n) {
        int j = (i * 2) % n;
        ans[(j + 2) % n] = ans[j] + (a[(j + 1) % n] - a[j]) * 2;
        sum -= ans[j];
    }
    rep(i, n) cout << ans[i] + sum / n << " ";
}

Measured memory_bytes: 2944
#include<iostream>

using namespace std;

int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	if (x + r > W || x - r < 0 || y + r > H || y - r < 0)
		cout << "No\n";
	else
		cout << "Yes\n";
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 10000000000;
const ll MOD = 1000000007;

using namespace std;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	long long g = gcd(a, b);
	return a / g * b;
}

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

	int now = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I')now++;
		if (s[i] == 'D')now--;
		ans = max(ans, now);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(){
  int M[N][N];
  int n,v,u,k;
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j>0) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2108
s = input()
k = int(input()) - 1
 
cnt1 = 0
for i in range(len(s)):
  if s[i] == '1':
    cnt1 += 1
  else:
    break
 
#print(cnt1, k)
if cnt1 > k:
  print(1)
else:
  print(s[cnt1])

Measured memory_bytes: 2940
my $N = <>;
my ($h, $n, $k, $l);
LOOP: for my $_h (1..3500) {
    my $a = 4*$_h-$N;
    next if ($a <= 0);
    for my $_n (($N*$h/$a)..3500) {
        ($h, $n) = ($_h, $_n);
        $k = $N*$h*$n;
        $l = 4*$h*$n-$N*($h+$n);
        last LOOP if ($l > 0 && $k % $l == 0);
    }
}
my $w = $k / $l;
print "$h $n $w";

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> x(n + 2);
  x.at(0) = x.at(n + 1) = 0;
  for(int i = 1; i <= n; i++) cin >> x.at(i);
  
  int sum = 0;
  for(int i = 1; i < n + 2; i++) sum += abs(x.at(i - 1) - x.at(i));
  
  int ans;
  for(int i = 1; i <= n; i++){
    ans = sum - abs(x.at(i - 1) - x.at(i)) - abs(x.at(i) - x.at(i + 1)) + abs(x.at(i - 1) - x.at(i + 1));
    cout << ans << "\n";
  }
}

Measured memory_bytes: 1664
#include <iostream>
#include <stack>
#include <algorithm>

using namespace std;

struct data
{
    long long cnt;
    long long num;
};

int main()
{
    stack<data> st;
    long long N, K, ans = 1 << 29;
    cin >> N >> K;

    data d;
    d.cnt = 0;
    d.num = 1;
    st.push(d);

    while (!st.empty())
    {
        data d = st.top();
        st.pop();

        if (d.cnt == N)
        {
            ans = min(d.num, ans);
            continue;
        }

        data new_d;
        new_d.cnt = d.cnt + 1;
        new_d.num = d.num * 2;
        st.push(new_d);

        data new_d2;
        new_d2.cnt = d.cnt + 1;
        new_d2.num = d.num + K;
        st.push(new_d2);
    }

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

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

struct Edge
{
	int src, dst;
	double weight;
	Edge(int src, int dst, double weight) : src(src), dst(dst), weight(weight) {}

	bool operator< (const Edge& e)const
	{
		return weight != e.weight ? weight > e.weight :
			src != e.src ? src < e.src : dst < e.dst;
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		map<int, int> id;
		vector<pii> pts(n);
		vi preid(n);
		rep(i, n){
			int b, x, y;
			scanf("%d%d%d", &b, &x, &y);
			pts[i] = pii(x, y);
			preid[i] = b;
			id[b] = i;
		}
		
		Graph G(n);
		rep(i, n) rep(j, i){
			pii diff(pts[i].first - pts[j].first, pts[i].second - pts[j].second);
			int dist = diff.first*diff.first + diff.second*diff.second;
			if(dist <= 2500){
				double w = sqrt(dist);
				G[i].push_back(Edge(i, j, w));
				G[j].push_back(Edge(j, i, w));
			}
		}
		
		int m;
		scanf("%d", &m);
		rep(i, m){
			int s, g;
			scanf("%d%d", &s, &g);
			s = id[s];
			g = id[g];
			
			vi pre(n, -1);
			priority_queue<Edge> Q;
			Q.push(Edge(-2, s, 0.0));
			while(!Q.empty()){
				Edge e = Q.top();
				Q.pop();
				if(pre[e.dst] != -1)
					continue;
				pre[e.dst] = e.src;
				if(e.dst == g)
					break;
				
				rep(j, G[e.dst].size()){
					Q.push(Edge(e.dst, G[e.dst][j].dst, e.weight + G[e.dst][j].weight));
				}
			}
			
			if(pre[g] == -1)
				puts("NA");
			else{
				vi path;
				int now = g;
				while(now != s){
					now = pre[now];
					path.push_back(now);
				}
				
				for(int j=path.size()-1; j>=0; --j)
					printf("%d ", preid[path[j]]);
				printf("%d\n", preid[g]);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char s[10000010];
int n;
int main()
{
    scanf("%s",s+1);
    int w;
    cin>>w;
    n=strlen(s+1);
    int pos=1;
    while(pos<=n)
    {
        printf("%c",s[pos]);
        pos+=w;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct mint {
    constexpr static int mod = 1000000007;
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    string s;
    cin >> n >> s;
    ll bc = 0, wc = 0;
    rep(i, 2 * n) {
        if (i % 2 == 0) {
            s[i] = (s[i] == 'B') ? 'W' : 'B';
        }
        if (s[i] == 'B') {
            bc++;
        }
        else {
            wc++;
        }
    }
    if (bc != wc) {
        cout << 0 << endl;
        return 0;
    }
    ll cnt = 0;
    mint ans = 1;
    rep(i, 2 * n) {
        if (s[i] == 'W') {
            cnt++;
        }
        else {
            ans *= cnt;
            cnt--;
        }
    }
    rep(i, n) ans *= (i + 1);
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 3784