akhauriyash/Code-Regression huggingface dataset:
W,H,N = map(int,input().split())
x = []
y = []
a = []
for i in range(N):
    x1,y1,a1 = [int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    a.append(a1)

block = [[True for i in range(W)]for j in range(H)]#block[x][y]
#debug
#for i in range(H):#x = W
    #  for j in range(W):#y = H
    #   print(block[i][j])
#   print(i,j)
for i in range(len(a)):
    if a[i] == 1:
        for j in range(x[i]):
            for k in range(H):
                block[k][j]=False
    elif a[i] == 2:
        for j in range(x[i],W):
            for k in range(H):
                block[k][j] = False
    elif a[i] == 3:
        for j in range(W):
            for k in range(y[i]):
                block[k][j]=False
    elif a[i] == 4:
        for j in range(W):
            for k in range(y[i],H):
                block[k][j]=False
count = 0

for i in range(W):
    for j in range(H):
        if block[j][i] == True:
            count+=1

print(count)



Measured memory_bytes: 3188
#include<iostream>
#include<set>
#include<map>
#include<cmath>
using namespace std;

int main() {
	int n, a;
	double ave = 0;
	cin >> n;
	set<int>st;
	map<int, int>mp;
	for (int i = 0; i < n; i++) {
		cin >> a;
		ave += a;
		if (st.find(a) == st.end()) {
			mp[a] = i;
		}
		st.insert(a);
	}
	ave /= n;
	double min = 99999999;
	int num1, num2;
	bool flag = true;
	for (auto itr = st.begin(); itr != st.end(); itr++) {
		double temp = abs(*itr - ave);
		if (temp < min) {
			num1 = *itr;
			min = temp;
		}
		if (temp == min) {
			num2 = *itr;
			flag = false;
		}
	}
	if (flag) {
		cout << mp[num1] << endl;
	} else {
		int a = mp[num1];
		int b = mp[num2];
		if (a > b)a = b;
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

const MOD = 1000000007

/* input */
var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
    sc.Scan()
    n, _ := strconv.Atoi(sc.Text())
    return n
}

/* fact */
func fact(x int, factMem map[int]int) int {
    if x == 0 {
        return 1
    }
    value, ok := factMem[x]
    if ok {
        return value
    }
    factMem[x] = x * fact(x - 1, factMem) % MOD
    return factMem[x]
}

/* inverse */
func inverse(x int, factMem map[int]int, inverseMem map[int]int) int {
    value, ok := inverseMem[x]
    if ok {
        return value
    }
    inverseMem[x] = power(fact(x, factMem), MOD - 2, MOD)
    return inverseMem[x]
}

/* power */
func power(x, y, z int) int {
    if y == 0 {
        return 1
    }
    if y % 2 == 0 {
        return power(x * x % z, y / 2, z)
    } else {
        return x * power(x, y - 1, z) % z
    }
    return 0
}

/* comb */
func comb(x int, y int, factMem map[int]int, inverseMem map[int]int) int {
    if x < y || y < 0 {
        return 0
    }
    return fact(x, factMem) * inverse(y, factMem, inverseMem) % MOD * inverse(x - y, factMem, inverseMem) % MOD
}

func main() {
    sc.Split(bufio.ScanWords)
    n := readInt()
    dic := make(map[int]int)
    left, right := 0, 0
    for i := 0; i < n + 1; i++ {
        a := readInt()
        index, ok := dic[a]
        if ok {
            left = index
            right = i
            break
        } else {
            dic[a] = i
        }

    }

    rem := n - right + left
    factMem := make(map[int]int)
    inverseMem := make(map[int]int)
    for i := 0; i < n + 1; i++ {
        fact(i, factMem)
    }
    wrt := bufio.NewWriter(os.Stdout)
    for i := 0; i < n + 1; i++ {
        fmt.Fprintln(wrt, (MOD + comb(n + 1, i + 1, factMem, inverseMem) - comb(rem, i, factMem, inverseMem)) % MOD)
        wrt.Flush()
    }
}

Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mod 1000000007

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin>>n>>k;
    if(k==1)
        cout<<0;
    else
        cout<<(n-(k-1))-1;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

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

const int MX = 105;
const int MM = 1000000007;

int N, W;
pii D[MX];

ll solve(int x){
	int w0 = D[1].first;
	ll T[MX][MX*3] = {};
	for(int t = 1; t <= N; t++){
		int w = D[t].first - w0, v = D[t].second;
		for(int i = x; i >= 1; i--){
			for(int j = w; j <= min(x*3ll, W-(ll)w0*x); j++){
				T[i][j] = max(T[i][j], T[i-1][j-w] + v);
			}
		}
	}
	ll mx = 0;
	for(int i = 0; i <= N*3; i++) mx = max(mx, T[x][i]);
	return mx;
}

int main()
{
	scanf("%d%d", &N, &W);
	for(int i = 1; i <= N; i++) scanf("%d%d", &D[i].first, &D[i].second);
	ll mx = 0;
	for(int i = 1; i <= N; i++){
		mx = max(mx, solve(i));
	}
	printf("%lld\n", mx);
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
  int key;
  struct node *p,*left,*right;
}node;
typedef struct node* Node;
void insert(int);
Node find(int);
void delNode(Node);
void inorder(Node);
void preorder(Node);
Node minimum(Node);
Node successor(Node);
Node root,NIL;

int main(){
  int i,m,k;
  char string[8];
  scanf("%d",&m);
  for(i = 0; i < m; i++){
    scanf("%s",string);
   if(strcmp(string,"insert") == 0){
      scanf("%d",&k);
      insert(k);
    }
    else if(strcmp(string,"find") == 0){
      scanf("%d",&k);
      if(NIL == find(k))printf("no\n");
      else printf("yes\n");
    }
    else if(strcmp(string,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(strcmp(string,"delete") == 0){
      scanf("%d",&k);
      delNode(find(k));
    }
  }
  return 0;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(node));
  z->left = NIL;
  z->right = NIL;
  z->key = k;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

Node find(int k){
  Node x = root;
  while(x != NIL && x->key != k){
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  return x;
}

void delNode(Node z){
  Node del,x;
  if(z->left == NIL || z->right == NIL) del = z;
  else del = successor(z);

  if(del->left != NIL) x = del->left;
  else x = del->right;

  if(x != NIL) x->p = del->p;

  if(del->p == NIL) root = x;
  else if(del == del->p->left) del->p->left = x;
  else if(del == del->p->right) del->p->right = x;

  if(del != z) z->key = del->key;
}

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

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

Node successor(Node x){
  Node y;
  if(x->right != NIL) return minimum(x->right);

  y = x->p;
  while(y != NIL && x == y->right){
    x = y;
    y = y->p;
  }
  return y;
}

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

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

int main(){
	string ss;
	cin >> ss;
	deque<char> s(ss.size());
	rep(i, ss.size()) s.at(i) = ss.at(i);
	ll q;
	cin >> q;
    ll cnt = 0;
  
      for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		
		if (t == 1) {
          cnt++;
		}
		if (t == 2) {
			int f;
			char c;
			cin >> f >> c;
			
			if ((f+cnt) % 2 == 1) {
				s.push_front(c);
			}
			if ((f+cnt) % 2 == 0) {
				s.push_back(c);
			}
         
		}
	}	
	if (cnt % 2 == 0) {
      for (int i = 0; i < s.size(); i++) {
      cout << s.at(i);
    }
    }
  if (cnt % 2 == 1) {
    for (int i = 0; i < s.size(); i++) {
      cout << s.at(s.size() - i-1);
    }
  }
  cout << endl;
}


Measured memory_bytes: 896
from random import randint
A=26

D=int(input())

C=[0]+list(map(int,input().split())) #減る満足度のベース
S=[0]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度

for i in range(1,D+1):
    S[i]=[0]+list(map(int,input().split()))

T=[0]
for i in range(D):
    T.append(int(input()))

L=[0]*(A+1)

X=0
for d in range(1,D+1):
    X+=S[d][T[d]]
    L[T[d]]=d
    
    for j in range(1,A+1):
        X-=C[j]*(d-L[j])

    print(X)


Measured memory_bytes: 78376
#include<bits/stdc++.h>
#define ll                long long int
#define ld                long double
#define F                 first
#define S                 second
#define C                 continue
#define G                 goto done
#define pb                push_back
#define pf                push_front
#define ppb               pop_back
#define ppf               pop_front
#define sz                size()
#define pi                acos(-1.0)
#define mod               1000000007
#define maxe              *max_element
#define mine              *min_element
#define min3(a,b,c)       min(a,min(b,c))
#define max3(a,b,c)       max(a,max(b,c))
#define min4(a,b,c,d)     min(a,min(b,min(c,d)))
#define max4(a,b,c,d)     max(a,max(b,max(c,d)))
#define mem(a,b)          memset(a,b,sizeof(a))
#define all(a)            (a).begin(),(a).end()
#define gcd(a,b)          __gcd(a,b)
#define lcm(a,b)          ((a)*((b)/gcd(a,b)))
#define case(a)           cout<<"Case "<<(a)<<": "
#define point(a)          fixed<<setprecision(a)
#define get(a)            for(auto &x:a) cin>>x;
#define print(a)          for(auto x:a) cout<<x<<" "; cout<<endl;
#define uniq(a)           sort(all(a)); (a).erase(unique((a).begin(),(a).end()),(a).end())
#define big(a)            transform((a).begin(),(a).end(),(a).begin(),::toupper)
#define small(a)          transform((a).begin(),(a).end(),(a).begin(),::tolower)
#define ischar(a)         (('a'<=a&&a<='z')('A'<=a&&a<='Z'))
#define isvowel(a)        (a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
#define fast              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tc                int test; cin>>test; while(test--)
using namespace std;
int main()
{
    ll k,n; cin>>k>>n; ll a[n]; get(a);
    map<ll,ll>mp;
    for(ll i=0;i<n;i++) mp[a[i]]++;
    if(mp[k]==0)
    {
        cout<<k; return 0;
    }
    ll m=k,mm=k;
    while(1)
    {
        m--;
        mm++;
        if(mp[m]==0 || mp[mm]==0) break;
    }
    if(mp[m]==0) cout<<m;
    else cout<<mm;
}




















Measured memory_bytes: 3644
//__professor_
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define lld long double
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define test ll t;cin>>t;while(t--)
#define mod 1000000007
#define inf 1000000000000000001
const double pi =3.141592653589793238463;
using namespace std;

int main()
{
	FAST;
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	for(ll i=0;i<n;i++)
	cin>>arr[i];
	ll dp[n];
	memset(dp,0,sizeof(dp));
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);

	for(ll i=2;i<n;i++)
	{
		ll ans=INT_MAX;
		for(ll j=1;j<=k && (i-j)>=0;j++)
		{
			ans=min(ans,dp[i-j]+abs(arr[i]-arr[i-j]));
		}
		dp[i]=ans;
		
	}

	cout<<dp[n-1]<<endl;

	return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vct vector<ll>
#define umap unordered_map<ll,ll>
#define mpp map<ll,ll>
#define stt set<ll>
#define pir pair<ll,ll>
#define vpp vector<pair<ll,ll> >

ll poww(ll x,ll y,ll m){   
    ll res=1;
    while(y){if(y%2==0){x=(x*x)%m;y=y/2;}else{res=(res*x)%m;y--;}}
    return res;
}
void prt(vct v)
{
    // cout<<"\n";
    for(ll i=0;i<v.size();i++)cout<<v[i]<<" ";
    cout<<"\n";
    
}
vct siev(ll n)
{
    vct ans;ll ar[n+1];
    memset(ar,-1,sizeof(ar));ar[0]=0;ar[1]=0;
    for(ll i=2;i<=n;i++)
    {if(ar[i]==-1){ans.push_back(i);ar[i]=1;for(ll j=2*i;j<=n;j=j+i)ar[j]=0;}}
    return ans;
}
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)if(n%i==0)return false;
    return true;
}

vct divsors(ll n)
{
    vct ans;ans.push_back(1);
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            ans.push_back(i);
            if(i!=(n/i))ans.push_back(n/i);
        }
    }
    return ans;
}
ll cnd(ll n){ll cnt=0;while(n){cnt++;n=n/10;}return cnt;}

