akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

mv_array = [set() for _ in range(n)]
score_mv_array = [[] for _ in range(n)]
score_array = [0]*n

def get_sum(array):
    score_array = [0]
    for i, a in enumerate(array):
        score_array.append(score_array[i]+a)
    return max(score_array)

def get_max(array, q, mod):
    if q == 0:
        m_score = get_sum(array[:mod])
    else:
        m_score = get_sum(array+array[:mod])
        m_score = sum(array)*(q-1) + m_score
    return m_score

for i in range(n):
    score = 0
    max_score = c[i]
    pos = i
    for j in range(k):
        pos = p[pos]-1
        if pos in mv_array[i]:
            len_mv = len(score_mv_array[i])
            q, mod = divmod(k-j, len_mv)
            score += get_max(score_mv_array[i], q, mod)
            max_score = max(score, max_score)
            break
        score += c[pos]
        mv_array[i].add(pos)
        score_mv_array[i].append(c[pos])
        max_score = max(score, max_score)
    score_array[i] = max_score

print(max(score_array))

Measured memory_bytes: 884604
# 幅優先探索で迷路を進む
# キューに次の行き先を突っ込み、popして進めるか判断していく

from collections import deque
import numpy as np

INF = pow(10, 8) * (-1)

## 入力
H, W = map(int, input().split())
maze = [] * H
for i in range(H):
  maze.append(list(input()))

## 移動の４方向ベクトル
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

## (sx, sy)から最も遠い場所までの移動距離を返す
def bfs(sx, sy):
  d = [[INF for i in range(W)] for j in range(H)] # dをINFで初期化
  d_arry = np.array(d)
  que = deque()
  # スタート地点をqueに入れ、その距離を0とする
  que.append([sx, sy])
  d_arry[sx][sy] = 0

  # queが空になるまでループ
  while len(que):
    # キューの先頭を取り出す
    pop_pair = que.popleft()
    # 移動４方向をループ
    for i in range(4):
      nx = pop_pair[0] + dx[i]
      ny = pop_pair[1] + dy[i]
    # 移動が可能かの判定と既に訪れたことがあるかの判定(d[nx][ny] != INF なら訪れたことがある)
      if 0 <= nx and nx < H and 0 <= ny and ny < W and maze[nx][ny] != '#' and d_arry[nx][ny] == INF:
        que.append([nx, ny])
        d_arry[nx][ny] = d_arry[pop_pair[0]][pop_pair[1]] + 1
    
  return d_arry.max()

## solve
max_distance = 0
for i in range(H):
  for j in range(W):
    if maze[i][j] == '.':
      res = bfs(i, j)
      if res > max_distance: max_distance = res

print(max_distance)

Measured memory_bytes: 12472
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 105;
int f[MAXN][MAXN][MAXN],n,m,mp[MAXN][MAXN],sum[2][MAXN][MAXN],sx,sy,ans;
char s[MAXN];
inline void chk(int &x,int a)
{
	if(a>x)x=a;
	ans=max(ans,x);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%s",s+1);
		for(int j=1;j<=m;++j){
			mp[i][j]=(s[j]=='o'),sum[0][i][j]=sum[0][i][j-1]+mp[i][j],sum[1][i][j]=sum[1][i-1][j]+mp[i][j];
			if(s[j]=='E')sx=i,sy=j;
		}
	}
	int ub,db,lb,rb;
	for(int u=0;sx-u>0;++u)
		for(int d=0;sx+d<=n;++d){
			ub=max(sx-u,d+1);
			db=min(sx+d,n-u);
			if(ub>db)continue;
			for(int l=0;sy-l>0;++l)
				for(int r=0;sy+r<=m;++r){
					lb=max(sy-l,r+1);
					rb=min(sy+r,m-l);
					if(lb>rb)continue;
					if(sy-(l+1)>=1+r)chk(f[d][l+1][r],f[d][l][r]+sum[1][db][sy-(l+1)]-sum[1][ub-1][sy-(l+1)]);
					if(m-l>=sy+r+1)chk(f[d][l][r+1],f[d][l][r]+sum[1][db][sy+r+1]-sum[1][ub-1][sy+r+1]);
					if(sx+d+1<=n-u)chk(f[d+1][l][r],f[d][l][r]+sum[0][sx+d+1][rb]-sum[0][sx+d+1][lb-1]);					
					if(sx-(u+1)>=1+d)chk(f[d][l][r],f[d][l][r]+sum[0][sx-(u+1)][rb]-sum[0][sx-(u+1)][lb-1]);
				}
		}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
const int MOD=1e9+7;
const int INF=1e18;
void io(string s="file"){freopen((s + ".in").c_str(), "r", stdin);freopen((s + ".out").c_str(), "w", stdout);}

int dp[1000005][2][2];
int n;

int f(int i,int zero,int nine){
    //cout<<zero<<" "<<nine<<"\n";
    if(i==n)return (zero && nine);
    int &ans=dp[i][zero][nine];
    if(ans!=-1)return ans;
    ans=0;
    for(int j=0;j<=9;j++){
        ans+=f(i+1,zero|(j==0),nine|(j==9));
        ans%=MOD;
    }
    return ans;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    memset(dp,-1,sizeof dp);
    cout<<f(0,0,0);
}

