akhauriyash/Code-Regression huggingface dataset:
N,C=map(int,input().split())
D=[list(map(int,input().split())) for i in range(C)]
c=[list(map(int,input().split())) for i in range(N)]

col=[[0 for i in range(C+1)] for j in range(3)]

for i in range(N):
    for j in range(N):
        col[(i+j+2)%3][c[i][j]]+=1

#print(col)

ans=10**15
import itertools
PRD=list(itertools.product([i for i in range(C)], repeat=3))

for i in range(len(PRD)):
    newc=[PRD[i][0],PRD[i][1],PRD[i][2]]
    if newc[0]==newc[1] or newc[1]==newc[2] or newc[2]==newc[0]:
        continue
    cost=0
    for j in range(3):
        for k in range(C):
            cost+=col[j][k+1]*D[k][newc[j]]
    ans=min(cost,ans)

print(ans)

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

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

    if (a <= 5)
    {
        cout << 0 << endl;
    }
    else if (a <= 12)
    {
        cout << (b / 2) << endl;
    }
    else
    {
        cout << b << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <tr1/unordered_set>
#include <tr1/unordered_map>
#include <bitset>
#include <cassert>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define inf 1e9
#define debug(a) cout << #a" = " << (a) << endl;
#define debugarry(a, n) for (int i = 0; i < (n); i++) { cout << #a"[" << i << "] = " << (a)[i] << endl; }
#define clr(x, y) memset(x, y, sizeof x)
#define LL long long
#define uLL unsigned LL

using namespace std;
int dp[20][30][200];
int main()
{
    //freopen("input.txt","r",stdin);
    int n,k,s;
    while(scanf("%d%d%d",&n,&k,&s)&&(n||k||s))
    {
        memset(dp,0,sizeof(dp));
        dp[0][0][0]=1;
        for(int i=0;i<k;i++)
        {
            for(int j=0;j<=n;j++)
            {
                for(int t=0;t<=s;t++)if(dp[i][j][t])
                {
                    for(int p=j+1;p<=n;p++)
                    {
                        dp[i+1][p][t+p]+=dp[i][j][t];
                    }
                }
            }
        }
        int sum=0;
        for(int i=0;i<=n;i++)
            sum+=dp[k][i][s];
        printf("%d\n",sum);
    }
    return 0;
}

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

vector <P> e;
ll p,q;

 
int main(){
  int w,h;
  cin>>w>>h;
  for(int i=0;i<w;i++){
    cin>>p;
    e.push_back(P(p,0));
  }
  for(int i=0;i<h;i++){
    cin>>q;
    e.push_back(P(q,1));
  }
  sort(e.begin(),e.end());
  int hc=-1,wc=-1;
  ll ans=0;
  for(int i=0;i<(int)e.size();i++){
    //cout<<e[i].first<<" "<<e[i].second<<endl;
    if(e[i].second == 0){
      wc++;
      ans+=(h-hc)*e[i].first;
    }
    else{
      hc++;
      ans+=(w-wc)*e[i].first;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4592
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
const int D_MAX_V=20002;
const int D_v_size=20002;
struct D_wolf{
	int t,c,r;
	D_wolf(){t=c=r=0;}
	D_wolf(int t1,int c1,int r1){
		t=t1;c=c1;r=r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from,int to,int cap){
	D_G[from].push_back(D_wolf(to,cap,D_G[to].size()));
	D_G[to].push_back(D_wolf(from,0,D_G[from].size()-1));
}
void D_bfs(int s){
	for(int i=0;i<D_v_size;i++)D_level[i]=-1;
	queue<int> Q;
	D_level[s]=0;
	Q.push(s);
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		for(int i=0;i<D_G[v].size();i++){
			if(D_G[v][i].c>0&&D_level[D_G[v][i].t]<0){
				D_level[D_G[v][i].t]=D_level[v]+1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v,int t,int f){
	if(v==t)return f;
	for(;D_iter[v]<D_G[v].size();D_iter[v]++){
		int i=D_iter[v];
		if(D_G[v][i].c>0&&D_level[v]<D_level[D_G[v][i].t]){
			int d=D_dfs(D_G[v][i].t,t,min(f,D_G[v][i].c));
			if(d>0){
				D_G[v][i].c-=d;
				D_G[D_G[v][i].t][D_G[v][i].r].c+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	for(;;){
		D_bfs(s);
		if(D_level[t]<0)return flow;
		for(int i=0;i<D_v_size;i++)D_iter[i]=0;
		int f;
		while((f=D_dfs(s,t,99999999))>0){flow+=f;}
	}
	return 0;
}
int X1[111];
int Y1[111];
int X2[111];
int Y2[111];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d%d",X1+i,Y1+i);
	}

	for(int i=0;i<a;i++){
		scanf("%d%d",X2+i,Y2+i);
	}
	int S=a*2;
	int T=a*2+1;
	for(int i=0;i<a;i++){
		add_edge(S,i,1);
		add_edge(i+a,T,1);
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			if(X1[i]<X2[j]&&Y1[i]<Y2[j]){
				add_edge(i,j+a,1);
			}
		}
	}
	printf("%d\n",max_flow(S,T));
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1 << 20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra() {
	priority_queue<pair<int, int> > PQ;
	vector<int> color(MAX, WHITE);
	vector<int> d(MAX, INFTY);

	d[0] = 0;
	PQ.push(make_pair(0, 0));
	color[0] = GRAY;

	while (!PQ.empty()) {
		pair<int, int> f = PQ.top(); PQ.pop();
		int u = f.second;

		color[u] = BLACK;

		if (d[u] < f.first*(-1))continue;

		for (int j = 0; j < adj[u].size(); j++) {
			int v = adj[u][j].first;
			if (color[v] == BLACK)continue;
			if (d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = GRAY;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

int main() {
	int k, u, v, c;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			adj[u].push_back(make_pair(v, c));
		}
	}

	dijkstra();

	return 0;
}

Measured memory_bytes: 8004
from collections import defaultdict, deque
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
N = int(input())
A = sorted(inpl())

print(A[-1] + sum(map(abs, A[1:-1])) - A[0])
for i in range(N-2, 0, -1):
  a = A[i]
  if a > 0:
    print(A[0], a)
    A[0] -= a
  else:
    print(A[-1], a)
    A[-1] -= a
print(A[-1], A[0])


Measured memory_bytes: 21256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){

	int a,b;
	int sum=0;
	double ave=0,cnt=0;
	char str;
	while(scanf("%d%c%d",&a,&str,&b)!=EOF){
        sum+=a*b;
        ave+=b;
        cnt++;


	}

    printf("%d\n%d\n",sum,(int)(ave/cnt+0.5));

	return 0;
}

Measured memory_bytes: 1188
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 
 
#define F first
#define S second
#define ll long long
#define pb push_back
#define db double
#define ld long double
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define all(x) (x).begin(),(x).end()
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//#define int long long
 
const int N = 1e5 + 1, inf = 2e9 + 7, mod = 1e9 + 7;
const ll INF = 2e18 + 7, MOD = 1e15 + 7;
 
char a[1001][1001];
int dp[1001][1001];

signed main() { __
    // freopen("a.in", "r", stdin);
    // freopen("a.out", "w", stdout);
    int n, m;
    cin>>n>>m;
    for(int i = 1;  i<= n; i++) for(int j = 1; j <=m ;j++) cin>>a[i][j];
    dp[1][1] = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(a[i][j] == '#' ) continue;
            dp[i][j] += (1LL * dp[i - 1][j] + dp[i][j - 1]) % mod;
        }
    }
    cout<<dp[n][m];
    return 0;
}


Measured memory_bytes: 5120
// Problem : Multiplication 2
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc169_b
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
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...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    fast_io;
    int n; cin>>n;
    vl v(n); in(v); sort(all(v));
    ll m=1;
    ll allow=(INFL+100);
    for(ll x:v){
    	if(x==0){
    		cout<<"0";
    		return 0;
    	}
    	allow=(INFL+100)/m;
    	if(x>allow){
    		cout<<"-1";
    		return 0;
    	}
    	m*=x;
    	if(m>INFL){
    		cout<<"-1";
    		return 0;
    	}
    }
    cout<<m;
}

Measured memory_bytes: 3964
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,m,i,j,sum;
    cin >> n>>m;
    int A[n][m];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin >> A[i][j];
        }
    }
    int B[m];
    for(i=0;i<m;i++) cin >> B[i];
    for(i=0;i<n;i++){
        sum = 0;
        for(j=0;j<m;j++) sum += A[i][j]*B[j];
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9+7;

int64_t dp[4][4][4][101];

int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    // A: 0, G: 1, C: 2, T: 3
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 4; j++) {
            for(int k = 0; k < 4; k++) {
                dp[i][j][k][0] = 0;
            }
        }
    }
    dp[3][3][3][0] = 1;
    for(int n = 0; n < N; n++) {
        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 4; j++) {
                for(int k = 0; k < 4; k++) {
                    for(int x = 0; x < 4; x++) {
                        if(
                            (j == 0 && k == 1 && x == 2) ||
                            (i == 0 && k == 1 && x == 2) ||
                            (j == 1 && k == 0 && x == 2) ||
                            (j == 0 && k == 2 && x == 1) ||
                            (i == 0 && j == 1 && x == 2)
                            ) {
                                continue;
                        }
                        dp[j][k][x][n + 1] += dp[i][j][k][n];
                        dp[j][k][x][n + 1] %= MOD;
                    }
                }
            }
        }
    }
    int64_t ans = 0;
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 4; j++) {
            for(int k = 0; k < 4; k++) {
                ans += dp[i][j][k][N];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  cout<<max({A,B,C})*10+(A+B+C-max({A,B,C}))<<endl;
return 0;}

Measured memory_bytes: 3640
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
map<int,int>mp;
int main(){
ll  n,k;
cin>>n>>k;
vector<ll> a(n),sum(n+1,0);
for(int i=0;i<n;i++){
    cin>>a[i];
    //a[i]--;
    sum[i+1]=sum[i]+a[i];
}
ll ans=0;
 queue<int> q;
for(int i=0;i<=n;i++){
  ll now=(sum[i]-i)%k;
  ans+=mp[now];
  mp[now]++;
  q.push(now);
  if(q.size()==k){
    mp[q.front()]--;
    q.pop();
}
}
cout<<ans<<endl;
}


Measured memory_bytes: 13568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int tmp,case_num = 1;

		while((tmp = sc.nextInt()) != 0){
			System.out.printf("Case %d: %d\n",case_num++, tmp);
		}
	}
}