ll fibdig(ll n)
{
    if (n == 1) 
        return 1; 
    long double d = (n * log10(1.6180339887498948)) -((log10(5)) / 2);
    return ceil(d); 
}


ll t;ll n,m,k;
// vct v;
ll t1,t2;
ll mod=1000000007;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // setprecision(10);
    cin>>n>>k;
    // ll hg[n];
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        cin>>t;
        if(t>=k)ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
n,c,k=map(int,input().split())
a=[int(input()) for _ in range(n)]

a.sort()
count=0
c_count=1
box=a[0]
for i in range(1,n):
    if c_count<c:
        if a[i]-box<=k:
            count+=1
            c_count+=1
        else:
            box=a[i]
            c_count=1
    else:
        box=a[i]
        c_count=1
    #print(count)
print(n-count)


Measured memory_bytes: 7384
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#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) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n,m,k;
  cin >> n >> m >> k;

  vector<int> a(n);
  REP(i,n) cin >> a[i];

  vec dp(n+1,0),cnt(n+1);
  FOR(i,1,k+1){
    vec tmp(n+1,0);
    int s = 0, t = 0;
    REP(j,n){
      while(t != s && dp[cnt[t-1]] < dp[j]) t--;
      cnt[t] = j;
      t++;
      if(j-cnt[s]+1 > m) s++;
      if(i>j+1) continue;
      tmp[j+1] = dp[cnt[s]] + a[j]*i;
    }
    dp = tmp;
  }
  
  int ans = 0;
  REP(i,n+1) ans = max(ans,dp[i]);

  cout << ans << endl;

  return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n;
    cin >> n;
    string s;
    cin >> s;

    if (n % 2 != 0) {
        cout << "No" << endl;
        exit(0);
    }

    REP(i, n / 2) {
        if (s.at(i) != s.at(i + n / 2)) {
            cout << "No" << endl;
            exit(0);
        }
    }

    MSG("Yes")
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

