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

int n,m,k;
int i,j;

cin >> n >> m;

int count[m+1]={};
int a[n][m]={};
int ans=0;


for(i=0;i<n;i++){
cin >> k;
for(j=0;j<k;j++){
cin >> a[i][j];
  }
}

for(i=0;i<n;i++){
  for(j=0;j<m;j++){
count[a[i][j]] ++;
  }
}

for(i=1;i<m+1;i++){
if(count[i] == n) ans++;
}

//cout << count[0] << count[1] << count[2] << count[3] << endl;
cout << ans << endl;
}


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

int main() {
  int N,H;
  cin >> N>>H;
  vector<vector<int>> a(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> a.at(i).at(j);
    }
  }
  vector<int>A(N);
  for (int i = 0; i < N; i++) {
    A.at(i)=a.at(i).at(1);
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  int n=H;
  int ans=0;
  int ma=0;
  for (int i = 0; i < N; i++) {
    ma=max(ma,a.at(i).at(0));
  }
  for (int i = 0; i < N; i++) {
    if(ma<A.at(i)){
      n-=A.at(i);
      ans++;
    }
    if(n<=0){
      break;
    }
  }
  if(n>0){
  ans+=(n-1)/ma+1;
  }
  
  cout<<ans<<endl;
  
}






Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
  	long long ans = 0LL;
  	for (int i = 1; i <= n; i++) {
     	for (int j = 1; j <= n; j++) {
         	for (int k = 1; k <= n; k++) {
            	ans += __gcd(i,__gcd(j,k));
            }
        }
    }
  	cout << ans << endl;
}

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

using namespace std;

int main(){
    vector<int> v;
    for(int i=0;i<10;i++){
    	int x;
    	cin >> x;
    	v.push_back(x);
    }
    sort(v.begin(),v.end());
    cout << v[9] << endl;
    cout << v[8] << endl;
    cout << v[7] << endl;
}



Measured memory_bytes: 3112
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;
vl A;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    A = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    solve();
}

// 2 <= N <= 2000
// 1 <= A_i <= 10^9
// 入力はすべて整数である。

