akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lint;

int N,M;
const int MAX_N = 1010;
const int MAX_M = 2010;
const lint INF = 1e18;

struct edge{int v,u,c;}s[MAX_M];
vector<vector<int>> path;

lint dist[MAX_N];
bool chk[MAX_N],vsi[MAX_N];

bool dfs(int u){
	vsi[u] = 1;
	if(chk[u])return 1;
	for(int v:path[u]){
		if(!vsi[v] && dfs(v))return 1;
	}
	return 0;
}

void solve(){
	for(int i=1;i<=N;i++){
		dist[i] = INF;
	}
	dist[1] = 0;
	for(int i=1;i<=N;i++){
		for(int j=0;j<M;j++){
			int v = s[j].v;
			int u = s[j].u;
			int c = s[j].c;
			if(dist[u] > dist[v]+c){
				dist[u] = dist[v]+c;
				if(i==N)chk[u] = 1;
			}
		}
	}
	
	if(dfs(N)){
		puts("inf");
		return;
	}
	printf("%lld\n",-dist[N]);
}

int main(){
	scanf("%d%d",&N,&M);
	path.assign(N+1,vector<int>());

	for(int i=0,x,y,z;i<M;i++){
		scanf("%d%d%d",&x,&y,&z);
		path[y].push_back(x);
		s[i] = {x,y,-z};
	}

	solve();

	return 0;
}

Measured memory_bytes: 384
n = int(input())
#x, a, b = map(int, input().split())
#l = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
al = []
for i in range(n):
    a = int(input())
    al.append(a)

al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)


Measured memory_bytes: 12984
#include <bits/stdc++.h>
using namespace std;
using ll=long long; 
int main(){
  ll m;
  cin>>m;
  ll N;
  cin>>N;
  ll A;
  cin>>A;
  ll b=m/N;
  if(m%N!=0){
    b+=1;
  }
  
  
  cout<<b*A<<endl;
  
    
  
}

Measured memory_bytes: 3588
while True:
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for _ in range(n)]
    for i in range(0, 60, 10):
        print(len(list(filter(lambda x: i <= x < i+10, a))))
    print(len(list(filter(lambda x: 60 <= x <=120, a))))

Measured memory_bytes: 19532
//b+k  の要素を b+((k+(e−m))mod(e−b))
//rotate(b,m,e)
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	int A[n];
	for(int i=0; i<n; i++)
		cin>>A[i];
	int q;
	cin>>q;
	while(q--){
		int b,m,e;
		cin>>b>>m>>e;
		rotate(A+b,A+m,A+e);
	}
	cout<<A[0];
	for(int i=1; i<n; i++)
		cout<<" "<<A[i];
	cout<<endl;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
const int N=3005,mo=998244353;
int f[N][N][2],A,B,C,D,i,j;
int main(){
	scanf("%d%d%d%d",&A,&B,&C,&D);
	f[A][B][0]=1;
	for(i=A;i<=C;++i)for(j=B;j<=D;++j){
		f[i+1][j][0]=(f[i+1][j][0]+1ll*f[i][j][0]*j)%mo;
		f[i][j+1][1]=(f[i][j+1][1]+1ll*f[i][j][0]*i)%mo;
		f[i+1][j][0]=(f[i+1][j][0]+f[i][j][1])%mo;
		f[i][j+1][1]=(f[i][j+1][1]+1ll*f[i][j][1]*i)%mo;
	}
	printf("%d\n",(f[C][D][0]+f[C][D][1])%mo);
}

Measured memory_bytes: 74180
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
   return ( *(long long*)a - *(long long*)b );
}