Measured memory_bytes: 97232
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
count=0
for i in range(n):
    a=list(map(int,input().split()))
    s=c
    for i in range(m):
        s+=a[i]*b[i]
    if s>0:
        count+=1
print(count)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}

#define MOD 1000000007
typedef long long ll;

int main(){
  int n;
  cin >> n;
  int a[1000];
  int y=0;
  int v[10]={0};
  FOR(i,n){
    cin >> a[i];
    if(a[i]>3199)y++;
    else v[a[i]/400]++;
  }
  int x=0;
  FOR(i,8){
    if(v[i]!=0){
      x++;
    }
  }
  cout << max(x,1) << " " << x+y << endl;
}

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

int main(int argc, char *argv[]){
        long double r;
        long double const PI = 3.141592653589793238L;

        cin >> r;       
        long double area = PI * r * r;
        long double len = 2 * PI * r;
        cout << fixed << area << " ";
        cout << fixed << len << "\n";
        return 0;
}

Measured memory_bytes: 3280
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int n,m,r=0;
	vector<int> v;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int a;
		scanf("%d",&a);
		v.push_back(a);
	}
	sort(v.begin(),v.end(),greater<int>());
	for(int i=0;i<m;i++)r+=v[i];
	printf("%d\n",r);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
   int n;cin>>n;
   int a[n];
   rep(i,n)cin>>a[i];
   ll sum =0;
   rep(i,n)sum+=a[i];
   ll x =sum;
   rep (i,n){
       //if(i==0)continue;
       if(i%2==1)x-=2*a[i];
   }
   vl ans;
 
   ans.push_back(x);
   rep(i,n-1){
       //if(i==0)continue;
       ans.push_back((a[i]-(ans[i]/2))*2);
   }
   for(ll res:ans){
       cout<<res<<' ';
   }
   cout<<endl;
}


Measured memory_bytes: 2676
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> DP;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;
ll N;
string s;
LP p[100];
LP p2[100];
ll pows[10];

int main()
{
    pows[0]=1;
    rep1(i,9){
        pows[i] = pows[i-1]*26;
    }
    cin>>N;
    rep(i,N){
        cin>>s>>p[i].sc;
        p[i].sc = -p[i].sc;
        rep(j, s.size()){
            p[i].fr += (s[j]-'a')*pows[9-j];
        }
        p2[i] = p[i];
    }
    sort(p2, p2+N);
    rep(i, N){
        ll res = 0;
        rep(j, N){
            if(p2[i] == p[j]) res = j;
        }
        cout<<res+1<<endl;
    }
}


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

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

    int n, a, b;
    cin >> n >> a >> b;

    if (max(a, b) > n || a + b > n + 1) {
        cout << -1 << endl;
        quick_exit(0);
    }

    if (min(a, b) == 1) {
        if (max(a, b) != n) {
            cout << -1 << endl;
            quick_exit(0);
        }
        //if (a == n) {
        //    for (int i = 0; i < n; i++) {
        //        cout << i + 1 << " \n"[i == n - 1];
        //    }
        //} else {
        //    for (int i = 0; i < n; i++) {
        //        cout << n - i << " \n"[i == n - 1];
        //    }
        //}
        //quick_exit(0);
    }

    if (a + b == n + 1) {
        for (int i = 0; i < a; i++) {
            cout << n - (a - 1) + i << " \n"[i == n - 1];
        }
        for (int i = a; i < n; i++) {
            cout << 1 + (n - 1) - i << " \n"[i == n - 1];
        }
        cout << flush;
        quick_exit(0);
    }

    if (1) {
        vector<int> r(n);
        int k0 = max(a, b);
        int k1 = min(a, b);

        vector<int> p(k1);
        int s = 0;
        for (int i = 1; i < k1; i++) {
            s += p[i] = 1;
        }
        s += p[0] = k0;

        s = n - s;
        for (int i = 1; i < k1; i++) {
            if (s == 0) break;
            int t = min(s, k0 - 1);
            p[i] += t;
            s -= t;
        }

        if (s != 0) {
            cout << -1 << endl;
            quick_exit(0);
        }

        s = 0;
        for (int i = 0; i < k1; i++) {
            for (int j = 0; j < p[i]; j++) {
                r[s + j] = s + p[i] - 1 - j;
            }
            s += p[i];
        }

        if (a > b) {
            reverse(r.begin(), r.end());
        }

        for (int i = 0; i < n; i++) {
            cout << r[i] + 1 << " \n"[i == n - 1];
        }
        cout << flush;
        quick_exit(0);
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int
int main(){
	ll n , i ;
	int m = INT_MIN ;
	cin >> n ;
	vector<string>v(n) , v1;
	map<string , ll>mp ;
	map<string , ll>:: iterator itr ;
	for(i = 0 ; i < n ; i++){
		cin >> v[i] ;
	}
	for(i = 0 ; i < n ; i++){
		mp[v[i]]++ ;
	}
    for(itr = mp.begin() ; itr != mp.end() ; itr++){
        if(itr->second > m)
       	   m = itr->second ;
    }
    for(itr = mp.begin() ; itr != mp.end() ; itr++){
    	if(itr->second == m)
    		v1.push_back(itr->first) ;
    }
    sort(v1.begin() , v1.end()) ;
    for(i = 0 ; i < v1.size() ; i++){
    	cout << v1[i] << "\n" ;
    }
}

Measured memory_bytes: 28404
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if(S=="RRR")prt(3);
    else if(S[0]=='R'&&S[1]=='R')prt(2);
    else if(S[1]=='R'&&S[2]=='R')prt(2);
    else if(S[0]=='R'||S[1]=='R'||S[2]=='R')prt(1);
    else prt(0);

    return 0;
}