Measured memory_bytes: 66324
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	int A,B,C;
	cin >> A >> B >> C;
	if(A == B && B == C) {
		cout << 1 << endl;
	}
	else if(A == B && B != C) {
		cout << 2 << endl;
	}
	else if(A == C && A != B) {
		cout << 2 << endl;
	}
	else if(B == C && A != B) {
		cout << 2 << endl;
	}
	else {
		cout << 3 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define db long double
#define il inline
#define re register
#define mkpr make_pair

using namespace std;
const int N=500000+10;
il int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
/*int to[N<<1],nt[N<<1],w[N<<1],hd[N],tot=1;
void add(int x,int y,int z)
{
	++tot,to[tot]=y,nt[tot]=hd[x],w[tot]=z,hd[x]=tot;
	++tot,to[tot]=x,nt[tot]=hd[y],w[tot]=z,hd[y]=tot;
}*/
int n,m,q,ff[N],w[N];
int findf(int x){return ff[x]==x?x:ff[x]=findf(ff[x]);}
struct edge
{
	int x,y,z;
	bool operator < (const edge &bb) const {return z<bb.z;}
}e[N],ee[N];

int main()
{
	n=rd(),q=rd();
	for(int i=1;i<=n;++i) ff[i]=i,w[i]=1<<30;
	while(q--)
	{
		int x=rd()+1,y=rd()+1,z=rd();
		e[++m]=(edge){x,y,z};
		w[x]=min(w[x],z+1),w[y]=min(w[y],z+2);
	}
	int ii=1;
	for(int i=2;i<=n;++i) if(w[i]<w[ii]) ii=i;
	for(int i=ii,j=ii%n+1;j!=ii;i=i%n+1,j=j%n+1) w[j]=min(w[j],w[i]+2);
	for(int i=1;i<n;++i) e[++m]=(edge){i,i+1,w[i]};
	e[++m]=(edge){n,1,w[n]};
	sort(e+1,e+m+1);
	LL ans=0;
	for(int i=1,j=n-1;i<=m&&j;++i)
		if(findf(e[i].x)!=findf(e[i].y)) --j,ans+=e[i].z,ff[findf(e[i].x)]=findf(e[i].y);
	printf("%lld\n",ans);
    return 0;
}


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

namespace CsTest
{
   
    public class Program
    {
        static void Main(string[] args)
        {
            int[] AB = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(AB[0] <= 5 ? 0 :(AB[0] >= 13 ? AB[1] : AB[1] / 2));
        }
    }
}


Measured memory_bytes: 11348
#[allow(unused_imports)]
use std::cmp::*;
use proconio::input;

fn main() {
    
    input! {
        d: usize,
        c: [i32; 26],
        s: [[i64; 26]; d],
    }

    let t = (0..d).map(|i| i % 26 + 1);
    for e in t {
        println!("{}", e);
    }
    
}


Measured memory_bytes: 2316
import java.util.BitSet;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] DY = { 1, 0, -1, 0 };
	static int[] DX = { 0, -1, 0, 1 };
	static int W, H;
	static char[][] mapL = new char[52][52];
	static char[][] mapR = new char[52][52];
	static BitSet visited = new BitSet(1 << 24);
	static int[] q = new int[50 * 50 * 50 * 50];

	public static void main(String[] args) {
		while (true) {
			W = sc.nextInt();
			H = sc.nextInt();
			if (W == 0) break;
			sc.nextLine();
			for (int i = 1; i <= H; ++i) {
				String line = sc.nextLine();
				mapL[i][0] = '#';
				for (int j = 0; j < W; ++j) {
					mapL[i][j + 1] = line.charAt(j);
				}
				mapL[i][W + 1] = '#';
				mapR[i][0] = '#';
				for (int j = 0; j < W; ++j) {
					mapR[i][j + 1] = line.charAt(W + 1 + j);
				}
				mapR[i][W + 1] = '#';
			}
			for (int i = 1; i <= W; ++i) {
				mapL[0][i] = mapL[H + 1][i] = mapR[0][i] = mapR[H + 1][i] = '#';
			}
			System.out.println(solve() ? "Yes" : "No");
		}
	}

	static boolean solve() {
		boolean[] visited = new boolean[H * W * H * W];
		int pos = 0;
		for (int i = 1; i <= H; ++i) {
			for (int j = 1; j <= W; ++j) {
				if (mapL[i][j] == 'L') {
					pos |= (i << 18) | (j << 12);
				}
				if (mapR[i][j] == 'R') {
					pos |= (i << 6) | j;
				}
			}
		}
		visited[posToIdx(pos)] = true;
		int qs = 0;
		int qe = 1;
		q[0] = pos;
		while (qs != qe) {
			int p = q[qs++];
			int y1 = p >> 18;
			int x1 = (p >> 12) & 0x3F;
			int y2 = (p >> 6) & 0x3F;
			int x2 = p & 0x3F;
			for (int i = 0; i < 4; ++i) {
				int ny1 = y1 + DY[i];
				int nx1 = x1 + DX[i];
				int ny2 = y2 + DY[i];
				int nx2 = x2 - DX[i];
				if (mapL[ny1][nx1] == '#') {
					ny1 = y1;
					nx1 = x1;
				}
				if (mapR[ny2][nx2] == '#') {
					ny2 = y2;
					nx2 = x2;
				}
				boolean goalL = mapL[ny1][nx1] == '%';
				boolean goalR = mapR[ny2][nx2] == '%';
				if (goalL && goalR) {
					return true;
				}
				if (!goalL && !goalR) {
					int np = (ny1 << 18) | (nx1 << 12) | (ny2 << 6) | nx2;
					int ni = posToIdx(np);
					if (!visited[ni]) {
						visited[ni] = true;
						q[qe++] = np;
					}
				}
			}
		}
		return false;
	}

	static int posToIdx(int p) {
		int y1 = p >> 18;
		int x1 = (p >> 12) & 0x3F;
		int y2 = (p >> 6) & 0x3F;
		int x2 = p & 0x3F;
		return ((y1 - 1) * W + (x1 - 1)) * H * W + ((y2 - 1) * W + (x2 - 1));
	}

}

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