up = sorted(p)
cntup = 0
for i in range(n):
  if(up[i] == p[i]):
    cntup += 1

if(cntup == n-2 or cntup == n):
  print("YES")
else:
  print("NO")


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=1000000007,N=200500;
int n,a[N],b[N],cnt[4050][4050],ifac[N],fac[N],inv[N];
int C(int n,int m){return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;}
void prework(int n)
{
    fac[0]=1;for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
    inv[1]=1;for(int i=2;i<=n;i++)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    ifac[0]=1;for(int i=1;i<=n;i++)ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
}
int qmod(int x){return x>=mod?x-mod:x;}
int main()
{
    scanf("%d",&n);
    prework(10000);int wn=0;
    for(int i=1;i<=n;i++)scanf("%d%d",a+i,b+i),wn=max(wn,max(a[i],b[i]));
    ++wn;
    for(int i=1;i<=n;i++)cnt[a[i]+wn][b[i]+wn]++,cnt[wn-a[i]][wn-b[i]]++;
    int ans=0;
    for(int i=1;i<=wn*2;i++)
        for(int j=1;j<=wn*2;j++)
        {
            int f=qmod(cnt[i-1][j]+cnt[i][j-1]);
            if(i>wn&&j>wn)ans=(ans+1ll*cnt[i][j]*f)%mod,cnt[i][j]=f;
            else cnt[i][j]=qmod(cnt[i][j]+f);
        }
    for(int i=1;i<=n;i++)ans=(ans-C(2*(a[i]+b[i]),2*a[i]))%mod;
    ans=1ll*ans*((mod+1)>>1)%mod;
    cout<<(ans+mod)%mod<<endl;
}