Measured memory_bytes: 3644
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String[] input = sc.nextLine().split(" ");
            int num = Integer.parseInt(input[0] + input[1]);
            double sqrtOfNumber = Math.sqrt(num);
            if (sqrtOfNumber == Math.floor(sqrtOfNumber)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
        sc.close();
    }
}

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

int main()
{
  string S1;
  string S2;
  char c;
  int i;
  int count;
  
  cin >> S1;
  cin >> S2;
  
  cout << 'A' << S2.at(0) << 'C' << endl;

}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int A, B;
  	std::cin >> A >> B;
  	if(A % 3 * B % 3 == 0 || (A + B) % 3 == 0){
      	std::cout << "Possible";
    }else{
      	std::cout << "Impossible";
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>	
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)
 
// random_device rd; mt19937 g(rd());
 
using namespace std;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}
 
const int mod = (int)1e9 + 7;
const int N = (int)1e5 + 123;
const ld eps = 1e-10;
 
int n;
ld x[N], y[N];
char d[N];
 
ld f(ld k)
{
	ld xmax = -1e9, xmin = 1e9;
	ld ymax = -1e9, ymin = 1e9;
	for(int i = 1; i <= n; i++)
	{
		ld curx = x[i], cury = y[i];
		if(d[i] == 'U') cury += k;
		if(d[i] == 'D') cury -= k;
		if(d[i] == 'R') curx += k;
		if(d[i] == 'L') curx -= k;
		xmax = max(xmax, curx);
		xmin = min(xmin, curx);
		ymax = max(ymax, cury);
		ymin = min(ymin, cury);
	}
	xmax -= xmin;
	ymax -= ymin;
	xmax *= ymax;
	return (ld)xmax;
}
 
int main ()
{                                  	
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();
	cin >> n;  
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> d[i];
	ld l = 0.0, r = 1e9;
	for(int i = 1; i <= 500; i++)
	{
		ld m1 = l + (r - l) / 3;
		ld m2 = r - (r - l) / 3;
		if(f(m1) > f(m2)) l = m1;
		else r = m2;
	}
	cout << fixed << min(f(r), f(l));
}  

Measured memory_bytes: 3456
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        g: [[i64; 3]; 3],
    }

    let mut d = [[0; 3]; 3];
    for i in 0..3 {
        d[i][0] = g[i][0] - g[i][1];
        d[i][1] = g[i][1] - g[i][2];
        d[i][2] = g[i][2] - g[i][0];
    }
    if d[0][0] == d[1][0] && d[1][0] == d[2][0]
        &&  d[0][1] == d[1][1] && d[1][1] == d[2][1]
        &&  d[0][2] == d[1][2] && d[1][2] == d[2][2] {
            println!("{}", "Yes");
        } else {
            println!("{}", "No");
        }
}


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