int main(void){
   
long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,b[100000]={0},count1=0,k,a2[100000]={0},b2;
char a[100000];
scanf("%lld",&n);
printf("%lld",(n-2)*180);
return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
main()
{

  int j;
  int length;
  int temp;
  int *buf;
  int sum = 0;
  int flag;

  scanf("%d",&length);

  buf = (int *)malloc(sizeof(int)*length);

  for(j = 0;j < length;j++)
    {
      scanf("%d",&buf[j]);
    }

  while(1)
    {
      flag = 0;
      for(j = length - 1;j > 0;j--)
	{
	  if(buf[j] < buf[j - 1])
	    {
	      temp = buf[j - 1];
	      buf[j - 1] = buf[j];
	      buf[j] = temp;
	      sum++;
	      flag = 1;
	    }
	}
      if(flag == 0) break;
    }

  for(j = 0;j < length;j++)
    {
      printf("%d",buf[j]);
      if(j != length - 1)
	{
	  printf(" ");
	}
    }
  printf("\n");
  printf("%d\n",sum);
return 0;
}

Measured memory_bytes: 604
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std ;

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N, K;
	
	cin >> N >> K;

	cout << int(K * pow(K-1,N-1)) << endl;

	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MOD = 1000000007;

int main(){
	vector<long long> inv(100001);
	vector<long long> fact(100001);
	vector<long long> factInv(100001);
	for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
	for(int i=2;i<inv.size();i++){
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		fact[i] = fact[i-1] * i % MOD;
		factInv[i] = factInv[i-1] * inv[i] % MOD;
	}
	auto comb = [&](int n, int r){
		if(n < r || r < 0) return 0LL;
		return fact[n] * factInv[n-r] % MOD * factInv[r] % MOD;
	};
    int N, K;
    while(cin >> N >> K){
        vector<long long> A(N);
        for(auto& t : A) cin >> t;
        sort(A.begin(), A.end());
        auto whole = comb(N, K);
        long long res = 0;
        for(int i=0;i+1<N;i++){
            int n1 = i+1;
            int n2 = N-n1;
            auto c = whole+2*MOD-comb(n1, K)-comb(n2, K);
            res += c * (A[i+1] - A[i]);
            res %= MOD;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 3328
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int e, f, g, h;
		e=a/3600;
		f=a%3600;
		g=f/60;
		h=f%60;
		
		System.out.println(""+e+":"+g+":"+h+"");
		sc.close();

	}

}

Measured memory_bytes: 26356
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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 (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int a, b; cin >> a >> b;
    int c = min(a, b), d = max(a, b);
    rep(i,d) {
        cout << c;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
      
ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47364
#include <stdio.h>

int main() {
	int i, score, avg = 0;
	for( i = 0; i < 5; i++) {
		scanf("%d", &score);
		if( score < 40 ) score = 40;
		avg += score;
	}
	avg /= 5;
	printf("%d\n", avg);
	return 0;
}

Measured memory_bytes: 600
// This code wrote by chtholly_micromaker(MicroMaker)
#pragma GCC optimize("Ofast,O3,inline")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
#define reg register
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define mem(x,y) memset(x,y,sizeof x)
#define sz(x) (int)(x).size()
#define ln puts("")
#define lsp putchar(32)
#define pb push_back
#define MP make_pair
#define dbg(x) cerr<<">"<<__func__<<"\tLine: "<<__LINE__<<' '<<#x<<": "<<x<<endl
using namespace std;
const int p=1e9+7;
const int MaxN=1000050;
template <class t> inline void read(t &s){s=0;
reg int f=1;reg char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();s*=f;return;}
template<class t,class ...A> inline void read(t &x,A &...a){read(x);read(a...);}
template <class t> inline void write(t x){if(x<0)putchar('-'),x=-x;
int buf[21],top=0;while(x)buf[++top]=x%10,x/=10;if(!top)buf[++top]=0;
while(top)putchar(buf[top--]^'0');return;}
inline void setIn(string s){freopen(s.c_str(),"r",stdin);return;}
inline void setOut(string s){freopen(s.c_str(),"w",stdout);return;}
inline void setIO(string s=""){setIn(s+".in");setOut(s+".out");return;}
template <class t>inline bool checkmin(t&x,t y){if(x>y){x=y;return 1;}return 0;}
template <class t>inline bool checkmax(t&x,t y){if(x<y){x=y;return 1;}return 0;}
inline int lowbit(int x){return x&(-x);}
inline int fpow(int a,int b)
{
	reg int res=1;
	for(;b;b>>=1,a=a*a%p)
		if(b&1)
			res=res*a%p;
	return res;
}
int f[MaxN],g[MaxN];
signed main(void)
{
	int n,H,D;read(n,H,D);
	reg int w=1,t=1;
	for(int i=2;i<=n;++i)
		(t*=i)%=p,(w+=t)%=p;
	f[0]=g[0]=1;
	for(int i=1;i<=H;++i)
		f[i]=(g[i-1]-(i>D?g[i-D-1]:0)+p)%p*w%p,g[i]=(g[i-1]+f[i])%p;
	write(f[H]*t%p*fpow(w,p-2)%p),ln;
	return 0;
}

/*
 * Check List:
 * 1. Input / Output File (USACO and OI and UVa)
 * 2. long long 
 * 3. Special Test such as n=1
 * 4. Array Size
 * 5. Memory Limit (OI) int is 4 and longlong is 8
 * 6. Mod (a*b%p*c%p not a*b*c%p  ,  (a-b+p)%p not a-b )
 * 7. Name ( int k; for(int k...))
 * 8. more tests , (T=2 .. more)
 * 9. blank \n after a case
*/






Measured memory_bytes: 19260
#include <algorithm>
#include <iostream>

using namespace std;

const int Size = 100000;

int main(int argc, char* argv[])
{
	int N;
	int M;
	cin >> N;
	cin >> M;
	int minID = 0;
	int maxID = Size+1;
	for (int i = 0; i < M; ++i)
	{
		int Li, Ri;
		cin >> Li;
		cin >> Ri;
		minID = std::max(minID, Li);
		maxID = std::min(maxID, Ri);
	}
	const int diffIDRange = maxID - minID;
	std::cout << ((diffIDRange < 0) ? 0 : diffIDRange + 1) << std::endl;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
	int N;
	cin >> N;
	cout << 180*(N-2) << endl;
}


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

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll x,y,z,a=0,b=0,c=0,d=0,sum,ans,total,cnt,n,m,k,p,kase,i;
string s1,s2;
#define N 100001
#define MX 1000000001
vector <ll> v;
map<ll,ll> mp;
set<ll> s;
map<ll,ll> :: iterator itr1, ptr1;
set<ll> :: iterator itr, ptr;


int main()
{

  cin>>n;

  if(n>=30)cout<<"Yes";
  else cout<<"No"<<endl;

    return 0;
}
// Happy Coding  (:


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vi x(N), y(M);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> y[i];
    }

    int z=y[0];
    for (int i = 0; i < M; i++) {
        z = min(z, y[i]);
    }

    for (int i = 0; i < N; i++) {
        if (z <= x[i]) {
            cout << "War" << endl;
            return;
        }
    }

    if (X < z && z <= Y) {
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

using namespace std;

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

	int day_no = (n - 4 + 7) % 7;

	string day;
	if (day_no == 0) day = "mon";
	if (day_no == 1) day = "tue";
	if (day_no == 2) day = "wed";
	if (day_no == 3) day = "thu";
	if (day_no == 4) day = "fri";
	if (day_no == 5) day = "sat";
	if (day_no == 6) day = "sun";
	cout << day << endl;
}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int s,w;
    cin>>s>>w;
    if(s==w || s<w)
        {
            cout<<"unsafe"<<endl;
        }
        else
        {
            cout<<"safe"<<endl;
        }
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n , x;
	cin >> n >> x;
	x = 2 * x  + 1;
	cout << (n + x - 1)/x;
}

Measured memory_bytes: 3580
from bisect import bisect_left, bisect_right

N = int(input())
S = list(input())
Q = int(input())

D = {chr(ord('a') + i): [] for i in range(26)}
for i, s in enumerate(S):
    D[s].append(i)

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1]), query[2]
        i -= 1
        s = S[i]
        if s == x:
            continue

        D[s].remove(i)
        next_i = bisect_left(D[x], i)
        D[x].insert(next_i, i)
        S[i] = x

    if query[0] == '2':
        l, r = int(query[1]), int(query[2])
        l, r = l - 1, r - 1
        ans = 0
        for i in range(26):
            s = chr(ord('a') + i)

            li = bisect_left(D[s], l)
            ri = bisect_right(D[s], r)

            if ri - li > 0:
                ans += 1

        print(ans)


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