typedef long long ll;
const ll mod=1e9+7;
const int N=2000000000;

void Run()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{
    Run();
    char c;
    cin>>c;
    if(c>='A'&&c<='Z')
        cout<<'A';
    else
        cout<<'a';
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MOD = 1e9+7;

int N, M;
int dp[303][303][303];

ll dfs(int turn, int ok, int now) {
	if (turn == M) {
		if (ok == N) return 1;
		else return 0;
	}
	int& ret = dp[turn][now][ok];
	if (ret != -1) return ret;
	ret = 0;
	(ret += (ll)ok*dfs(turn+1, now, now)%MOD) %= MOD;
	(ret += (ll)(now-ok) * dfs(turn+1, ok, now)%MOD) %= MOD;
	if (now < N) (ret += dfs(turn+1, ok, now+1)) %= MOD;
	return ret;
}

int main() {
	cin >> N >> M;
	memset(dp, -1, sizeof(dp));
	ll ans = dfs(0, 1, 1);
	for (int i = 1; i <= N-1; i++) {
		(ans *= i) %= MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 108928
import itertools

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

# まずループを見つけてみる

loopstart = -1
loopend = -1
path = []
nextcity = 0
FLAGS = [False for _ in range(N)]
for i in range(N):
    currentcity = nextcity
    path.append(nextcity)
    FLAGS[nextcity] = True
    nextcity = A[nextcity]-1
    if FLAGS[nextcity]:
        loopstart = nextcity
        loopend = currentcity
        path.append(nextcity)
        break
#print(path)

# ループまでの距離
toloop = path.index(loopstart)

# ループ内の距離
looplength = path.index(loopend) - toloop + 1

#print(toloop)
#print(looplength)
if K < toloop + looplength + 1:
    print(path[K] + 1)
else:
    fromloopstart = (K - toloop) % looplength
    print(path[toloop + fromloopstart] + 1)

Measured memory_bytes: 107240
n, m = map(int, input().split())
lmax = 0
rmin = 1000000
for _ in range(m):
    l, r = map(int, input().split())
    lmax = max(lmax, l)
    rmin = min(rmin, r)
if lmax > rmin:
    print(0)
else:
    print(rmin-lmax+1)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int p[100005];
long long result(int n,int mod)
{
	int i;
	long long ans=1;
	for(i=1;i<=n;i++)
	{
		ans=ans%mod*2;
		ans%=mod;
	}
	return ans;
}
int main()
{
	int n,a[100005],count=0,b,flag=1;
	cin >> n;
	long long ans;
	if(n%2!=0)
	{
		for(int i=1;i<=n;i++)
		{
			cin >> a[i];
			if(a[i]%2!=0)
				flag=0;
			p[a[i]]++;
		}
		if(p[0]!=1)
			flag=0;
		else
		{
			for(int i=1;i<=n;i++)
			{
				if(a[i]!=0&&p[a[i]]!=2)
					flag=0;
			}
		}
		
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			cin >> a[i];
			if(a[i]%2==0)
				flag=0;
			p[a[i]]++;
		}
		if(p[0]!=0)
			flag=0;
		else
		{
			for(int i=1;i<=n;i++)
			{
				if(a[i]!=0&&p[a[i]]!=2)
					flag=0;
			}
		}
	}
	if(flag)
	{
		b=n/2;
		ans=result(b,1000000000+7);
		cout << ans;
	}
	else
		cout << "0";

	return 0;
}



Measured memory_bytes: 1024
N = int(input())
dist = [[float("inf") if i != j else 0 for i in range(N)] for j in range(N)]

for i in range(N):
    dist[i] = list(map(int, input().split()))

ans = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                print(-1)
                exit()

for i in range(N):
    for j in range(i + 1, N):
        for k in range(N):
            if k == i or k == j:
                continue
            # kを通る迂回ルートが存在する場合dist[i][j]取り除く(=カウントしない)
            if dist[i][j] == dist[i][k] + dist[k][j]:
                break
        else:
            # 迂回ルートが一つもなかった場合は答えに加算する
            ans += dist[i][j]
print(ans)

Measured memory_bytes: 75824
#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;
int data[100001] = {0};
int evens[100001] = {0};
int odds[100001] = {0};

int cnt_elems(int* ar, int tgt, int* ind_handle){
  int res = 0;
  int ind = -1;
  for(int i=0; i < 100001; i++){
    if(ar[i] == tgt){
      res++;
      ind = i;
    }
  }
  *ind_handle = ind;
  return res;
}

int main(){
  int n = 0;
  int num_evens = 0;
  int num_odds = 0;
  scanf("%d", &n);
  for(int i=0; i < n; i++){
    scanf("%d", data + i);
    if(i % 2 == 0){
      //scanf("%d", evens + i/2);
      num_evens++;
      evens[data[i]]++;
    }else{
      //scanf("%d", odds + i/2);
      num_odds++;
      odds[data[i]]++;
    }
  }

  int num_mostpop_evens = *max_element(evens, evens + 100001);
  int num_mostpop_odds = *max_element(odds, odds + 100001);

  //printf("%d %d\n", num_mostpop_evens, num_mostpop_odds);

  int ind_tiers_evens = -1;
  int num_tiers_evens = cnt_elems(evens, num_mostpop_evens, &ind_tiers_evens);
  int ind_tiers_odds = -1;
  int num_tiers_odds = cnt_elems(odds, num_mostpop_odds, &ind_tiers_odds);

  //printf("%d %d / %d %d\n", num_tiers_evens, num_tiers_odds, ind_tiers_evens, ind_tiers_odds);

  int res = 0;
  if(num_tiers_evens == 1 && num_tiers_odds == 1 && ind_tiers_evens == ind_tiers_odds){
    auto cmp = [](int a, int b){return a > b;};
    set<int, decltype(cmp)> s(cmp);
    for_each(evens, evens + 100001, [&](int n){s.insert(n);});
    int num_secondpop_evens = 0;
    if(s.size() > 1){
      num_secondpop_evens = *(++s.begin());
    }
    s.clear();
    for_each(odds, odds + 100001, [&](int n){s.insert(n);});
    int num_secondpop_odds = 0;
    if(s.size() > 1){
      num_secondpop_odds = *(++s.begin());
    }
    int res1 = n - num_secondpop_odds - num_mostpop_evens;
    int res2 = n - num_mostpop_odds - num_secondpop_evens;
    res = min(res1, res2);
    
    
    

  }else{
    res = n;
      res -= num_mostpop_evens;
      res -= num_mostpop_odds;
    
  }
  printf("%d\n", res);
  
  return 0;
}


Measured memory_bytes: 1408
import kotlin.math.min

fun main() {
    val s = readLn()
    val t = readLn()
    var ans = Int.MAX_VALUE
    for (i in s.indices) {
        if (i + t.length > s.length) break
        var change = 0
        for (j in t.indices) {
            if (s[i + j] != t[j]) change++
        }
        ans = min(ans, change)
    }
    println(ans)
}

// Input Reader
private fun readLn() = readLine()!!

Measured memory_bytes: 36040
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            nums = sorted(datasets[dataset][rgb_key])

            for hand in WINNING_HANDS:
                while hand[0] in nums and hand[1] in nums and hand[2] in nums:
                    tmp = nums.copy()
                    if hand[0] in tmp:
                        tmp.pop(tmp.index(hand[0]))
                        if hand[1] in tmp:
                            tmp.pop(tmp.index(hand[1]))
                            if hand[2] in tmp:
                                tmp.pop(tmp.index(hand[2]))
                                match_count += 1
                                nums = tmp
                            else:
                                break
                        else:
                            break
                    else:
                        break

                    if match_count == 3:
                        results.append(1)
                        break

        if dataset < num_of_datasets and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7784
#include<stdio.h>
int main()
{
	int n, k;
	char s[11];
	scanf("%d%s%d", &n, s, &k);
	int i;
	k--;
	for (i = 0; i < n; i++)
		if (s[i] != s[k])
			s[i] = '*';
	printf("%s\n", s);
	return 0;
}

Measured memory_bytes: 128
#include "stdio.h"

int main()
{
	int N,v,j;
	int A[100];
	scanf("%d",&N);
	for (int i=0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 1; i < N; i++) {
		for (int k = 0; k < N - 1; k++)printf("%d ", A[k]);
		printf("%d\n", A[N - 1]);
		v = A[i];
		j = i - 1;
		while (j >= 0 and A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		
	}

	for (int k = 0; k < N - 1; k++)printf("%d ", A[k]);
	printf("%d\n", A[N - 1]);

	
	
	return 0;
}


Measured memory_bytes: 2644
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int counter = 0;
    int a[210];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    bool is_ok = true;
    while(is_ok) {
        for (int i = 0; i < n; i++) {
            if (a[i] % 2 == 0) {
                a[i] /= 2;
            } else {
                is_ok = false;
            }
        }
        if (is_ok) {
            counter++;
        } else {
            break;
        }
    }
    cout << counter;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ld double
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pob pop_back
#define pll pair<ll,ll>
using namespace std;

int main() 
{
	ll n,cnt=0;
	cin>>n;
	string s;
	cin>>s;
	int i;
	for(i=1;i<=s.length();i++)
	{
		if(s[i]!=s[i-1])
			cnt++;
	}
	cout<<cnt;
	return 0;
}


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

using namespace std;

#define INF 1000000

int n;
int v[20][20];
int dp[100000];

void solve(){
	int a = (1<<n);
	for(int i=0;i<a+2;i++) dp[i] = INF;
	dp[0] = 0;
	for(int i=0;i<a;i++){
		int minR;
		if(dp[i] == INF) continue;
		for(int j=0;j<n;j++){
			if((i & (1<<j)) != 0) continue;
			minR = v[j][0];
			for(int k=0;k<n;k++){
			if((i & (1<<k)) != 0){
			minR = min(minR,v[j][k+1]);
        }
    }

      int bit = (i | (1<<j));
      dp[bit] = min(dp[bit],dp[i]+minR);
    }
  }

  cout<<dp[a-1]<<endl;
}

int main(){
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			for(int j=0;j<n+1;j++){
			cin>>v[i][j];
			}
		}
		solve();
	}
}



Measured memory_bytes: 3352
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 250000;
const int K = 19;
int n, q;
int mod = 998244353;
int s1[N], s2[N], a[N], ans[N], f[N], invf[N], dp[N][5];
vector < pair < int, int > > v;
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int c(int n, int k){
    if (k < 0) return 0;
    return f[n] * invf[k] % mod * invf[n - k] % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        int x = dp[i - 1][0];
        dp[i][0] = dp[i - 1][0] + a[i];
        x = min(x, dp[i - 1][1]);
        dp[i][1] = 2 * (a[i] == 0) + a[i] % 2 + x;
        x = min(x, dp[i - 1][2]);
        dp[i][2] = (a[i] + 1) % 2 + x;
        x = min(x, dp[i - 1][3]);
        dp[i][3] = 2 * (a[i] == 0) + a[i] % 2 + x;
        x = min(x, dp[i - 1][4]);
        dp[i][4] = x + a[i];
    }
    int ans = 1e17;
    for (int i = 0; i < 5; i++) ans = min(ans, dp[n][i]);
    cout << ans;
}