int main() {
    int n,ans,i=0;
    cin>>n;
    ans = n;
    char s1,s2;
    while(i<n){
        cin>>s1;
        if(s1==s2){
            ans-=1;
        }
        s2=s1;
        i++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <sstream>
using namespace std;

using Weight = int;
using Capacity = int;
struct Edge {
	int src, dst; Weight weight; Capacity cap;
	Edge(int s, int d, Weight w, Capacity c) : src(s), dst(d), weight(w), cap(c) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

struct FordFulkerson {
	typedef vector<vector<Capacity>> Matrix;
	int n, t;
	vector<bool> vis;
	vector<vector<Capacity>> cap, flow;
	vector<vector<int>> g;
	Capacity inf;
	FordFulkerson(int n)
		: n(n), cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
		g(n, vector<int>()), inf(numeric_limits<Capacity>::max() / 8) {
	}
	FordFulkerson(const Graph &graph) {
		*this = FordFulkerson(graph.size());
		for(int i = 0; i < n; i++) {
			for(auto &e : graph[i]) addEdge(e.src, e.dst, e.cap);
		}
	}
	void addEdge(int u, int v, Capacity c) {
		cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
		g[u].push_back(v); g[v].push_back(u);
	}
	Capacity solve(int s, int t) {
		this->t = t;
		Capacity res = 0, aug = 1;
		while(aug > 0) {
			vis.assign(n, false);
			res += (aug = augment(s, inf));
		}
		return res;
	}
	Capacity augment(const int &v, const Capacity &lim) {
		vis[v] = true;
		if(v == t) return lim;
		for(const int &d : g[v]) {
			if(vis[d] || flow[v][d] == cap[v][d]) continue;
			Capacity aug = augment(d, min(lim, cap[v][d] - flow[v][d]));
			flow[v][d] += aug;
			flow[d][v] -= aug;
			if(aug > 0) return aug;
		}
		return 0;
	}
};

typedef pair<int, int> Pii;

vector<int> f(string s) {
	replace(s.begin(), s.end(), '+', ' ');
	//cout << s << endl;
	vector<int> ret(51);

	stringstream ss(s);
	while(ss >> s) {
		stringstream ss2(s);
		if(s.find('x') == string::npos) {
			ss2 >> ret[0];
		}
		else {
			char c;
			int a = 1, L = 1;
			if(s[0] != 'x') ss2 >> a;
			if(s.find('^') != string::npos) {
				ss2 >> c >> c >> L; // x^L
			}
			ret[L] = a;
		}
	}
	return ret;
}

int u[500];
int v[500];

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

	int N, M;
	while(cin >> N >> M, N) {
		map<Pii, vector<int> > poly;
		for(int i = 0; i < M; i++) {
			string p;
			cin >> u[i] >> v[i] >> p;
			u[i]--, v[i]--;
			poly[Pii(u[i], v[i])] = f(p);
		}

		vector<int> ans(51);
		for(int i = 50; i >= 0; i--) {
			Graph G(N);

			for(auto&& p : poly) {
				int a = p.first.first, b = p.first.second, c = p.second[i];
				G[a].emplace_back(a, b, 0, c);
				G[b].emplace_back(b, a, 0, c);
			}

			FordFulkerson ff(G);
			int f = ff.solve(0, N - 1);
			ans[i] = f;

			for(int j = 0; j < M; j++) {
				int a = u[j], b = v[j];
				if(ff.flow[a][b] != 0 && ff.flow[a][b] != ff.cap[a][b]) {
					for(int l = 0; l <= i; l++) {
						poly[Pii(a, b)][l] = 1e8;
					}
				}
			}
		}

		bool flag = false;
		for(int i = 50; i >= 0; i--) {
			if(ans[i] == 0) continue;
			if(flag) cout << "+";
			flag = true;
			if(i == 0 || ans[i] != 1) cout << ans[i];
			if(i != 0) cout << "x";
			if(i >= 2) cout << "^" << i;
		}
		if(!flag) cout << 0;
		cout << "\n";
	}
}

Measured memory_bytes: 3340
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




int N;
vector<int> E[151010];
//-----------------------------------------------------------------------------------
double dp[151010];
double dfs(int cu, int pa = -1) {
    double ret = 0;
    int cnt = 0;
    for (int to : E[cu]) if (to != pa) ret += dfs(to, cu) + 1, cnt++;
    if (0 < cnt) ret /= cnt;
    return dp[cu] = ret;
}
//-----------------------------------------------------------------------------------
double ans[151010];
void dfs2(int cu, int pa = -1) {
    // for ans
    double sm = 0; int cnt = 0;
    for (int to : E[cu]) sm += dp[to] + 1, cnt++;
    if (0 < cnt) ans[cu] = sm / cnt;
    else ans[cu] = sm;

    for (int to : E[cu]) if (pa != to) {
        dp[cu] = sm - dp[to] - 1;
        if (1 < cnt) dp[cu] /= (cnt - 1);
        dfs2(to, cu);
    }
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, 0, N - 1) {
        int a, b;
        scanf("%d%d", &a, &b);
        E[a].push_back(b);
        E[b].push_back(a);
    }

    dfs(1);
    dfs2(1);

    rep(i, 1, N + 1) printf("%.10f\n", ans[i]);
}

Measured memory_bytes: 19712
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}


	class P{
		int s;
		int t;
		public P(int s, int t) {
			this.s=s;
			this.t=t;
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<P> ans = new ArrayList<>();
		for(int i=0; i<n-1; i++) {
			ans.add(new P(i+1, n));
		}

		ArrayList<P> tmp = new ArrayList<>();
		for(int i=0; i<n-1;i++) {
			for(int j=0; j<i; j++) {
				tmp.add(new P(i+1, j+1));
			}
		}

		int mx = (n-1)*(n-2)/2;
		if(mx<k) {
			System.out.println(-1);
			sc.close();
			return;
		}

		int add = mx-k;

		for(int i=0; i<add; i++) {
			ans.add(tmp.get(i));
		}

		System.out.println(ans.size());
		for(P p : ans) {
			System.out.println(p.s+" "+p.t);
		}
		sc.close();
	}


}


Measured memory_bytes: 40696
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
)

func (p *problem) solve() {
	N := p.NextInt()
	a := p.NextInts()

	var evens []int
	for i := 0; i < N; i++ {
		if a[i]%2 == 0 {
			evens = append(evens, a[i])
		}
	}

	var cnt int
	for len(evens) > 0 {
		x := evens[0] / 2
		evens = evens[1:]
		cnt++
		if x%2 == 0 {
			evens = append(evens, x)
		}
	}
	fmt.Printf("%v", cnt)
}

var (
	debug  bool
	output string
)

