akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int mod = 998244353, N = 500123;;
int fac[N], inv[N], n, k;
int C(int x, int y) {
  if (y < 0 || x < y) return 0;
  return (ll) fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int calc(int x, int y, int l) {
  if (l <= 0) return 0;
  return (mod + C(x + y, x) - C(x + y, x + l)) % mod;
}
int main() {
  fac[0] = fac[1] = inv[0] = inv[1] = 1;
  for (int i = 2; i < N; i++) {
    fac[i] = (ll) fac[i - 1] * i % mod;
    inv[i] = mod - (ll) mod / i * inv[mod % i] % mod;
  }
  for (int i = 2; i < N; i++) {
    inv[i] = (ll) inv[i] * inv[i - 1] % mod;
  }
  scanf("%d%d", &n, &k);
  int ans = 0;
  for (int r = 0; r <= k; r++) {
    int b = k - r;
    if (r < b) continue;
    if (r == b) {
      ans = (ans + calc(r, b - 1, r - n + 1)) % mod;
    } else {
      ans = (ans + calc(r, b, r - n + 1)) % mod;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 4096
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(N):
    S = input()
    if S == "AC":
        ac += 1
    elif S == "WA":
        wa += 1
    elif S == "TLE":
        tle += 1
    else:
        re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

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

int x[10003]={};

int main(){
	int a,b;
	while (1){
		cin>>a>>b;
		if (a==0 && b==0)return 0;
		for (int i=0;i<a;i++){
			for (int j=0;j<b;j++)cout<<"#";
			cout<<endl;
		}
		cout<<endl;
	}
	
}


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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c;
  if(b%a==0){
    d=b;
  }
  else{
    d=(b/a)*a+a;
  }
  if(b<=d&&d<=c){
    cout<<"OK"<<endl;
  }
  else{
    cout<<"NG"<<endl;
  }
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;
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;
}

const int MAX_N = 1e5 + 3;
ll dp[MAX_N];
ll mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> issafe(n+1, true);
  rep(i,m) {
    int a; cin >> a;
    issafe[a] = false;
  }

  rep(i,MAX_N) dp[i] = 0;

  dp[0] = 1;
  if (issafe[1]) dp[1] = 1;
  for (int i=2; i<=n; ++i) {
    if (issafe[i-1]) dp[i] += dp[i-1];
    if (issafe[i-2]) dp[i] += dp[i-2];
    dp[i] %= mod;
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int h, w, n;
    cin >>h >> w >> n;
    int m = max(h, w);
    cout << (m+n-1)/m << endl;
}

Measured memory_bytes: 256
n = gets.to_i
w = n.times.map{gets.chomp}

if w.size != w.uniq.size
    puts "No"
    exit
end

shiri = w[0][0]

n.times do |i|
    if w[i][0] != shiri
        puts "No"
        exit
    end
    shiri = w[i][-1]
end

puts "Yes"


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0, 0,-1,1,-1, 1,-1};
int dy[]={0,1,-1, 0,1,-1,-1, 1};

typedef long double number;
typedef valarray<number> point;
const int dim = 2;

number dot(const point& a, const point& b) {
  return (a * b).sum();
}
point cross(const point& a, const point& b) {
  return a.cshift(+1)*b.cshift(-1)
       - a.cshift(-1)*b.cshift(+1);
}
number dist2(const point& a, const point& b) {
  return dot(a-b, a-b);
}

struct min_ball {
    point center;
    number radius2;
    void add(const point& p) {
        ps.push_back(p);
    }
    void compile() {
        m = 0;
        center.resize(dim, 0);
        radius2 = -1;
        make_ball(ps.end());
    }
    template <class OUT>
        void support(OUT out) {
            copy(ps.begin(), supp_end, out);
        }
    min_ball() {
        for (int i = 0; i <= dim; ++i) {
            c[i].resize(dim, 0);
            v[i].resize(dim, 0);
        }
    }
    private:
    list<point> ps;
    list<point>::iterator supp_end;
    int m;
    point v[dim+1], c[dim+1];
    number z[dim+1], r[dim+1];
    void pop() { --m; }
    void push(const point& p) {
        if (m == 0) {
            c[0] = p; r[0] = 0;
        } else {
            number e = dist2(p, c[m-1]) - r[m-1];
            point delta = p - c[0];
            v[m] = p - c[0];
            for (int i = 1; i < m; ++i)
                v[m] -= v[i] * dot(v[i], delta) / z[i];
            z[m] = dot(v[m], v[m]);
            c[m] = c[m-1] + e*v[m]/z[m]/2;
            r[m] = r[m-1] + e*e/z[m]/4;
        }
        center  = c[m];
        radius2 = r[m]; ++m;
    }
    void make_ball(list<point>::iterator i) {
        supp_end = ps.begin();
        if (m == dim + 1) return;
        for (list<point>::iterator k = ps.begin(); k != i; ) {
            list<point>::iterator j = k++;
            if (dist2(*j, center) > radius2) {
                push(*j); make_ball(j); pop();
                move_to_front(j);
            }
        }
    }
    void move_to_front(list<point>::iterator j) {
        if (supp_end == j) ++supp_end;
        ps.splice (ps.begin(), ps, j);
    }
};


int main(){
    int n;cin >> n;
    min_ball mi;
    for (int i = 0; i < n; i++) {
        valarray<number> b(2);
        cin >> b[0] >> b[1];
        mi.add(b);
    }
    mi.compile();
    number r = mi.radius2;
    cout << setprecision(30) << fixed << sqrt(r) << endl;
    return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
//using namespace atcoder;

typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	string s;
	rep(i, n) s +="ACL";
	cout << s <<"\n";
	return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define PB push_back
#define in insert
#define MP make_pair
#define F first
#define S second
 void faster()
 {
 	ios_base::sync_with_stdio(false);
 	cin.tie(NULL);
 	cout.tie(NULL);
 }
 void inout()
 {
 	freopen("in.txt","r",stdin);
 	freopen("out.txt","w",stdout);
 }
 void solve()
 {
 	ll n,k;
 	cin>>n>>k;
 	ll ara[n+10];
 	for(int i=1;i<=n;i++)
 	{
 		cin>>ara[i];
 	}
 	sort(ara+1,ara+n+1);
 	ll sum=0;
 	for(int i=1;i<=k;i++)
 	{
 		sum+=ara[i];
 	}
 	cout<<sum;
 }
 int main()
 {
 	faster();
 	//inout();
 	solve();
 	return 0;

 }

Measured memory_bytes: 3656
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            Array.Sort(line);
            int A = line[0];
            int B = line[1];
            int C = line[2];
            Console.WriteLine((B - A) + (C - B));
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int money=0,money1=0,all=0;
	while(1){
	cin>>money;
	if(money==0){break;}
	money1=1000-money;
	all+=(money1/500);
	all+=(money1%500/100);
	all+=(money1%500%100/50);
	all+=(money1%500%100%50/10);
	all+=(money1%500%100%50%10/5);
	all+=(money1%500%100%50%10%5/1);
	cout<<all<<endl;
	all=0;
	}
	return 0;
}


Measured memory_bytes: 3020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long


signed main(){
	
	int a,b;cin>>a>>b;
	int ans = max(a+b,a-b);
	ans = max(ans,a*b);
	cout << ans << endl;
}

//cout << ans << endl;

Measured memory_bytes: 256
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math


def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))