Measured memory_bytes: 12544
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

typedef long long int ll;

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

  int N, W;
  cin >> N >> W;
  vector<ll> w, v;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    w.push_back(x);
    v.push_back(y);
  }

  vector<vector<ll> > dp(N+2, vector<ll>(N * 1000 + 2, (ll) 9e18));
  for (int i = 0; i <= N; i++) dp[i][0] = 0;
  for (int j = 1; j < N * 1000 + 2; j++) {
    for (int i = 0; i < N; i++) {
      if (v[i] > j) dp[i+1][j] = min(dp[i][j], w[i]);
      else dp[i+1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
    }
  }

  int limit = 0;
  while (dp[N][limit+1] <= W) limit++;
  cout << limit << endl;
  return 0;
}


Measured memory_bytes: 81024
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    rep(1, m, N + 1)
    {
        ll ans = 0;
        rep(1, i, N + 1)
        {
            ll num = i * i;
            if (num > m)
            {
                break;
            }
            rep(1, j, N + 1)
            {
                num = i * i + j * j + i * j;
                if (num > m)
                {
                    break;
                }
                rep(1, k, N + 1)
                {
                    num = i * i + j * j + i * j + k * k + j * k + k * i;
                    if (num == m)
                    {
                        ans++;
                    }
                    if (num > m)
                    {
                        break;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int m = saori.saori_hayami();
		HashSet<Integer> hs = new HashSet<Integer>();
		for(int i = 0;i < m;i++){
			hs.add(saori.saori_hayami() - 1);
		}
		int[] dp = new int[n];
		for(int j = 0;j < n;j++){
			if(hs.contains(j)){
				continue;
			}
			if(j == 0){
				dp[j] = 1;
			} else if(j == 1) {
				dp[j] = dp[j-1] + 1;
			} else {
				dp[j] = (dp[j-1] + dp[j-2])%1000000007;
			}
			
		}
		System.out.println(dp[n-1]%1000000007);
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int gcd(int x,int y)
{
	int r;
	while(1)
	{
		r=x%y;
		if(r==0) break;
		x=y;y=r;
	}
	return y;
}

int main()
{
	int k;
	cin>>k;
	long long sum=0;
	
	for(int i=1;i<=k;i++)
		for(int j=1;j<=k;j++)
			for(int l=1;l<=k;l++)
				sum+=gcd(i,gcd(j,l));
	
	cout<<sum<<endl;
	return 0;
}

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

H = list(map(int,input().split()))

flowers = [0] * N

start = 0
end = 0

con = 0

while flowers != H:
	for i in range(0,N):
		if H[i] > flowers[i]:
			start = i
			for j in range(i,N):
				if H[j] == flowers[j]:
					end = j
					break
				else:
					end = N
			break


	for k in range(start,end):
		flowers[k] += 1
	con += 1
	start = 0
	end = 0
	
	


print(con)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  int sum = 0;
  cin >> s;
  for (char ch: s) {
    sum += (ch - '0');
  }
  if (sum % 9 == 0) cout << "Yes\n";
  else cout << "No\n";
  return (0);
}


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

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int cntl=0,cntr=0;
  vector<int> vec(n,0);
  for(int i=0;i<n-1;i++){
    if(s.at(i)=='W') cntl++;
    vec.at(i+1) = cntl;
  }
  for(int i=n-1;i>0;i--){
    if(s.at(i) == 'E') cntr++;
    vec.at(i-1) += cntr;
  }
  int tmp = vec.at(0);
  for(int i=0;i<n;i++){
    if(tmp>vec.at(i)) tmp=vec.at(i);
  }
  cout << tmp << endl; 
}

Measured memory_bytes: 1796
import java.util.*;

import javax.xml.crypto.Data;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean Er = false;
		int max = m;
		for(int i = 0; i < n; i++) {
			int in = sc.nextInt();
			int out = sc.nextInt();
			m += in;
			m -= out;
			max = Math.max(m, max);
			if(m < 0) Er = true;
		}
		if(Er) {
			System.out.println(0);
		}
		else {
			System.out.println(max);
		}
	}


}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  int count = 0;
  if(A==5) count++;
  if(B==5) count++;
  if(C==5) count++;
  
  if(count==2) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N;
  cin >> N;
  vector<pair<int, int>> X(N);
  int a, b;
  REP(i, N){
    cin >> a >> b;
    X[i].first = a-b;
    X[i].second = a+b;
  }

  sort(ALL(X));

  /* REP(i, N){ */
  /*   cout << X[i].first << " " << X[i].second << endl; */
  /* } */

  int ans = 1;
  int l = X[0].first;
  int r = X[0].second;
  FOR(i, 1, N){
    int left = X[i].first;
    int right = X[i].second;
    if(r <= left){
      ans++;
      r = right;
    }else if(r > right) r = right;
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
    string S;
    cin >> S;
    int d = S.size();
    if (d == 1) cout << S << endl;
    else {
        if (count(S.begin()+1, S.end(), '9') == d-1) {
            cout << (int)(S[0]-'0') + 9*(d-1) << endl;
        } else cout << (int)(S[0]-'0'-1) + 9*(d-1) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define lihanyang ll
#define lhy int
#define huaji std
using namespace huaji;
bool prime(int n)
{

	if (n==1) return 0;
	for (int i=2;i*i<=n;i++)  
	{
		if(n%i==0) return 0;
	}
	return 1;
}

int main()
{

    int p;
    cin>>p;
    cout<<"ABC"<<p<<endl;
}

Measured memory_bytes: 256
N = int(input())
check_list = []
for _ in range(N):
    a, b = input().split()
    if a == b:
        check_list.append(1)
    else:
        check_list.append(0)
        
total_list = []
for i in range(len(check_list) - 1):
    total_list.append(sum(check_list[i:i + 3]))

if max(total_list) >= 3:
    print('Yes')
else:
    print('No')

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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef vector<int> vi;
typedef long long ll;
#define all(c) begin(c),end(c)

auto solve() {
    int a, b;
    cin >> a >> b;
    if (a < 0 && b > 0) return "Zero";
    else if (a > 0 && b > 0) return "Positive";
    else {
        int d = abs(abs(a) - abs(b)) + 1;
        if (d % 2 == 0) return "Positive";
        else return "Negative";
    }
}

int main() {
    cout << solve() << endl;
    return 0;
}


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

using namespace std;

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

int main(){
	
	double a;
	while(cin>>a){
		double sum = 0;
		rep(i,10){
			sum += a;
			if(i%2==0)a*=2;
			else a/=3;
		}
		printf("%.9lf\n",sum);
	}
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mx = 1e18+10;
vector<ll>adj[100010];
bool visited[100010];
vector<ll>dp(100010);
//dp[i] -> length of longest path from i
void addEdge(ll x,ll y){
    adj[x].push_back(y);
}
void dfs(ll src){
    visited[src]=true;
    for(ll i=0;i<adj[src].size();i++){
        if(!visited[adj[src][i]]){
            dfs(adj[src][i]);
        }
        dp[src]=max(dp[src],1+dp[adj[src][i]]);
    }
}
void solve(){
    ll n,m;cin>>n>>m;ll x,y;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        addEdge(x,y);
    }
    ll ma=0;
    for(int i=1;i<=n;i++){
        visited[i]=false;
        dp[i]=0;
    }
    for(ll i=1;i<=n;i++){
        dfs(i);
    }
    for(int i=1;i<=n;i++)
    ma=max(ma,dp[i]);
    cout<<ma;
}
int main(){
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 8576
# -*- coding: utf-8 -*-


def main():
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    n = 100
    grid = [['.'] * n for _ in range(n // 2)]

    for _ in range(n // 2):
        grid.append(['#'] * n)

    print(n, n)

    for i in range(0, n // 2, 2):
        for j in range(0, n, 2):
            if b > 0:
                grid[i][j] = '#'
                b -= 1
            else:
                break

    for i in range(51, n, 2):
        for j in range(0, n, 2):
            if a > 0:
                grid[i][j] = '.'
                a -= 1
            else:
                break

    for g in grid:
        print(''.join(map(str, g)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,k) for(i=0;i<k;i++)
#define P pair<int,int>
ll n, k, b, c, i, j, x, y, z = 0, m = 0;
ll a[100000], yy[100000] = {};
string s[100000];
P p[100000];
vector<ll> v;
char cc[100000][10];


int main() {
	cin >> n;

	rep(i, n) {
		cin >> cc[i];
		sort(cc[i], cc[i] + 10);
		s[i] = cc[i];
	}
	sort(s, s + n);
	rep(i, n - 1) {
		if (s[i] == s[i + 1])m++;
		else {
			z = z + ((m + 1) * m) / 2;
			m = 0;
		}
	}
	z = z + ((m + 1) * m) / 2;

	cout << z;
	return 0;
}

Measured memory_bytes: 8192
#include <cstdio>

using namespace std;

long long a, b, c, ans[4];

int main()
{
    scanf("%lld%lld%lld", &a, &b, &c);
    ans[1] = (a % 2) ? b * c : 0;
    ans[2] = (b % 2) ? a * c : 0;
    ans[3] = (c % 2) ? a * b : 0;
    if(!ans[1] || !ans[2] || !ans[3])ans[0] = 0;
    else
    {
        ans[0] = ans[1] < ans[2] ? ans[1] : ans[2];
        ans[0] = ans[0] < ans[3] ? ans[0] : ans[3];
    }
    printf("%lld", ans[0]);
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
typedef long long ll;
int N;

int main(){
    cin >> N;
    for(ll h=1;h<=3500;h++){
        for(ll n=1;n<=3500;n++){
            if(4*h*n-n*N-N*h<=0) continue;
            if((N*h*n)%(4*h*n-n*N-N*h)==0){
                cout << h << " " << n << " " << (N*h*n)/(4*h*n-n*N-N*h) << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

x = int(input())

for i in range(-118, 119+1):
    for j in range(-119, 118+1):
        if i**5 -  j**5 == x:
            print(i, j)
            sys.exit(0)


Measured memory_bytes: 63864