// ll N, vl A
// 幼児のうれしさの合計の最大値を出力せよ。
void solve(){
    vl ord(N);rep(i,N)ord[i]=i;
    sort(all(ord),[&](ll x,ll y){return A[x]>A[y];});
    
    vvl dp(N+1,vl(N+1));
    rep(i,N)repe(j,i){
        ll k=i-j;
        chmax(dp[j+1][k],dp[j][k]+A[ord[i]]*abs(ord[i]-j));
        chmax(dp[j][k+1],dp[j][k]+A[ord[i]]*abs(N-1-k-ord[i]));
    }

    ll ans=0;
    repe(i,N)chmax(ans,dp[i][N-i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 34596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
//#define f first
//#define s second
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
//#define INF (1LL<<31)
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const ll MAX = 1000000000000000000;
typedef pair<int,ll> pii;
typedef pair<ll,int> pi;
typedef tuple<long long,int> tp;
typedef tuple<int,int,long long> tu;
typedef multimap<pii , int> mpp;
typedef priority_queue< tp , vector<tp>, greater<tp>>  minheap;
typedef priority_queue<pii , vector<pii>> maxheap;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
const int maxi = 305;

double p[maxi][maxi][maxi];
double ev[maxi][maxi][maxi];

int main()
{
	FASTIO;
	int n;
	cin >> n ;
	vector<int> count(4);
	int temp;
	for(int i=0;i<n;i++){
		cin >> temp;
		count[temp]++;
	}
	
	p[count[1]][count[2]][count[3]]=1;
	
	for(int c=n;c>=0;--c){
		for(int b=n;b>=0;--b){
			for(int a=n;a>=0;--a){
				
				if(a==0&&b==0&&c==0)
					continue;
				
				if(a+b+c>n)
					continue;
				
				double p_waste = (double)(n-(a+b+c))/n;
				
				double ev_waste = (double)p_waste/(1-p_waste);
				
				ev[a][b][c] += ev_waste*p[a][b][c];
				
				
				if(a!=0){
					double p_go = (double)(a)/(a+b+c);
					p[a-1][b][c] += p[a][b][c]*p_go;
					ev[a-1][b][c] += ev[a][b][c]*p_go;
				}
				
				if(b!=0){
					double p_go = (double)(b)/(a+b+c);
					p[a+1][b-1][c] += p[a][b][c]*p_go;
					ev[a+1][b-1][c] += ev[a][b][c]*p_go;
				}
				
				if(c!=0){
					double p_go = (double)(c)/(a+b+c);
					p[a][b+1][c-1] += p[a][b][c]*p_go;
					ev[a][b+1][c-1] += ev[a][b][c]*p_go;
				}
				
			}
		}
	}
	
	printf("%.13lf\n", ev[0][0][0]+(count[1]+2*count[2]+3*count[3]));
	//cout << ev[0][0][0]+(count[1]+2*count[2]+3*count[3]) << "\n";
	return 0;
}


Measured memory_bytes: 438528
// 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int x;
    cin >> x;
    int ans = (x == 0) ? 1 : 0;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3536
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;

namespace Atcoder
{
	class Program
	{
		/*
			string s = Console.ReadLine();
			string[] ST = Console.ReadLine().Split(' ').ToArray();
			string S = strArray[0];
			string T = strArray[1];

			int[] HWN = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int H = intArray[0];
			int W = intArray[1];
			int N = int.Parse(Console.ReadLine());

			List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToList());
			
			double[] R = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray();

			Boolean ok = false;
			
			List<int> dp = Enumerable.Repeat(値, 個数).ToList();
			
			Console.WriteLine(ans);
			Console.WriteLine("Yes");
			Console.WriteLine("No");
			Console.ReadKey();
			Console.WriteLine(cnt);

			for(int i= 0; i < N; i++)
		*/

		static void Main(string[] args)
		{
			int[] rDx = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int r = rDx[0];
			int D = rDx[1];
			int x = rDx[2];

			for(int i = 0;i < 10;i++)
            {
				x = x * r - D;
				Console.WriteLine(x);
			}
		}
		class Item : IComparable
		{
			public string A;
			public int B;
			public Item(string a, int b)
			{
				this.A = a;
				this.B = b;
			}
			public int CompareTo(object obj)
			{
				return B - ((Item)obj).B;
			}
		}

		/// <summary>
		/// 回文
		/// </summary>
		/// <param name="Target"></param>
		/// <param name="len"></param>
		/// <returns></returns>
		static bool Palindrome(string Target , int len)
        {
			bool yes = true;

			for(int i = 0;i < len; i++)
            {
				if(Target[i] != Target[len - 1 - i])
                {
					yes = false;
					break;
                }
            }
			return yes;
        }

		/// <summary>
		/// アナグラム
		/// </summary>
		/// <param name="word1"></param>
		/// <param name="word2"></param>
		/// <returns></returns>
		static bool IsAnagramOf(string word1, string word2)
		{
			//char[] val1 = word1.ToCharArray();
			//char[] val2 = word2.ToCharArray();
			//Array.Sort(val1);
			//Array.Sort(val2);
			//word1 = new string(val1);
			//word2 = new string(val2);

			//return word1 == word2;
			return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x));
		}

		/// <summary>
		/// 最小公倍数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Lcm(BigInteger a, BigInteger b)
		{
			return a * b / Gcd(a, b);
		}

		/// <summary>
		/// 最大公約数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Gcd(BigInteger a, BigInteger b)
		{
			if (a < b)
				// 引数を入替えて自分を呼び出す
				return Gcd(b, a);
			while (b != 0)
			{
				var remainder = a % b;
				a = b;
				b = remainder;
			}
			return a;
		}
	}
}

Measured memory_bytes: 27968
import Data.List
import Control.Applicative

main = do
  _ <- getLine
  xs <-  map read <$> words <$> getLine :: IO [Int]
  let bp = length xs `div` 2
  let xs' = sort xs
  let b1 = xs' !! (bp - 1)
  let b2 = xs' !! bp
  putStrLn.unwords.(map show) $ map (\i -> if i > b1 then b1 else b2) xs


Measured memory_bytes: 148860
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)
	up, _ := strconv.Atoi(s[0:2])
	down, _ := strconv.Atoi(s[2:])
	if 1 <= up && up <= 12 {
		if down == 0 || 13 <= down {
			fmt.Println("MMYY")
		} else {
			fmt.Println("AMBIGUOUS")
		}
	} else if 1 <= down && down <= 12 {
		if up == 0 || 13 <= up {
			fmt.Println("YYMM")
		} else {
			fmt.Println("AMBIGUOUS")
		}
	} else {
		fmt.Println("NA")
	}
}


Measured memory_bytes: 512
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        int res = 0;
        if (n % 1000 != 0) {
            res = n - ((n/1000) + 1) * 1000;   
        }
        System.out.println(-res);
    }
}

Measured memory_bytes: 35724
# include <cmath>
# include <iostream>
# include <iomanip>


using namespace std;


int main() {
    double a, b, x; cin >> a >> b >> x;
    double s = x/a;
    double rad;

    if (s >= a*b/2) {  // triangle
        double h = (a*b-s)*2/a;
        rad = atan2(h, a);
    }
    else {  // rectangle
        double w = s*2/b;
        rad = atan2(b, w);
    }

    double ans = rad/(2*acos(-1))*360;
    cout << setprecision(10) << ans << endl;
    return 0;
}



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