Measured memory_bytes: 68648
#include <stdio.h>

int main(void) {
	int variety, num, sum = 0;
	int price[1000] = { 0 };

	scanf("%d %d", &variety, &num);
	for (int i = 0; i < variety; i++) {
		scanf("%d", &price[i]);
	}

	int min = price[0];
	for (int i = 0; i < variety - 1; i++) {
		for (int j = variety - 1; j > i; j--) {
			if (price[j-1] > price[j]) {
				int temp = price[j];
				price[j] = price[j - 1];
				price[j - 1] = temp;

			}
		}
	}

	for (int i = 0; i < num; i++) {
		sum += price[i];
	}

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 2140
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    else:
        arc = ""
        sum = m + f
        if m == -1 or f == -1:
            arc = "F"
        elif sum >= 80:
            arc = "A"
        elif 65 <= sum and sum < 80:
            arc = "B"
        elif 50 <= sum and sum < 65:
            arc = "C"
        elif 30 <= sum and sum < 50:
            arc = "D"
            if r >= 50:
                arc = "C"
        elif sum < 30:
            arc = "F"

        print("{}".format(arc))


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
using I = long long;
int main() {
  int N;
  cin >> N;
  vector<I> A(N), B(N);
  for(auto i=0; i<N; ++i) cin >> A[i] >> B[i];
  I r = 1e18;
  for(auto i=0; i<N; ++i) if(A[i] > B[i]) r = min(r, B[i]);
  cout << max<I>(0ll, accumulate(begin(A), end(A), 0ll) - r) << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

struct edge{int to; ll cost;};
typedef pair<ll,int> P;

void dijkstra(int s,vector<ll>&d,const vector<vector<edge>>&G){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d.begin(),d.end(),INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main() {
    int N; cin >> N;
    vector<string> v(N);
    REP(i,N) cin >> v[i];
    vector<vector<edge>> G(N);
    vector<ll> d(N);
    REP(i,N)REP(j,N) {
        if(v[i][j]=='1') G[i].push_back((edge){j,1});
    }
    ll ans = 0;
    REP(i,N) {
        dijkstra(i,d,G);
        ll tmp = 0;
        REP(j,N) tmp = max(tmp, d[j]);
        bool check = true;
        REP(j,N)REP(k,N) {
            if(v[j][k]=='1'&&d[j]==d[k]) check = false;
        }
        if(check) ans = max(ans, tmp);
    }
    cout << (ans?ans+1:-1) << endl;
}

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

int main (){
    int a, b, c;
    cin>>a>>b>>c;
    if (b-c>-1){
        cout<<"delicious"<<endl;
    }
    else if(c-b<a+1){
        cout<<"safe"<<endl;
    }
    else{
        cout<<"dangerous"<<endl;
    }
    
}


Measured memory_bytes: 256
A=[[0,0,0],[0,0,255],[0,255,0],[0,255,255],[255,0,0],[255,0,255],[255,255,0],[255,255,255]]
B=['black','blue','lime','aqua','red','fuchsia','yellow','white']
while(l=gets)!="0\n"do puts B[A.length.times.map{|i|[A[i].zip(l[1..-1].unpack("a2a2a2").map{|e|e.to_i(16)}).map{|e|(e[0]-e[1])**2}.reduce(&:+),i]}.min[1]]end

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

int main() {
  int d;
  cin >> d;
  vector<int> c(26);
  rep(i, 26) cin >> c[i];
  vector<vector<int>> s(d, vector<int>(26));
  rep(i, d) rep(j, 26) cin >> s[i][j];
  ll score = 0;
  vector<int> last(26, 0);
  for (int i = 1; i < d+1; i++) {
    // i日目
    rep(k, 26) {
      score -= c[k] * (i - last[k]);
    }
    ll temp = score;
    int temp_type = 0;

    rep(j, 26) {
      // Type jのコンテストを開催したとすると
      ll cur = score;
      cur += s[i-1][j];
      cur += c[j] * (i - last[j]); // 引いた分、戻す
      if (cur > temp) {
        temp = cur;
        temp_type = j;
      }
    }
    score = temp;
    last[temp_type] = i;
    cout << temp_type + 1 << '\n';

  }
  //cout << score << '\n';
  return 0;
}

Measured memory_bytes: 3684
import Foundation

let topLine = readLine()!.components(separatedBy: " ").map{ Int($0)! }
let middleLine = readLine()!.components(separatedBy: " ").map{ Int($0)! }
let buttomLine = readLine()!.components(separatedBy: " ").map{ Int($0)! }
let N = Int(readLine()!)!
var numbers: [Int] = []
var hit: [Bool] = [false,false,false,false,false,false,false,false,false]

for i in 0...N - 1{
    numbers.append(Int(readLine()!)!)
}

for i in 0...2 {
    for j in 0...N - 1{
        if topLine[i] == numbers[j]{
            hit[i] = true
            
        } else if middleLine[i] == numbers[j] {
            hit[i + 3] = true
            
        } else if buttomLine[i] == numbers[j] {
            hit[i + 6] = true
            
        }
    }
}

if hit[0] == true && hit[1] == true && hit[2] == true  {
    print("Yes")
} else if hit[3] == true && hit[4] == true && hit[5] == true{
    print("Yes")
} else if hit[6] == true && hit[7] == true && hit[8] == true{
    print("Yes")
} else if hit[0] == true && hit[3] == true && hit[6] == true{
    print("Yes")
} else if hit[1] == true && hit[4] == true && hit[7] == true{
    print("Yes")
} else if hit[2] == true && hit[5] == true && hit[8] == true{
    print("Yes")
} else if hit[0] == true && hit[4] == true && hit[8] == true{
    print("Yes")
} else if hit[2] == true && hit[4] == true && hit[6] == true{
    print("Yes")
} else {
    print("No")
}

Measured memory_bytes: 14072
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){

		int N = scan.nextInt();
		int[] arr = new int[N];
		for(int i = 0; i < N; i++){
			arr[i] = scan.nextInt();
		}

		for(int i = 0; i < N; i++){
			if(i != N - 1){
				System.out.printf("%d ", arr[i]);
			}else{
				System.out.printf("%d\n", arr[i]);
			}
		}

		// ??????????????????
		for(int i = 1; i < N; i++){
			int v = arr[i];
			int j = i - 1;
			// j???0??\???????????????????´?arr[j]????\\???????´?????????§?????????
			while(j >= 0 && arr[j] > v){
				arr[j+1] = arr[j];
				j--;
				arr[j+1] = v;
			}
			for(int k = 0; k < N; k++){
				if(k != N - 1){
					System.out.printf("%d ", arr[k]);
				}else{
					System.out.printf("%d\n", arr[k]);
				}
			}
		}
	}
}

Measured memory_bytes: 44132
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String input;

        while((input = br.readLine()) != null){
            String[] line = input.split(",");

            int[] distance = new int[12];
            int sum = 0;
            int velA;
            int velB;

            for(int i = 0; i < 10; i++){
                distance[i] = Integer.parseInt(line[i]);
                sum += distance[i];
            }

            velA = Integer.parseInt(line[10]);
            velB = Integer.parseInt(line[11]);

            double intersec = (double)sum / (velA + velB) * velA;

            int forward = 0;
            int pos = 0;
            do{
                forward += distance[pos];
                pos++;
            }while(forward < intersec);

            System.out.println(pos);

        }

    }
}


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

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

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> A(N), B(N);
    REP(i, N) {
        int a;
        cin >> a;
        A.at(i) = make_pair(a, i);
    }
    REP(i, N) {
        int a;
        cin >> a;
        B.at(i) = make_pair(a, i);
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    vector<pair<int, int>> ary(N);
    bool flag = false;
    REP(i, N) {
        if (A.at(i).first > B.at(i).first) {
            cout << "No" << endl;
            exit(0);
        } else {
            ary.at(i) = make_pair(A.at(i).second, B.at(i).second);
            if (!flag && i != 0 && A.at(i) <= B.at(i - 1))
                flag = true;
        }
    }

    sort(ary.begin(), ary.end());
    vector<bool> check(N, false);
    check.at(0) = true;
    int idx = ary.at(0).second;
    int cnt = 1;

    while (check.at(idx) == false) {
        check.at(idx) = true;
        idx = ary.at(idx).second;
        cnt++;
    }
    if (cnt != N || flag == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 2560
n = gets.to_i
a = gets.split.map(&:to_i).sort_by{|x| -x}
if a.include?(0)
  puts '0'
  exit
end
b = 1
a.each do |x|
  b *= x
  if b > 10 ** 18
    puts '-1'
    exit
  end    
end
puts b

Measured memory_bytes: 24680
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define pb push_back
const long long mod=1e9+7;
int main()
{
    ll t,n,x,i,j;
    cin>>n;
    vector<ll>v;

    while(n--)
    {
        cin>>x;
        v.pb(x);
    }

    ll sum=0;

    for(i=0; i<63; i++)
    {
        ll one=0,zero=0;
        for(j=0; j<v.size(); j++)
        {
            if(v[j]%2==0)
                zero++;
            else
                one++;
            v[j]/=2;
        }
        one%=mod;
        zero%=mod;

        sum= (sum+(((zero*one)%mod * ((1ll<<i)%mod))%mod))%mod;
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 6384
import static java.lang.Math.max;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	char[] x;
	char[] y;
	boolean[][] flag;
	int[][] c;
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			
			String X = sc.next();
			x = X.toCharArray();
			String Y = sc.next();
			y = Y.toCharArray();
			
			flag = new boolean[X.length()][Y.length()];
			c = new int[X.length()][Y.length()];
			
			int ans = LCS(X.length()-1, Y.length()-1);
			System.out.println(ans);
		}
		
		sc.close();
	}
	
	int LCS(int i, int j) {
		if(i == -1 || j == -1)
			return 0;
		
		if(flag[i][j] == true)
			return c[i][j];
		
		flag[i][j] = true;
		
		if(x[i] == y[j])
			return c[i][j] = LCS(i-1, j-1)+1;
		
		return c[i][j] = max(LCS(i-1,j), LCS(i,j-1));
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

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


Measured memory_bytes: 71448
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, k; cin >> n >> k;
    ll x[n];
    rep(i, n){
        cin >> x[i];
    }

    if(n == 1){
        cout << abs(x[0]) << endl;
        return 0;
    }

    ll vmin = 1e18;
    ll vtemp;
    rep(i, n - k + 1){
        if(x[i]*x[i+k-1] >= 0){
            vtemp = max(abs(x[i]), abs(x[i+k-1]));
        }
        else{
            vtemp = max(abs(x[i]), abs(x[i+k-1])) 
                    + min(abs(x[i]), abs(x[i+k-1])) * 2;
        }

        vmin = min(vtemp, vmin);
    }

    cout << vmin << endl;



    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main()
{
    int A, B;
    std::cin >> A >> B;

    int fee = B;
    if (A <= 5)
    {
        fee = 0;
    }
    else if (A <= 12)
    {
        fee /= 2;
    }

    std::cout << fee << std::endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

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

signed main()
{
    int n; cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    rep(i,n) cin >> x[i] >> u[i];

    double ans = 0;
    rep(i,n){
        if (u[i]=="JPY")
            ans += x[i];
        else
            ans += x[i] * 380000;
    }

    cout << fixed << setprecision(9);
    cout << ans << endl;

    return 0;
}


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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n; std::cin >> n;
  vector<pi> robots;
  rep(i, n) {
    int x, l, r; std::cin >> x >> l;
    r = x + l;
    l = x - l;
    pi robot;
    robot.fi = r, robot.se = l;
    robots.pb(robot);
  }
  sort(rng(robots));
  int ans = 0, cur = -inf;
  rep(i, n) {
    if (cur <= robots[i].se) {
      ans++;
      cur = robots[i].fi;
    }
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 1400
def main():
  num = list(map(int,input().split()))
  if num[0]-num[1]>0 and (num[0]-num[1])%2==0:
    print(num[0]-int((num[0]-num[1])/2))
  elif num[1]-num[0]>0 and (num[1]-num[0])%2==0:
    print(num[1]-int((num[1]-num[0])/2))
  else:
    print("IMPOSSIBLE")
main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,s,i,j,ans=0;
    scanf("%d %d",&k,&s);
    for(i=0;i<=k;i++)
    {
        for(j=0;j<=k;j++)
        {
            int ij=s-i-j;
            if(ij<=k && ij>=0) ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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



int main() {
	int i, j, k, l;
	int m, h, g;
	int f = 0;
	int n;
	char a[5];
	char b[5];


	scanf("%s", a);
	scanf("%s", b);

	if (a[0] == b[0]) {
		f++;
	}
	if (a[1] == b[1]) {
		f++;
	}
	if (a[2] == b[2]) {
		f++;
	}

	printf("%d", f);

	return 0;
}

Measured memory_bytes: 128
A=int(input())
B=int(input())
C=int(input())
X=int(input())
counter=0

for a in range(A+1):
    a_total=a*500
    for b in range(B+1):
        b_total=b*100
        for c in range(C+1):
            c_total=c*50
            total_amount=(a_total+b_total+c_total)
            if X==total_amount:
                counter=counter+1
print(counter)

Measured memory_bytes: 9072
import collections
a = int(input())
ppp = [0]
ppp = list(map(int,input().split()))
count = 0             
data = collections.Counter(ppp)
aaa = 0
for k, v in data.items():
    if int(k) > int(v):
        aaa = v
        count += aaa
    elif int(k) < int(v):
        aaa = v-k
        count += aaa
    
print(count)

Measured memory_bytes: 18672
#include <bits/stdc++.h>
using namespace std;
int num[]={59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1};
                                         //右辺の要素数が[]の中に自動で入る
int count(int a, int cnt){// ここが動的計画法
    if(!a)return cnt;// !a は a == 0 ということ
    for(int i = 0;i < 12;i++)if(a >= num[i]){
        if(i == 11)return cnt + a;
        return min(count(a - num[i], cnt + 1),count(a - num[i + 1], cnt + 1));
                     //1番大きな引き出し方と2番目を同時に試して少ない方が答え
    }
}
int main(){
    int a,cnt=0;
    cin>>a;
    cout<<count(a,0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	a+=b;
	int x=1,num=0;
	for(register int i=a.size()-1;i>=0;i--){
		num+=(a[i]-'0')*x;
		x*=10;
	}
	if(int(sqrt(num))==sqrt(num))  cout<<"Yes"<<endl;
	else  cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);
  if(n==1){
    printf("Hello World\n");
  }else{
    int a,b;
    scanf("%d\n%d\n",&a,&b);
    printf("%d\n",a+b);
  }
  
  return 0;
}
  


Measured memory_bytes: 1696
# https://atcoder.jp/contests/abc098/tasks/arc098_b
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


class CumSum1d:
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        from itertools import accumulate
        self.ls_accum = [0] + list(accumulate(ls))

    def total(self, i, j):
        # もとの配列lsにおける[i,j)の中合計
        return self.ls_accum[j] - self.ls_accum[i]


class CumXor1d:
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        self.ls_accum = [0]
        for l in ls:
            self.ls_accum.append(l ^ self.ls_accum[-1])

    def total(self, i, j):
        # もとの配列lsにおける[i,j)の中合計
        return self.ls_accum[j] ^ self.ls_accum[i]


from collections import deque
N = int(input())
A = read_ints()

# どの[ii,jj)を持ってきてもxorsumとaddsumが成り立つ最長の区間[i,j)に対してn=j-iに対してn * (n - 1) // 2 + n をすれば良い ? いや若干ダブりが存在して微妙に合わない
# 一旦最長の区間のidxを取得してダブリの区間はその後に考慮しよう?
# 前処理としてxorとadd両方の累積xorと累積和を作ってあげる
# でi,jを尺取法などで取得すれば良い

cumsum = CumSum1d(A)
cumxor = CumXor1d(A)
# 尺取法でaddとxorした区間和が一致する一番長い[i,j)を取ってくる
ids = []
r_pre = 0
for l in range(0, N):
    r = max(r_pre, l + 1)  # ありえるidxに
    while r <= N and cumsum.total(l, r) == cumxor.total(l, r):
        r += 1  # totalのrはすでに半開区間 それを満たさなくなったときのrとしたら半開区間の更にその先に行く
    if r != r_pre:
        r_pre = r
        ids.append((l, r - 1))


ans = 0
for l, r in ids:
    n = r - l
    ans += n + n * (n - 1) // 2
# さらにダブっている部分を取り除く
if len(ids) > 1:
    for (_, r), (l, _) in zip(ids, ids[1:]):
        n = max(0, r - l)
        ans -= n + n * (n - 1) // 2


print(ans)


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

typedef struct node {
    int key;
    struct node *prev, *next;
} Node;

Node *nil;

void Init() {
    nil = (Node *)malloc( sizeof(Node) );
    nil->next = nil;
    nil->prev = nil;
}

//?????°??????????????\??°??´????????????
void Insert( int key ) {
    Node *x = (Node *)malloc( sizeof(Node) );
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

void Delete( Node *t ) {
    if ( t == nil ) return; // ??´??????????????????
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free( t );
}

void DeleteFirst() {
    Delete( nil->next );
}

void DeleteLast() {
    Delete( nil->prev );
}

Node * ListSearch( int key ) {
    Node *cur = nil->next;
    while ( cur != nil && cur->key != key ) {
        cur = cur->next;
    }
    return cur;
}

void DeleteKey( int key ) {
    // ??????????´¢??°?????????
    Delete( ListSearch(key) );
}

void PrintList() {
    Node *cur = nil->next;
    while ( cur != nil ) {
        if ( cur != nil->next ) {
            printf( " " );
        }
        printf( "%d", cur->key );
        cur = cur->next;
    }
    printf( "\n" );
}

int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf( "%d", &n );
    Init();
    
    for ( i = 0; i < n; i++ ) {
        scanf( "%s%d", &com, &key );
        if ( com[0] == 'i' ) {
            Insert( key );
            np++;
            size++;
        } else if ( com[0] == 'd' ) {
            if ( com[6] == 'F' ) {
                DeleteFirst();
            } else if ( com[6] == 'L' ) {
                DeleteLast();
            } else {
                DeleteKey( key );
                nd++;
            }
            size--;
        }
    }

    PrintList();
    
    return 0;
}

Measured memory_bytes: 31788
while True:
    A,B = map(list, input().split())
    if len(A) == 1:
        break
    hit=0
    blowPlusHit=0
    for i in range(4):
        if A[i] == B[i]:
            hit+=1
        for j in range(4):
            if A[i]==B[j]:
                blowPlusHit += 1
    print(f"{hit} {blowPlusHit-hit}")


Measured memory_bytes: 5584
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<vector<int>> abc(N,vector<int>(3));
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      cin >> abc.at(i).at(j);
    }
  }

  vector<vector<int>> dp(N+1,vector<int>(3,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      int x=(j+1)%3;
      int y=(j+2)%3;
      dp.at(i+1).at(j)=max(dp.at(i).at(x)+abc.at(i).at(j),dp.at(i).at(y)+abc.at(i).at(j));
    }
  }
  int ans=0;
  for(int i=0;i<3;i++)  ans=max(ans,dp.at(N).at(i));
  cout << ans << endl;

  return 0;
}

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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	
	for(int i=0;i>=0;i++){
		c-=b;
		if(c<=0){
			cout<<"Yes";
			break;
		}
		
		a-=d;
		if(a<=0){
			cout<<"No";
			break;
		}
	}
	return 0;
}

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

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class BEcho {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        string S;
        in>>S;
        string t = S.substr(0, N/2);
        if(t+t==S) out<<"Yes\n";
        else out<<"No\n";
    }
};


int main() {
	BEcho solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,count=1,mx=0;
    cin>>n;
    long long a[n];
    for(long long i=0;i<n;i++)
        cin>>a[i];
    for(long long i=1;i<n;i++)
    {
        if(a[i]<=a[i-1])
            count++;
        else
        {
            mx=max(count,mx);
            count=1;

        }
    }
    mx=max(count,mx);
    cout<<mx-1<<"\n";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb emplace_back
#define pi pair<int,int>
using namespace std;
const int maxn = 1e5 + 4;

int n;
int a[maxn][3], dp[maxn][3];

int main(){
	cin>>n;
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < 3; ++j){
			cin>>a[i][j];
		}
	}
	for (int i = 0; i < 3; ++i){
		dp[0][i] = a[0][i];
	}
	for (int i = 1; i < n; ++i){
		for (int j = 0; j < 3; ++j){
			dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + a[i][j];
		}
	}
	cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]})<<'\n';

}

