akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right !=NIL){
    x = x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u == NIL || k== u->key){
    return u;
  }
  if(k < u->key){
    return treeSearch(u->left,k);
  }
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left ==NIL || z->right ==NIL){
    y =z;
  }
  else {y = treeSuccessor(z);}
  if(y->left != NIL){
    x = y->left;
  }
  else x = y->right;
  if(x != NIL){
    x->parent = y->parent;
  }
  if(y->parent ==NIL){
    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 insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x !=NIL){
    y = x;
    if(z->key < x->key){
      x=x->left;
    }
    else {x = x->right;}
  }
    z->parent = y;
    if(y==NIL){
      root = z;
    }
      else if(z->key < y->key){
	y->left = z;
      }
      else {y->right = z; }
    }

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

int i,j,n;
string str;

int main(){
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++) cin >> a[i];
  int mini = a[0];
  for(int i = 1;i < n;i++) if(mini > a[i]) mini = a[i];
  bool f = false;
  for(int i = 0;i < n;i++){
    if(a[i]-mini > 1){
      cout << "No" << endl;
      return 0;
    }
    else if(a[i]-mini == 1){
      f = true;
    }
  }
  if(f){
    int count1 = 0,count2 = 0;
    for(int i = 0;i < n;i++){
      if(a[i]-mini){
        count2++;
      }
      else{
        count1++;
      }
    }
    if(count1+1 <= mini+1 && mini+1 <= count1+count2/2){
      cout << "Yes" << endl;
      return 0;
    }
  }
  else{
    if(mini+1 == n || mini <= n/2){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int n,m,cnt;
queue<pii>q;
char c[1010][1010];
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>c[i][j];
			if(c[i][j]=='#')
			{
				q.push(pii(i,j));
			}
		}
	}
	while(!q.empty())
	{
		queue<pii>qq=q;
		while(!q.empty())
		{
			q.pop();
		}
		cnt++;
		while(!qq.empty())
		{
			pii p=qq.front();
			qq.pop();
			int x=p.first,y=p.second;
			for(int i=0;i<4;i++)
			{
				int xx=x+dx[i],yy=y+dy[i];
				if(xx>=0 && xx<n && yy>=0 && yy<m && c[xx][yy]=='.')
				{
					q.push(pii(xx,yy));
					c[xx][yy]='#';
				}
			}
		}
	}
	cout<<cnt-1<<endl;
	return 0;
}

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

#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
#define sz(x) (int)(x).size()
#define nopos string::npos
#define fr(i,a,b) for(i=a;i<=b;i++)

ll ans,timee,endd;
int n,k,ar[200007],i,j;

int main()
{

    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(cin>>n>>k)
    {
        fr(i,0,n-1)
         scanf("%d",ar+i);

        timee=0;
        ans=endd=k;

        fr(i,1,n-1)
         {
             ans-=max(0LL,endd-ar[i]);
             ans+=k;
             endd=ar[i]+k;
         }

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



    return 0;
}




Measured memory_bytes: 1024
#include <iostream>

using namespace std;

const int NIL = -1; 

typedef struct {
	int degree; //度 
	int parent; 
	int left;
	int right;
} Node;

int *preSeq; //前序序列 
int *inSeq;//中序序列 

Node *Tree; //树 

int root;

int searchIn(int node,int n) {
	for(int i=0;i<n;i++) {
		if (inSeq[i] == node) {
			return i;
		}
	}
	return -1;
}

int nextParent() {
	static int pIndex = 0;
	return preSeq[pIndex++];
}

void buildTree(int n,int p,int l,int r) {
	if (l >= r) {
		return;
	}
	int c = nextParent();
	int m = searchIn(c,n);
	buildTree(n,m,l,m);
	buildTree(n,m,m+1,r);
	Tree[c].parent = (p == NIL ? p : inSeq[p]);
	
	if (p != NIL) {
	  int parent = Tree[c].parent;
	  if (p>l) {
		 Tree[parent].left = c;
		 //cout << parent << ".l" << c << endl;
 	  }
	  if (r > p) {
	  	Tree[parent].right = c;
	  	//cout << parent << ".r" << c << endl;
	  }
    }
}


void Postorder(int node) {
	if (Tree[node].left != NIL) {
	  Postorder(Tree[node].left);
    }
    if (Tree[node].right != NIL) {
	  Postorder(Tree[node].right);
    }
    cout << node;
    if (node != root) {
    	cout << " ";
	} else {
		cout << endl;
	}
}


int main() {
	int n;
	cin >> n;
	Tree = new Node[n+1];
	preSeq = new int[n+1];
	inSeq = new int[n+1];
	
	for (int i=0;i<=n;i++) {
		Tree[i].parent = Tree[i].left = Tree[i].right = NIL;
	}
	
	for (int i=0;i<n;i++) {
		cin >> preSeq[i];
	}
	
	for (int i=0;i<n;i++) {
		cin >> inSeq[i];
	}
	
	
	buildTree(n,NIL,0,n);
	
	for (int i=1;i<=n;i++) {
		if (Tree[i].parent == NIL) {
			root = i;
			break;
		}
	}
	
	Postorder(root);
	
	delete[] Tree;
	delete[] preSeq;
	delete[] inSeq;
	/*delete[] Depth;
	delete[] Heigh;*/
	
	return 0;
	
}


Measured memory_bytes: 3100
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n){
		vector<int> a(n);
		REP(i,n) cin >> a[i], a[i]--;
		int ans = 0;
		REP(i,n){
			if(a[a[i]] == i){
				ans++;
			}
		}
		cout << ans/2 << endl;
	}
	return 0;
}


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