int main(){
  string s;
  cin >> s;
  int ans=0;
  if(s[0]=='R' && s[1]=='R' && s[2]=='R') ans=3;
  else if(s[0]=='R' && s[1]=='R') ans=2;
  else if(s[1]=='R' && s[2]=='R') ans=2;
  else if(s[0]=='S' && s[1]=='S' && s[2]=='S') ans=0;
  else ans=1;

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL A[200010];
int n; 
LL f(LL b)
{
	LL sum = 0;
	for(int i = 1; i<=n; i++)
	{
		sum += abs(A[i]-i-b);
	}
	return sum;
}
int main()
{
	cin>>n;
	LL minv = 10e10;
	LL maxv = -10e10;
	for(int i = 1; i<=n; i++)
	{
		cin>>A[i];
		minv = min(minv, A[i]-i);
		maxv = max(maxv, A[i]-i);
	}
	// ternary search
	LL left = minv;
	LL right = maxv+1;
	while(right - left >= 3)
	{
		LL m1 = (right-left)/3+left;
		LL m2 = 2*(right-left)/3+left;
		//if m1 < m2 discard [m2,r]
		LL fm1 = f(m1);
		LL fm2 = f(m2);
		if (fm1<fm2)
		{
			right = m2;
		}
		else
		{
			left = m1;
		}
	}
	LL ans = f(left);
	for(int i = left +1 ; i<=right; i++)
	{
		ans = min(ans, f(i));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
    ll int jhogeo = 1;
    rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
    return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}

int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){    
  int N; cin>>N;
  vector<int> A(N);
  rep(i,0,N) cin>>A[i];
  vector<int> r(N);
  vector<int> g(N);
  vector<int> b(N);

  rep(i,0,N){
    r[i]=0;
    g[i]=0;
    b[i]=0;
  }
  
  rep(i,0,N-1){
    if(r[i]==A[i]){
      r[i+1]=r[i]+1;
      g[i+1]=g[i];
      b[i+1]=b[i];
    }else if(g[i]==A[i]){
      g[i+1]=g[i]+1;
      r[i+1]=r[i];
      b[i+1]=b[i];
    }else if(b[i]==A[i]){
      b[i+1]=b[i]+1;
      g[i+1]=g[i];
      r[i+1]=r[i];
    }else{
      r[i+1]=r[i];
      g[i+1]=g[i];
      b[i+1]=b[i];
    }
  }
    ll int ans=1;
    rep(i,0,N){
      ans=(ans*((r[i]==A[i])+(g[i]==A[i])+(b[i]==A[i])))%MOD;
    }
    cout<<ans;
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 200;
int n;


int main() {
	scanf("%d", &n);
	map<int,int> tot;
	REP(i,'a','z') tot[i]=INF;
	REP(i,1,n) { 
		string s;
		cin>>s;
		map<int,int> h;
		REP(i,'a','z') h[i]=0;
		for(auto t:s) ++h[t];
		for(auto t:h) tot[t.x]=min(tot[t.x],t.y);
	}
	for (auto t:tot) {
		while (t.y--) putchar(t.x);
	}
	hr;
}








Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

vector<int> make_prime(int N){
  bool p[N+1];
  memset(p, true, sizeof(p));
  p[0] = p[1] = false;
  for(int i = 0 ; i*i < N ; i++){
    if(p[i]){
      for(int j = 2*i ; j < N ; j += i){
	p[j] = false;
      }
    }
  }
  vector<int> ret;
  for(int i = 0 ; i <= N ; i++){
    if(p[i]) ret.push_back(i);
  }
  return ret;
}
 
int main(){
  vector<int> prime = make_prime(50000);
  int m, a, b;
  while(cin >> m >> a >> b, m|a|b){
    double a_b = (double)a / (double)b;
    int max_p = 0;
    int ans1, ans2;
    for(int i = 0 ; i < prime.size() ; i++){
      if(prime[i]*prime[i] > m) break;
      for(int j = i ; j < prime.size() ; j++){
	int M = prime[i]*prime[j];
	if(M > m) break;
	if( (M <= m) && (a_b <= (double)prime[i] / (double)prime[j]) ){
	  if(max_p <= M){
	    max_p = M;
	    ans1 = prime[i], ans2 = prime[j];
	  }
	}
      }
    }
    cout << ans1 << ' ' << ans2 << endl;
  }

  return 0;
}

Measured memory_bytes: 1328
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i) = 0; (i) <= (n); (i)++)
using namespace std;

int N, Ma, Mb;
int a[40];
int b[40];
int c[40];

int dp[41][401][401];