Measured memory_bytes: 2560
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;

vector<vector<int>> v;
vector<bool> d;
int ans = 0;

void dfs(int p) {
  d[p] = true;
  bool isallreached = true;
  for (int i = 0; i < d.size(); ++i) {
    if (d[i] == false)isallreached = false;
  }
  if (isallreached) {
    ans++;
    d[p] = false;
    return;
  }

  for (int i = 0; i < v[p].size(); ++i)
  {
    if (d[v[p][i]] == false)dfs(v[p][i]);
  }


  d[p] = false;

}

int main()
{
  int n, m;
  cin  >> n >> m;
  v = vector<vector<int>>(n); //頂点aの接続先頂点リスト
  d = vector<bool>(n, false);

  for (int i = 0; i < m; ++i)
  {
    int a, b;
    cin >> a >> b;
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
  }



  int cnt = 0;
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < n; ++i) {
      if (v[i].size() == 1) {
        // cout << i << "-" << v[i][0] << endl;
        cnt++;
        for (int k = 0; k < v[v[i][0]].size(); k++) {
          if (v[v[i][0]][k] == i)v[v[i][0]].erase(v[v[i][0]].begin() + k);
        }

        v[i].pop_back();
      }
    }
  }



  cout << cnt << endl;

  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for(int i=0;i<m;i++){
    int a , b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  vector<int> dist(n, -1);
  queue<int>  que;
  vector<int> ans(n,-1);
  
  dist[0] = 0;
  que.push(0);
  
  while(!que.empty()){
    int v = que.front();
    que.pop();
     
    for(int nv : g[v]){
      if(dist[nv] != -1) continue;
      
      dist[nv] = dist[v] +1;
      ans[nv] = v;
      que.push(nv);
      
      }
    }
  cout << "Yes" << endl;
  for(int i=0;i<n;i++){
    if(i==0) continue;
    int s = ans[i];
    ++s;
    cout << s <<endl;
  }
  
  
}


Measured memory_bytes: 10728
#include <stdio.h>
int main(){
  char s[10];
  int c,i,k;
  c = 0;
  scanf("%s",s);
  for(i=0;i<4;i++){
    for(k=0;k<4;k++){
      if(s[i] == s[k]) c++;
    }
  }
  if(c == 8) printf("Yes");
  else printf("No");
}

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

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

    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    
    for (int i = 0; i < N; i++)
    {
        cout << S[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
N=int(input())
L=list(map(int,input().split()))
MAX, SUM=0,0
for i in range(N): #4個分
  if MAX<L[i]:
    MAX=L[i]
for i in range(N):
  SUM=SUM+L[i]
if MAX>=SUM-MAX:
  print('No')
else:
  print('Yes')

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		String S = scan.next();
		int an = 0;
		int b = 0;
        for(int i=0 ;i<a;i++ ){

        	
        	if('I'==S.charAt(i)){
        		an++;
        	}else{
        		an--;
        	}

        	if(b<an){
        		b=an;
        	}
        }
        System.out.println(b);
    }
}

Measured memory_bytes: 23892