func main() {
	flag.BoolVar(&debug, "debug", false, "Print debug logs")
	flag.BoolVar(&debug, "d", false, "Print debug logs")
	flag.StringVar(&output, "output", "stdout", "Specify output target (Default: stdout)")
	flag.StringVar(&output, "o", "stdout", "Specify output target (Default: stdout)")
	flag.Parse()

	if debug {
		out := os.Stdout
		if output != "stdout" {
			logfile, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY, 0666)
			if err != nil {
				panic(err)
			}
			defer logfile.Close()
			out = logfile
		}
		log.SetOutput(out)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) PrintInt(d int) {
	p.Printf("%d\n", d)
}

func (p *problem) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) Printfln(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, fmt.Sprintf("%v\n", format), a...); err != nil {
		panic(err)
	}
}

func (p *problem) NextInt() int {
	return stoi(p.Next())
}

func (p *problem) NextInts() []int {
	line := p.NextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) NextSSLine() []string {
	return strings.Split(p.Next(), " ")
}

// Next reads line and return string.
func (p *problem) Next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 6016
import collections

N = int(input())
A = list(map(int, input().split()))

Ad = dict(collections.Counter(A))
# A_set = list(set(A))
# Ad = {a_set:A.count(a_set) for a_set in A_set}
# Ad = {}
# for i in A:
#   if not i in Ad:
#     Ad[i]=0
#   Ad[i] += 1

score_sum = sum([x*(x-1)/2 for x in list(Ad.values())])

for a in A:
    print(int(score_sum - (Ad[a] - 1)))


Measured memory_bytes: 26780
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char s[11];
  int count=0;
  scanf("%s", s);
  if (s[0] == 'A')
  {
    for (int i = 1; i < strlen(s); i++)
    {
      if (s[i] == 'C')
      {
        count++;
        if(i<2 || i>=strlen(s)-1){
          puts("WA");
          return 0;
        }
      }else{
        if(s[i]>='A' && s[i]<='Z'){
          puts("WA");
          return 0;
        } 
      }
    }
    if(count!=1){
          puts("WA");
          return 0;
    }else{
          puts("AC");
          return 0;
    }
  }
  puts("WA");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main() {
    double r;
    cin>>r;
    double menseki=M_PI*r*r;
    double syuui=M_PI*2*r;
    printf("%lf %lf\n",menseki,syuui);

    return 0;
}


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


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;

int dp[60][10100][60] = { 0 };

int main(void){
	int n, a, b;

	cin >> n >> a >> b;

	cout << min(a * n, b) << endl;
}

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