def solve():
    return

def main():
    st = input()
    if st.islower():
        print("a")
    else:
        print("A")


TestCases = False

if TestCases:
    for i in range(get_int()):
        main()
else:
    main()


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

int main(){
  string s;
  cin >> s;
  string res = "";
  for(int i = 0;i < s.size();i+=2){
    res += s[i];
  }
  cout << res << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    ll n;
    cin >> n;
    int cnt = 0;
    vector<ll> a;
    vector<ll> b; 
    for(ll i = 1; i * i <= n-1; i++){
        if((n-1) % i == 0){
            if((n-1)/i == i) a.push_back(i);
            else{
                a.push_back(i);
                a.push_back((n-1)/i);
            }
        }
    }
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            if(i == n/i) b.push_back(i);
            else{
                b.push_back(i);
                b.push_back(n/i);
            }
        }
    }
    for(int i = 0; i < a.size(); i++){
        if(a[i] != 1) cnt++;
    }
    for(int i = 0; i < b.size(); i++){
        ll tmp = n;
        ll div = b[i];
        if(div == 1) continue;
        while(tmp % div == 0){
            tmp = tmp / div;
        }
        if(tmp % div == 1) cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>

using namespace std;
int main()
{

	int n;
	scanf("%d",&n);
	int sol = 0;
	for (int i = 1;i<=n;i++)
	{
		int x = i;
		int t = 0;
		while(x > 0){
			t++;
			x/=10;
		}
		if (t%2)sol++;
	}
	printf("%d\n",sol);
	return 0;
}

Measured memory_bytes: 256
/*
First, solve the problem.Then write the code. - John Johnson
@author: returnAC
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define need_for_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // Thanks Joshua :)
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
int n;
vector<pair<int,int>>a;	
bool comp(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.second!=b.second)
		return a.second<b.second;
	else
		return a.first>b.first;
}
bool check()
{
	int time = 0;
	for(int i=0;i<a.size();i++)
	{
		time+=a[i].first;
		if(time>a[i].second)
			return false;
	}
	return true;
}
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	need_for_speed;
	cin>>n;
	a.resize(n);
	for(int i=0;i<n;i++)
		cin>>a[i].first>>a[i].second;
	sort(a.begin(),a.end(),comp);
	if(check())
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

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

int main()
{
	int N, W;
	cin >> N >> W;
	vector<long long> dp(W+1, 0);
	for (int i = 0; i < N; ++i)
	{
		long long w, v;
		cin >> w >> v;
		for (long long j = W - w; j >= 1; j--)
		{
			if (dp[j] != 0)
				dp[j+w] = max(dp[j+w], dp[j] + v);
		}
		dp[w] = max(dp[w], v);
	}
	cout << *max_element(dp.begin(), dp.end());
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mood;
		}
		x = x * x % mood;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, m, s[2000], t[2000];
int dp[2010][2010];

signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> s[i];
	for (int i = 0; i < m; i++)cin >> t[i];
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++)dp[i][0] = 1;
	for (int i = 1; i <= m; i++)dp[0][i] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i - 1] == t[j - 1])dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			else dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
			dp[i][j] += mod;
			dp[i][j] %= mod;
		}
	}
	cout << dp[n][m] << endl;
}

Measured memory_bytes: 31744
# 発想はわかったが実装まで出来なかった
N, M = list(map(int, input().split()))
ab = []
for i in range(M):
    ab.append(list(map(int, input().split())))

ans = 0

def dfs(x):
    visited[x] = True
    for i in range(len(graph[x])):
        if visited[graph[x][i]]:
            continue
        else:
            dfs(graph[x][i])

for i in range(M):
    visited = [False for k in range(N + 1)]
    visited[0] = True
    graph = [[] for k in range(N + 1)]
    for j in range(M):
        if j != i:
            graph[ab[j][0]].append(ab[j][1])
            graph[ab[j][1]].append(ab[j][0])
    dfs(1)

    for j in range(N + 1):
        if visited[j]:
            continue
        else:
            ans += 1
            break

print(ans)

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

using namespace std;

int main(){
    int n,k,q,a,c;
    cin>>n>>k>>q;
    vector<int> play(n);
    fill(play.begin(), play.end(), 0);
    c=q-k;
    for(int i=0;i<q;i++){
        cin>>a;
        play[a-1]++;
    }
    for(int i=0;i<n;i++) if(play[i]>c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
} 

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
  int n,m,d,i,j,flg,cnt,k;
  char a[100][101];
  scanf("%d %d %d",&n,&m,&d);
  for(i=0;i<n;i++)	scanf("%s",a[i]);
  cnt=0;
  for(i=0;i<n;i++)	{
    for(j=0;j<m;j++)	{
      flg=1;
      for(k=0;k<d;k++)	{
	if(k+j>=m || a[i][k+j]!='.')	{
	  flg=0;	break;
	}
      }
      cnt+=flg;
      flg=1;
      for(k=0;k<d;k++)	{
	if(k+i>=n || a[i+k][j]!='.')	{
	  flg=0;	break;
	}
      }
      cnt+=flg;
    }
  }
  printf("%d\n",cnt);
  return 0;
}


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

int a[100010][2],n,x,y,nx,ny,mx,my,ans;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		a[x][i%2]++;
	}
	for(int i=1;i<=100000;i++){
		if(a[i][1]>=x)nx=x,x=a[i][1],mx=i;
		else if(a[i][1]>nx)nx=a[i][1];
		if(a[i][0]>=y)ny=y,y=a[i][0],my=i;
		else if(a[i][0]>ny)ny=a[i][0];
	}
	if(mx==my){
		if(nx+y>x+ny)ans=n-nx-y;
		else ans=n-x-ny;
	}
	else ans=n-x-y;
	printf("%d",ans);
	return 0;
}


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


int main(){
    string a[3];
	cin>>a[0]>>a[1]>>a[2];
    int l[3] = {0};
    int k = 0;
    
    while(l[k] < a[k].size()){
    	int n = (int)(a[k][l[k]] - 'a');
        l[k] += 1;
        k = n;
    }
    if(k == 0)
    	cout<<"A"<<endl;
    else if(k == 1)
     	cout<<"B"<<endl;
    else
     	cout<<"C"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

void CountingSort(short*,short*,int);

int n;

int main(){
  int i;
  int k=0;
  short A[2000001], B[2000001];

  scanf("%d",&n);

  for(i = 1; i <= n; i++){
    scanf("%d",&A[i]);
    if(k < A[i]) k = A[i];
  }
  CountingSort(A,B,k);

  for(i = 1; i < n; i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[i]);

  return 0;
}

void CountingSort(short* A,short* B,int k){
  int i,j;
  int C[10001];
  for(i = 0; i <= k; i++){
    C[i] = 0;
  }

  for(j = 1; j <= n; j++){
    C[A[j]]++;
  }

  for(i = 1; i <= k; i++){
    C[i] = C[i] + C[i-1];
  }

  for(j = n; j >= 1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N, M;
	vector<P> ab, cd;

	cin >> N >> M;
	ab.resize(N+1);
	cd.resize(M+1);
	for(int i = 1; i <= N; i++)
		cin >> ab[i].first >> ab[i].second;
	for(int i = 1; i <= M; i++)
		cin >> cd[i].first >> cd[i].second;

	vector<int> ans(N+1);
	for(int i = 1; i <= N; i++){
		llong mini = inf;
		for(int j = 1; j <= M; j++){
			llong dis = abs(ab[i].first - cd[j].first) + abs(ab[i].second - cd[j].second);
			if(dis < mini)
				mini = dis, ans[i] = j;
		}
	}

	for(int i = 1; i <= N; i++)
		cout << ans[i] << endl;

	return 0;
}

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

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N+1,0), B(M+1,0);
    ll a, b;
    for (ll i=1; i<N+1; i++) {
        cin >> a;
        A[i] = a + A[i-1];
    }
    for (ll i=1; i<M+1; i++) {
        cin >> b;
        B[i] = b + B[i-1];
    }

    // vector<ll> c(N);
    ll maxj = M;
    ll ans = 0;
    for (ll i=0; i<N+1; i++) {
        if (A[i] > K) {
            break;
        }
        for (ll j=maxj; j>=0; j--) {
            if (A[i]+B[j] <= K) {
                ans = max(ans,i+j);
                maxj = j;
                break;
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 6388
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;

struct co{
	int z;
	int x;
};

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n,m;
	cin >> n >> m;
	vector<string> grid(n);
	for (int z=0;z<n;z++){
		cin >> grid[z];
	}
	bool ended = false;
	ll c = 0;
	vector <co> blacks;
	for (int z=0;z<n;z++){
		for (int x=0;x<m;x++){
			if (grid[z][x] == '#'){
				co temp;
				temp.z = z;
				temp.x = x;
				blacks.push_back(temp);
			}
		}
	}
	while (!ended){
		ended = true;
		vector <co> newblacks;
					bool work = false;
		for (int y=0;y<blacks.size();y++){
			ll z = blacks[y].z;
			ll x = blacks[y].x;
			if (z != 0) {
				if (grid[z-1][x] == '.'){
					work = true;
					co temp;
					temp.z = z-1;
					temp.x = x;
					newblacks.push_back(temp);
					grid[z-1][x] = '#';
				}
			}
			if (z != n-1){
				if (grid[z+1][x] == '.'){
					work = true;
					co temp;
					temp.z = z+1;
					temp.x = x;
					newblacks.push_back(temp);
					grid[z+1][x] = '#';
				}
			}
			if (x != 0){
				if (grid[z][x-1] == '.'){
					work = true;
					co temp;
					temp.z = z;
					temp.x = x-1;
					newblacks.push_back(temp);
					grid[z][x-1] = '#';
				}
			}
			if (x != m-1){
				if (grid[z][x+1] == '.'){
					work = true;
					co temp;
					temp.z = z;
					temp.x = x+1;
					newblacks.push_back(temp);
					grid[z][x+1] = '#';
				}
			}
		}
		for (int z=0;z<n && ended;z++){
			for (int x=0;x<m && ended;x++){
				if (grid[z][x] == '.'){
					ended = false;
				}
			}
		}
		blacks = newblacks;
		if (work) c++;
	}
	cout << c << endl;
	cin >> n;
	
}

Measured memory_bytes: 14188
using System;

namespace Atc_0020
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            int ans = 0;
            for (int i = 0; i < str.Length; i++)
            {
                ans += int.Parse(str.Substring(i, 1));
            }

            if (ans % 9 == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 32960
#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<iostream>
#include<algorithm>//next_permutation
#include<complex>
#include<math.h>
#include<sstream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, j, n) for (int i = j; i < (int)(n); i++)
using ll = long long int;
int main() {
	int K;
	string S;
	cin >> K >> S;
	if (S.size() > K) {
		rep(i, K) {
			cout << S.at(i);
		}
		cout << "..." << endl;
	}
	else {
		cout << S << endl;
	}
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	string ans;
	for(int j=0; j<ty-sy; j++){
		ans += 'U';
	}
	for(int j=0; j<tx-sx; j++){
		ans += 'R';
	}
	for(int j=0; j<ty-sy; j++){
		ans += 'D';
	}
	for(int j=0; j<tx-sx+1; j++){
		ans += 'L';
	}
	for(int j=0; j<ty-sy+1; j++){
		ans += 'U';
	}
	for(int j=0; j<tx-sx+1; j++){
		ans += 'R';
	}
	ans += "DR";
	for(int j=0; j<ty-sy+1; j++){
		ans += 'D';
	}
	for(int j=0; j<tx-sx+1; j++){
		ans += 'L';
	}
	ans += 'U';
	
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//abc054_c.cpp
//Tue Jun  5 22:05:14 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

int graph[8][8] = {};
int visit[8] = {};
int n,m;
int countc;
int ans;

void dfs(int v, int node) {
	countc++;
	visit[v] = 1;
	if (countc == node){
		ans++;
	}
	for (int i=0;i<node;i++){
		if (graph[v][i] == 1 && visit[i]==0){
			dfs(i,node);
		}
	}
	countc--;
	visit[v]--;
}

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

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

	countc = 0;
	ans = 0;
	dfs(0,n);

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a<<' '<<b<<' '<<3*c-a-b<<' '<<endl;
    cout<<4*c-2*a-b<<' '<<c<<' '<<2*a+b-2*c<<' '<<endl ;
    cout<<a+b-c<<' ' <<2*c-b<<' '<<2*c-a<<' '<<endl ;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int w,h,n,x[10001],y[10001],s,t,u,i,j;
	scanf("%d %d %d",&w,&h,&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&x[i],&y[i]);
	}
	u=0;
	for(i=1;i<n;i++){
		s=x[i]-x[i-1];
		t=y[i]-y[i-1];
		if(s<=0&&t<=0){
			s=s*-1;
			t=t*-1;
			if(s<t){
				u=u+t;
			}
			else{
				u=u+s;
			}
		}
		else if(s>0&&t>0){
			if(s<t){
				u=u+t;
			}
			else{
				u=u+s;
			}
		}
		else if(s>0&&t<=0){
			t=t*-1;
			u=u+s+t;
		}
		else{
			s=s*-1;
			u=u+s+t;
		}
	}
	printf("%d\n",u);
	return 0;
}
			
		
		
		
		
		
		


Measured memory_bytes: 2140
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数
ll d[1000000];
ll e[3000000];

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	if (a > b) {
		PRINTD(a+(a - 1));
	}
	else if (a < b) {
		PRINTD(b+(b - 1));
	}
	else {
		PRINTD(a+b);
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <string>

int main(int argc, char *argv[]) {
  int q;
  std::cin >> q;
  std::map<std::string, long> m;
  for (int i = 0; i < q; ++i) {
    int c;
    std::string key;
    std::cin >> c >> key;
    switch (c) {
    case 0:
      int x;
      std::cin >> x;
      m[key] = x;
      break;
    case 1:
      std::cout << m.at(key) << std::endl;
      break;
    }
  }
}



Measured memory_bytes: 27804
def m(L,R):
 global c;c+=len(L)+len(R)
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 T+=R[::-1]
 return T[::-1]
def d(A):s=len(A)//2;return m(d(A[:s]),d(A[s:])) if len(A)>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)


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

vector< vector<int> > v(100000);
queue< pair<int,int> > q;

signed main(){

  int n,m; cin >> n >> m;
  for(int i = 0; i < m; i++){
    int p,y; cin >> p >> y;
    q.push({p,y});
    v[p].push_back(y);
  }

  for(int i = 1; i <= n; i++){
    sort(v[i].begin(),v[i].end());
  }

  for(int i = 0; i < m; i++){
    pair<int,int> p = q.front();
    q.pop();
    auto it = lower_bound(v[p.first].begin(),v[p.first].end(),p.second) - v[p.first].begin();
    printf("%06d%06d\n",p.first,it+1);
  }

  return 0;
}


Measured memory_bytes: 7808
# ABC077c
from bisect import bisect_left
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()

ans = 0
for i in b:
    smallPos = bisect_left(a, i)
    BigPos = bisect_left(c, i+1)
    ans += smallPos*(n-BigPos)
print(ans)


Measured memory_bytes: 92644
#include <iostream>
#include <string>

using namespace std;

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

    for(int i=0;i<n.length();i++){
        if(n.at(i) == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long

using namespace __gnu_pbds;
using namespace std;

template <class T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main()
{
    usaco();
    vector <int> d(1e6+1);
    for (int i = 2; i <= 1e6; ++i)
        for (int j = i; j <= 1e6; j += i)
            d[j]++;
    ll n, ans = 0;
    cin >> n;
    for (int i = 1; i < n; ++i)
        ans += d[i]+1;
    cout << ans << '\n';
}


Measured memory_bytes: 7084
import sys

input = sys.stdin.readline

Q = int(input())

primes = set()
not_p = set()
for i in range(2, 10**5 + 1):
# for i in range(2, 10 + 1):
    if i not in not_p:
        primes.add(i)
        for j in range(i+i, 10**5+1, i):
        # for j in range(i+i, 10+1, i):
            not_p.add(j)
# print(primes)
# print(not_p)

acum = [0 for _ in range(10**5+1)]
for i in range(3, 10**5+1, 2):
# for i in range(3, 10, 2):
    if i in primes and ((i+1) // 2) in primes:
        # print(i, "like2017")
        acum[i] += 1
    acum[i] += acum[i-2]
# print(acum[:10])

for _ in range(Q):
    l, r = map(int, input().split())
    print(acum[r] - acum[l - 2])

Measured memory_bytes: 18700
#include<stdio.h>

int n,k;
int exp[200000],sumk,ans;

int main(){
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d",&exp[i]);
    sumk+=exp[i];
    if(i==k-1)ans=sumk;
    if(i>=k){
      sumk-=exp[i-k];
      if(ans<sumk)ans=sumk;
    }
  }
  printf("%.12f",(ans+k)/(double)2);
  return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int X, Y;
  char U;
  map<int, vector<pair<int, char> > > amap, bmap, cmap, dmap;
  for(int i=0;i<N;++i) {
    cin>>X>>Y>>U;
    amap[X].push_back(mp(Y, U));
    bmap[Y].push_back(mp(X, U));
    cmap[X-Y].push_back(mp(X, U));
    dmap[X+Y].push_back(mp(X, U));
  }
  for(int i=0;i<=200000;++i) {
    sort(amap[i].begin(), amap[i].end());
    sort(bmap[i].begin(), bmap[i].end());
  }
  for(int i=-200000;i<=200000;++i) {
    sort(cmap[i].begin(), cmap[i].end());
  }
  for(int i=0;i<=400000;++i) {
    sort(dmap[i].begin(), dmap[i].end());
  }
  int min1=-1, max1=-1;
  int ans = inf;
  for(int i=0;i<=200000;++i) {
    max1 = -1;
    min1 = -1;
    for(int j=0;j<amap[i].size();++j) {
      if(amap[i][j].se=='U') {
        min1 = amap[i][j].fi;
      }
      if(amap[i][j].se=='D') {
        max1 = amap[i][j].fi;
        if(min1!=-1) ans = min(ans, (max1-min1)*5);
      }
    }
  }
  for(int i=0;i<=200000;++i) {
    max1 = -1;
    min1 = -1;
    for(int j=0;j<bmap[i].size();++j) {
      if(bmap[i][j].se=='R') {
        min1 = bmap[i][j].fi;
      }
      if(bmap[i][j].se=='L') {
        max1 = bmap[i][j].fi;
        if(min1!=-1) ans = min(ans, (max1-min1)*5);
      }
    }
  }
  for(int i=-200000;i<=200000;++i) {
    max1 = -1;
    min1 = -1;
    for(int j=0;j<cmap[i].size();++j) {
      if(cmap[i][j].se=='U') {
        min1 = cmap[i][j].fi;
      }
      if(cmap[i][j].se=='L') {
        max1 = cmap[i][j].fi;
        if(min1!=-1) ans = min(ans, (max1-min1)*10);
      }
    }
  }
  for(int i=-200000;i<=200000;++i) {
    max1 = -1;
    min1 = -1;
    for(int j=0;j<cmap[i].size();++j) {
      if(cmap[i][j].se=='R') {
        min1 = cmap[i][j].fi;
      }
      if(cmap[i][j].se=='D') {
        max1 = cmap[i][j].fi;
        if(min1!=-1) ans = min(ans, (max1-min1)*10);
      }
    }
  }
  for(int i=0;i<=400000;++i) {
    max1 = -1;
    min1 = -1;
    for(int j=0;j<dmap[i].size();++j) {
      if(dmap[i][j].se=='R') {
        min1 = dmap[i][j].fi;
      }
      if(dmap[i][j].se=='U') {
        max1 = dmap[i][j].fi;
        if(min1!=-1) ans = min(ans, (max1-min1)*10);
      }
    }
  }
  for(int i=0;i<=400000;++i) {
    max1 = -1;
    min1 = -1;
    for(int j=0;j<dmap[i].size();++j) {
      if(dmap[i][j].se=='D') {
        min1 = dmap[i][j].fi;
      }
      if(dmap[i][j].se=='L') {
        max1 = dmap[i][j].fi;
        if(min1!=-1) ans = min(ans, (max1-min1)*10);
      }
    }
  }
  if(ans==inf) cout<<"SAFE"<<endl;
  else cout<<ans<<endl;
}



Measured memory_bytes: 116968
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"


int main(int argc, char const *argv[]) {

  int LL;
  std::cin >> LL;



  if (LL == 1) {
    std::cout << "Hello World" << '\n';
  }else{
    int A, B;
    std::cin >> A>>B;
      std::cout << A+B << '\n';
  }



  return 0;
}


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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9)+7>;

const int MAXN = 2e5;
int N;
int A[MAXN];

int main() {
	string S;
	cin >> S;
	N = int(S.size());
	bool alternating = true;
	for (int i = 1; i < N; i++) {
		if (S[i] == S[i-1]) alternating = false;
	}
	if (alternating) {
		cout << 1 << '\n';
		return 0;
	}
	A[0] = 0;
	for (int i = 0; i < N; i++) {
		char c = S[size_t(i)];
		assert(c == 'a' || c == 'b');
		A[i+1] = A[i] + (c - 'a' + 1);
		A[i+1] %= 3;
	}

	num dp[3][3];
	memset(dp, 0, sizeof(dp));
	assert(A[0] == 0);
	dp[0][1] = dp[0][2] = 1;
	num res = 0;
	for (int i = 1; i <= N; i++) {
		int a = A[i];
		int x = (A[i] + 1) % 3, y = (A[i] + 2) % 3;

		num n = dp[x][a] + dp[y][a];
		dp[x][a] = 0;
		dp[y][a] = 0;
		if (a == A[N]) res += n;
		dp[a][x] += n;
		dp[a][y] += n;
	}

	cout << res << '\n';

	return 0;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i) // ROF(i,n,0)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define SUM(a) accumulate(all(a),int(0))
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

signed main(){
  int n, k; cin >> n >> k;
  vi p(n); rep(i,n) cin >> p[i];
  vi s(n+1); rep(i,n) s[i+1] = s[i] + p[i];
  int ans = 0;
  rep(i,n-k+1){
    chmax(ans, s[i+k]-s[i]);
  }
  ans += k;
  printf("%.10f\n", double(ans)/2);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using V = std::vector<T>;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const i64 INF = 1LL << 50;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  i64 K;
  cin >> N >> K;
  V<int> P(N);
  REP(i, N) {
    cin >> P[i];
    P[i]--;
  }
  V<i64> C(N);
  REP(i, N) cin >> C[i];

  auto calc = [&](int i) -> i64 {
    V<bool> visited(N);
    int cur = i;
    i64 res = -INF;
    i64 score = 0;
    int cycle = 0;
    while (!visited[cur]) {
      visited[cur] = true;
      int nx = P[cur];
      score += C[nx];
      res = max(res, score);
      ++cycle;
      if (cycle == K) return res;
      cur = nx;
    }
    if (score <= 0) {
      return res;
    }

    i64 m = K / cycle;
    res = max(res, (m - 1) * score + res);
    int cur2 = i;
    i64 res2 = 0;
    i64 score2 = 0;
    REP(j, K % cycle) {
      int nx = P[cur2];
      score2 += C[nx];
      res2 = max(res2, score2);
      cur2 = nx;
    }
    DEBUG(i, score, cycle, m, res2);
    res = max(res, m * score + res2);
    return res;
  };
  i64 ans = -INF;
  REP(i, N) {
    i64 score = calc(i);
    ans = max(ans, score);
  }
  cout << ans << endl;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> as(n), bs(m), isec;
    set<int> ss;
    for (int i = 0; i < n; i++) {
        cin >> as[i];
        ss.insert(as[i]);
    }
    for (int i = 0; i < m; i++) {
        cin >> bs[i];
        ss.insert(bs[i]);
    }
    sort(as.begin(), as.end());
    sort(bs.begin(), bs.end());
    set_intersection(as.begin(), as.end(), bs.begin(), bs.end(), back_inserter(isec));
    cout << isec.size() << ' ' << ss.size() << endl;
    for (int c : isec) {
        cout << c << '\n';
    }
    for (int s : ss) {
        cout << s << '\n';
    }
}


Measured memory_bytes: 14276
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int t = sc.nextInt();
		int min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++){
		    int c_i = sc.nextInt();
		    int t_i = sc.nextInt();
		    if(t_i <= t){
		        min = min(min, c_i);
		    }
		}

		
		// 計算
		int result = min;
		
		// 出力
		if(result == Integer.MAX_VALUE){
		    System.out.println("TLE");
		}else{
		    System.out.println(result);
		}
		
	}
}

Measured memory_bytes: 23764
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll a,b;
  cin >> a >> b;
  a += b;
  if(a<10) cout <<a<<endl;
  else cout <<"error\n";
}


Measured memory_bytes: 256
L, R = list(map(int, input().split()))
b = 0
ans = 10000

if R - L >= 2019:
    ans = 0
else:
    for i in range(L, R + 1):
        if i % 2019 == 0:
            ans = 0
        else:
            for j in range(i + 1, R + 1 ):
                if j % 2019 == 0:
                    ans = 0
                else:
                    b = i * j % 2019
                    ans = min(b, ans)   
print(ans)

Measured memory_bytes: 3060
n = gets.to_i
min = last = gets.to_i
profits = []
(n-1).times{
  current = gets.to_i
  if (current <= min)
    profits<<(current-last) if (profits.bsearch{|i| i >= 0} == nil)
    min = current if (current < min)
  end
  profits<<(current-min) if (current > last)
  last = current
}
puts profits.max

Measured memory_bytes: 9684
#include<cstdio>
const int N=21,M=1e9+7;
inline int Mod(int a){return a<M?a:a-M;}
int n,f[N][1<<N],A[N],a,lg[1<<N];
signed main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	  for(int j=0;j<n;j++)scanf("%d",&a),A[i]|=a*(1<<j);
	for(int i=0;i<n;i++)lg[1<<i]=i;
	for(int i=0;i<n;i++)
	  for(int I=0;I<(1<<n);I++)
		for(int II=I&A[i],j;II;II-=II&-II){
		  j=lg[II&-II];
		  f[i][I]=Mod(f[i][I]+(i?f[i-1][I-(1<<j)]:I==(1<<j)));
		}
	printf("%d",f[n-1][(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 176512
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

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

    if(N == 3){
        cout << "2 5 63\n"; return 0;
    }

    vector<int> ans(N);
    ans[0] = 2;
    ans[1] = 3;
    ans[2] = 4;
    ans[3] = 9;

    int num = 4;

    int next = 8;
    while(N - num >= 2 && next <= 29998){
        for(int i=0; i<2; i++) ans[num+i] = next + 2*i;
        num += 2;
        next += 6;
    }

    next = 15;
    while(N - num >= 2 && next <= 29994){
        for(int i=0; i<2; i++) ans[num+i] = next + 6*i;
        num += 2;
        next += 12;
    }

    next = 6;
    while(N - num >= 1 && next <= 30000){
        ans[num] = next;
        num++;
        next += 6;
    }

    // cout << num << endl;
    debug(ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int naive_grundy(int a, int k){
    if(a / k == 0) return 0;
    int mx = a / k;
    set<int> gs;
    for(int i=1; i<=mx; i++)
        gs.insert(naive_grundy(a-i, k));
    int pos = 0;
    for(auto g : gs){
        if(pos != g) return pos;
        pos++;
    }
    return pos;
}

int grundy(int a, int k){
    int m = a / k;
    if(a % k == 0) return m;

    int b = a - a/k - 1;
    if(b/k != a/k) return grundy(b, k);

    int f = (a-m*k) / (m+1);
    int tmp = a-f*(m+1);
    return grundy(tmp, k);
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N), K(N);
    for(int i=0; i<N; i++) cin >> A[i] >> K[i];

    int g = 0;
    for(int i=0; i<N; i++)
        g ^= grundy(A[i], K[i]);
    if(g == 0) cout << "Aoki" << endl;
    else cout << "Takahashi" << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
list=[]
for i in range(N):
  list.append(input())
AC = list.count('AC')
WA = list.count('WA')
TLE = list.count('TLE')
RE = list.count('RE')


print("AC x "+str(AC))
print("WA x "+str(WA))
print("TLE x "+str(TLE))
print("RE x "+str(RE))

Measured memory_bytes: 79284
# 入力
N = int(input())
witness = [[-1] * N for _ in range(N)]
for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        witness[i][x - 1] = y

# 正直者の組を作り判定
ans = 0
for i in range(1, 2 ** N + 1):
    honest = [0] * N
    for j in range(N):
        if str(format(i, 'b')).zfill(N)[j] == "1":
            honest[j] = 1

    is_correct = True
    for j in range(N):
        if honest[j] == 1:
            for k in range(N):
                if witness[j][k] == -1:
                    pass
                elif witness[j][k] != honest[k]:
                    is_correct = False
    if is_correct:
        ans = max(ans, sum(honest))

print(ans)


Measured memory_bytes: 3064
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parent = [i for i in range(self.n)]
    self.rank = [0] * self.n
  
  def find_root(self, x):
    if self.parent[x] == x:
      return x
    else:
      self.parent[x] = self.find_root(self.parent[x])
      return self.parent[x]
  
  def unite(self, x, y):
    rx = self.find_root(x)
    ry = self.find_root(y)
    if rx == ry:
      return
    if self.rank[rx] < self.rank[ry]:
      self.parent[rx] = ry
    else:
      self.parent[ry] = rx
      if self.rank[rx] == self.rank[ry]:
        self.rank[rx] += 1
  
  def is_same(self, x, y):
    return self.find_root(x) == self.find_root(y)

N, Q = map(int, input().split())
uf = UnionFind(N)
for _ in range(Q):
  p, a, b = map(int, input().split())
  if p == 0:
    uf.unite(a, b)
  else:
    if uf.is_same(a, b):
      print(1)
    else:
      print(0)


Measured memory_bytes: 6048
n,a,b=map(int,input().split())
s=input()

cnta=0
cntb=0

for i in range(n):
    if s[i]=="a":
        if cnta+cntb<a+b:
            print("Yes")
            cnta+=1
        else:
            print("No")
    elif s[i]=="b":
        if cntb<b and cnta+cntb<a+b:
            print("Yes")
            cntb+=1
        else:
            print("No")
    else:
        print("No")


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X,A,B;
  cin >> X >> A >> B;
  if(B-A<=0){
    cout << "delicious" << endl;
    return 0;
  }
  if(B-A<=X){
    cout << "safe" << endl;
    return 0;
  }
  if(B-A>=X+1){
    cout << "dangerous" << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;

int main(int argc, char **argv) {
    string str;
    cin >> str;

    int res = 0;
    for(int i = 0; i < str.size(); ++i)
        if(str[i] == 'o')
            ++res;

    cout << (res + (15 - str.size()) >= 8 ? "YES" : "NO") << endl;
}

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

using namespace std;

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

    int rules_followed = true;

    map <string, int> used;
    string previous_word;
    for(int i = 1; i <= no_of_words; i++)
    {
        string current_word;
        cin >> current_word;

        if(used[current_word] || (i > 1 && current_word[0] != previous_word[previous_word.size() - 1]))
           rules_followed = false;

        used[current_word] = true;
        previous_word = current_word;
    }

    cout << (rules_followed ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256