signed main()
{
	cin >> N >> Ma >> Mb;
	REP(i, N) cin >> a[i] >> b[i] >> c[i];

	REPE(i, N)REP(j, 400)REPE(k, 400) dp[i][j][k] = INT_MAX;

	dp[0][0][0] = 0;
	REP(i, N)
	{
		REP(j, 400)REPE(k, 400)
		{
			if (dp[i][j][k] < INT_MAX)
			{
				dp[i + 1][j + a[i]][k + b[i]] = MIN(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
				dp[i + 1][j][k] = MIN(dp[i + 1][j][k], dp[i][j][k]);
			}
		}
	}

	int min = INT_MAX;
	REP(j, 400)REPE(k, 400)
	{
		if (j * Mb == Ma * k && j*k != 0)
		{
			min = MIN(min, dp[N][j][k]);
		}
	}

	if (min == INT_MAX)
	{
		cout << "-1" << endl;
	}
	else
	{
		cout << min << endl;
	}
}

Measured memory_bytes: 51712
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	ll n,s;
	cin>>n>>s;
	if(n<s){
		cout<<-1<<endl;
		return 0;
	}
	ll I;
	loop(i,2,10000000){
		if((ll)i*i>n){
			I=i;
			break;
		}
		ll sum=0;
		ll t=n;
		while(t){
			sum+=t%i;
			t/=i;
		}
		if(sum==s){
			cout<<i<<endl;
			return 0;
		}
	}
	for(int a=I;a>=0;a--){
		if(a==0){
			if(n==s){
				cout<<n+1<<endl;
				return 0;
			}
			continue;
		}
		ll c=s-a;
		if(c<0)continue;
		if((n-c)%a)continue;
		ll b=(n-c)/a;
		if(a<b&&c<b);
		else continue;
		cout<<b<<endl;
		return 0;
	}
	cout<<-1<<endl;
}
// ab+c=n  a+c=s


Measured memory_bytes: 256
while True:
    N,X = map(int,input().split())
    if N == 0 and X == 0:
        break
    ans = 0
    for a in range(1,N+1):
        for b in range(1,N+1):
            if b <= a:
                continue
            c = X-(a+b)
            if c > b and c <= N:
                ans += 1
    print(ans)



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

const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.14159265;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

#define cout cout << setprecision(12)

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void dbg(T a) { cout << a << ' '; }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;
double d;

/*--------------------template--------------------*/

int main() {
    cin >>n>>m;
  int answ[n];
  fill(answ,answ+n,-1);
  int c[m], s[m];
  REP(i,m) {
  	cin >> s[i] >> c[i];
    if(n>1&&s[i]==1&&c[i]==0) {
    	dbg(-1);
        return 0;
    }
    if(answ[s[i]-1]!=-1&&answ[s[i]-1]!=c[i]) {
    	dbg(-1);
        return 0;
    }
    if(answ[s[i]-1]==-1) {
    	ans+=pow(10,(n-s[i]))*c[i];
    	answ[s[i]-1] = c[i];
    }
  }
  if(answ[0]==-1&&n>1) {
  	ans+=pow(10,n-1);
  }
  dbg(ans);
}


Measured memory_bytes: 512
data_num = int(input())
nums = list(map(int, input().split(" ")))
cnt = 0
for i in range(data_num):
    min_idx = i
    for j in range(i, data_num):
        if nums[j] < nums[min_idx]:
            min_idx = j

    if i != min_idx:
        nums[i], nums[min_idx] = nums[min_idx], nums[i]
        cnt += 1

print(" ".join(map(str,nums)) + "\n" + str(cnt))

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

int main()
{
    int N,a;
    cin >> N;
    int max=0, min=0,cnt=0;
    int flag[8]={0};
    for(int i=0; i<N; i++) {
        cin >> a;
        if(a>=3200){
            cnt++;
        }
        else if(a<400) {
            if(!flag[0]){
                flag[0]++;
                min++;
            }
        }
        else if(a<800) {
            if(!flag[1]){
                flag[1]++;
                min++;
            }
        }
        else if(a<1200) {
            if(!flag[2]){
                flag[2]++;
                min++;
                }
        }
        else if(a<1600) {
            if(!flag[3]) {
                flag[3]++;
                min++;
            }
        }
        else if(a<2000){
            if(!flag[4]) {
                flag[4]++;
                min++;
            }
        }
        else if(a<2400) {
            if(!flag[5]) {
                flag[5]++;
                min++;
            }
        }
        else if(a<2800) {
            if(!flag[6]) {
                flag[6]++;
                min++;
            }
        }
        else if(a<3200) {
            if(!flag[7]) {
                flag[7]++;
                min++;
            }
        }
        else {}
    }
    if(N==cnt) {
        min = 1;
        max = cnt;
    }
    else { max = min+cnt; }
    cout << min << " " << max << endl;

    return 0;
}