int main() {
  int A;
  int B;
  cin >> A >> B;
  if (A % 3 == 0) {
    cout << "Possible" << endl;
  } else if (B % 3 == 0) {
    cout << "Possible" << endl;
  } else if ((A + B) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int a=in(),b=in(),c=in(),d=in(),e=in(),f=in(),i,j,k,l,tw,ts,answ=f,anss=0;
	int A=a*100,B=b*100;
	for(i=0;A*i<=f;i++){
		for(j=0;B*j<=f-A*i;j++){
			if(i!=0||j!=0){
				for(k=0;c*k<=f-A*i-B*j;k++){
					for(l=0;d*l<=f-A*i-B*j-c*k;l++){
						tw=A*i+B*j+c*k+d*l;
						ts=c*k+d*l;
						if(c*k+d*l<=(a*i+b*j)*e&&(ts*answ>=anss*tw)){
							answ=tw;
							anss=ts;
						}
					}
				}
			}
		}
	}
	print2(answ,anss);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n)cin >> a[i];

    ll ans = 0;
    ll flag = 0;
    for(int i=1; i<n; ++i){
        while(a[i-1]==a[i])i++;
        if(flag==0){
            ans++;
            if(a[i] > a[i-1])flag=1;
            else flag=-1;
        }
        else if(flag > 0 && a[i]<a[i-1])flag=0;
        else if(flag < 0 && a[i]>a[i-1])flag=0;
    }
    if(flag==0)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1024
/*
Template for vjudge.net

	Author: Iqbal Hossain Rasel
	CodeForces: The_Silent_Man
	AtCoder   : IHR57
	TopCoder  : IHR57

*/
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 100005
using namespace std;

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

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

vector<ii> v;

bool comp(ii A, ii B)
{
    if(A.ff == B.ff)
        return A.ss < B.ss;
    return A.ff < B.ff;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif
    int l, r, n, m;

    cin>>n>>m;

    for(int i = 0; i < m; i++){
        cin>>l>>r;
        v.pb(mp(l, r));
    }

    sort(v.begin(), v.end(), comp);

    int Mx = 0, Mn = 1e9;
    int cnt = 1;
    for(int i = 0; i < v.size(); i++){
        Mx = max(Mx, v[i].ff);
        Mn = min(Mn, v[i].ss);
        if(Mn - Mx <= 0){
            cnt++;
            if(i < v.size() - 1){
                Mx = v[i].ff;
                Mn = v[i].ss;
            }
        }
    }

    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 1400
import java.util.*

public fun pow(a : Long, t : Long) : Long {
    if (t == 0L) return 1L
    var x = pow(a, t shr 1)
    x *= x
    if (t and 1L == 1L) x *= a
    return x
}

fun main(args: Array<String>) {
    var x = readLine()!!.toLong()
    var count = 0L
    while(x>1L){
        x /= 2L
        count++
    }
    println(pow(2L, count.toLong()+1)-1)
}


Measured memory_bytes: 31700
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (_, _, _, K) = read!(usize, usize, usize, usize);
    let mut A = read![[i64]];
    let B = read![[i64]];
    let C = read![[i64]];

    A.sort_by(|l, r| r.cmp(l));

    let mut W = vec![];
    for b in &B {
        for c in &C {
            W.push(b + c);
        }
    }
    W.sort_by(|l, r| r.cmp(l));

    let N = A.len();
    let M = W.len();
    let mut wis = vec![0; N];

    for _ in 0..K {
        let mut next_ai = 0;
        let mut next_sum = 0;

        for ai in 0..N {
            let wi = wis[ai];
            if wi >= M {
                continue;
            }

            let sum = A[ai] + W[wi];
            if next_sum < sum {
                next_sum = sum;
                next_ai = ai;
            }
        }

        println!("{}", next_sum);
        wis[next_ai] += 1;
    }
}


Measured memory_bytes: 16636
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int day[n];
    for(int i = 0; i < n; i ++){
        cin >> day[i];
    }
    for(int j = 0; j < n - 1; j ++){
        cout << day[n - j - 1] << " ";
    }
    cout << day[0] <<endl;
    return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> va[10];
	for(int i = 0; i < M; i++){
		int k;
		cin >> k;
		for(int j = 0; j < k; j++){
			int s;
			cin >> s;
			s--;
			va[i].push_back(s);
		}
	}
	vector<int> p(M);
	for(int i = 0; i < M; i++) cin >> p[i];
	int res = 0;
	for(int i = 0; i < (1 << N); i++){
		bool flag = true;
		for(int j = 0; j < M; j++){
			int cnt = 0;
			for(int k = 0; k < va[j].size(); k++){
				if(i & (1 << va[j][k])) cnt++;
			}
			if(p[j] != cnt % 2) flag = false;
		}
		if(flag) res++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main()
{
  int H, W;
  cin >> H >> W;
  int a[H + 1][W + 1];
  for (int i = 1; i <= H; i++)
  {
    for (int j = 1; j <= W; j++)
      cin >> a[i][j];
  }
  vector<P> route;
  int y = 1;
  int x = 1;
  bool right = true;
  while (route.size() < H * W)
  {
    route.push_back(make_pair(y, x));
    if (right)
    {
      if (x == W)
      {
        right = false;
        y++;
      }
      else
        x++;
    }
    else
    {
      if (x == 1)
      {
        right = true;
        y++;
      }
      else
        x--;
    }
  }
  vector<int> ans;
  for (int i = 0; i < route.size() - 1; i++)
  {
    if (a[route[i].first][route[i].second] % 2 != 0)
    {
      ans.push_back(i);
      a[route[i].first][route[i].second]--;
      a[route[i + 1].first][route[i + 1].second]++;
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << route[ans[i]].first << " " << route[ans[i]].second << " " << route[ans[i] + 1].first << " " << route[ans[i] + 1].second << endl;
  return 0;
}

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

int main(){
    int n; cin >> n;
    string ans = "";
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    while(n != 0){
        if(n % 2 != 0){
            n -= 1;
            ans = "1" + ans;
        }else{
            ans = "0" + ans;
        }
        n = n / (-2);
    }
    cout << ans << endl;
}

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

using namespace std;

int min_cost(array<array<int, 10>, 10> &c, int n, int st,
             vector<vector<int>> &memo) {
  if (n == 1) {
    return 0;
  }

  if (memo[n][st] < 0) {
    int ans = -1;
    for (int i = 0; i <= 9; ++i) {
      if (st & (1 << i)) {
        continue;
      }

      int cost = min_cost(c, i, st | (1 << i), memo) + c[n][i];
      if (ans < 0 || cost < ans) {
        ans = cost;
      }
    }

    memo[n][st] = ans;
  }

  return memo[n][st];
}

int main(int argc, const char *argv[]) {
  int h, w;
  cin >> h >> w;

  array<array<int, 10>, 10> c;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> c[i][j];
    }
  }

  vector<vector<int>> memo(10, vector<int>(2048, -1));
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int a;
      cin >> a;
      if (a != -1) {
        ans += min_cost(c, a, 0, memo);
      }
    }
  }

  cout << ans << '\n';
}

Measured memory_bytes: 3744
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
if A1 > B1:
    A1, B1 = B1, A1
    A2, B2 = B2, A2

A, B = A1 * T1 + A2 * T2, B1 * T1 + B2 * T2
if A < B:
    print(0)
elif A == B:
    print("infinity")
else:
    c = 0
    l = 0
    r = 1<<100
    while r - l > 1:
        m = (l+r) // 2
        if B * (m-1) + B1 * T1 > A * (m-1) + A1 * T1:
            l = m
            c = 1
        elif B * (m-1) + B1 * T1 == A * (m-1) + A1 * T1:
            l = m
            c = 0
        else:
            r = m
    print((l-1) * 2 + c)

Measured memory_bytes: 3064
A ,B = map(int,(input().split()))
one = 300000
two = 200000
three = 100000
result = 0
if A == 1 and B == 1:
    print(one + one + 400000)
    exit(0)
