akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

string s;

int main()
{

    cin >> s;
    int n = s.size();
    vector<int> ans(n);
    int c = 0;
    int memo = 0;
    string sss;
    int sw;
    int fff;
    for (int i = 0; i < n; i++)
    {
        sw = 0;
        if (i == 0)
        {
            memo = 0;
        }
        else if (s[i - 1] == 'L' && s[i] == 'R' || i == n - 1)
        {
            if (i == n - 1)
            {
                i++;
                //fff=n-3;
            }
            
            c = i - memo;
            sss = s.substr(memo, c);
            sw = 1;
            memo = i;
            //fff--;

        }
        
        if(s[i - 1] == 'R' && s[i] == 'L'){
            fff=i-1;
        }

        if(s[i - 2] == 'R' && s[i-1] == 'L'&&i==n){
            fff=i-2;
        }
        

        if (sw == 1)
        {
            int nnn = sss.size();
            //cout << nnn << endl;
            
            int a = nnn/2;
            int b = a;
            if(nnn%2==1){
                a++;
            }
            int f;
            for (int j = 0; j < nnn; j++)
            {
                if(sss[j]=='L'){
                    if(j%2==0){
                        int ccc=b;
                        b=a;
                        a=ccc;
                    }
                    f=j;
                    break;
                }
            }
            //cout<<"f"<<f<<endl;
            //cout<<"fff"<<fff<<endl;
            ans[fff]=a;
            ans[fff+1]=b;

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int c[11][11];
int a[334][334];

int main(int argc, char const *argv[]) {
    int h,w;
    cin >> h >> w;
    int n = 10;
    ll ans = 0;
    REP(i,10) REP(j,10) cin >> c[i][j];
    REP(k,n) REP(i,n) REP(j,n) c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
    REP(i,h) REP(j,w) {
        cin >> a[i][j];
        if (a[i][j] == -1) continue;
        ans += c[a[i][j]][1];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var N string
	fmt.Scan(&N)
	if N[0] == N[1] && N[1] == N[2] {
		fmt.Println("Yes")
	} else if N[1] == N[2] && N[2] == N[3] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()

void J(string& s){
    rotate(s.begin(), s.end() - 1, s.end());
}

void C(string& s){
    rotate(s.begin(), s.begin() + 1, s.end());
}

void E(string& s){
    int n = (int)s.size();
    swap_ranges(s.begin(), s.begin() + (n >> 1), s.begin() + (n >> 1) + (n & 1));
}

void A(string& s){
    reverse(all(s));
}

void P(string& s){
    rep(i, (int)s.size())if(isdigit(s[i]))s[i] = (s[i] + 9 - '0') % 10 + '0';
}

void M(string& s){
    rep(i, (int)s.size())if(isdigit(s[i]))s[i] = (s[i] + 1 - '0') % 10 + '0';
}

int main(){
    int n;
    cin >> n; cin.ignore();
    while(n--){
        string order, mes;
        cin >> order >> mes;
        reverse(all(order));
        rep(i, (int)order.size()){
            if(order[i] == 'J')J(mes);
            if(order[i] == 'C')C(mes);
            if(order[i] == 'E')E(mes);
            if(order[i] == 'A')A(mes);
            if(order[i] == 'P')P(mes);
            if(order[i] == 'M')M(mes);
        }
        cout << mes << '\n';
    }
    return 0;
}

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

int main(){
 string s,t,u;
 int a,b;
 cin >> s>>t;
 cin >> a>>b;
 cin >>u ;
 if (u==s)cout << a-1 << ' ' << b << endl;
 else cout <<a <<' ' <<b-1 << endl;
}

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

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a; cin >> a;
    for (int i = 1; i < 10; ++i){
        if(a%i == 0 && a/i < 10){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";


    return 0;
}

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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back

using namespace std;

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

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector <vector <int>> G(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    G[u].pb(v);
    G[v].pb(u);
  }
  vector <ll> cnt(n + 1, 0);
  while (q--) {
    int u, add;
    cin >> u >> add;
    cnt[u] += add;
  }
  function <void(int,int)> dfs = [&] (int u, int p) -> void {
    cnt[u] += cnt[p];
    for (int v: G[u]) {
      if (v == p) continue;
      dfs(v, u);
    }
  };
  dfs(1, 0);
  for (int u = 1; u <= n; u++) cout << cnt[u] << " \n"[u == n];
  return (0);
}


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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        int ans = 0;
        int N = ReadInt();
        List<List<int>> g = new List<List<int>>();
        for (int i = 0; i < N; i++)
        {
            int A = ReadInt();
            List<int> xy = new List<int>();
            for (int j = 0; j < A; j++)
            {
                int[] inputs = ReadInts();
                xy.Add(inputs[0]);
                xy.Add(inputs[1]);
            }
            g.Add(xy);
        }

        bool f = false;
        int tm;
        int[] torf = new int[N];
        for (int i = 0; i < Math.Pow(2, N); i++)
        {
            int n = i;
            tm = 0;
            for (int j = 0; j < N; j++)
            {
                torf[j] = n % 2;
                if (torf[j] == 1) tm += 1;
                n /= 2;
            }
            for (int j = 0; j < N; j++)
            {
                if (torf[j] == 1)
                {
                    for (int k = 0; k < g[j].Count / 2; k++)
                    {
                        int x = g[j][k * 2] - 1;
                        int y = g[j][k * 2 + 1];
                        if (torf[x] != y)
                        {
                            f = true;
                        }
                    }
                }
            }
            if (!f)
            {
                ans = Math.Max(ans, tm);
            }
            f = false;
        }

        return ans.ToString();
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 13268
import Foundation

var s = Int(readLine()!)!
var a: [Int] = []

while a.indexOf(s) == nil {
    a.append(s)
    if s % 2 == 0 {
        s /= 2
    } else {
        s = 3 * s + 1
    }
}
print(a.count + 1)

Measured memory_bytes: 2432
($a,$b,$c,$k)=glob<>;
$ans=0;
if($k){
	$n=$k<$a?$k:$a;
	$ans+=$n;
	$k-=$n;
}
if($k){
	$n=$k<$b?$k:$b;
	$k-=$n;
}
if($k){
	$n=$k<$c?$k:$c;
	$ans-=$n;
	$k-=$n;
}
print$ans

Measured memory_bytes: 5340
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
ans_list = [0] * N
for a in A:
    ans_list[a - 1] += 1
for i in range(N):
    print(ans_list[i])

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

int main(){
    int N;
    cin >> N;
    int maxL =0;
    int sum = 0;
    int ans = 0;
    vector<int> vec(N);
    for(int i = 0; i < N;i++){
        cin >> vec.at(i);
        sum = sum + vec.at(i);
        maxL = max(maxL,vec.at(i));
    }
    
    ans = sum - maxL;

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

    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std; int l[10000000][4]; int memo[10000000][4];int n;
int rek(int x, int a){
	if (x==n-1) return l[x][a];
	if (memo[x][a]) return memo[x][a];
	if (a==0) return memo[x][a]=l[x][a]+max(rek(x+1,a+1),rek(x+1,a+2));
	else if (a==1) return memo[x][a]=l[x][a]+max(rek(x+1,a+1),rek(x+1,a-1));
	else if (a==2) return memo[x][a]=l[x][a]+max(rek(x+1,a-1),rek(x+1,a-2));
}
int main(){
	cin >> n;
	for (int i=0; i<n; i++){
		for (int j=0; j<3; j++) cin >> l[i][j];
	}
	cout << max(rek(0,0),max(rek(0,1),rek(0,2)));
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int a,b,c;

void solve(){
	ll ans=0;
	if(b>=c)
		cout<<b+c<<endl;
	else{
		ans+=(2*b);
		c-=b;
		if(c>a){
			ans+=a+1;
		}
		else{
			ans+=c;
		}
		cout<<ans<<endl;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>a>>b>>c;
	solve();
	return 0;
}


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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


int main()
{
	fastio;
	ll dp[2010]={0};
	ll n,x,y;
	cin>>n>>x>>y;
	ll i,j,k;
	for(i=2;i<=n;i++)
	{
		for(j=1;j<i;j++)
		{
			ll mi=min(abs(x-j)+1+abs(i-y),i-j);
			dp[mi]++;
		}
	}
	for(i=1;i<=n-1;i++)
		cout<<dp[i]<<endl;

    return 0;
}





Measured memory_bytes: 3660
from collections import defaultdict


def main():
    H, W = [int(q) for q in input().split()]
    h, w = [int(q) for q in input().split()]

    print(H * W - h * W - w * H + h * w)
    # table = [
    #     [int(q) for q in input().split()]
    #     for _ in range(a)
    # ]



if __name__ == '__main__':
    main()


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int a,b;
    cin>>a>>b;
    if (a<10&&b<10)
    {
        /* code */
        cout<<a*b<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
    
    
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
//cout<<fixed<<setprecision(11);
const string nl="\n";
const ll MOD=1e9+7;
const ll ARR_MAX = 1e5+1;
const ll VAL_MAX = 1e5+1;
const ll INF=1e14;

vector<int> tree[ARR_MAX];
int dist[ARR_MAX][2];
//0 is u,1 is v
// int dist_v[ARR_MAX];

void dfs(int par,int x,int dis,int src){
	dist[x][src]=dis;
	for(int y:tree[x]){
		if(y!=par){
			dfs(x,y,dis+1,src);
		}
	}
}

void solve(){
    int n;cin>>n;
    int t_st,a_st;
    cin>>t_st>>a_st;
    t_st--;a_st--;
    for(int i=0;i<n-1;i++){
    	int u,v;cin>>u>>v;
    	u--;v--;
    	tree[u].pb(v);
    	tree[v].pb(u);
    }
    dfs(-1,t_st,0,0);
    dfs(-1,a_st,0,1);
    
    // for(int i=0;i<n;i++){
    // 	cout<<i<<" "<<dist[i][0]<<" "<<dist[i][1]<<nl;
    // }

    int mx=0;
    for(int i=0;i<n;i++){
    	if(dist[i][0]<dist[i][1]){
    		mx=max(mx,dist[i][1]-1);
    	}
    }
    cout<<mx<<nl;
}

int main(){
    fastio();
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 11648
#MLE注意！ not は使わず !=
#0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    s = []
    for _ in range(n):
        a = input().rstrip()
        s.append(a)
    print(len(set(s)))

if __name__ == '__main__':
    main()

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



int main(){
    string ans = "Three";

    int N;
    cin >> N;
    vector<char> arare(N);
    for(int i = 0;i<N;i++){
        cin >> arare.at(i);
        //cout << arare.at(i);
        if(arare.at(i) == 'Y'){
            ans = "Four";
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

string s;

int N;

int main(){
  cin >> N >> s;
  char L = 'W';
  char R = 'E';

  int ls = 0;
  int rs = 0;
  rep(i,0,N - 1){
    rs += s[i] == R;
  }
  int ans = N;
  rep(i,0,N - 1){
    if(s[i] == R) rs--;
    ans = min(ans , ls + rs);
    if(s[i] == L) ls++;
  }

  cout << ans <<endl;
}


Measured memory_bytes: 900
#include<cstdio>
#include<algorithm>
#define SZ 262144
using namespace std;
int w[201000], n;
struct Tree {
	int IT[SZ + SZ];
	void Put(int a, int b) {
		a += SZ;
		IT[a] = b;
		while (a != 1) {
			a >>= 1;
			IT[a] = max(IT[a * 2], IT[a * 2 + 1]);
		}
	}
	int Max(int b, int e) {
		b += SZ, e += SZ;
		int r = -1e9;
		while (b <= e) {
			r = max(r, max(IT[b], IT[e]));
			b = (b + 1) >> 1, e = (e - 1) >> 1;
		}
		return r;
	}
}Mn, Mx;
int  K, NO[201000], S[201000];
void Add(int b, int e) {
	if (b < 1)b = 1;
	if (e >= n - K + 1)e = n - K + 1;
	if (b > e)return;
	S[b]++, S[e + 1]--;
}
int main() {
	int i, res = 0;
	scanf("%d%d", &n,&K);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		Mn.Put(i, -w[i]);
		Mx.Put(i, w[i]);
	}
	for (i = 1; i <= n - K; i++) {
		if (-Mn.Max(i, i + K) == w[i] && w[i + K] == Mx.Max(i, i + K)) {
			NO[i + 1] = 1;
		}
	}
	for (i = 1; i < n; i++) {
		if (w[i] > w[i + 1]) {
			Add(i - K + 2, i);
		}
	}
	int ck = 0;
	for (i = 1; i <= n-K+1; i++) {
		S[i] += S[i - 1];
		if (!S[i])ck = 1;
		if (!NO[i] && S[i])res++;
	}
	printf("%d\n", res+ck);
}

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

int main(){
    unsigned long N;
    cin >> N;
    string s;
    cin >> s;
    unsigned long a{0};
    char c{'{'};
    for(const auto& i : s){
        if(c != i){
            c = i;
            ++a;
        }
    }
    cout << a << endl;
    return 0;
}

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

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

    vector<string> s(n);
    int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
    for(int i = 0; i < n; i++) {
        cin >> s.at(i);
        if (s.at(i) == "AC") c0++;
        if (s.at(i) == "WA") c1++;
        if (s.at(i) == "TLE") c2++;
        if (s.at(i) == "RE") c3++;
    }

    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;

    return 0;
}


Measured memory_bytes: 6376
/*
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
*/
#include <bits/stdc++.h>

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

int main()
{
    int ans,n,k;
    cin >> n >> k;
    ans = (int)(log(n) / log(k) + 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
using namespace std;
int main(){
    int y,m,d;
    while(scanf("%d%d%d",&y,&m,&d) != EOF){
        if(y <= 1868 && m <= 9 && d <= 7){
            printf("pre-meiji\n");
            continue;
        }
        if(y == 1989 && m == 1 && d >= 8 || y > 1989){
            y -= 1988;
            printf("heisei %d %d %d\n",y,m,d);
        }
        else if(y == 1926 && m == 12 && d >= 25 || y > 1926){
            y -= 1925;
            printf("showa %d %d %d\n",y,m,d);
        }
        else if(y == 1912 && m == 7 && d >= 30 || y == 1912 && m >= 8 || y > 1912){
            y -= 1911;
            printf("taisho %d %d %d\n",y,m,d);
        }
        else if(y == 1868 && m == 9 && d >= 8 || y == 1868 && m >= 10 || y > 1868){
            y -= 1867;
            printf("meiji %d %d %d\n",y,m,d);
        }
    }
    return 0;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  int A,B,C,D,K;
  cin>>A>>B>>C>>D>>K;
  int t = C*60+D-(A*60+B)-K;
  cout<<t<<endl;
}

Measured memory_bytes: 3636
from queue import deque

n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
li = [[] for _ in range(n)]

for i,j in l:
    i,j = i-1,j-1
    li[i].append(j)
    li[j].append(i)

stack = 0
color = [0]*n

work_queue = deque([])
visited = [False]*n
visited[0] = True
color_list = [0]*n
work_queue.append(stack)
path = {}
ma = 0
while work_queue:
    here = work_queue.popleft()
    color = 1
    for i in li[here]:
        if visited[i]:
            continue
        work_queue.append(i)
        visited[i] = True
        if color_list[here] == color:
            color += 1
        path[(here,i)] = color
        color_list[i] = color
        ma = max(ma,color)
        color += 1

print(ma)
for i,j in l:
    i,j = i-1,j-1
    print(path[(i,j)])

Measured memory_bytes: 99668
N=int(input())
A=[]
max1=0
max2=0
for i in range(N):
	A.append(int(input()))
	
max1=max(A)
cnt=0
for i in range(N):
	if max1 is A[i]:
		cnt += 1
	elif max2 < A[i]:
		max2 = A[i]	
		
for i in range(N):
	if cnt >= 2:
		print(max1)
	else:	
		if max1 == A[i]:
			print(max2)
		else:
			print(max1)


Measured memory_bytes: 12532
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> vec;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    vec.push_back(s);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < n; i++) {
    cout << vec[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int k, i, cnt;
    long n;
    int h[100000];
    
    scanf("%ld %d", &n, &k);
    for(i = 0; i < n;  i++){
        scanf("%d", &h[i]);
    }
    
    cnt = 0;
    
    for(i = 0; i < n; i++){
        if(h[i] >= k){
            cnt = cnt + 1;
        }
    }
    
    printf("%d", cnt);
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;
 
 
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  int r;
  cin >> r;
  cout << r*r << endl;
}

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

string s;

unsigned c_len(char c, unsigned& i) {
	unsigned start = i;
	while (s[i] == c) {
		i++;
	}
	return i - start;
}

int main () {
	unsigned result = 0;
	cin >> s;
	
	for (unsigned i = 0; i < s.size();) {
		unsigned lj = c_len('J', i);
		unsigned lo = c_len('O', i);
		unsigned li = c_len('I', i);
		
		if (lo <= lj && lo <= li) {
			result = max(result, lo);
		}
	}
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 2052
#include <cstdio>
// B - 81

using namespace std;

int main() {
    int N,i,j;

    scanf("%d",&N);

    for (i = 1;i <= 9;i++) {
        for (j = 1;j <= 9;j++) {
            if (i * j == N) {
                printf("Yes\n");
                return 0;
            }
        }
    }

    printf("No\n");

    return 0;
}

Measured memory_bytes: 128
import math
from functools import reduce
import fractions


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


N, X = map(int, input().split())
x = list(map(int, input().split()))
dif = [abs(X - x[0])]

if N > 1:
    for i in range(N - 1):
        dif.append(x[i + 1] - x[i])
print(abs(gcd_list(dif)))


Measured memory_bytes: 16316
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,cnt,cnt2; cin>>n;
    vector<int> a(n,0);
    vector<int> b(n,0);
    set<int> ans;
    rep(i,n) cin>>a[i];
    for(int i=n-1;i>=0;i--){
        cnt=2*i+1; cnt2=0;
        while(cnt<n){
            cnt2+=b[cnt];
            cnt+=i+1;
        }
        b[i]=(a[i]+cnt2)%2;
        if(b[i]) ans.insert(i+1);
    }
    cout<<ans.size()<<endl;
    int i=0;
    for(auto q : ans){
        i++;
        cout<<q<<(i==ans.size() ? "\n" : " ");
    }
}

Measured memory_bytes: 8448
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

static const int NMAX = 1e5;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

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

    ll n,k;
    cin >> n >> k;
    vector<int> v(n+1);
    ll sum =0;
    for(int i =0; i < n; ++i)
    {
        cin >> v[i];
        sum+=v[i];
    }
    vector<ll> fact;
    for(int i =1; i*i <=sum; ++i)
    {
        if(sum % i == 0)
        {
            fact.push_back(i);
            fact.push_back(sum/i);
        }
    }

    ll ans =1;
    for(int i =0; i < (int) fact.size(); ++i)
    {
        multiset<ll> vals;
        ll totalCost = 0;
        ll used = 0;

        for(int j = 0; j < n; ++j)
        {
            vals.insert(v[j] % fact[i]);
            totalCost += fact[i] - (v[j] % fact[i]);
        }

        for(auto it = vals.begin(); it != vals.end(); ++it)
        {
            used += *it;
            totalCost -= fact[i] - *it;
            if(used == totalCost && used <= k)
            {
                ans = max(ans, fact[i]);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

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

int main( )
{
    long long int k, i, j, l;
    long long int s = 0;
    cin >> k;
    for (i = 1; i <= k; i++) {
        for (j = 1; j <= k; j++) {
            for (l = 1; l <= k; l++) {
                s += __gcd(__gcd(i, j), l);
            }
        }
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 3632
def abc061_c():
    s = str(input())

    l = []
    def saiki(i,moji):
        if i == len(s)-1:
            #print(moji)
            l.append(sum(list(map(int,moji.split("+")))))
            return

        #いれる
        saiki(i+1,moji+"+"+s[i+1])
        #いれない
        saiki(i+1,moji+s[i+1])

    saiki(0,s[0])

    print(sum(l))


abc061_c()

Measured memory_bytes: 9200
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;
#define toInt(_char) _char - '0'

using namespace std;
//
// Created by karayuu on 2018-12-18.
//

int main() {
    int c[5][4][11] = {0};
    int n = 0;
    cin >> n;

    FOR(i, 0, n) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        c[b][f][r] += v;
    }

    FORN(i, 1, 4) {
        FORN(j, 1, 3) {
            FORN(k, 1, 10) {
                cout << " " << c[i][j][k];
            }
            cout << endl;
        }
        if (i != 4) cout << "####################" << endl;
    }
}


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

int main(void) {
  lint N;
  cin >> N;
  lint m = 1e16;
  for(lint i = 1; i * i <= N; i++) {
    if(N % i) continue;
    m = min(m, i + N / i - 2);
  }
  cout << m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n;
vector<string> memo;
void dp(string cur,int maxsofar){
    if (cur.size()==n){
        memo.pb(cur);
        return;
    }
    for (int i=0;i<=maxsofar+1;i++){
        string temp=cur;
        temp.pb('a'+i);
        dp(temp,maxsofar+(i==maxsofar+1));
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    string temp;
    temp.pb('a');
    dp(temp,0);
    //cout<<memo.size()<<'\n';
    for (auto i:memo){
        cout<<i<<'\n';
    }
}


Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int sum=0;
    int temp=n;
    while(temp){
        sum+=temp%10;
        temp/=10;
    }
    if(n%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int M = 998244353;
ll dp[3005],a[3005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,s;
    cin>>n>>s;
    for(int i=1;i<=n;i++) cin>>a[i];
    ll ans = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=s;j>=a[i];j--) dp[j] = (dp[j]+dp[j-a[i]])%M;
        dp[a[i]] = (dp[a[i]]+i)%M;
        ans = (ans+dp[s]*(n-i+1))%M;
        dp[s] = 0;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
    int n, total = 0;
    scanf("%d", &n);
    int d[n];
    for(int i = 0; i < n; i++) scanf("%d", &d[i]);
    for(int i = 0; i < n-1; i++) {
        for(int j = i+1; j < n; j++) {
            total += d[i] * d[j];
        }
    }
    printf("%d\n", total);
    return 0;
}

Measured memory_bytes: 128
import time

x,y = map(int,raw_input().split())
b = int(min(x,y))
a = int(max(x,y))

def gcd(a,b):
    if a % b != 0:
        r = a % b
        return gcd(b,r)
    else:
        print(b)

gcd(a,b)
		

Measured memory_bytes: 6420
#include<bits/stdc++.h>
#define pb push_back
#define ins insert
#define F first
#define S second
#define var auto
using namespace std;
typedef long long ll;
const int Max = 1e5 + 10;
const int Mod = 1e9 + 7;

int main()
{
	int n;cin >> n;
	vector<pair<int,pair<int,int> > > vec;
	for(int i = 0; i < n ; i++)
	{
		int t , x, y;cin >> t >> x >> y;
		vec.pb({t,{x , y}});
	}
	sort(vec.begin() , vec.end());
	pair<int,pair<int,int> > lastP = {0 , {0 , 0}};
	bool ok = true;

	for(var v : vec)
	{
		pair<int,pair<int,int> > delta = {v.F - lastP.F , { abs(v.S.F - lastP.S.F) , abs(v.S.S - lastP.S.S) }};
		
		ok &= (delta.S.S + delta.S.F) <= delta.F && (delta.S.S + delta.S.F) % 2 == delta.F % 2;

		lastP = v;
	}
	if(ok)
		cout << "Yes\n";
	else
		cout << "No\n";
}



Measured memory_bytes: 4872
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define ll long long
using namespace std;

int main() {
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    cout << max(0,min(y2,y1)-max(x1,x2)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(void){
    int n;cin>>n;
    vector<int>v(n,0);vector<int>J(n,-1);
    vector<vector<pair<int,int>>>G(n);
    int x,y;ll z;
    rep(i,n-1){
        cin>>x>>y>>z;x--;y--;z%=2;
        G[x].push_back(make_pair(y,z));
        G[y].push_back(make_pair(x,z));
    }
    int ju=0;
    queue<pair<int,int>>q;J[0]=0;v[0]=1;
    rep(i,G[0].size()){q.push(make_pair(G[0][i].first,G[0][i].second));}
    while(q.empty()==false){
        int f=q.front().first;int s=q.front().second;q.pop();
        if(s%2==0)v[f]=1;
        rep(i,G[f].size()){
            if(J[G[f][i].first]==-1)
            q.push(make_pair(G[f][i].first,s+G[f][i].second));
            J[G[f][i].first]=0;
        }
    }
    rep(i,n)cout<<v[i]<<endl;
}

Measured memory_bytes: 7168
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			String str1 = sc.next();
			if(str1.equals("-")) break;
			LinkedList<Character> red = new LinkedList<Character>();
			LinkedList<Character> green = new LinkedList<Character>();
			LinkedList<Character> bottom = new LinkedList<Character>();
			LinkedList<Character> ans = new LinkedList<Character>();
			for(int i =0; i < str1.length(); i++){
				red.addFirst(str1.charAt(i));
			}
			str1 = sc.next();
			for(int i =0; i < str1.length(); i++){
				green.addFirst(str1.charAt(i));
			}
			str1 = sc.next();
			for(int i =0; i < str1.length(); i++){
				bottom.addFirst(str1.charAt(i));
			}
			char cand = green.removeLast();
			while(! red.isEmpty() || ! green.isEmpty()){
				if(bottom.contains(cand)){
					cand = red.removeLast();
				}
				else{
					ans.addLast(cand);
					cand = green.removeLast();
				}
			}
			if(!bottom.contains(cand)){
				ans.addLast(cand);
			}
			//print
			for(int i=0; i < ans.size();i++){
				System.out.print(ans.get(i));
			}
			System.out.println();
		}
	}

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

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;

ll m_pow(int p, int n){
    if(n==0) return 1;
    else if(n%2){
        ll now = m_pow(p,(n-1)/2);
        return ((now*now)%MOD)*p%MOD;
    }else{
        ll now = m_pow(p,n/2);
        return now*now%MOD;
    }
}

ll m_comb(int n, int k){
    if(n<k) return 0;
    else if(n==k || k==0) return 1;
    vector<ll> fact(n+1);
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1]*i%MOD;
    return ( (fact[n]*m_pow(fact[k],MOD-2))%MOD ) * m_pow(fact[n-k],MOD-2) % MOD;
}

int main(){
    int s;
    cin >> s;
    ll ans = 0;
    if(s==1 || s==2) ans = 0;
    else{
        int bar = 0;
        while(1){
            int ball = s-3*(bar+1);
            if(ball<0) break;
            //cout << bar+ball << " " << ball << endl;
            ans += m_comb(bar+ball,ball);
            //cout << m_comb(bar+ball,ball) << endl;
            ans %= MOD;
            bar++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	before := sc.nextStr()
	set := make(map[string]bool)
	set[before] = true
	ok := true
	for i := 1; i < N; i++ {
		next := sc.nextStr()
		if set[next] || before[len(before)-1] != next[0] {
			ok = false
		}
		set[next] = true
		before = next
	}

	if ok {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
	wtr.Flush()
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int func(int num) {
	int a = 1;
	rep(i, log10(num))a *= 10;
	return a;
}
signed main()
{
	int N;
	cin >> N;
	map<pair<int, int>, int>m;
	for (int i = 1; i <= N; i++) {
		int top, bottom;
		top = i / func(i);
		bottom = i % 10;
		pair<int, int>p = make_pair(top, bottom);
		m[p]++;
	}
	int ans = 0;
	rep(i, 10) {
		rep(j, 10) {
			pair<int, int>p1 = make_pair(i, j);
			pair<int, int>p2 = make_pair(j, i);
			ans += m[p1] * m[p2];
		}
	}
	cout << ans;
}

Measured memory_bytes: 896
main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  print $ if odd k
          then length [x | x <- [1..n], x `mod` k == 0] ^ 3
          else length [x | x <- [1..n], x `mod` k == 0] ^ 3 + length [x | x <- [1..n], x `mod` k == k `div` 2] ^ 3


Measured memory_bytes: 892
#include <stdio.h>

int main(void){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0)
        puts("Yes");
    else
        puts("No");
    return 0;
}

Measured memory_bytes: 580
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {

        var hw = Input.ar;
        var hhww = Input.ar;
        WriteLine((hw[0]-hhww[0])*(hw[1]-hhww[1]));
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 11092
import numpy as np 
from sys import stdin, setrecursionlimit
 

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

t = 1
tpass = [1]
k = 0
j = 1
temp3 = [0]*N
for i in range(N):
    temp = A[t-1] 
    if i == K-1:
        print(temp)
        exit()
    if temp3[temp-1] != 0 :
        idx = tpass.index(temp)
        l = len(tpass)
        j = -1
        break
    else:
        
        t = temp
        temp3[t-1] = 1
        tpass.append(temp)
        k += 1

try:
    a = K - k
    loop = l - idx
    b = a % loop 
    temp2 = tpass[idx:]
    ans = temp2[b-1]
    print(ans)
except:
    pass

Measured memory_bytes: 51076
'use strict';
(function(stdin) {
	var lines  = stdin.toString().split('\n');
	var result = (function(params,data) {

		var A = creatVector(data,0,params[0]);
		var B = creatVector(data,params[0],params[0] + params[1]);

		var result = [];
		for(var i = 0; i < params[0]; i++) {
			var line = [];
			for(var j = 0; j < params[2]; j++) {
				var sum = 0;
				for(var k = 0; k < params[1]; k++) {
					sum += A[i][k] * B[k][j];
				}
				line.push(sum);
			}
			result.push(line.join(' '));
		}
		return result.join('\n');

		function creatVector(data,beginIndex,endIndex) {
			return data.slice(beginIndex,endIndex)
				.map(function(v) { 
					return v.split(' ').map(Number);
			});
		}

	}(
		lines.shift().split(' ').map(Number)
		,lines
		));

	console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

int main(){
  int i=0,array[26]={},b,j;
  char c;
  string s;
  cin>>s;
  
  for(c='a';c<='z';c++){
      for(j=0;j<s.size();j++){
      array[i]+=(s[j]==c);
    }
    if(array[i]%2==1){
      cout<<"No"<<endl;
      return 0;
    }
    i++;
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2;
}


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

int main(){
    
    int W, H;
    cin>>W>>H;
    
    int x, y, r;
    cin>>x>>y>>r;
    
    if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H)
cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

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

int main(){
    int h, w; cin >> h >> w;
    vector<string> maze(h);
    rep(i,h) cin >> maze[i];
    int ans = 0;
    rep(si,h)rep(sj,w){
        if(maze[si][sj]=='#') continue;
        vector<vector<int> > dist(h,vector<int>(w,-1));
        queue<P> q;
        q.push(P(si,sj));
        dist[si][sj] = 0;
        while(!q.empty()){
            P current_pos = q.front();
            q.pop();
            int x = current_pos.first;
            int y = current_pos.second;
            rep(dir,4){
                int nx = x + dx[dir];
                int ny = y + dy[dir]; 
                if(nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
                if(maze[nx][ny] == '#') continue;
                if(dist[nx][ny] == -1){
                    q.push(P(nx,ny));
                    dist[nx][ny] = dist[x][y] + 1;
                }
            }
        }
        rep(i,h)rep(j,w){
            if(dist[i][j] == -1) continue;
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll INF=1e18;
const int maxn=(2e5)+10;
int n,p1,p2;
ll m,a[maxn],cnt;
bool solve(ll mid) {
	ll res=0;
	int pos;
	if (mid==0) {
		res=cnt*(n-cnt)+cnt*(cnt-1)/2;
		res+=(ll)p1*(n-p2+1);
	} else if (mid>0) {
		pos=p1+1;
		for (int i=1;i<=p1;i++) {
			while (pos>=2&&a[pos-1]*a[i]<=mid) pos--;
			res+=p1-pos+1;
		}
		pos=n;
		for (int i=p2;i<=n;i++) {
			while (pos>=p2&&a[pos]*a[i]>mid) pos--;
			res+=pos-p2+1;
		//	printf("%d %d\n",i,pos);
		}
		for (int i=1;i<=n;i++)
			if (a[i]!=0&&a[i]*a[i]<=mid) res--;
		//printf("%lld\n",res);
		res/=2;
		//printf("%lld\n",res);
		res+=cnt*(n-cnt)+cnt*(cnt-1)/2;
		res+=(ll)p1*(n-p2+1);
	} else {
		pos=n+1;
		for (int i=p1;i>=1;i--) {
			while (pos>p2&&a[pos-1]*a[i]<=mid) pos--;
			res+=n-pos+1;
		//	printf("%d %d\n",i,pos);
		}
	}
	//printf("res=%lld\n",res);
	return res>=m;
}
int main() {
//	freopen("1.txt","r",stdin);
	read(n);
	read(m);
	for (int i=1;i<=n;i++) {
		read(a[i]);
		if (a[i]==0) cnt++;
	}
	sort(a+1,a+n+1);
	//for (int i=1;i<=n;i++) printf("%lld ",a[i]); printf("\n");
	p2=n+1;
	for (int i=1;i<=n;i++) {
		if (a[i]<0) p1=max(p1,i);
		if (a[i]>0) p2=min(p2,i);
	}
	//printf("p1=%d p2=%d\n",p1,p2);
//	printf("%d\n",solve(-12));
	//return 0;
	ll l=-INF,r=INF,mid,res;
	while (l<=r) {
		mid=(l+r)/2;
		if (solve(mid)) res=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",res);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
    cin>>a>>b;
    if(a>0 || (abs(b)-abs(a))%2){
	cout<<"Positive"<<endl;
	}
    else if(a==0 || (a<0 && b>0)){
	cout<<"Zero"<<endl;
	}
    else{
	cout<<"Negative"<<endl;
	}
    return 0;
}

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

#define MAX_N 100000

using namespace std;

int n;

string s;

int cod[MAX_N + 1];
int k;

void out()
{
    cout << "-1\n";

    exit(0);
}

void verif()
{
    if(s[n] == '1')
        out();

    if(s[1] == '0')
        out();

    for(int i = 1; i < n - i; i ++)
    {
        if(s[i] != s[n - i])
            out();
    }
}

int main()
{
    cin >> s;
    n = s.size();

    s.resize(n + 1);
    for(int i = n; i >= 1; i --)
        s[i] = s[i - 1];

    verif();

    int last = 1;
    for(int i = 1; i <= n; i ++)
    {
        if(s[i] == '1' || (i == n))
        {
            int cate = i - last;
            cod[i] = (++ k);

            if(i > 1)
            {
                cout << cod[i] << " " << cod[last] << "\n";

                for(int j = 2; j <= cate; j ++)
                {
                    (++ k);
                    cout << cod[i] << " " << k << "\n";
                }
            }

            last = i;
        }
    }

    return 0;
}


Measured memory_bytes: 2048
import sys
input = sys.stdin.readline
N = int(input())
A = []
xy = []
for i in range(N):
    a = int(input())
    A.append(a)
    temp = []
    for j in range(a):
        x,y= map(int,input().split())
        temp.append((x,y))
    xy.append(temp)

ans = 0
for i in range(2**N):
    b = bin(i)[2:].zfill(N)
    valid = True
    for i in range(N):
        if b[i] == '0':
            continue
        else:
            for x,y in xy[i]:
                if int(b[x-1]) != y:
                    valid = False
                    break
    if valid:
        ans = max(ans, b.count('1'))

print(ans)


Measured memory_bytes: 45404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

class BIT{
public:
	vector<int> bit;
	int M;
	// 1-index
	BIT(int M):
		bit(vector<int>(M+1, 0)), M(M) {}

	int sum(int i) {
		if (!i) return 0;
		return bit[i] + sum(i-(i&-i));
	}

	void add(int i, int x) {
		if (i > M) return;
		bit[i] += x;
		add(i+(i&-i), x);
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,q;
	cin >> n >> q;
	BIT bit(n);
	FOR(j,0,q){
		int com,x,y;
		cin >> com >> x >> y;
		if(com){
			cout << bit.sum(y)-bit.sum(x-1) << endl;
		}else{
			bit.add(x,y);
		}
	}
}


Measured memory_bytes: 3336
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;

typedef vector<double> point;
typedef const point &rpoint;

point add(rpoint p1, rpoint p2){
	point p(3);
	for(int i = 0; i < 3; ++i)
		p[i] = p1[i] + p2[i];
	return p;
}

point sub(rpoint p1, rpoint p2){
	point p(3);
	for(int i = 0; i < 3; ++i)
		p[i] = p1[i] - p2[i];
	return p;
}

point mul(double t, rpoint p2){
	point p(3);
	for(int i = 0; i < 3; ++i)
		p[i] = t * p2[i];
	return p;
}

double abs(rpoint p){
	double s = 0.0;
	for(int i = 0; i < 3; ++i)
		s += p[i] * p[i];
	return sqrt(s);
}

int main(){
	int n;
	point p(3);

	while( scanf("%d", &n), n != 0 ){
		vector<point> v;
		v.reserve(n);

		for(int i = 0; i < n; ++i){
			for(int j = 0; j < 3; ++j){
				scanf("%lf", &p[j]);
			}
			v.push_back(p);
		}
		
		double mv = 0.5;
		double minr;
		while( mv > 1e-8 ){
			for(int k = 0; k < 50; ++k){
				minr = -1.0;
				int mini = -1;
				
				for(int i = 0; i < n; ++i){
					double r = abs(sub(v[i], p));
					if( minr < r ){
						minr = r;
						mini = i;
					}
				}
				
				p = add(p, mul(mv, sub(v[mini], p) ) );
			}
			
			mv *= 0.5;
		}
		
		printf("%.10f\n", minr);
	}
}

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

using namespace std;

typedef long long ll;

int main(){
	int x, n;
	cin >> x >> n;
	set<int> st;
	for(int i = 0; i < n; i++){
		int cur;
		cin >> cur;
		st.insert(cur);
	}
	int sol = INT_MAX;
	for(int i = x; i <= 101; i++){
		if(st.count(i)) continue;
		sol = min(sol, abs(x - i));
	}
	for(int i = x; i >= 0; i--){
		if(st.count(i)) continue;
		sol = min(sol, abs(x - i));
	}
	if(st.count(x - sol)) cout << x + sol << '\n';
	else cout << x - sol << '\n';
}


Measured memory_bytes: 3520