Measured memory_bytes: 256
"use strict"
function Main(input) {
  input = input.trim().split('\n');
  const N = Number(input[0].trim());
  const A = input[1].trim().split(' ').map(Number);
  
  let map = {};
  let ret = 'YES';
  for(let i=0; i<N; i++){
    map[A[i]] = map[A[i]] ? map[A[i]] + 1 : 1;
  }

  for(let k in map){
    if(map[k] > 1){
      ret = 'NO';
      break;
    }
  }

  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
int a,s=1,d=0,f,g=0;
  cin >>a ;
  for(s;s<=a;s++){
  f=s;
    d=0;
    while(f>0){
      f/=10;
      d++;}
    if(d%2!=0){
    g++; }
  
  }cout <<g <<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n,m,c;
	cin >> n >> m >> c;
	int b[20];
	int ans = 0;
	for(int i = 0;i < m;i++) cin >> b[i];
	for(int i = 0;i < n;i++) {
		int sum = c,t;
		for(int j = 0;j < m;j++) {
			cin >> t;
			sum += t * b[j];
		}
		if(sum > 0) ans++;
	}
	cout << ans << endl;
#ifdef _DEBUG
	system("pause");
#endif
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
 
 
int main(){
  int n;
  cin >> n;
    string s;
    cin >> s;
  int ans = 0;
  rep(i, n) {
    if (i==0 || i==1) continue;
    if (s[i-2]=='A' && s[i-1]=='B' && s[i]=='C') ans++;
  }
    
    
    
    
    cout << ans << endl;
    return 0;
}

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


def f(a: int, b: int, c: int) -> int:
    if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
        return 0
    if a == b == c:
        return -1
    return f((b + c) // 2, (c + a) // 2, (a + b) // 2) + 1


def main():
    a, b, c = map(int, input().split())

    # See:
    # https://www.youtube.com/watch?v=UHfTqvaD0pk
    print(f(a, b, c))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long

using namespace std;

string s;
int k, n;

signed main() {
	ios::sync_with_stdio(false);

	cin >> s >> k, n = s.size();
	if (s[0] != s[n - 1]) {
		int cnt = 1, tot = 0;
		for (int i = 1; i < n; ++i)
			if (s[i] == s[i - 1]) ++cnt;
			else tot += cnt / 2, cnt = 1;
		tot += cnt / 2;
		cout << tot * k << endl;
	} else {
		int P = 0, S = 0;
		for (int i = 0; i < n; ++i)
			if (s[i] == s[0]) ++P;
			else break;
		for (int i = n - 1; ~i; --i)
			if (s[i] == s[n - 1]) ++S;
			else break;
		if (P == n) {
			cout << n * k / 2 << endl;
			return 0;
		}
		int cnt = 1, tot = 0;
		for (int i = P; i < n - S; ++i)
			if (s[i] == s[i - 1]) ++cnt;
			else tot += cnt / 2, cnt = 1;
		tot += cnt / 2;
		cout << tot * k + P / 2 + S / 2 + (P + S) / 2 * (k - 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
def examC(mod):
    N, M = LI()
    fac = [1]*max(N,M)
    for i in range(1,max(N,M)):
        fac[i] = (i+1)*fac[i-1]%mod
    if abs(N-M)==1:
        ans = fac[N-1]*fac[M-1]%mod
    elif abs(N-M)==0:
        ans = fac[N-1]*fac[M-1]*2%mod
    else:
        ans = 0
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC(mod)


Measured memory_bytes: 39408
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int x;
int main(){
    cin >> x;
    int thousands = x/500;
    x -= 500*thousands;
    int fives = x/5;
    x -= 5*fives;
    ll ans = 1000*thousands + 5*fives;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <math.h>

using namespace std;

int main (){
	int A,B,C;
	int ans;
	int K;
	cin >> A >> B >> C >> K;
	
	int tmp = pow(2, K);
	
	if ( A>=B && A>=C ){
		ans = A*tmp+B+C;
		} else if ( B>A && B>=C ){
			ans = B*tmp+C+A;
		} else if ( C>A && C>B ){
				ans = C*tmp+A+B;
		}  
	cout << ans << endl;
    }

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

int main()
{
        string s1,s2;cin>>s1>>s2;
    int n=s1.size();
    int m=s2.size();
    int c=0;
    sort(s1.begin(),s1.end());
    for(int i=0;i<m;i++)
        for(int j=i+1;j<=m;j++)
        if(s2[i]<s2[j])
            swap(s2[i],s2[j]);
    int x=min(n,m);
    if(s1==s2)
        cout<<"No";
    else {
        for(int i=0;i<x;i++)
        if(s1[i]>s2[i])
            {
            cout<<"No";
            break;
            }
        else if(s1[i]<s2[i])
            { cout<<"Yes";
                break;
            }
        else if(s1[n-1]==s2[n-1]&&n<m)
            {
                cout<<"Yes";break;
            }
            else
            { cout<<"No";
                break;
            }
            }

    return 0;
   }

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <cmath>
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> P;

#define rep(i, m) for(ll i=0;i<(m);i++)
#define rep1(i, m) for(ll i=1;i<=(m);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int N;
int b[100010];

int main() {
   cin >> N;
   rep(i, N) {
      int j;
      cin >> j;
      b[j]++;
   }
   int maxval = 0;
   rep(i, 100000) {
      maxval = max((i >= 1) ? (b[i-1] + b[i] + b[i+1]) : (b[i] + b[i+1]), maxval);
   }
   cout << maxval << endl;
}

Measured memory_bytes: 640
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll LOG = 20;
ll n, m, a[N];
int main(){
	IOS;
	cin >> n >> m;
	ll k;
	for (int i = 0; i < n; i++){
		cin >> k;
		for (int j = 0; j < k; j++){
			ll v;
			cin >> v;
			a[v] ++;
		}
	}
	ll Cnt = 0;
	for (int i = 1; i <= m; i++){
		if (a[i] == n) Cnt++;
	}
	cout << Cnt;
	
	
	
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 256
def main():
    import math
    N, A, B = map(int, input().split())
    h = [int(input()) for i in range(N)]
    d = A - B

    l = 1
    r = max(h)
    while(l+1 < r):
        m = (l+r)//2
        t = m*B
        count = 0
        for x in h:
            if x > t:
                count += math.ceil((x-t)/d)
        if count <= m:
            r = m
        else:
            l = m

    print(r)


main()


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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  map<int,int> cnt;
  int rem = 0;
  ll ans = 0;
  cnt[0]++;
  ll pow10 = 1;
  for (char c : s) {
    rem = (rem+(c-'0')*pow10)%2019;
    pow10 = pow10*10%2019;
    ans += cnt[rem]++;
  }
  cout << ans << endl;
}


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

struct dijkstra{
    vector<int> color;
    vector<vector<P>> adj;
    vector<int> d;
    vector<int> p;
    int n_;
    dijkstra(int n):color(n,0),adj(n),d(n,INF),p(n,-1){
        n_ = n;
    }
    void init(){
        rep(i,n_){
            int u,k;cin>>u>>k;
            rep(j,k){
                int v,c;cin>>v>>c;
                P tmp = make_pair(c,v);
                adj[i].push_back(tmp);
            }
        }
    }
    void solve(){
        init();
        d[0] = 0;
        p[0] = -1;
        priority_queue<P> Q;
        Q.push(make_pair(-d[0],0));
        //Qには、(-重み、頂点番号)を入れる.
        while(!Q.empty()){
            P u = Q.top();Q.pop();
            color[u.second] = 2;
            for(P v:adj[u.second]){    
                if(color[v.second]!=2 && -u.first+v.first < d[v.second]){
                    d[v.second] = -u.first + v.first;
                    p[v.second] = u.second;
                    color[v.second] = 1;
                    Q.push(make_pair(-d[v.second],v.second));
                }
            }
        }
        rep(i,n_){
            cout<<i<<" "<<d[i]<<endl;
        }
    }
};


int main(){
    int n;cin>>n;
    dijkstra dj(n);
    dj.solve();
    return 0;
}


Measured memory_bytes: 7872
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 日  1/13 22:32:34 2019

# Usage
#
"""
def get_input():
    _ = input()
    A = [int(i) for i in input().split(" ")]
    B = [int(i) for i in input().split(" ")]

    return A, B


def solve(A, B):
    """
    >>> solve([2,3,5],[3,4,1])
    >>> solve([2,3,3],[2,2,1])
    """
    need_magic = [a_each - b_each for a_each,b_each in zip(A,B)]
    if sum(need_magic) < 0:
        return -1
    else:
        plus = [x for x in need_magic if x > 0]
        minus = [x for x in need_magic if x < 0]
        return check_needs(plus, minus)


def check_needs(plus, minus):
    target = sum(minus)
    count = 0
    for magic in sorted(plus, reverse=True):
        if target >= 0:
            break
        target += magic
        count += 1
    return count + len(minus)


if __name__ == '__main__':
    a = get_input()
    print(solve(a[0], a[1]))


Measured memory_bytes: 18424
#include<stdio.h>

int main(void){
    int N,K;
    scanf("%d %d",&N,&K);
    char S[N];
    scanf("%s",S);
    if(S[K-1]=='A'){
        S[K-1]='a';
    }else if(S[K-1]=='B'){
        S[K-1] = 'b';
    }else if(S[K-1]=='C'){
        S[K-1]='c';
    }
    printf("%s",S);
    return 0;
}

Measured memory_bytes: 128
while True:
    A = list(map(int, input().split()))
    if A[0] == 0:
        break
 
    n, m = A[0], A[1]
    ans = 0
    for i in range(n, m+1):
        b = i
        while b % 5 == 0:
            b //= 5
        while b % 3 == 0:
            b //= 3
        while b % 2 == 0:
            b //= 2
        if b == 1:
            ans += 1
    print(ans)   
      


Measured memory_bytes: 5596
n=int(input())
 
field=[[0 for i in range(20)]for j in range(15)]
 
for i in range(n):
   
    b,f,r,v=map(int,input().split())
    h=(b-1)*4+f-1
    w=r*2-1
    n=v
    field[h][w]+=n
     
for y in range(15):
   
    for x in range(20):
       
        if(y%4==3):field[y][x]='#'
        elif x%2==0 :field[y][x]=' '
        print(field[y][x],end='')
     
    print()


Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000003;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;
ll mypow(ll a,ll b){
	ll res=1;
	a%=mo;
	while(b){
		if(b&1)
			res=res*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return res;
}
int main()
{
ll q;
cin >> q;
ll t[q][3] = {};
vector<ll> kaij;
kaij.push_back(1);
for(ll i = 1; i < mo*2; i++){
    kaij.push_back((kaij[i-1]*i)%mo);
}
rep(i, q)
{
    cin >> t[i][0]>>t[i][1]>>t[i][2];
}
rep(i,q){
    if(t[i][1]==0)ans=mypow(t[i][0],t[i][2]);
    else if(t[i][0]==0)ans=0;
    else{
        t[i][0]=t[i][0]*mypow(t[i][1],mo-2)%mo;
        ll y=t[i][0]+t[i][2]-1;
        if(y>=mo)ans=0;
        else ans=kaij[y]*mypow(t[i][1],t[i][2])*mypow(kaij[t[i][0]-1],mo-2);
    }
    cout << ans%mo << endl;
}


return 0;
}

Measured memory_bytes: 21096
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
int main()
{
    vector<ll>v;
   ll a,b,c,d;
   cin>>a>>b>>c>>d;
   v.push_back(a*c);
   v.push_back(a*d);
   v.push_back(b*c);
   v.push_back(b*d);
   sort(v.rbegin(),v.rend());
   cout<<v[0]<<endl;
   return 0;
}


Measured memory_bytes: 3624
s = gets.chomp
s_len = s.length
t = gets.chomp

s_array = s.split('')
t_array = t.split('')

t_uniq_array = t_array.uniq
indexes = {}
t_uniq_array.each do |t_e|
    r = s_array.map.with_index { |e,i| e == t_e ? i : nil }.compact
    r_f = r.first
    if r_f == nil
        puts "-1"
        exit
    end
    r.push(r_f + s_len)
    indexes[t_e] = r
end
ans = 0

memo = {}
t_uniq_array.each {|t_e| memo[t_e] = {} }

t_array.each do |t_e|
    start = ans % s_len
    a = memo[t_e][start]
    if a == nil
        a = indexes[t_e].bsearch{|i| start <= i }
        memo[t_e][start] = a
    end
    ans += (a - start + 1)
end
print ans


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

bool used[51][51][51][51];
int roomL[51][51], roomR[51][51];

int s_to_i(char c) {
  switch (c) {
  case '#':
    return -1;
  case '.':
    return 0;
  case 'L':
  case 'R':
    return 1;
  case '%':
    return 2;
  }
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    int R, C;
    cin >> C >> R;
    if (R == 0 && C == 0) break;
    REP(i, R) {
      string rowL, rowR;
      cin >> rowL >> rowR;
      REP(j, C) {
	roomL[i][j] = s_to_i(rowL[j]);
	roomR[i][j] = s_to_i(rowR[j]);
      }
    }	  

    int slr = 0, slc = 0, elr = 0, elc = 0, srr = 0, src = 0, err = 0, erc = 0;
    REP(r, R) REP(c, C) {
      if (roomL[r][c] == 1) slr = r, slc = c;
      else if (roomL[r][c] == 2) elr = r, elc = c;
      if (roomR[r][c] == 1) srr = r, src = c;
      else if (roomR[r][c] == 2) err = r, erc = c;
    }
    //cout << slr << ' ' << slc << ' ' << elr << ' ' << elc << ' ' << srr << ' ' << src << ' ' << err << ' ' << erc << endl;
    REP(i, R) REP(j, C) REP(k, R) REP(l, C) used[i][j][k][l] = false;
    
    queue<P> que;
    que.push(P(slr * C + slc, srr * C + src));

    bool flag = false;
    while (!que.empty()) {
      P p = que.front(); que.pop();
      int lr = p.first / C, lc = p.first % C, rr = p.second / C, rc = p.second % C;
      //cout << lr << ' ' << lc << ' ' << rr << ' ' << rc << endl;
      if (lr == elr && lc == elc && rr == err && rc == erc) {
	flag = true;
	break;
      } else if (used[lr][lc][rr][rc] || (lr == elr && lc == elc) || (rr == err && rc == erc)) {
	continue;
      }

      used[lr][lc][rr][rc] = true;
      REP(i, 4) {
	int nlr = lr + dr[i], nlc = lc + dc[i], nrr = rr + dr[(i+2*(i&1))%4], nrc = rc + dc[(i+2*(i&1))%4];
	if (nlr < 0 || nlr >= R || nlc < 0 || nlc >= C || roomL[nlr][nlc] == -1) nlr = lr, nlc = lc;
	if (nrr < 0 || nrr >= R || nrc < 0 || nrc >= C || roomR[nrr][nrc] == -1) nrr = rr, nrc = rc;
	if (!used[nlr][nlc][nrr][nrc]) que.push(P(nlr * C + nlc, nrr * C + nrc));
      }
    }
    cout << (flag ? "Yes" : "No") << endl;    
  }
  return 0;
}

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

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e3+5;

int a, b;
char c;
ll dp[N][N];

int main () {
    scanf("%d%d", &a, &b);
    dp[1][1] = 1;
    for (int i = 1; i <= a; i++) for (int j = 1; j <= b; j++) {
        scanf(" %c", &c);
        if (i == 1 and j == 1) continue;
        if (c == '.') dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
    }
    printf("%lld\n", dp[a][b]);
    return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
using Long = long long;

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

  set<int> S;

  for( int i = 0 ; i < n ; ++i ){
      int _x;
      cin >> _x;
      S.insert(_x);
  }

  for( int i = 0 ; i < 60 ; ++i ){
      if( S.count(x - i) == 0 ){
          cout << x - i;
          return 0;
      } else if( S.count(x + i ) == 0){
          cout << x + i ;
          return 0;
      }
  }
  
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;

void Main(){

  int N; cin>>N;
  int x[N];
  int y[N];
  rep(i,N){
    cin>>x[i]>>y[i];
  }

  vector<pair<double,int>> ve;

  rep(i,N){
    double radian = atan2(y[i],x[i]);
    ve.emplace_back(radian,i);
  }

  SORT(ve);

  auto vec=ve;

  ve.insert(ve.end(),ALL(vec));
  
  double ans=0;

  rep(i,N){
    reps(j,i,min(i+N,2*N)){
      double xsum=0, ysum=0;
      reps(k,i,j+1){
        xsum+=x[ve[k].second];
        ysum+=y[ve[k].second];
      }
      double dist=sqrt(xsum*xsum+ysum*ysum);

      maxi(ans,dist);
    }
  }

  cout<< ans <<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 384
import math
n=int(input())
#a,b,c,d=map(int,input().split())
k=pow(n,0.5)
ans=1
if(n<=3):
	print(1)
else:
	ans=-1
	for i in range(1,n+1):
		for j in range(2,n+1):
			if(pow(i,j)<=n):
				if(ans<pow(i,j)):
					ans=pow(i,j)
				
			else:
				break
	print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;

int main(){
  string S;
  cin >> S;
  string s[S.length()];
  int cnt[S.length()];
  int fr_id = 0;
  int ll_id = S.length();
  int sr_id = S.length();
  int sl_id = S.length();
  for(int i = 0; i < S.length(); i++){
    s[i] = S.substr(i, 1);
  }

  for(int i = 0; i < S.length(); i++){
    if(i == 0 || s[i] == "R" && s[i-1] == "L"){
      fr_id = i;
    }
    if(s[i] == "R" && s[i+1] == "L"){
      sr_id = i;
    }
    if(s[i] == "L" && s[i-1] == "R"){
      sl_id = i;
    }
    if(i == S.length()-1 || s[i] == "L" && s[i+1] == "R"){
      ll_id = i;
    }
    if(ll_id == i){
      FSG(j, fr_id, ll_id+1){
        if(j == sr_id){
          cout << (sr_id - fr_id) / 2 + 1 + (ll_id - sl_id)/2 + (ll_id - sl_id)%2 << " ";
        }
        else if (j == sl_id){
          cout << (sr_id - fr_id) / 2 + (sr_id - fr_id) % 2+ (ll_id - sl_id)/2 + 1 << " ";
        }
        else{
          cout << 0 << " ";
        }
      }
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 6016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
llong t[1024];
llong a[1024];

int main() {
    cin >> n;

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

    llong taka = t[0];
    llong ao = a[0];

    for (int i = 1; i < n; i++) {
        if (taka % t[i]) taka += t[i] - (taka % t[i]);
        if (ao % a[i]) ao += a[i] - (ao % a[i]);

        if (taka / t[i] > ao / a[i]) {
            ao += (taka / t[i] - ao / a[i]) * a[i];
        }
        else {
            taka += (ao / a[i] - taka / t[i]) * t[i];
        }
    }

    cout << taka + ao << endl;

    return 0;
}


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

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define PR       pair<ll, ll>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int k;
    cin >> k;
    ll sum = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int z = 1; z <= k; z++) {
                int g = __gcd(z, __gcd(i, j));
                sum += g;
            }
        }
    }
    cout << sum << '\n';
    return 0;
}


Measured memory_bytes: 3632
mod=998244353
w=[]
dp=[0]*200005
ds=[0]*200005
dp[1]=1
ds[1]=1
n,k=map(int,input().split())
for i in range(k):
    a,b=map(int,input().split())
    w.append((a,b))

for i in range(2,n+1):
    for j,k in w:
        li=i-k
        ri=i-j
        if ri<0: continue
        li=max(li,1)
        dp[i]+=ds[ri]-ds[li-1];
        dp[i]%=mod
    ds[i]=ds[i-1]+dp[i]
    ds[i]%=mod

print(dp[n])


Measured memory_bytes: 76692