#define ll long long
#define rep(i,n) for(int i = 0;i < (n); i++)

int main() {
	ll n;
	ll i, j;
	cin >> n;
	ll a[19][19] = { 0 };
	ll sum[20][20] = { 0 };
	double d;
	ll buf;
	ll ans = 0;
	int buf2, buf5;

	rep(i, n) {
		cin >> d;
		buf = llround(d * 1e9);
		buf2 = 0;		buf5 = 0;
		while (buf % 2 == 0) {
			buf2++;
			buf /= 2;
		}
		while (buf % 5 == 0) {
			buf5++;
			buf /= 5;
		}
		if (buf2 > 18)buf2 = 18;
		if (buf5 > 18)buf5 = 18;
		a[buf2][buf5]++;
	}
	for (i = 18; i >= 0; i--) {
		for (j = 18; j >= 0; j--) {
			sum[i][j] = a[i][j] + sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1];
		}
	}
	for (i = 18; i >= 0; i-- ) {
		for (j = 18; j >= 0; j--) {
			if (i >= 18 - i && j >= 18 - j) {
				ans += a[i][j] * (sum[18 - i][18 - j] - 1);
			}
			else {
				ans += a[i][j] * (sum[18 - i][18 - j]);
			}
			
		}
	}
	cout << ans / 2 << endl;

	return 0;
}

Measured memory_bytes: 3640
import java.io.*;
public class Main
{
  public static void main(String args[]) throws IOException
  {
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      
      int N,T;
      long X,Y,i,c=0;
      
      //System.out.println();
      
      String s[]=br.readLine().trim().split(" ");
      X=Long.parseLong(s[0]);
      Y=Long.parseLong(s[1]);
      
      for(i=X;i<=Y;i*=2)
      {
          c++;
      }
      System.out.println(c);
  }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int a;
  cin >> a;
  string s;
  cin >> s;
  if(a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
}


Measured memory_bytes: 256
import numpy as np
import sys

s=list(map(int,input().split()))
S=[]
for i in range(s[2]):
  S.append(int(input()))

P=np.array([s[1]-s[2]]*s[0])
for i in range(s[2]):
  P[S[i]-1]+=1

for i in range(s[0]):
  if P[i]<=0:
    print('No')
  else:
    print('Yes')

Measured memory_bytes: 17848
X, Y, Z, K = gets.split(' ').map(&:to_i)
a = gets.split(' ').map(&:to_i).sort.reverse
b = gets.split(' ').map(&:to_i).sort.reverse
c = gets.split(' ').map(&:to_i).sort.reverse

e = []
score = []

a.each do |i|
  b.each do |j|
    e.push(i + j)
  end
end

e.sort.reverse[0, K].each do |i|
  c.each do |j|
    score.push(i + j)
  end
end

score.sort.reverse[0, K].each do |i|
  puts i
end

Measured memory_bytes: 108784
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>

#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF ll(1e9)
#define INFL ll(1e18)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) {return c - '0';}

class CMaximumVolume {
public:
	void solve(std::istream& in, std::ostream& out) {
	    double L; in >> L;

	    out << setprecision(12) << L * L * L /27 << '\n';
	}
};


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

