akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
const int INF = 1001001001;
vector<int> to[100005];

int main() {
  int n, m;
  cin >> n >> m;
  rep (i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    // 行き先が全部入ってる
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(n, INF); // 距離
  vector<int> pre(n, -1); // 直前の頂点
  dist[0] = 0;
  q.push(0);
  while(!q.empty()) {
    int v = q.front(); q.pop();
    for (int u: to[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }

  cout << "Yes" << endl;
  rep (i, n){
    if (i == 0) continue;
    int ans = pre[i];
    ans++;
    cout << ans << endl; 
  }
}

Measured memory_bytes: 10668
import sys,heapq
n,*a=list(map(int,sys.stdin.read().split()))
def f(l,m,n,d):
	s=0
	q=[]
	for i in range(l,m,d):
		s+=a[i]
		heapq.heappush(q,a[i]*d)
	r=[s]
	for i in range(m,n,d):
		s+=a[i]
		heapq.heappush(q,a[i]*d)
		s-=heapq.heappop(q)*d
		r.append(s)
	return r
ra=f(0,n,2*n,1)
rb=reversed(f(3*n-1,2*n-1,n-1,-1))
print(max(x-y for x,y in zip(ra,rb)))

Measured memory_bytes: 127576
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define pll pair <ll,ll>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

// FOR DEBUGGING
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", ";
	else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const int mod = 1e9+7;
const long double pi = acos(-1);
const ll INF = 1e15;

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	string s,t;
	cin >> s >> t;
	int ans = 0;
	rep0(i,s.size()) if(s[i]!=t[i]) ans++;
	cout << ans;

	return;
}

int main(){

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

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H(0), W(0);
  cin >> H >> W;
  string str[H];
  for(int i = 0; i < H; i++)
  {
    cin >> str[i];
  }
  

  vector<vector<int>> n(H, vector<int>(W, 0));  
  for(int i = 0; i < H; i++)
  {
   	for(int j = 0; j < W; j++)
    {
    	if( str[i].at(j) == '#')
        { 
          // increment the nb for neighbour 8 cells  
          for(int idxi = max(i - 1, 0); idxi <= min(i + 1, H - 1); idxi++)
          {
            for(int idxj = max(j - 1, 0); idxj <= min(j + 1, W - 1); idxj++)
            {
               if( (idxi != i || idxj != j) && str[idxi].at(idxj) != '#' ) 
               {
                  n.at(idxi).at(idxj)++;
               }
            }
          }
          
        }
    }   
  }
  
  for(int i = 0; i < H; i++)
  {
   	for(int j = 0; j < W; j++)
    {
      if( str[i].at(j) == '#')
      {
        cout << '#';
      }
      else
      {
        cout << n.at(i).at(j);
      }
    }  
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m;
    cin >> n >> m;
    const ll N = 1<<n;

    vl a(m), b(m), c(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        rep(j, b[i]) {
            ll x;
            cin >> x;
            x--;
            c[i] |= 1<<x;
        }
    }

    vvl dp(m+1, vl(N,INF));  // dp[i+1][S] : 鍵iまで(iは0-index)で開いた宝箱の集合がSとなるときの費用の最小値
    dp[0][0] = 0;
    rep(i, m) {
        rep(s, N) {
            chmin(dp[i+1][s], dp[i][s]);
            chmin(dp[i+1][s | c[i]], dp[i][s] + a[i]);
        }
    }
        
    if(dp[m][N-1] == INF) {
        out(-1);
    }
    else {
        out(dp[m][N-1]);
    }

    re0;
}

Measured memory_bytes: 32384
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007

ll a[2][200]={0};



int main(){
  ll n;
  cin >> n;
  ll sum1[200]={0},sum2[200]={0};//1origin
  rep(i,2){
    rep(j,n){
      cin >> a[i][j];
      if(i==0)sum1[j+1]+=a[i][j]+sum1[j];
      if(i==1)sum2[j+1]+=a[i][j]+sum2[j];
    }
  }
  ll res=0,ans=0;
  rep(i,n-1){
    res=sum1[i+1]+(sum2[n]-sum2[i]);
    ans=max(res,ans);
  }
  if(n==1)ans=sum1[1]+sum2[1];
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
S = [input() for _ in range(N)]


DICS = defaultdict(int)
for s in S:
    d = [0] * 26
    for ch in s:
        d[ord(ch)-ord("a")] += 1
    DICS[tuple(d)] += 1
ans = 0
for key in DICS:
    if DICS[key] > 1:
        ans += DICS[key] * (DICS[key] - 1) // 2

print(ans)

Measured memory_bytes: 122052
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define pb push_back
#define ll long long 
#define pii pair<int,int>
#define fi first
#define se second
#define bg begin
cs int RLEN=(1<<20)|3;
inline char gc(){
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob)?EOF:*ib++;
}
inline int read(){
	char ch=gc();
	int res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
	return f?res:-res;
}
inline ll readll(){
	char ch=gc();
	ll res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
	return f?res:-res;	
}
inline int readstring(char *s){
	char ch=gc();int l=0;
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++l]=ch,ch=gc();
	return l;
}
inline char readchar(){
	char ch=gc();
	while(isspace(ch))ch=gc();return ch;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a<b?a=b:0;}
cs int N=200005;
struct node{
	int a,b,id;
	node(int x=0,int y=0,int z=0):a(x),b(y),id(z){}
	friend inline node operator +(cs node &a,cs node &b){return node(a.a+b.a,a.b+b.b,a.id);}
	friend inline bool operator <(cs node &a,cs node &b){
		return ((ll)a.a*b.b==(ll)a.b*b.a)?(a.id==b.id?(a.a==b.a?a.b<b.b:a.a<b.a):a.id<b.id):((ll)a.a*b.b<(ll)a.b*b.a);
	}
	friend inline bool operator >(cs node &a,cs node &b){
		return ((ll)a.a*b.b==(ll)a.b*b.a)?(a.id==b.id?(a.a==b.a?a.b>b.b:a.a>b.a):a.id>b.id):((ll)a.a*b.b>(ll)a.b*b.a);
	}
	friend inline bool operator ==(cs node &a,cs node &b){
		return a.a==b.a&&a.b==b.b&&a.id==b.id;
	}
}a[N];
struct heap{
	priority_queue<node,vector<node>,greater<node> >a,b;
	void push(node x){a.push(x);}
	void erase(node x){b.push(x);}
	node top(){while(b.size()&&a.top()==b.top())a.pop(),b.pop();return a.top();}
}q;
int fa[N],p[N],n;
inline int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read();fa[1]=1;
	for(int i=2;i<=n;i++)p[i]=read(),fa[i]=i;
	for(int i=1;i<=n;i++){
		int t=read();
		if(t==1)a[i].a=1;
		else a[i].b=1;a[i].id=i;
		if(i>1)q.push(a[i]);
	}ll res=0;
	for(int i=2;i<=n;i++){
		node x=q.top(),y=a[find(p[x.id])];
		if(y.id>1)q.erase(y);
		q.erase(x),res+=(ll)y.a*x.b;
		fa[x.id]=fa[y.id],y=y+x;
		a[y.id]=y;
		if(y.id>1)q.push(y);
	}cout<<res<<'\n';
}

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

#define FOR(i,a,b) for(int i = (a);i < (b);++i)
typedef long long ll;

int main(){
   int n; cin >> n;
   if(n %2 == 0){
       cout << (n/2)*(n/2);
   }else{
       cout << (n*n - 1)/4 << endl;
   }
   return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int H[] = new int[N];
    for(int i=0; i<N; i++) H[i] = sc.nextInt();
    int ans = 0;
    int tmp = 0;
    for(int i=0; i<N-1; i++){
      if(H[i] >= H[i+1]) tmp++;
      else{
        ans = Math.max(ans, tmp);
        tmp = 0;
      }
    }
    ans = Math.max(ans, tmp);
    out.println(ans);
      
  }
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define minit(a,b) memset(a,b,sizeof(a))

int n, m, a[10];
string id;

int dp[2][10];

void solve() {
	reverse(id.begin(), id.end());
	
	minit(dp, 0);
	dp[0][0] = 1;
	
	for_(i,0,n) {
		int nw = i % 2, nx = (i + 1) % 2;
		
		for_(j,0,10) dp[nx][j] = 0;
		
		for_(j,0,10) {
			if (id[i] == '*') {
				for_(k,0,m) {
					int v = a[k] * (i % 2 + 1);
					int jj = ( j + (v % 10) + (v / 10) ) % 10;
					dp[nx][jj] += dp[nw][j];
				}
			} else {
				int v = (id[i] - '0') * (i % 2 + 1);
				int jj = ( j + (v % 10) + (v / 10) ) % 10;
				dp[nx][jj] += dp[nw][j];
			}
		}
	}
	
	cout << dp[n % 2][0] << endl;
}

int main() {
	cin >> n >> id >> m;
	for_(i,0,m) cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 1332
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    scanf("%d", &i);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    scanf("%lld", &i);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

constexpr char BR = '\n';

///////////////////////////////////////////////////

int main()
{
    int N;
    io >> N;

  	ll ans = 0;
    for (int k = 1; k <= N; k++)
    {
        for (int j = k; j <= N; j += k)
        {
            ans += j;
        }
    }
    io << ans << BR;
}


Measured memory_bytes: 3860
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define all(x)                (x).begin(), (x).end()

vector<int> g[101010];

int dfs(int s) {
        int res = 0;
        vector<int> v;
        for (auto ns : g[s]) v.push_back(dfs(ns));
        sort(all(v));
        rep(i, v.size()) res = max(res + 1, v[i]); 
        return res + 1;
}

signed main() { 
        int n;
        cin >> n;
        rep(i, n - 1) {
                int a;
                cin >> a;
                a --;
                g[a].push_back(i + 1);
        }
        cout << dfs(0) - 1 << endl;
        return 0;
}               


Measured memory_bytes: 13568
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main() {
  // ========================================================
  int n;
  cin >> n;
  REP(i, n) {
    int inp;
    cin >> inp;
    if (inp % 2 == 0 && inp % 3 != 0 && inp % 5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
}

//最大公約数
ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

Measured memory_bytes: 256
# from fractions import gcd
# mod = 10 ** 9 + 7
# N = int(input())
# a = list(map(int,input().split()))
# a,b,c = map(int,input().split())
# ans = [0] * N
# math.ceilで切り上げ
# dp = [[0] * 4 for i in range(3)] #2次元配列初期化
# dp = [[[0] * 2 for i in range(3)] for j in range(5)]
# (ord('A'))でASCII出力 Aは65
import math
import statistics
import string


def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  # xからyまでの階乗をzで割ったあまりを求める
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):#最大公約数 math.gcdが使えない時の手段として入れとく。pythonが更新されたらいらなくなるはず
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

N, A, B = splitintinput()
amari = 0
ans = 0
ans += A * int(N/(A+B))

amari = N%(A+B)

if amari >= A:
    print(ans+A)
else:
    print(ans+amari)

Measured memory_bytes: 5892
N, D = map(int,input().split())
li = []
for _ in range(N):
    li.append(list(map(int,input().split())))

s = 0
c = 0
for n1 in range(-1,N-1):
    for n2 in range(n1+1,N-1):
        for d in range(D):
            s = s + abs(li[n1][d] - li[n2][d]) ** 2
        s_float = float(s**(1/2))
        if s_float.is_integer():
            c += 1
        s = 0
print(c)


Measured memory_bytes: 3188
#include "bits/stdc++.h"

using namespace std;


#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 (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int N;
	cin >> N;
	vector<int>a;
	a.resize(N-1);
	int ans = 0;
	rep(i, N-1) {
		cin >> a[i];
	}
	rep(i, N) {
		if (i == 0)ans += a[0];
		else if (i == N - 1)ans += a[N - 2];
		else {
			ans += min(a[i-1], a[i]);
		}
	}
	print(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps=1e-8;
int main() {
	string s;
	cin >> s;
	bool out = true;
	int len = s.length();
	int m = 0; int e = 0; int w = 0;
	rep(i, len) {
		if (s[i] == 'm') {
			m++;
		}
		else if (s[i] == 'e') {
			e++;
		}
		else {
			w++;
		}
		if (m < e || e < w || m < w) {
			out = false; break;
		}
		if (m > 0 && e > 0 && w > 0) {
			m--; e--; w--;
		}
		if (m == 0) {
			if (i == len - 1)out = true;
			else {
				out = false;
			}
			break;
		}
	}
	if (out) {
		cout << "Cat" << endl;
	}
	else {
		cout << "Rabbit" << endl;
	}
	return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;
const int mod= 1e9 + 7;
typedef pair<int, int> P;//firstは最短距離、secondは頂点の番号

bool A[21][21];
int ans;

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

	int H, W; cin >> H >> W;

	FOR(i, 0, H)FOR(j, 0, W) {
		char cur; cin >> cur;
		if (cur == '.') {
			A[i][j] = true;
		}
	}

	FOR(i, 0, H)FOR(j, 0, W) {//探索開始の頂点を決める
		if (!A[i][j])continue;

		int d[21][21];//決めた頂点からの距離
		FOR(a, 0, 21)FOR(b, 0, 21)d[a][b] = -1;

		d[i][j] = 0;
		queue<pair<int, int>> que;
		que.emplace(i, j);

		while (!que.empty()) {
			pair<int, int> cur = que.front(); que.pop();
			int h = cur.first, w = cur.second; 
			int dh[4] = { 1,0,-1,0 }, dw[4] = {0,1,0,-1};
			FOR(a, 0, 4){
				int nh = h + dh[a], nw = w + dw[a];
				if (nh < H&&nh >= 0 && nw >= 0 && nw < W) {
					if (A[nh][nw]==true&&d[nh][nw]==-1) {
						d[nh][nw] = d[h][w]+1;
						que.emplace(nh, nw);
					}
				}
			}
		}
		
		FOR(a, 0, H) {
			FOR(b, 0, W) {
				ans = max(ans, d[a][b]);
			}
		}
	}
	cout << ans << endl;
	

	return 0;
}


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

int main(){
    string in;
    cin >> in;

    ll res = 0;
    vector<ll> bucket(2020,0);
    int n = in.size();
    for(int i=0;i<n;i++) {
        vector<ll> bucketNext(2020,0);
        for(int j=0;j<2020;j++) {
            int next = (j*10 + (in[i]-'0'))%2019;
            bucketNext[next] += bucket[j];
        }
        res += bucketNext[0];
        bucket = bucketNext;
        bucket[in[i]-'0']++;
    }
    printf("%lld\n", res);
}


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

int main() {
	int n;
	cin >> n;
	vector<float>v(n);
	for(int i=0;i<n;i++)
	{
		cin >> v.at(i);
	}
	sort(v.begin(),v.end());
	float f=v.at(0);
	for(int i=1;i<n;i++)
	{
		f=(f+v.at(i))/2.0;
	}
	cout <<fixed << setprecision(15) <<  f << endl;
}


Measured memory_bytes: 3692
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    l = [1, 2, 4, 8, 16, 
        32, 64, 128, 256, 512,
        1024, 2048, 4096, 8192, 16384, 
        32768, 65536, 131072, 262144, 524288, 
        1048576, 2097152, 4194304, 8388608, 16777216, 
        33554432, 67108864, 134217728, 268435456, 536870912, 
        1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 
        34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 
        1099511627776]
    c = 0
    while l[c]<h and l[c+1]<=h:
        c += 1
    print(2*l[c]-1)
    return

if __name__=='__main__':
    h = I()
    solve()

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

int main() {
	int n, q; cin >> n >> q;
	vector<int> a(n - 1), b(n - 1), p(q), x(q);
	rep(i, 0, n - 1) cin >> a[i] >> b[i];
	rep(i, 0, q) cin >> p[i] >> x[i];
	
	vector<ll> ans(n), r(n), ad(n);
	rep(i, 0, n - 1) r[b[i] - 1] = a[i] - 1;
	rep(i, 0, q) ad[p[i] - 1] += x[i];
	rep(i, 0, n) ans[i] = ans[r[i]] + ad[i];
	
	rep(i, 0, n) {
		if (i > 0) cout << " ";
		cout << ans[i];
	}
	cout << endl;

	return 0;
}

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

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

	char S[101] = {'\0'};
	cin >> S;
	
	int count = 0;
	for (int i = 0; S[i] != '\0'; i++) count++;

	if (count <= K) {
		cout << S;
	}
	else {
		for (int i = 0; i < K; i++)
			cout << S[i];
		cout << "..." << endl;
	}

	return 0;
}

Measured memory_bytes: 3636
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

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

    if (a == 'H') {
        if (b == 'H') { cout << 'H' << endl; }
        else { cout << 'D' << endl; }
    }
    else {
        if (b == 'H') { cout << 'D' << endl; }
        else { cout << 'H' << endl; }
    }
}

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

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


vector<int> prime;
bool is_prime[100005];

void sieve(int n){

    for(int i=0; i<=n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<=n; i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i; j <= n; j += i) is_prime[j] = false;
        }
        
        
    }
    
}