if A == 3:
    result += three
if A == 2:
    result += two
if A == 1:
    result += one
if B == 3:
    result += three
if B == 2:
    result += two
if B == 1:
    result += one
print(result)

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

int main(){
    long long n,k;
    long long ans;
    cin>>n>>k;

    n=n%k;
    
    if(n<(k-n)){ans=n;}
    else{ans=(k-n);}
    
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;


int main() {

    int N;
    cin >> N;
    int d;
    vector<int> ds;
    for (int i = 0; i < N; ++i) {
        cin >> d;
        ds.push_back(d);
    }

    int sum = 0;
    for (int i = 0; i < N - 1; ++i) {
        for (int j = i + 1; j < N; ++j) {

            sum = sum + (ds[i] * ds[j]);

        }
    }

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

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

#define N 500000

int n;

struct Tree{
	int key;
	struct Tree *parent,*left,*right;
};
struct Tree *NILL,*root;

void find(struct Tree *root,int key){
	int flag =0;
	while(root!=NILL){
		if(root->key > key)root = root->left;
		else if(root->key == key) {
			printf("yes\n");
			flag =1;
			break;
		}
		else root = root->right;
	}
	if(!flag)printf("no\n");
}

struct Tree * find1(struct Tree *root,int key){
	int flag =0;
	while(root!=NILL){
		if(root->key > key)root = root->left;
		else if(root->key == key) {
			flag =1;
			break;
		}
		else root = root->right;
	}
	if(!flag)return NILL;
	return root;
}

void insert(struct Tree *z){
	struct Tree *x,*y;
	y = NILL;
	x = root;
	while(x != NILL){
		y = x;
		if(z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->parent = y;
	if(y == NILL)  {
		root = z;
	}
	else if(z->key < y->key) y->left = z;
	else y->right = z;
}

struct Tree * tm(struct Tree *z){
	while(z->left !=NILL) z = z->left;
	return z;
}

struct Tree * succecer(struct Tree *z){
	if(z->right != NILL) return tm(z->right);
	struct Tree *y = z->parent;
	while(y!=NILL && z==y->right){
		z=y;
		y = y->parent;
	}
	return y;
}

void delete(struct Tree *z){
	struct Tree *y,*x;
	if(z->left == NILL || z->right == NILL) y = z;
	else y = succecer(z);
	if(y->left != NILL){
		x = y->left;
	}
	else{
		x = y->right;
	}
	if(x!=NILL){
		x->parent = y->parent;
	}
	if(y->parent == NILL){
		root = x;
	}
	else{
		if(y==y->parent->left){
			y->parent->left = x;
		}
		else{
			y->parent->right = x;
		}
	}
	if(y!=z){
		z->key = y->key;
	}
}

void mid(struct Tree *root){
	if(root == NILL) return;
	mid(root->left);
	printf(" %d", root->key);
	mid(root->right);
}

void inorder(struct Tree *root){
	if(root == NILL) return;
	printf(" %d",root->key);
	inorder(root->left);
	inorder(root->right);
}

void print(){
	struct Tree *r;
	r = root;
	mid(r);
	printf("\n");
	inorder(r);
	printf("\n");
}

int main(){
	struct Tree *t;
	scanf("%d",&n);
	int i;
	int key;
	char instruct[7];
	for(i=0;i<n;i++){
		scanf("%s",instruct);
		if(!strcmp(instruct,"insert")){
			scanf("%d",&key);
			t = (struct Tree *)malloc(sizeof(struct Tree));
			t->key = key;
			t->right = NILL;
			t->left = NILL;
			//T[i]->key  = key;
			insert(t);
		}
		else if(!strcmp(instruct,"find")){
			scanf("%d",&key);
			find(root,key);
		}
		else if(!strcmp(instruct,"delete")){
			scanf("%d",&key);
			delete(find1(root,key));
		}
		else print();
	}
	return 0;
}

Measured memory_bytes: 19364
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int n,c,d[31][31],ccc,cl[3][31],a[31],b,ans=1<<30;
int main(){
	memset(cl,0,sizeof(cl));
	cin>>n>>c;
	for(int i=1;i<=c;i++)
		for(int j=1;j<=c;j++)
			cin>>d[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			cin>>ccc;
			cl[(i+j)%3][ccc]+=1;
		}
	for(a[0]=1;a[0]<=c;a[0]++)
		for(a[1]=1;a[1]<=c;a[1]++)
			for(a[2]=1;a[2]<=c;a[2]++) if(a[0]!=a[1]&&a[1]!=a[2]&&a[2]!=a[0]){
				b=0;
				for(int i=0;i<3;i++)
					for(int j=1;j<=c;j++){
						b+=cl[i][j]*d[j][a[i]];
					}
				ans=min(ans,b);
				//cout<<b<<' '<<a[0]<<a[1]<<a[2]<<endl;
		}
	cout<<ans<<endl;
}


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

int main(){
    int n,t,e;
    while(cin >> n >> t >> e){
        bool f = false;
        for(int i=0;i<n;i++){
            int a;
            cin >> a;
            if(!f){
                for(int j=a;j<=t+e;j+=a){
                    if(j >= t - e && j <= t + e){
                        f = true;
                        break;
                    }
                }
                if(f) cout << i+1 << endl;
            }
        }
        if(!f) cout << -1 << endl;
    }
}

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

namespace ABC145B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            bool hantei = true;
            if (S.Length % 2 == 0)
            {
                int t = S.Length / 2;
                for(int i = 0; i < t; i++)
                {
                    if (S[i].ToString() != S[i + t].ToString())
                    {
                        hantei = false;
                    }
                }
            }
            else
            {
                hantei = false;
            }
            if (hantei) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


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

typedef long long gg;

void _solve(){
    int n;
    cin>>n;
    gg ans=0;
    for(int j=1;j<=n;++j){
        gg t=n/j;
        ans+=(1+t)*t/2*j;
    }
    cout<<ans<<endl;
}

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


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

int main(){
  int n,w;
  cin>>n>>w;
  ll vec[n][2];
  ll dp[n+1][1010*n];
  for(int i=0;i<n;i++){
    for(int j=0;j<2;j++){
      cin>>vec[i][j];
    }
  }
  //vec[i][0]=weight,vec[i][1]=value
  //dp[i][j]=0~i,value:j min cost
  for(int i=0;i<1010*n;i++){
    dp[0][i]=0;
    if(i!=0){
      dp[0][i]=1e15;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<=1010*n;j++){
      dp[i+1][j]=dp[i][j];
      if(j>=vec[i][1]){
        dp[i+1][j]=min(dp[i+1][j],dp[i][j-vec[i][1]]+vec[i][0]);
      }
    }
  }
  for(int i=1010*n-1;i>=0;i--){
    if(dp[n][i]<=w){
      cout<<i<<endl;
      return 0;
    }
  }
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, x; cin >> N >> x;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  ll sum = 0;
  ll cnt = 0;
  for (ll i = 0; i < N; i++) {
    if (sum + A[i] > x) break;
    if (i == N-1 && sum + A[i] != x) break;
    sum += A[i];
    cnt++;
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3616
import java.util.Scanner;
class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			if(n==0)break;
			boolean boo = true;
			long pro = 1;
			int count2 = 0;
			int count5 = 0;
			for(int i = 1; i < n+1 ; i++){
				pro = i ;
				while(pro % 5 == 0){
					count5++;
					pro /=5;
				}
				while(pro % 2 == 0){
					count2++;
					pro /=2;
				}
			}
			System.out.println(Math.min(count2,count5));
		}
	}
}

Measured memory_bytes: 26136
# -*- coding: utf-8 -*-

def main():
     s = input()
     n = len(s)

     s1 = s[:((n-1)//2)]
     s2 = s[(n+3)//2-1:]

     if check(s) and check(s1) and check(s2):
          print('Yes')
     else:
          print('No')


def check(s):
     s_r = ('').join(reversed(s))
     
     # print('s:{}, s_r:{}'.format(s, s_r))
     if s == s_r:
          return True
     return False

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
N = int(input())
l = [0]*31
for i in range(0,30):
    l[i+1] = l[i] + 4**i

mlist = [0] * 61
for i in range(30):
    mlist[i*2+1] = l[i]
    mlist[i*2] = l[i]
mlist = mlist[1:-1]

def zojudge(N, d):
    if ((N-1) // 2**d) % 2 == 0:
        return "1"
    else:
        return "0"

L = [zojudge(N - m, i) for (i, m) in enumerate(mlist)]
S = int("".join(reversed(L)))
print(S)



Measured memory_bytes: 3064
#17:30
n = int(input())
i = 11
cnt = 0
ans = []
while cnt < n:
  for j in range(2,int(i**.5)+1):
    if i % j == 0:
      i += 10
      break
  else:
    cnt += 1
    ans.append(i)
    i += 10
print(' '.join(list(map(str,ans))))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int a[1<<18];
int f[1<<18],g[1<<18];
void Add_val(int p,int v){
	if(v>=f[p])
		g[p]=f[p],f[p]=v;
	else if(v>=g[p])
		g[p]=v;
}
int ans[1<<18];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<(1<<n);i++)
		scanf("%d",&a[i]);
	for(int i=0;i<(1<<n);i++)
		f[i]=a[i],g[i]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<(1<<n);j++){
			if(j&(1<<i)){
				Add_val(j,f[j^(1<<i)]);
				Add_val(j,g[j^(1<<i)]);
			}
		}
	}
	for(int i=1;i<(1<<n);i++){
		ans[i]=f[i]+g[i];
		if(ans[i-1]>ans[i])
			ans[i]=ans[i-1];
	}
	for(int i=1;i<(1<<n);i++)
		printf("%d\n",ans[i]);
	return 0;
}


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

int main() {
    int n,k,a;
    cin>>n>>k;
    vector<int> num(n);
    for(int i=0; i<n; i++) {
        cin>>a;
        num[a-1]++;
    }
    sort(num.begin(), num.end());
    int count=0;
    for(int i=0; i<n+1; i++) {
        if(num[i]) count++;
    }
    int count_ch=0;
    for(int i=n-count; i<n-k; i++) {
        count_ch += num[i];
    }
    cout<<count_ch<<endl;
}

Measured memory_bytes: 1024