	CMaximumVolume solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
s=gets.to_i
a=[s]
def f(n)
    if n%2==0
        return n/2
    else
        return 3*n+1
    end
end

for i in 1..1000000
    ne=f(a[i-1])
    if a.include?(ne)
        p i+1
        break
    else
        a<<ne
    end
end

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

using namespace std;

const int maxn=1e5+5,mod=1e9+5;

typedef long long ll;

int main()
{
    int N,K,S;
    while(scanf("%d%d%d",&N,&K,&S)!=EOF)
    {
        int i;
        for(i=1; i<=K; i++)
        {
            printf("%d ",S);
        }
        if(S+1>1e9)
            S=0;
        for(i=K+1; i<=N; i++)
            printf("%d ",S+1);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1280
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
      int p = 0;
      for(int j = 0; j < i; j++) {
        if(h[j] > h[i]) p++;
      }
      if(p == 0) ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22608
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
char a,b;
int main() {
    cin>>a>>b;
    if(a=='H' && b=='H')cout<<"H"<<endl;
    if(a=='H' && b=='D')cout<<"D"<<endl;
    if(a=='D' && b=='H')cout<<"D"<<endl;
    if(a=='D' && b=='D')cout<<"H"<<endl;


    return 0;
}


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

int main(){

	string s, p;
	cin >> s >> p;
	int frag = 0;

	s += s;

	int sLen = s.length();
	int pLen = p.length();

	for(int i = 0; i < sLen - pLen; i++){
		if(s.substr(i, pLen) == p){
			frag = 1;
			break;
		}
	}

	if(frag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;
#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool istrue(ll bit,ll a[][16],ll n){
  for(int i=0;i<n;i++){
        if(bit&(1<<i)){
       //  cout<<bit<<"%%%"<<i<<endl;
            for(int j=0;j<n;j++){
           //     cout<<a[i][j]<<"-------"<<(bit&(1<<j))<<endl;
                 if(a[i][j]==1 && !(bit&(1<<j))){
                     return false ;
                 }
                 if(a[i][j]==0 && (bit&(1<<j))){
                     return false;
                 }
             }
        }
  }
return true;
}
void solve(){
ll n;
cin>>n;
ll a[16][16];
mems(a,-1);
for(ll i=0;i<n;i++){
    ll k,x,y;
    cin>>k;
    for(int j=0;j<k;j++){
        cin>>x>>y;
        x--;
        a[i][x]=y;

    }

}
ll ans=0;
for(ll bit=0;bit<(1<<n);bit++){

    if(istrue(bit,a,n))
    { 
        ll cnt=0;
        for(int i=0;i<n;i++)
        if(bit&(1<<i))cnt++;
     //   deb(cnt);
   ans=max(ans,cnt);
    }

}
cout<<ans<<endl;
  
}

int main(){
    ll t=1;
//cin>>t;
    while(t--){
     solve();
 //    cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
import Control.Monad
import Data.Function
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Vector.Unboxed as U

solve n m s lines exchanges = ans where
  ans =
    map (minimum . map snd)
    . tail
    . groupBy ((==) `on` fst)
    . ((1,0):)
    . map (\((v, _), (t, _)) -> (v, t))
    . M.toAscList
    $ dijkstra suc (1, min 2450 s)
  suc (u, s) = ex ++ [((v,s-a), b) | (v,a,b) <- adj M.! u, s>=a] where
    ex = [((u, s+c), d) | s+c <= 2450]
    (c,d) = U.fromListN n exchanges U.! (u-1)
  adj = foldr addL (M.fromList . zip [1..n] $ repeat []) lines
  addL (u,v,a,b) = M.adjust ((v,a,b):) u . M.adjust ((u,a,b):) v

main = do
  [n, m, s] <- readWords
  lines <- replicateM m $ (\[a,b,c,d]->(a,b,c,d)) <$> readWords
  exchanges <- replicateM n $ (\[a,b]->(a,b)) <$> readWords
  mapM_ print $ solve n m s lines exchanges

readWords = map read . words <$> getLine

dijkstra suc st = M.delete st res where
  res = go (M.singleton st (0, st), S.singleton (0, st))
  go (res, que)
    | S.null que = res
    | otherwise = go $ foldr f (res, S.deleteMin que) (suc u)
    where
      (du, u) = S.findMin que
      f (v, cost) (res, que)
        | v `M.member` res && fst (res M.! v) <= alt = (res, que)
        | otherwise = (M.insert v (alt, u) res, S.insert (alt, v) que)
        where alt = du + cost


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

int main() {
    int N; cin >> N;
    vector<int> X(N);
    vector<int> Y(N);
    vector<int> H(N);
    rep(i, N){
        cin >> X[i] >> Y[i] >> H[i];
    }
    bool ok = true;
    int cH;
    int cx, cy;
    for (int i = 0; i < 101; i++){
        for (int j = 0; j < 101; j++){
            ok = true;
            int hf = 0;
            int xf, yf;
            int counter = 0;
            while(hf == 0){
                xf = X[counter];
                yf = Y[counter];
                hf = H[counter];
                counter++;
                cH = hf + abs(i-xf) + abs(j-yf);
            }
            for (int n = 0; n < N; n++){
                int x = X[n];
                int y = Y[n];
                int h = H[n];
                if(h == 0){
                    int Hnow = abs(i-x) + abs(j-y);
                    if(Hnow < cH){
                        ok = false;
                        break;
                    }
                } else {
                    int Hnow = h + abs(i-x) + abs(j-y);
                    if(Hnow != cH){
                        ok = false;
                        break;
                    }
                }
            }
            if(ok){
                cx = i;
                cy = j;
                break;
            }
        }
        if(ok)break;
    }

    cout << cx << " " << cy << " " << cH << endl;

    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];

    vector<int> min_a(n), max_a(n);
    min_a[0] = a[0];
    max_a[n-1] = a[n-1];
    rep(i, 1, n) min_a[i] = min(min_a[i - 1], a[i]);
    rrep(i, n - 1, 0) max_a[i] = max(max_a[i + 1], a[i]);

    int max_diff = 0;
    rep(i, 0, n - 1)
        max_diff = max(max_diff, max_a[i + 1] - min_a[i]);
    
    map<int, int> small_cnt, big_cnt;
    rep(i, 0, n - 1)
    if (max_a[i + 1] - a[i] == max_diff)
        ++small_cnt[a[i]];
    rrep(i, n, 1)
    if (a[i] - min_a[i - 1] == max_diff)
        ++big_cnt[a[i]];

    ll ans = 0;
    for (auto s_cnt: small_cnt)
    {
        int small, cnt;
        tie(small, cnt) = s_cnt;
        ans += min(cnt, big_cnt[max_diff + small]);
        // cout << small << ' ' << cnt << ' ' << max_diff - small << ' ' << big_cnt[max_diff - small] << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
#define MOD 998244353
using namespace std;
typedef long long ll;

int main(){
    int n;  cin >> n;
    vector<int>d(n);
    int max = 0;
    rep(i, n){
        int tmp;    cin >> tmp;
        if(max < tmp)   max = tmp;
        if((i==0&&tmp!=0) || (i > 0 && tmp == 0)){
            cout << 0 << endl;
            return 0;
        }
        d[tmp]++;
    }
    ll ans = 1;
    for(int i = 1; i <= max; i++){
        rep(j, d[i]){
            ans *= d[i-1];
            ans %= MOD;
        }    
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for _ in range(n)]
Count=0
for t in a:
    Sum=0
    for i in range(m):
        Sum+=t[i]*b[i]
    if Sum+c>0:
        Count+=1
print(Count)

Measured memory_bytes: 3064
import heapq

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A = [-1 * i for i in A]

    heapq.heapify(A)

    for i in range(M):
        a = heapq.heappop(A)
        a = -1 * (-1 * a // 2)
        heapq.heappush(A, a)


    x = -1 * sum(A)
    print(x)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    double r;
    cin>>r;
    cout<<r*6.28318530717958623200;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
long long int a[100010],b[100010];
long long int s[100010];
long long int ans[100010];
long long int f[100010];
long long findd(long long x) { return f[x] == x ? x : f[x] = findd(f[x]); }
int main()
{
    long long int n,m;
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
    {
        f[i]=i;
        s[i]=1;
    }
    for(int i=0;i<m;i++)
    {
        scanf("%lld%lld",&a[i],&b[i]);
    }
    long long int sum=(n-1)*n/2;
    for(int i=m-1;i>=0;i--)
    {
        ans[i]=sum;
        int aa=findd(a[i]);
        int bb=findd(b[i]);
        if(aa!=bb)
        {
            f[bb]=aa;
            sum-=s[aa]*s[bb];
            s[aa]+=s[bb];
        }
    }
    for(int i=0;i<m;i++)
        printf("%lld\n",ans[i]);
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fixed;
const ll mod =1000000007;
int main()
{
   
        FastIO

        ll n;
        cin>>n;
        cout<<(n+1)/2;
        return 0;
    }

Measured memory_bytes: 256
#include<stdio.h>

#define ll long long

ll max(ll *p, int len){
    ll m = p[0];
    for(int i = 1; i < len; i++) if(m < p[i]) m = p[i];
    return m;
}

ll min(ll *p, int len){
    ll m = p[0];
    for(int i = 1; i < len; i++) if(m > p[i]) m = p[i];
    return m;
}

void solve(ll *a, ll h, ll w, ll *ans){
    ll s, mi;
    s = h * w;
    for(int i = 1; i < h; i++){
        a[0] = i*w;
        a[1] = (h - i) / 2 * w;
        a[2] = s - a[0] - a[1];
        mi = max(a, 3) - min(a, 3);
        if(i == 1 || ans[0] > mi) ans[0] = mi;

        a[1] = w / 2 * (h - i);
        a[2] = s - a[0] - a[1];
        mi = max(a, 3) - min(a, 3);
        if(i == 1 || ans[1] > mi) ans[1] = mi;
    }
}

int main(void){
    ll h, w;
    ll a[3], ans1[2], ans2[2];

    scanf("%lld %lld", &h, &w);
    solve(a, h, w, ans1);
    solve(a, w, h, ans2);

    printf("%lld", min(ans1,2) > min(ans2,2) ? min(ans2,2) : min(ans1,2));

    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
#include <complex>
using namespace std;
using VI = vector<int>;

int cnt(int i) {
    if (i % 2) return 0;
    return 1 + cnt(i / 2);
}

int main() {
    using P = pair<int, int>;
    vector<P> hoge;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        hoge.push_back(P(cnt(i), i));
    }
    sort(hoge.begin(), hoge.end());
    cout << hoge.back().second << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int a,b,c,d;
    int h1,h2,k1,k2;
    cin >> h1 >> h2 >> k1 >> k2;
    cin >> a >> b >> c >> d;
    int aa = a * h1 + b * h2;
    int bb = a * k1 + b * k2;
    aa += (h1 / 10) * c + (h2 / 20) * d;
    bb += (k1 / 10) * c + (k2 / 20) * d;
    if(aa > bb){
        cout << "hiroshi" << endl;
    }else if(aa < bb){
        cout << "kenjiro" << endl;
    }else{
        cout << "even" << endl;
    }
}


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

namespace program
{
    class Program
    {
        static void Main()
        {
          string s = Input.ScanStr();
          int res=0;
          for(int i=0;i<6;i++) if(s[i]=='1') res++;
          
          Console.WriteLine(res);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {


      public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);
            int k = sc.nextInt();
            int ans = 1;
            int modulo = 7;
            while (modulo%k !=0){
                  modulo = (modulo * 10 + 7) % k;
                  ans ++;
                  if(ans >=k+2){
                        ans = -1;
                        break;
                  }
            }
            System.out.println(ans);

      }


}


Measured memory_bytes: 35500
use std::io;

fn main() {

    let a500 = get_num();
    let b100 = get_num();
    let c50  = get_num();
    let x    = get_num();
    let mut pattern = 0;

    'top: for i in 0..(a500 + 1) {
        if i*500 > x { continue; }

        'middle: for j in 0..(b100 + 1) {
            if i*500 + j*100 > x { continue 'top; }

            for k in 0..(c50 + 1) {
                if 500*i + 100*j + 50*k > x { continue 'middle; }
                if 500*i + 100*j + 50*k == x {
                    pattern += 1;
                }
            }
        }
    }

    println!("{}", pattern);
}


fn get_num() -> i32 {

    let mut input_str = String::new();
    io::stdin().read_line(&mut input_str)
        .expect("Failed to read line")
        ;

    let input_num: i32 = match input_str.trim().parse() {
        Ok(num) => num ,
        Err(_)  => panic!("input wrong number."),
    };

    input_num
}


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

using namespace std;


int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a > b) {
		if (a > c && c > b) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		if (a < c && c < b) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}

	}


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define d double
int n;
d s,x,ans;
int main()
{
    scanf("%d%lf%lf",&n,&s,&x);
    d nn=n+n;
    for(res i=n;i>=1;--i) {
        ans+=s+(nn-1)/2*x;
        d dd=s+(2*s+5*x)/nn;
        d xx=x+4*x/nn;
        x=xx,s=dd,nn-=2;
    }
    printf("%.10lf\n",ans);
    return 0;
}

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

using namespace std;

int n, k;
vector<vector<int> > edges;
vector<bool> hasVisited;
vector<int> edges_color;
map<pair<int, int>, int> edges_index;

void solve(int node, int color)
{
    //cout << node << " " << color << endl;

    int next_color = color;
    for(int i = 0; i < edges[node].size(); ++i)
    {
        //cout << "loop: " << i << endl;
        int next_node = edges[node][i];
        if(!hasVisited[next_node])
        {
            next_color = (next_color + 1) % k;
            edges_color[edges_index[make_pair(node, next_node)]] = next_color;
            hasVisited[next_node] = true;
            solve(next_node, next_color);
        }
    }
}

int main()
{
    cin >> n;
    
    edges.resize(n + 1);
    hasVisited.resize(n + 1, false);
    edges_color.resize(n);

    for(int i = 1; i <= n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
        edges_index[make_pair(a, b)] = i;
        edges_index[make_pair(b, a)] = i;
    }

    k = 1;
    for(int i = 1; i <= n; ++i) {
        k = max(k, (int)edges[i].size());
    }

    hasVisited[1] = true;
    solve(1, -1);

    cout << k << endl;
    for(int i = 1; i <= n - 1; ++i) {
        cout << edges_color[i] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 18944
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>

using namespace std;

struct Info{
	Info(){
		team_id = rank = 0;
	}
	Info(int arg_id,int arg_rank){
		team_id = arg_id;
		rank = arg_rank;
	}
	int team_id,rank;
};

int main(){

	int num;
	scanf("%d",&num);

	int*table = new int[num+1];
	int*result = new int[num+1];
	for(int i = 1; i <= num;i++){
		table[i] = 0;
	}

	vector<int> V[num+1];

	int E,from,to;

	queue<Info> Q;

	scanf("%d",&E);

	for(int i = 0; i < E; i++){
		scanf("%d %d",&from,&to);
		V[from].push_back(to);
		table[to]++;
	}

	int count = 0,label = num+1;
	for(int i = 1; i <= num; i++){
		if(table[i] == 0){
			Q.push(Info(i,label));
			count++;
		}
	}

	Info tmp;

	label -= count;
	int pre_rank = 999999999,index = 1;
	bool FLG = false;

	count = 0;

	while(!Q.empty()){
		tmp = Q.front();
		Q.pop();
		count++;
		if(pre_rank == 999999999){
			pre_rank = tmp.rank;
		}else{
			if(pre_rank == tmp.rank){
				FLG = true;
			}else{
				pre_rank = tmp.rank;
			}
		}
		result[index++] = tmp.team_id;

		for(int i = 0; i < V[tmp.team_id].size(); i++){
			table[V[tmp.team_id][i]]--;
			if(table[V[tmp.team_id][i]] == 0){
				Q.push(Info(V[tmp.team_id][i],label));
			}
		}
		label -= count;
		count = 0;
	}

	for(int i = 1; i <= num; i++){
		printf("%d\n",result[i]);
	}
	if(FLG)printf("1\n");
	else{
		printf("0\n");
	}

	return 0;
}

Measured memory_bytes: 3264
#include<cstdio>
#include<algorithm>
#define _ 0
#define INF 0x7fffffff
#define mod 1000000007
#define re register
#define drep(i ,l ,r) for(re int i = (r) ; i >= (l) ; -- i)
#define rep(i ,l ,r) for(re int i = l ; i <= r ; ++ i)
#define Next(u ,i) for(re int i = head[u] ; i ; i = e[i].next)
const int N = 2e3 + 1;
int dp[N],s,sum;
int read() {
    char cc = getchar() ; int cn = 0 ,flus = 1;
    while(cc < '0' || cc > '9') {if(cc == '-') flus = - flus ; cc = getchar();}
    while(cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0' ,cc = getchar();
    return flus * cn;
}
int main()
{
	dp[0] = 1;
	rep(i ,3 ,N - 1) dp[i] = (dp[i] + (sum = (sum + dp[i - 3]) % mod)) % mod;
	s = read();
	printf("%d",dp[s]);
	return ~~(0^_^0);
}

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

using namespace std;

#define _int64 long long

int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  if (a+b==15) printf("+\n");
  else if (a*b==15) printf("*\n");
  else printf("x\n");
  return 0;
}

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

int main()
{
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  bool fl = true;
  for(int i = 0; i < min(s.size(), t.size()) && fl; ++i)
  {
    if(s[i] == t[i]) continue;
    if(s[i] < t[i])
    {
      cout << "Yes" << endl;
      return 0;
    }
    else fl = !fl;
  }
  cout << (fl && s.size() < t.size() ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=510;
int n,m;
char s[N][N],ans[N][N],anss[N][N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int k=1;k<=n;k++)
		scanf("%s",s[k]+1);
	for(int k=1;k<=n;k++)
		for(int i=1;i<=m;i++)
			ans[k][i]=anss[k][i]='.';	
	for(int k=1;k<=n;k++)
		for(int i=1;i<=m;i++)
			if(s[k][i]=='#')
				ans[k][i]=anss[k][i]='#';
	for(int k=1;k<=n;k++)
		ans[k][1]='#',anss[k][m]='#';
	for(int k=1;k<=n;k+=2)
		for(int i=1;i<m;i++)
			ans[k][i]='#';
	for(int k=2;k<=n;k+=2)
		for(int i=2;i<=m;i++)
			anss[k][i]='#';
	for(int k=1;k<=n;k++)
		ans[k][m+1]=anss[k][m+1]='\0';
	for(int k=1;k<=n;k++)
		printf("%s\n",ans[k]+1);
	for(int k=1;k<=n;k++)
		printf("%s\n",anss[k]+1);
	return 0;
}

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

int N, M;
int data[52];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    for(int i = 0; i < M; ++i){
        int a, b;
        cin >> a >> b;
        ++data[a];
        ++data[b];
    }
    for(int i = 1; i <= N; ++i){
        cout << data[i] << endl;
    }

    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int ans=1;
    int arr[n];
    cin>>arr[0];
    int mn=arr[0];
    for(int i=1;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]<mn)
            {ans++;
            mn=arr[i];}
    }
    cout<<ans;
}


Measured memory_bytes: 1024
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> list = new ArrayList<String>();

        int n = sc.nextInt();
        int l = sc.nextInt();

        for(int i = 0; i < n ; i++){
            list.add(sc.next());
            
        }
        
        Collections.sort(list);
        list.stream().forEach(s -> System.out.print(s));

        System.out.println();

    }
}

Measured memory_bytes: 27220
def partition(A,p,r):
    x=A[r][1]
    i=p-1
    for j in xrange(p,r):
        if A[j][1]<=x:
            i+=1
            A[i],A[j]=A[j],A[i]
    A[i+1],A[r]=A[r],A[i+1]
    return i+1

def quicksort(A,p,r):
    if p<r:
        q=partition(A,p,r)
        quicksort(A,p,q-1)
        quicksort(A,q+1,r)

def merge(A,left,mid,right):
    n1=mid-left
    n2=right-mid
    l=[A[left+i] for i in xrange(n1)]
    r=[A[mid+i] for i in xrange(n2)]
    l.append([0,float('inf')])
    r.append([0,float('inf')])
    i=0
    j=0
    for k in xrange(left,right):
        if l[i][1]<=r[j][1]:
            A[k]=l[i]
            i=i+1
        else:
            A[k]=r[j]
            j=j+1

def mergesort(A,left,right):
    if left+1<right:
        mid=(left+right)/2
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right)
        
n=input()
card_1=[[0]*2 for i in xrange(n)]

for i in xrange(n):
    card_1[i][0],card_1[i][1]=map(str,raw_input().split())
    card_1[i][1]=int(card_1[i][1])

card_2=list(card_1)
quicksort(card_1,0,n-1)
mergesort(card_2,0,n)

if card_1==card_2:
    print("Stable")
else :
    print("Not stable")

for i in xrange(n):
    card_1[i]=map(str,card_1[i])
    print(" ".join(card_1[i]))

Measured memory_bytes: 35412
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<string>;
using P =pair<int,int>;
const ll mod=1000000007;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

int main(){
    ll n,k;
    cin>>n>>k;
    ll tmp=n/k;
    ll tmp1=pow(tmp,3);//tmp*tmp*tmp;
    if(k%2!=0){
        cout<<tmp1<<endl;
    }else{
        ll tmp2=(n+k/2)/k;
        ll tmp3=pow(tmp2,3);//tmp2*tmp2*tmp2;
        cout<<tmp1+tmp3<<endl;
    }
}

Measured memory_bytes: 3920
import java.util.Scanner

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt

    var primes = mutable.MutableList(2)
    for (i <- 3 to 55555 by 2) {
      if (!primes.map(i % _).contains(0)) {
        primes += i
        if (primes.count(_ % 10 == 1) == N) {
          return primes.filter(_ % 10 == 1).mkString(" ")
        }
      }
    }
    throw new Exception()
  }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; ++i) cin >> L[i];
  sort(L.begin(), L.end());
  int ret = 0;
  for(int i=0; i < N-2; ++i){
    for(int j=i+1; j < N-1; ++j){
      auto c = L[i] + L[j] - 1;
      auto itr = upper_bound(L.begin()+j+1, L.end(), c);
      ret += itr - L.begin() - j - 1;
  }}
  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int i,n,p=1;
	cin>>n;
	int a[n+1]={0};
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=0;i<1000000;i++){
//		cout<<i<<" "<<p<<" "<<a[p]<<endl;;
		p=a[p];
		if(p==2){
			cout<<i+1<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	
	return 0;
}

Measured memory_bytes: 640
def main():
    h,w = map(int,input().split())
    n = int(input())
    ls = [int(x) for x in input().split()]
    ans = [[0 for _ in range(w)] for _ in range(h)]
    i,j = 0,0
    now = 1
    while len(ls)!=0:
        cnt = ls.pop(0)
        while cnt!=0:
            if j==w:
                i+=1
                j= 0
            ans[i][j] = now
            cnt-=1
            j +=1
        now +=1
    
    for i in range(h):
        if i%2==0:
            for j in range(w):
                if j == w-1:
                    print(ans[i][j])
                else:
                    print(ans[i][j],end=" ")
        else:
            for j in reversed(range(w)):
                if j == 0:
                    print(ans[i][j])
                else:
                    print(ans[i][j],end=" ")

if __name__ == '__main__':
    main()

Measured memory_bytes: 48488
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n,k;
  cin >> n >> k;
  vint X(n),Y(n),Z(n);
  rep(i,n) cin >> X[i] >> Y[i] >> Z[i];
  int ans = 0;
  rep(i,2){
    rep(j,2){
      rep(s,2){
        vint tmp(n);
        rep(t,n){
          if(i == 0) tmp[t] -= X[t];
          else tmp[t] += X[t];
          if(j == 0) tmp[t] -= Y[t];
          else tmp[t] += Y[t];
          if(s == 0) tmp[t] -= Z[t];
          else tmp[t] += Z[t];
        }
        sort(tmp.begin(),tmp.end());
        int ttmp = 0;
        for(int m = n-1;m >= n-k;m--){
          ttmp += tmp[m];
        }
        ans = max(ans,ttmp);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
k,n=map(int,input().split())
if(n==0):
    print(k)
else:
  l=list(map(int,input().split()))
  c=1
  d=0
  if(k not in l):
      print(k)
  else:  
      while(d==0):
        if(k-c not in l):
           print(k-c)
           break
        if(k+c not in l):
           print(k+c)
           break
        c=c+1
        
        
      
      

Measured memory_bytes: 9180
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


int x[30];
int y[30];

int main(){
  string s;
  string t;
  cin >> s >> t;
  int N = s.size();
  rep(i,s.size()){
    int idx_s = (int)(s[i] - 'a');
    int idx_t = (int)(t[i] - 'a');
    x[idx_s]++;
    y[idx_t]++;
  }
  sort(x,x+26,greater<int>());
  sort(y,y+26,greater<int>());
  rep(i,26){
    if(x[i] != y[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}



Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
  long long N;
  cin >> N;
  string str = to_string(N);

  int sum = 0;
  for (int i = 0; i < (int)str.size(); ++i)
  {
    sum += (str[i] - '0');
  }

  if (N%sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int H, W;
    string S[50];
    cin >> H >> W;
    REP(i, H) cin >> S[i];

    int white = 0;
    REP(y, H) REP(x, W) 
        if (S[y][x] == '.') white++;

    int d = 1;
    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};
    queue<pii> q;
    q.push({0, 0});
    while (!q.empty()) {
        set<pii> next;
        while (!q.empty()) {
            pii p = q.front(); q.pop();
            int x = p.first, y = p.second;
            if (x == W - 1 && y == H - 1) {
                cout << white - d << endl;
                return 0;
            }
            S[y][x] = '#';
            REP(i, 4) {
                int nx = x + dx[i], ny = y + dy[i];
                if (0 <= nx && nx < W &&
                    0 <= ny && ny < H &&
                    S[ny][nx] == '.')
                    next.insert({nx, ny});
            }
        }
        for (auto n : next)
            q.push(n);
        d++;
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll ;
typedef vector< ll > vi ;
typedef pair<ll, ll > ii ;
string s ;
bool ch(int i)
{
    if(s[i-1] != s[i+1] )
        return 1 ;
}
int main()
{

    cin >> s ;
    int b = 0 ;
    if(s[0] != s[s.length()-1])
    {
        if(s.length()%2 == 0)
            b=0;
        else
            b=1;
    }
    else
    {
        if((s.length())%2 == 0)
            b=1;
        else
            b=0;
    }
    if(b%2 == 0)
        cout << "Second" <<endl ;
    else
        cout << "First" <<endl ;

}


Measured memory_bytes: 512