struct UnionFind {
  vector<int> parent;
  vector<int> num_node;

  UnionFind(int N) : parent(N), num_node(N, 1) {
    for (int i = 0; i < N; i++) {
      parent[i] = i;
    }
  }

  // 根を求める
  int root(int x) {
    if (parent[x] == x) {
      return x;
    }

    // 経路圧縮
    parent[x] = root(parent[x]);
    return parent[x];
  }

  // 同一判定
  bool is_same(int x, int y) {
    return this->root(x) == this->root(y);
  }

  // 併合
  void unite(int x, int y) {
    x = this->root(x);
    y = this->root(y);

    // すでに一緒ならなにもしない
    if (x == y) {
      return;
    }
    parent[x] = y;
    num_node[y] += num_node[x];
  }

  // 同一グループのノード数
  int size(int x) {
    return num_node[root(x)];
  }
};

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

  ll h, w;
  cin >> h >> w;
  vs s(h);
  rep(i, h) {
    cin >> s[i];
  }

  ll n = h * w;
  UnionFind uf(n);
  vector<vb> visited(h, vb(w));

  rep(i, n) {
    ll y = i / w;
    ll x = i % w;

    if (visited[y][x]) {
      continue;
    }

    queue<P> q;
    q.push(make_pair(y, x));

    while (!q.empty()) {
      auto it = q.front();
      q.pop();

      ll v = it.first * w + it.second;
      uf.unite(i, v);

      ll y = it.first;
      ll x = it.second;

      if (y > 0) {
        if (!visited[y - 1][x] && s[y - 1][x] != s[y][x]) {
          q.push(make_pair(y - 1, x));
          visited[y - 1][x] = true;
        }
      }
      if (y < h - 1) {
        if (!visited[y + 1][x] && s[y + 1][x] != s[y][x]) {
          q.push(make_pair(y + 1, x));
          visited[y + 1][x] = true;
        }
      }

      if (x > 0) {
        if (!visited[y][x - 1] && s[y][x - 1] != s[y][x]) {
          q.push(make_pair(y, x - 1));
          visited[y][x - 1] = true;
        }
      }
      if (x < w - 1) {
        if (!visited[y][x + 1] && s[y][x + 1] != s[y][x]) {
          q.push(make_pair(y, x + 1));
          visited[y][x + 1] = true;
        }
      }
    }
  }

  vector<P> vp(n);

  rep(i, n) {
    ll y = i / w;
    ll x = i % w;
    if (s[y][x] == '.')
      vp[uf.root(i)].first++;
    else
      vp[uf.root(i)].second++;
  }

  ll ans = 0;
  rep(i, n) {
    ans += vp[i].first * vp[i].second;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12072
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        long n = nl();
        long a = nl();

        long ans = n;

        for (int i = 1; i <= 40; i++) {
            if (a * i > n) break;

            long x = (long) Math.pow(n, 1.0 / (i + 1));

            long high = (i + 1) * (x + 1);
            long low = (i + 1) * x - 1; // 誤差を考慮
            while (high - low > 1) {
                long mid = (high + low) / 2;
                long p = mid / (i + 1);
                long q = mid % (i + 1);

                long t = 1;
                for (int j = 0; j <= i; j++) {
                    if (j < q) {
                        t *= (p + 1);
                    } else {
                        t *= p;
                    }
                    if (t >= n) break;
                }

                if (t >= n) {
                    high = mid;
                } else {
                    low = mid;
                }
            }

            ans = Math.min(ans, a * i + high);
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 8276
use std::cmp;
use std::collections::BTreeSet;

fn main() {
    let sc = std::io::stdin();
    let mut sc = Scanner { reader: sc.lock() };

    let n: usize = sc.read();
    let a: Vec<usize> = sc.read_vec(1 << n);

    let mut top: Vec<(usize, usize)> = (0..(1 << n)).map(|i| (a[i], i)).collect();
    let mut ans = vec![0; 1 << n];
    for mask in 1..(1 << n) {
        let mut set = BTreeSet::new();
        set.insert(top[mask]);
        for pos in 0..n {
            let pos_mask = 1 << pos;
            let sub_mask = mask & (!pos_mask);
            set.insert(top[sub_mask]);
        }
        let mut iter = set.iter().rev();
        top[mask] = *iter.next().unwrap();

        let &(top2, _) = iter.next().unwrap();
        ans[mask] = cmp::max(ans[mask - 1], top[mask].0 + top2);
        println!("{}", ans[mask]);
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 15356
/*||>>>> Praveen Ojha <<<<>>>> 15 June 2019 <<<<>>>> 17:26:44 <<<<||*/
// #pragma GCC optimize("Ofast") //(Very Fast but Inaccurate)
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //(Small operations in many loops)
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf 1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
map <pii,int> mp;
int32_t main(){__
	int n;
	cin>>n;
	vi x(n),y(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}
	int maxi=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)
				continue;
			mp[{x[i]-x[j],y[i]-y[j]}]++;
			maxi=max(maxi,mp[{x[i]-x[j],y[i]-y[j]}]);
		}
	}
	cout<<n-maxi<<"\n";
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846264338327950288
#define mt make_tuple


void love() {
	int n;
	cin>>n;

	ll ans = 0L;
	int a[n-1];
	int f;
	int l;
	for(int i = 0; i<n-1; i++) cin>>a[i];

	ans = a[0];
	for(int i = 0; i<n-2; i++) {
		ans += min(a[i], a[i+1]);
	}
	ans += a[n-2];
	cout<<ans<<endl;
}

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

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

template <ll mod> class modint
{
private:
    ll x;

public:
    modint(ll x = 0) : x(x >= 0 ? x % mod : (x % mod) + mod) {}
    modint &operator+=(const modint rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator-=(const modint rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator*=(const modint rhs) {
        (x *= rhs.x) %= mod;
        return *this;
    }
    modint &operator/=(const modint rhs) {
        *this *= rhs.inv();
        return *this;
    }
    modint operator+(const modint rhs) const { return modint(*this) += rhs; }
    modint operator-(const modint rhs) const { return modint(*this) -= rhs; }
    modint operator*(const modint rhs) const { return modint(*this) *= rhs; }
    modint operator/(const modint rhs) const { return modint(*this) /= rhs; }

    modint operator-() const { return modint(-x); }

    modint pow(ll n) const {
        modint e = *this, ret = modint(1);
        while (n) {
            if (n & 1) ret *= e;
            e *= e, n >>= 1;
        }
        return ret;
    }

    modint inv() const { return pow(mod - 2); }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m.x;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }
};
using mint = modint<1000000007>;

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

    int n; cin >> n;
    vector<string> s(2);
    cin >> s[0] >> s[1];

    mint ans = 1;
    for (int i = 0; i < n; i++) {
        if (s[0][i] == s[1][i]) {
            if (i == 0) ans *= 3;
            else if (s[0][i - 1] == s[1][i - 1]) ans *= 2;
        } else {
            if (i == 0) ans *= 6;
            else if (s[0][i - 1] == s[1][i - 1]) ans *= 2;
            else ans *= 3;
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    char S[5];
    scanf("%s",&S);
    if(S[0]==S[1]){
        printf("Bad");
    }else if(S[1]==S[2]){
        printf("Bad");
    }else if(S[2]==S[3]){
        printf("Bad");
    }else{
        printf("Good");
    }
    return 0;
}

Measured memory_bytes: 128
from collections import deque

n = int(input())
my_Linkedlist = deque()

for i in range(n):
  input_str=input().split()
  if input_str[0]=="insert":
      my_Linkedlist.appendleft(input_str[1])
  elif input_str[0]=="delete":
      if my_Linkedlist.count(input_str[1])>0:
          my_Linkedlist.remove(input_str[1]) #删除第一个值为value的元素
  elif input_str[0]=="deleteFirst":
      my_Linkedlist.popleft()
  elif input_str[0]=="deleteLast":
    my_Linkedlist.pop()
    
print(*my_Linkedlist)


Measured memory_bytes: 69732
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int dp[1100][11000];

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, n + 1) rep(j, h + 1) dp[i][j] = INF;
  
  dp[0][0] = 0;
  rep(i, n) rep(j, h + 1) {

    // 使わない場合
    chmin(dp[i + 1][j], dp[i][j]);

    // 使う場合
    int nj = min((int)j + a[i], h);
    chmin(dp[i + 1][nj], dp[i + 1][j] + b[i]);

  }
  cout << dp[n][h] << endl;
}

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

def solve(Y,M,D):
    ans = 0
    ans += (Y - 1) * (19 + 20) * 5
    ans += ((Y -1)// 3) * 5
    ans += 19 * (M-1)
    if Y % 3 ==0:
        ans += (M-1)
    else:
        ans += (M // 2)
    ans += (D-1)
    print(196470 - ans)
    

for i in range(n):
    l = input().split(' ')
  
    solve(int(l[0]) , int(l[1]), int(l[2]))




Measured memory_bytes: 5600
n = int(input())
x = list(map(int, input().split()))

ans = 1


for i in range(n):
    ans = ans*x[i]
    if ans > 1000000000000000000:
        ans = -1
        break

for i in range(n):
    if x[i] == 0:
        ans = 0
        break


print(ans)


Measured memory_bytes: 21664
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

N = iin()
A = iln()

right = 0
ans = 0
total = 0
xtotal = 0
for left in range(N):
    while right < N and total+A[right] == xtotal^A[right]:
        total += A[right]
        xtotal += A[right]
        right += 1
    ans += right-left
    if left == right: right+=1
    else:
        total -= A[left]
        xtotal ^= A[left]
print(ans)


Measured memory_bytes: 27148
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;
#define For(i,l,r) for (int i = l; i <= r; ++i)
#define Fill(a,b) memset(a,b,sizeof(a))
#define Cor(i,l,r) for (int i = l; i >= r; --i)
#define flt double
#define MaxN 1020304

int n,a[MaxN],w; flt cnt[MaxN];
int main() {
	while (cin >> n >> w) {
		if (!n && !w) break ;
		For(i,1,n) scanf("%d",&a[i]);
		sort(a + 1,a + n + 1);
		if (a[n] < w) {
			puts("0.01");
			continue ;
		}
		int Tot = a[n] / w + 1;
		flt Max = 0; Fill(cnt,0);
		For(i,1,n) cnt[a[i] / w + 1] += 1., Max = max(Max,cnt[a[i] / w + 1]);
		flt ans = 0.01, c = 1. ,dec = 1./ (Tot - 1.);
		For(i,1,Tot) {
			ans += cnt[i] / Max * c;
			c -= dec;
		}
		printf("%.12lf\n",ans);
	}
	return 0;
}

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

int main() {
  vector<int> vec(3);
  for(int i = 0; i < 3; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  if(vec.at(0) == 5 && vec.at(1) == 5 && vec.at(2) == 7){
    cout <<"YES"<<endl;
  }else{
    cout << "NO" <<endl;
  }
}

Measured memory_bytes: 256
typedef long long ll;

using namespace std;


#include<iostream>


int main(int argc, char *argv[])
{
    int D, N;
    cin >> D >> N;
    ll base = 1;

    while(D > 0 ){
        base*=100;
        D--;
    }

    if(N==100){
        N++;
    }
    
    cout << (N*base) << endl;
    
    return 0;
}


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

int main(){
    double N,K;
    cin>>N>>K;
    double ans=0,n=N;
    for(ll i=0;n>0;){
        if(K>n){
            i++;
            K/=2;
        }else{
            ans+=1.0/N*pow(0.5,i);
            n--;
        }
    }
    
    cout<<fixed<<setprecision(32)<<ans;
}

Measured memory_bytes: 4232
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        a: [usize; n],  // Vec<(i32, i32, i32)>
    }
    for i in 1..=n - k {
        if a[k + i - 1] > a[i - 1] {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

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

int main(){
    int n, m; cin>>n>>m;
    vector<vector<P>> g(n+10);
    for(int i=0; i<m; i++){
        int p, y; cin>>p>>y;
        p--;
        g[p].emplace_back(P(y, i));
    }

    for(int i=0; i<n; i++){
        sort(g[i].begin(), g[i].end());
    }

    int cnt=0;
    vector<string> ans(m);
    for(int i=0; i<n; i++){
        for(int j=0; j<g[i].size(); j++){
            int y, id;
            tie(y, id)=g[i][j];
            int hdigit=0, tdigit=0, head=i+1, tail=j+1;
            while(head>0){
                head/=10;
                hdigit++;
            }
            while(tail>0){
                tail/=10;
                tdigit++;
            }
            for(int k=1; k<=6-hdigit; k++) ans[id]+="0";
            head=i+1;
            char hnum[6], tnum[6];
            for(int k=0; head>0; k++){
                hnum[k]=head%10+'0';
                head/=10;
            }
            for(int k=hdigit-1; k>=0; k--) ans[id]+=(hnum[k]);
            for(int k=1; k<=6-tdigit; k++) ans[id]+="0";
            tail=j+1;
            for(int k=0; tail>0; k++){
                tnum[k]=tail%10+'0';
                tail/=10;
            }
            for(int k=tdigit-1; k>=0; k--) ans[id]+=(tnum[k]);
        }
    }

    for(int i=0; i<m; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 13952
#include <algorithm>
#include <atcoder/all>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using namespace atcoder;
using ll = long long;

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

    fenwick_tree<ll> fw(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    for (int i = 0; i < Q; i++) {
        int q, p, x;
        cin >> q >> p >> x;
        if (q == 0) {
            fw.add(p, x);
        } else {
            cout << fw.sum(p, x) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 8240
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std; 
#define MAXN 200
#define MAXM 50
vector <int> buckets(2000000,0);
vector <int> buckets2(2000000,0);
int main(int argc,char const* argv[])
{
  int n,k,ans=0,numcount=0,c;
  cin >> n >> k;
  vector<int> A(n,0);
  for(int i=0;i<n;i++)
    {
      cin >> A[i];
      buckets[A[i]]++;
      if(buckets[A[i]]!=0) buckets2[A[i]]=1;
    }
  for(int i=0;i<2000000;i++)
    {
      if(buckets2[i]==1) numcount++;
    }
   for(int i=0;i<2000000;i++)
    {
      if(buckets[i]==0) buckets[i]=100000000;
    }
  if(numcount>k)
    {
      c=numcount-k;
      sort(buckets.begin(),buckets.end());
      for(int i=0;i<c;i++)
	{
	  ans+=buckets[i];
	}
    }
	  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 16640
N = int(input())
p = list(map(float, input().split()))
dp = [[0.0 for i in range(N+1)] for j in range(N+1)]
dp[0][0] = 1.0
for i in range(N):
    for j in range(N):
        dp[i+1][j+1] += dp[i][j] * p[i]
        dp[i+1][j] += dp[i][j] * (1 - p[i])
temp = (N+1) // 2
ans = 0
for i in range(temp, N+1):
    ans += dp[N][i]
print(ans)

Measured memory_bytes: 153224
#include<bits/stdc++.h>
using namespace std;
string s,t;
long long x[100],ans,a;
vector<int> v[100];
int main(){
	cin>>s>>t;a=s.size();
	for (int i=0;i<s.size();i++) x[s[i]-'a']++;
	for (int i=0;i<t.size();i++)
		if (x[t[i]-'a']==0){
			cout<<-1<<endl;
			return 0;
		}
	for (int i=0;i<s.size();i++) v[s[i]-'a'].push_back(i);
	int n=-1;
	for (int i=0;i<t.size();i++){
		auto b=upper_bound(v[t[i]-'a'].begin(),v[t[i]-'a'].end(),n);
		if (b==v[t[i]-'a'].end()){
			ans++;
			b=v[t[i]-'a'].begin();
		}
		n=*b;
	}
	cout<<ans*a+(long long)n+1<<endl;
	return 0;
}

Measured memory_bytes: 1216
"use strict"
function main(arg) {
    var data = arg.trim().split("\n")[0].split(" ").map(Number)
    var N = data[0]
    var K = data[1]
    console.log(N.toString(K).split("").length)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

int n;
ll dp[90];

int main(){
  scanf("%d",&n);
  REP(i,90) dp[i] = 0;
  dp[0]=2;
  dp[1]=1;
  FOR(i,2,90) dp[i] = dp[i-1]+dp[i-2];
  printf("%lld\n",dp[n]);
}


Measured memory_bytes: 128
#! /usr/bin/env python
# -*- coding : utf-8 -*-
while True:
    m, f, r = map(int,input().split())
    if r == m == f == -1:
        break
    elif m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print("A")
    elif m + f >= 65 and m + f < 80:
        print("B")
    elif m + f >= 50 and m + f < 65:
        print("C")
    elif m + f >= 30 and m + f < 50:
        if r >= 50:
            print("C")
        else:
            print("D")
    elif m + f < 30:
        print("F")

Measured memory_bytes: 7640
s = str(input())

r = 0
l = len(s)-1
result = 0
h = True
while r < l:
    if s[r] == s[l]:
        r += 1
        l -= 1
    elif s[l] == 'x':
        result += 1
        l -= 1
    elif s[r] == 'x':
        result += 1
        r += 1
    else:
        h = False
        break

if h:
    print(result)
else:
    print(-1)

Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("[" #x "] Time : %.3lf s.\n", (clock() - __my_start_clock) * 1.0 / CLOCKS_PER_SEC)
#define TIMESTAMPf(x, ...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock) * 1.0 / CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char *what) : what(what){};
  __timestamper(const string &what) : what(what){};
  ~__timestamper() {
    TIMESTAMPf("%s", what.data());
  }
} __TIMESTAMPER("end");
#else
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

const int P = 200003;
const int MINDEEP = 4;


void add(ll *a, ll *b, int deep, int coef) {
  for (int i = 0; i < (1 << deep); i++)
    a[i] += b[i] * coef;
}

void mul(ll *a, ll *b, ll *res, int deep) {
  if (deep == MINDEEP) {
    for (int i = 0; i < (1 << deep); i++)
      for (int j = 0; j < (1 << deep); j++)
        res[i + j] += a[i] * b[j];
    return;
  }
  mul(a, b, res, deep - 1);
  mul(a + (1 << (deep - 1)), b + (1 << (deep - 1)), res + (1 << deep), deep - 1);
  vector<ll> temp(1 << deep);
  add(a, a + (1 << (deep - 1)), deep - 1, 1);
  add(b, b + (1 << (deep - 1)), deep - 1, 1);
  mul(a, b, &temp[0], deep - 1);
  add(a, a + (1 << (deep - 1)), deep - 1, -1);
  add(b, b + (1 << (deep - 1)), deep - 1, -1);
  add(&temp[0], res, deep, -1);
  add(&temp[0], res + (1 << (deep)), deep, -1);
  add(res + (1 << (deep - 1)), &temp[0], deep, 1);
}


int main() {
#ifdef LOCAL
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif

  vector<int> id(P, -1);
  vector<int> rid(P - 1, -1);
  int cur = 1;
  for (int i = 0; i < P - 1; i++) {
    assert(i == 0 || cur != 1);
    id[cur] = i;
    rid[i] = cur;
    cur = (2 * cur) % P;
  }

  constexpr int PSIZE_LOG = 18;
  constexpr int PSIZE = 1 << PSIZE_LOG;

  int n;
  while (scanf("%d", &n) == 1) {
    vector<ll> a(PSIZE);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      int x;
      scanf("%d", &x);
      if (x == 0) {
        continue;
      }
      a[id[x]]++;
      ans -= (x * 1LL * x) % P;
    }
    vector<ll> b = a;
    vector<ll> res(PSIZE * 2);
    mul(&a[0], &b[0], &res[0], PSIZE_LOG);
    for (int i = 0; i < (int)res.size(); i++) {
      ans += res[i] * 1LL * rid[i % (P - 1)];
    }
    ans /= 2;
    printf("%lld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 17268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf = 1e18;
unsigned long mix(unsigned long a, unsigned long b, unsigned long c){
    a=a-b;  a=a-c;  a=a^(c >> 13);
    b=b-c;  b=b-a;  b=b^(a << 8);
    c=c-a;  c=c-b;  c=c^(b >> 13);
    a=a-b;  a=a-c;  a=a^(c >> 12);
    b=b-c;  b=b-a;  b=b^(a << 16);
    c=c-a;  c=c-b;  c=c^(b >> 5);
    a=a-b;  a=a-c;  a=a^(c >> 3);
    b=b-c;  b=b-a;  b=b^(a << 10);
    c=c-a;  c=c-b;  c=c^(b >> 15);
    return c;
}
unsigned long seed = mix(clock(), time(NULL), 69420228);
int n;
ll cst[26], sat[366][26], last[26], tmp[26];
ll tester(vector<int>v){
	ll res = 0ll;
	memset(last, 0ll, sizeof(last));
	for(int nw, i=0; i<n; i++){
		nw = v[i];
		res += sat[i][nw-1];
		last[nw-1] = i+1;
		for(int j=0; j<26; j++)
			res -= cst[j]*(i+1-last[j]);
	}
	return res;
}
bitset<370>vis;
int rand(int x){return rand()%x+1;}
vector<int>gen(int hm, int x){
	vector<int>res;
	for(int cr=rand()%x+1, times=0; times<hm; cr=rand(x)%x+1, times++)
		res.push_back(cr);
	return res;
}
int randlf(int l, int r){return rand()%(r-l+1)+l;}
vector<int>lgg={1, 2, 4, 8, 16, 32, 64, 128};
vector<int>best;
int main(){
	srand(seed);
	scanf("%d", &n);
	memset(last, 0ll, sizeof(last));
	for(int i=0; i<26; i++) scanf("%lld", &cst[i]);
	for(int i=0; i<n; i++) for(int j=0; j<26; j++)
		scanf("%lld", &sat[i][j]);
	ll res = 0ll;
	vector<int>base;
	for(int nw, i=0; i<n; i++){
		memset(tmp, 0ll, sizeof(tmp));
		for(nw=0; nw<26; nw++){
			tmp[nw] += sat[i][nw];
			for(int j=0; j<26; j++) if(j != nw)
				tmp[nw] -= cst[j] * (i+1-last[j]);
		}
		ll get = -inf; int id = -1;
		for(nw=0; nw<26; nw++) 
			if(get < tmp[nw]){
				get = tmp[nw]; id = nw;
			}else if(get == tmp[nw] && cst[nw] > cst[id]){
				get = tmp[nw]; id = nw;
			}
		base.push_back(id+1); 
		last[id] = i+1; res += tmp[nw];
	}
	best=base;
	for(int times=0; times<400; times++){
		for(int k=7; k>0; k--){
			vector<int>changeid, changeval;
			for(int tt=0; tt<5*(11-k); tt++){
				int cv = randlf(lgg[k-1], lgg[k]);
				changeid = gen(cv, 365);
				changeval = gen(cv, 26);
				vector<int>cur = best;
				for(int i=0; i<cv; i++)
					cur[changeid[i]-1] = changeval[i];
				if(tester(best) < tester(cur))
					best = cur;
			}
		}
	}
	for(int i=0; i<n; i++) printf("%d\n", best[i]);
	return 0;
}

Measured memory_bytes: 3920
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
	int A, B, C, D, E, K, i;
	scanf("%d %d %d %d %d %d", &A, &B, &C, &D, &E, &K);
	if(abs(A - B) > K){
		printf(":(\n");
		return 0;
	}
	if(abs(A - C) > K){
		printf(":(\n");
		return 0;
	}
	if(abs(A - D)> K){
		printf(":(\n");
		return 0;
	}
	if(abs(A - E) > K){
		printf(":(\n");
		return 0;
	}
	if(abs(C - B) > K){
		printf(":(\n");
		return 0;
	}
	if(abs(D - B) > K){
		printf(":(\n");
		return 0;
	}
	if(abs(E - B) > K){
		printf(":(\n");
		return 0;
	}
	if(abs(C - D) > K){
		printf(":(\n");
		return 0;
	}
	if(abs(C - E) > K){
		printf(":(\n");
		return 0;
	}
	if(abs(D - E) > K){
		printf(":(\n");
		return 0;
	}
	printf("Yay!\n");

	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
  char a='A';
  char b,c;

  while(scanf("%c,%c",&b,&c)!=EOF){
    if(b==a){
      a=c;
    }else if(c==a){
      a=b;
    }
  }
    printf("%c\n",a);
    return 0;
}

Measured memory_bytes: 1740
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define eb emplace_back
typedef long long ll;
#define int ll
auto const inf = numeric_limits<int>::max()/4;
  
using Weight = int;
using Capacity = int;
struct Edge {
    int src, dst; Weight weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;
  
pair<vector<Weight>, bool> spfa(const Graph &g, int s){
    const Weight inf = numeric_limits<Weight>::max()/4;
    const int n = g.size(); priority_queue<int> q;
    vector<Weight> dist(n, inf); vector<int> inQ(n);
    vector<int> count(n);
    dist[s] = 0; q.emplace(s); inQ[s] = true; ++count[s];
    bool negCycle = false;
    for(int i = 0; q.size(); i++){
        int v = q.top(); q.pop(); inQ[v] = false;
        for(auto &e : g[v]){
            if(dist[v] != inf && dist[e.dst] > dist[v] + e.weight){
                dist[e.dst] = dist[v] + e.weight;
                if(!inQ[e.dst]){
                    q.emplace(e.dst); inQ[e.dst] = true; ++count[e.dst];
                    if(count[e.dst] >= n){ negCycle = true; goto END; }
                }
            }
        }
    }
 END:;
    return make_pair(dist, !negCycle);
}
  
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    #define endl '\n'
    int V,E,r;
    while(cin >> V >> E >> r){
        Graph g(V);
        rep(i,E){
            int a,b,c;
            cin >> a >> b >> c;
            g[a].eb(a,b,c);
        }
        bool ok;
        vector<Weight> dist;
        tie(dist, ok) = spfa(g,r);
        if(ok){
            for(int i = 0; i < (int)dist.size(); i++){
                if(dist[i] == inf) cout << "INF";
                else cout << dist[i];
                cout << endl;
            }
        } else {
            cout << "NEGATIVE CYCLE" << endl;
        }
    }
}

Measured memory_bytes: 25084
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }

        Arrays.sort(p);
        int sum = 0;
        for (int i = 0; i < k; i++) {
            sum += p[i];
        }
        System.out.println(sum);
    }
}


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

int main() {
	char a = 0, b = 0;
	cin >> a >> b;

	//a = h:b = h, a = d:b = d --> h
	if ((a == 'H' && b == 'H') || (a == 'D' && b == 'D')) {
		cout << 'H' << endl;
	}else cout << 'D' << endl;
}

Measured memory_bytes: 256