int main(){

    int x; cin >> x;
    sieve(100004);
    
    
    int i = x;
    while (1) {
        if(is_prime[i]){
            cout << i << endl;
            return 0;
        }
        i++;
        
    }

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

ll solve(int N, vi &A){
	ll ans = 0;
	int ix = 1;
	rp(i,0,N){
		if(A[i]!=ix){
			ans++;
		}
		else{
			ix++;
		}
	}
	return ans<N?ans:-1;
}

int main(){
	int N; cin>>N;
	vi A(N);
	rp(i,0,N)cin>>A[i];
	ote(solve(N,A));
}


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

int main(){
    ll A,B,C;
    cin>>A>>B>>C;
    ll sum = A+B+C;
    ll d=0;
    ll r=0;
    while(1){
        if(sum%3==0){
            d = sum / 3;
            if((d>=A) && (d>=B) && (d>=C)){
                cout << r << endl;
                return 0;
            }
        }
        sum += 2;
        r++;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

minn = 10000
j = 0
for i in h:
	num = t - i * 0.006
	j += 1
	if abs(num-a) < minn:
		minn = abs(num-a)
		ans = j
print (ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#define MAX_N 999999+16

int prime[MAX_N];
bool is_prime[MAX_N + 1];
int sieve(int n){
	int p = 0;
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; ++i){
		if (is_prime[i]){
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i)
				is_prime[j] = false;
		}
	}
	return p;
}
int main(){

	int n;
	while (cin >> n){
		cout << sieve(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 2444
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <stack>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
vector<int> vec;
int main() {
    string X;
    stack<char> st;
    cin >> X;
    rep(i, 0, X.length()) {
        if (X[i] == 'S') {
            st.push(X[i]);
        } if (X[i] == 'T') {
            if (!st.empty() && st.top() == 'S') {
                st.pop();
            } else {
                st.push(X[i]);
            }
        }
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 644
#include<stdio.h>

/* a^b */
int opow(int a, int b)
{
  int i;
  int ret = 1;
  for(i = 0; i < b; i++)
    ret *= a;
  return ret;
}

int hash(char *str)
{
  int i, ret = 0;
  for (i = 0; str[i] != '\0'; i++)
    ;
  
  for (i = 0; str[i] != '\0'; i++) {
    switch(str[i]) {
    case 'A':
      break;
    case 'C':
      ret += 1 * opow(4, i);
      break;
    case 'G':
      ret += 2 * opow(4, i);
      break;
    case 'T':
      ret += 3 * opow(4, i);
      break;
    }
  }
  return ret;
}


int main()
{
  short int dict[1700000];
  int n, i, j, nstr;
  char command[7];
  char str[13];
  char ans[1000000];
  int nans = 0;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %s", command, str);
    j = hash(str);
    for(nstr = 0; str[nstr] != '\0'; nstr++)
      ;
    if( command[0] == 'i' ) {
      dict[j] |= (1<<(nstr-1));
    } else {
      if( (dict[j] & (1<<(nstr-1))) != 0 ) ans[nans++] = 'y';
      else ans[nans++] = 'n';
    }
  }
  for (i = 0; i < nans; i++) {
    if(ans[i] == 'y')
      printf("yes\n");
    else
      printf("no\n");
  }
  /*  for (i = 0; i < nans; i++) {
    printf("%c\n", ans[i]);
    } */
  return 0;
}

Measured memory_bytes: 4392
#include <stdio.h>

int main(void)
{
	double x1, x2, x3;
	double y1, y2, y3;
	double xp, yp;
	double z1, z2, z3;
	
	while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) != EOF){
		z1 = (x3 - x2) * (yp - y2) - (y3 - y2) * (xp - x2);
		z2 = (x1 - x3) * (yp - y3) - (y1 - y3) * (xp - x3);
		z3 = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1);
		
		if ((z1 > 0 && z2 > 0 && z3 > 0) || (z1 < 0 && z2 < 0 && z3 < 0)){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 612
a, b = tuple([int(e) for e in input().split(' ')])

if (a + b) % 2 != 0:
    print('IMPOSSIBLE')
else:
    k = int((a + b) / 2)
    if abs(a - k) == abs(b - k):
        print(k)
    else:
        print(-1 * k)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005;
int n,a[N];
int Abs(int x){return x>0?x:-x;}
int main(){
	//freopen("aa.in","r",stdin);
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",a+i);
	sort(a+1,a+1+n);
	int k=1;
	for(i=1;i<n;++i)if(Abs(a[n]-2*a[i])<Abs(a[n]-2*a[k]))k=i;
	printf("%d %d\n",a[n],a[k]);
	return 0;
}

Measured memory_bytes: 640
// AOJ 1124

#include <iostream>

using namespace std;

#define out(n) cout << n << endl

int main(void)
{
	int n, q;
	while (cin >> n >> q, n && q){
		int maxnum = 0;
		int m, x;
		int data[128];
		fill(data, data + 128, 0);
		for (int i = 0; i < n; i++){
			cin >> m;
			for (int j = 0; j < m; j++){
				cin >> x;
				data[x]++;
			}
		}

		// for (int i = 0; i < 10; i++){
		// 	cout << i << " : " << data[i] << endl;
		// }

		for (int i = 0; i < 128; i++){
			maxnum = max(maxnum, data[i]);
		}
		if (q <= maxnum){
			for (int i = 0; i < 128; i++){
				if (maxnum == data[i]){
					cout << i << endl;
					break;
				}
			}
		}
		else {
			cout << "0" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

int c[10], deg[10];

int main() {
#ifdef zerol
    freopen("a.in", "r", stdin);
#endif
    FOR (i, 0, 3) {
        int a, b; cin >> a >> b;
        deg[a]++; deg[b]++;
    }
    FOR (i, 1, 5) {
        c[deg[i]]++;
    }
    if (c[1] == 2 && c[2] == 2) puts("YES");
    else puts("NO");
}


Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) // <a> must be sorted in advance

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}


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

    string s[2];
    cin >> s[0] >> s[1];
    if(s[0][0]==s[1][2] && s[0][1]==s[1][1] && s[0][2]==s[1][0]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
N = int(input())

A = [int(input()) for _ in range(N)]

sort_A = sorted(A)
max_A = sort_A[-1]
next_max_A = sort_A[-2]

for a in A:
    if a == max_A:
        print(next_max_A)
    else:
        print(max_A)


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

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int a,b,cnt = 0;
  cin >> a >> b;
  for(int i = a; i <= b; i++ ){
    int v = i/10000;
    int w = i/1000 % 10;
    int y = i /10 % 10;
    int z = i % 10;
    //cout << v << " " << w;
    if(v==z && y==w) cnt ++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>       // printf,scanf
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>  //sort,binarySearch
#include <functional> 
#include <iomanip> // setprecision
#include <utility>    // c+11 Array
#include <set>
#include <sstream>
#define PI 3.141592653589793238462643383279
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define debug(x) cout << #x << " = " << x << endl;
#define debret(x) debug(x) ; return 0;

using namespace std;

int main()
{
    int N;
    cin >> N;
    int a[N + 1];
    fill(a, a + N + 1, (int)1e+9);

    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    int ans = 0;
    int pre = a[0];
    int cnt = 0;
    for (int i = 1; i < N; i++) {
        if (pre >= a[i]) {
            cnt++;
        } else {
            cnt = 0;
        }
        pre = a[i];
        ans = max(cnt, ans);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
<?php
  	$n = fgets(STDIN);
	$b = explode(' ', trim(fgets(STDIN)));
	$total = $b[0];
	for($i=1;$i<$n-1;$i++){
      $total += min($b[$i-1],$b[$i]);
    }
	$total += $b[$n-2];
	echo($total);

Measured memory_bytes: 3576
import sys
a,b=map(int,input().split())
s=input()
for i in range(a):
    if s[i]=='-':
        print('No')
        sys.exit()
if  s[a]!='-':
    print('No')
    sys.exit()
for i in range(b):
    if s[i+a+1]=='-':
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cmath>
#include<iostream>
#include<string>
using namespace std;
int main() {
	int X;
	cin >> X;
	int ans = 1;
	for (int b = 1;b < X;b++) {
		for (int p = 2;p < X;p++) {
			if (pow(b, p) > X)break;
			if (pow(b, p) >= ans)ans = pow(b, p);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef unsigned int Int;

Int func(Int n){
  Int out = (n%2==0) ? n/2 : 3*n+1;
  return out;
}

int main(){
  bool flags[1000000]={};
  Int s,ai;
  Int i=1;

  scanf("%d", &s);

  ai = s;
  while(1){
    if(flags[ai]++){
      break;
    }
    ai = func(ai);
    ++i;
  }

  printf("%d\n", i);
  
  return 0;
}

Measured memory_bytes: 1152
import sys

def main():
  n, x, y = map(int, sys.stdin.buffer.readline().split())
  L = [0] * n
  for i in range(1, n):
    for j in range(i + 1, n + 1):
      d = j - i
      if i <= x and y <= j:
        d -= y - x - 1
      elif i <= x and x < j < y:
        d = min(d, x - i + y - j + 1)
      elif x < i < y and y <= j:
        d = min(d, i - x + j - y + 1)
      elif x < i and j < y:
        d = min(d, i - x + y - j + 1)
      L[d] += 1
  for a in L[1:]:
    print(a)

main()

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

string alpha="abcdefghijklmnopqrstuvwxyz";

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

  string s;
  ll k;
  cin>>s>>k;
  for(int i=0;i<s.size();i++){
    ll c=((alpha.size()-(s[i]-'a')))%alpha.size();
    if(i==s.size()-1)s[i]=(char)((s[i]-(int)'a'+k)%alpha.size()+(int)'a');
    else if(c<=k)k-=c,s[i]='a';
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 592
from itertools import accumulate
n,m=map(int,input().split())
t=[0 for i in range(n)]
for i in range(m):
    l,r=map(int,input().split())
    t[l-1]+=1
    if r<n:
        t[r]-=1
ans=list(accumulate(t))
tmp=0
for i in range(n):
    if ans[i]==m:
        tmp+=1
print(tmp)

Measured memory_bytes: 81704
#include<bits/stdc++.h>
using namespace std;
int co;
int cou;
vector<vector<pair<int,int> > > a;
vector<vector<int> > gr;
void saiki(int,int);
int fl[10000];
int main(){
  while(1){
    int n;
    cin >> n;
    if(!n)break;
    a=vector<vector<pair<int,int> > >(n,vector<pair<int,int> >(n));
    gr=vector<vector<int> >(n,vector<int> (n,-1) );
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> a[i][j].first >> a[i][j].second;
      }
    }
    for(int i=0;i<10000;i++){
      fl[i]=-1;
    }
    
    co=0;
    cou=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(gr[i][j]==-1){
	  cou++;
	  saiki(i,j);
	}
	//	cout << gr[i][j] << " ";//
      }
      //cout << endl;
	
    }
    cout << co << endl;
  }
  return 0;
}
void saiki(int I,int J){
  if(gr[I][J]==cou){
    co++;
    return;
  }
  if(gr[I][J]==-1){
    gr[I][J]=cou;
    saiki(a[I][J].second,a[I][J].first);
  }
  else return;
  
}

Measured memory_bytes: 3224
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set> 
#include<cmath>
    using namespace std;
    //long long p = 998244353;
    long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
    vel kai(max_kai, 1);
    vel inv_kai;
    int rui(int a, int n, int mod) {
        if (n == 0) { return 1 % mod; }
        int x = rui(a, n / 2, mod);
        x *= x; x %= mod;
        if (n % 2 == 1) { x *= a; x %= mod; }
        return x;
    }
    vel pa;
    int root(int x) {
        if (pa[x] == -1) { return x; }
        int ans = root(pa[x]); pa[x] = ans;
        return ans;
    }
    void marge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) { pa[x] = y; }
    }
    int gcd(int x, int y) {
        if (x < y) { return gcd(y, x); }
        if (y == 0) { return x; }
        return gcd(y, x % y);
    }
    long long modinv(long long a, long long m) {
        long long b = m, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }
void solve(vel& ans, vvel &chi,int pot) {
    for (auto x : chi[pot]) {
        solve(ans, chi,x);
        int qans = ans[x];
        mmax(ans[pot], qans+1);
    }
}
signed main() {
    int n; cin >> n;
    string ret(2 * n,'1');
    string s, t; cin >> s >> t;
    rep(i, n) { ret[2 * i] = s[i]; ret[2 * i + 1] = t[i]; }
    cout << ret << endl;
    return 0;
}
// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 1408
<?php

    while(true){
        $mark = explode(" ", trim(fgets(STDIN)));
        if(array_sum($mark) == -3) exit;    
        
        $total = $mark[0] + $mark[1];
    
        if($mark[0] * $mark[1] < 0 || $total < 30){
            echo "F"."\n";
        } elseif ($total >= 80) {
            echo "A"."\n";
        } elseif ($total >= 65){
            echo "B"."\n";
        } elseif ($total < 50 && $mark[2] < 50){
            echo "D"."\n";
        } else {
            echo "C"."\n";
        } 
    }

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

set<ll> primes;

ll gcd(ll a, ll b) {
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    double sg = sqrt(g) + 1;
    for(ll i = 2; i <= sg; ++i){
        if(g % i == 0) {
            primes.insert(i);
            while(g % i == 0) g /= i;
        }
    }
    if(g != 1) primes.insert(g);
    cout << primes.size() + 1 << "\n";
    return 0;
}

Measured memory_bytes: 256
// Problem Link: 
// Tutorial Link: 

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL n, a[100005], q;
map<LL, LL> mm;

int main()
{
	FIO;
    cin >> n;
    rep(i,1,n) cin >> a[i];
    LL sum = 0;
    rep(i,1,n) {
        sum += a[i];
        mm[a[i]]++;
    }
    cin >> q;
    while(q--) {
        LL b, c;
        cin >> b >> c;
        sum += c * mm[b] - b * mm[b];
        mm[c] += mm[b];
        mm[b] = 0;
        cout << sum << "\n";
    }
}

Measured memory_bytes: 10164
import java.lang.Exception

fun main(args:Array<String>?): Unit {
    while(true){
        val query = readLine()!!.trim()
        if (query == "#") return
        println(
                if (canReach(query)) "Yes" else "No"
        )
    }
}
fun canReach(order: String): Boolean {
    tailrec fun sub(current: Town, path: Int): Boolean {
        return if (path == order.length) current.isGoal
        else sub(current.moveTo(order[path]), path + 1)
    }
    return sub(Town.A, 0)
}

sealed class Town {
    open fun moveTo(path: Char): Town = throw Exception()
    open val isGoal: Boolean = false
    object Outer: Town() {
        override fun moveTo(path: Char): Town {
            return this
        }
    }
    object A: Town() {
        override fun moveTo(path: Char): Town {
            return when(path){
                '0' -> X
                '1' -> Y
                else -> super.moveTo(path)
            }
        }
    }
    object X: Town() {
        override fun moveTo(path: Char): Town {
            return when(path){
                '0' -> Outer
                '1' -> Z
                else -> super.moveTo(path)
            }
        }
    }
    object Y: Town() {
        override fun moveTo(path: Char): Town {
            return when(path){
                '0' -> X
                '1' -> Outer
                else -> super.moveTo(path)
            }
        }
    }
    object Z: Town(){
        override fun moveTo(path: Char): Town {
            return when(path){
                '0' -> W
                '1' -> B
                else -> super.moveTo(path)
            }
        }
    }
    object W: Town() {
        override fun moveTo(path: Char): Town {
            return when(path){
                '0' -> B
                '1' -> Y
                else -> super.moveTo(path)
            }
        }
    }
    object B: Town() {
        override val isGoal: Boolean
            get() = true
        override fun moveTo(path: Char): Town {
            return when(path){
                '0' -> Y
                '1' -> X
                else -> super.moveTo(path)
            }
        }
    }
}


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

int main(){
    int n,x,count=0;
    cin>>n>>x;
    while(n!=0||x!=0){
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                for(int k=j+1;k<=n;k++){
                    if((i+j+k)==x) count++;
                }
            }
        }
        cout<<count<<endl;
        count=0;
        cin>>n>>x;
    }
    
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

int main(){
    int s, w;
    cin >> s >> w;

    if(w >= s) cout << "unsafe\n";
    else cout << "safe\n";
    return 0;
}

Measured memory_bytes: 3648