akhauriyash/Code-Regression huggingface dataset:
import sys

h,w=list(map(int,input().split()))
s=[]

left=[[0]*w for _ in range(h)]
right=[[0]*w for _ in range(h)]
up=[[0]*w for _ in range(h)]
down=[[0]*w for _ in range(h)]

for i in range(h):
    s.append([x for x in sys.stdin.readline().strip()])

for i in range(h):
    cntl=0
    cntr=0
    for jl in range(w):
        jr=w-jl-1

        if s[i][jl]=='#':
            cntl=0
        else:
            cntl+=1
        
        if s[i][jr]=='#':
            cntr=0
        else:
            cntr+=1
        
        left[i][jl]=cntl
        right[i][jr]=cntr

for j in range(w):
    cntu=0
    cntd=0
    for iu in range(h):
        id=h-iu-1

        if s[iu][j]=='#':
            cntu=0
        else:
            cntu+=1
        
        if s[id][j]=='#':
            cntd=0
        else:
            cntd+=1
        
        up[iu][j]=cntu
        down[id][j]=cntd
ret=0

for i in range(h):
    for j in range(w):
        ret=max(ret,left[i][j]+right[i][j]+up[i][j]+down[i][j]-3)

print(ret)


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int t = 'A' - 'a';
    string a, b, c;
    cin >> a >> b >> c;

    cout << (char)(a[0] + t) << (char)(b[0] + t) << (char)(c[0] + t) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();
	        int[] cnt =new int[N];
	        int cnt0=0;
	        if(N%2==0)cnt0++;
	        long[] a = new long[N];
	        for (int i=0 ; i<N-1; i++) {
	            a[i] = Long.parseLong(sc.next());
	            if(a[i]==0) {
	            	cnt0++;
	            	if(cnt0>1) {
	            		System.out.println(0);
	            		return;
	            	}
	            } else if(a[i]==N%2){
	            	System.out.println(0);
	            	return;
	            } else {
	            	cnt[(int) (a[i]/2)]++;
	            	if(cnt[(int) (a[i]/2)]>2){
		            	System.out.println(0);
		            	return;	            		
	            	}
	            }
	        }
	        long ans=1;
	        for(int i=0;i<N/2;i++) {
	        	ans=(ans*2)%mod;
	        }
	        System.out.println(ans);
	 }
	 

}


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

int main(){
    string s;
    cin >> s;
    int total = 0;
    if (s[0] == '1') total += 1;
    if (s[1] == '1') total += 1;
    if (s[2] == '1') total += 1;
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define  fill(st,et,val,arr) for(int i=st;i<=et;i++)arr[i]=val;
#define all(v) v.begin(),v.end()
template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}
 
const int M=1e9 + 7;
const int MAX=1e5+7;
using namespace std;
bool comp(pair<int,int> &a,pair<int,int> &b)
{
	if(a.first!=b.first)
	   return a.first<b.first;
	else
		return a.second>b.second;
}
void printQ(deque<int> q)
{
	for(int i=0;i<q.size();i++)
	{
		cout<<q[i]<<" ";
	}
	cout<<endl;
}

int32_t main() 
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int a,b;cin>>a>>b;
	for(int i=1;i<=3;i++)
	{
		if(a!=i && b!=i)cout<<i<<endl;
	}
	return 0;
}






















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

using namespace std;

string s, t;
int dp[3001][3001];

int main(){
	cin >> s >> t;
	for(int i = 0; i < s.size(); ++i){
		for(int j = 0; j < t.size(); ++j){
			if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j]+1;
			else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
		}
	}

	string ans = "";
	int i = s.size(), j = t.size();
	while(i > 0 && j > 0){
		if(dp[i][j] == dp[i-1][j]) --i;
		else if(dp[i][j] == dp[i][j-1]) --j;
		else{
			--i; --j;
			ans += s[i];
		}
	}
	reverse(ans.begin(), ans.end());

	cout << ans << endl;
}

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

#define int long long

using namespace std;

const int N = 1e5 + 5;
int a[N], n;

signed main(){
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);

    int sum = 0;

    for (int i = 1; i <= n; i++) sum += a[i];
    int tot = n * (n + 1) / 2;

    if (sum % tot == 0) {
        int res = sum / tot;
        bool f = true;

        for (int i = 1; i <= n; i++) {
            int j = i + 1;
            if (j > n) j = 1;
            int val = a[j] - a[i] - res;
            if (val > 0 || val % n != 0) f = false;
        }

        if (f) printf("YES");
        else printf("NO");
    }
    else printf("NO");
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  string S, T;
  cin >> S >> T;

  vector<int> S_TBL[26];
  for (uint i = 0; i < S.size(); i++) {
    S_TBL[S[i] - 'a'].push_back(i+1);
  }

  uint j = 0;
  int64_t Ans = 0;
  for (uint i = 0; i < T.size(); i++) {
    auto& tbl = S_TBL[T[i] - 'a'];
    if (tbl.size() == 0) {
      cout << "-1" << endl;
      return 0;
    }
    auto itr = lower_bound(tbl.begin(), tbl.end(), j + 1);
    if (itr != tbl.end()) {
      Ans += (*itr - j);
      j = *itr;
    } else {
      itr = tbl.begin();
      Ans += S.size() - j + *itr;
      j = *itr;
    }
  }
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int cnt[2] = {0};
    rep(i, sz(s)) {
        s[i] == '0' ? cnt[0]++ : cnt[1]++;
        
    }
    cout << min(cnt[0], cnt[1]) * 2 << endl;
}


Measured memory_bytes: 512
n,m=map(int,input().split())
edge=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edge[a].append(b)
c=[[0]*(n+1) for i in range(3)]
s,t=map(int,input().split())
c[2][s]=1
q=[s]
def ken(a):
    tl=[]
    for i in q:
        for j in edge[i]:
            if not c[a][j]:
                tl.append(j)
                c[a][j]=1
    return tl
for i in range(n):
    q=ken(0)
    q=ken(1)
    q=ken(2)
    if c[2][t]==1:
        print(i+1)
        break
else:
    print(-1)

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

int main(){
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
  	reverse(t.begin(), t.end());   

    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define change(x, y) {int t = x; x = y; y = t;}

int main(){
    int cnt = 1;
    int uninum[4][9];
    int uniprime[4];
    int unisecond[4];
    double time[4][9];
    double timeprime[4];
    double timesecond[4];
    int unibottom[3];
    double timebottom[3];
    
    int i,j;
    
    for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 8; j++) {
            scanf("%d %lf", &uninum[i][j], &time[i][j]);
            if (j == 1) {
                uniprime[i] = uninum[i][j];
                timeprime[i] = time[i][j];
            }
            else if (j == 2){
                unisecond[i] = uninum[i][j];
                timesecond[i] = time[i][j];
            }
            if (timeprime[i] > timesecond[i] && j == 3) {
                change(timeprime[i], timesecond[i]);
                change(uniprime[i], unisecond[i])
            }
            if (timeprime[i] > time[i][j] && j > 2) {
                unisecond[i] = uniprime[i];
                timesecond[i] = timeprime[i];
                uniprime[i] = uninum[i][j];
                timeprime[i] = time[i][j];
            }
            else if (timesecond[i] > time[i][j] && j > 2){
                unisecond[i] = uninum[i][j];
                timesecond[i] = time[i][j];
            }
        }
    }
    for (i = 1; i <= 3; i++) {
        printf("%d %0.2f\n", uniprime[i], timeprime[i]);
        printf("%d %0.2f\n", unisecond[i], timesecond[i]);
    }
    for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 8; j++) {
            if (uniprime[i] != uninum[i][j] && unisecond[i] != uninum[i][j]) {
                if (cnt == 1) {
                    unibottom[1] = uninum[i][j];
                    timebottom[1] = time[i][j];
                }
                else if (cnt == 2){
                    unibottom[2] = uninum[i][j];
                    timebottom[2] = time[i][j];
                }
                if (timeprime[i] > timesecond[i] && cnt == 3) {
                    change(timebottom[1], timebottom[2]);
                    change(unibottom[2], unibottom[2])
                }
                if (timebottom[1] > time[i][j] && cnt > 2) {
                    unibottom[2] = unibottom[1];
                    timebottom[2] = timebottom[1];
                    unibottom[1] = uninum[i][j];
                    timebottom[1] = time[i][j];
                }
                else if (timebottom[2] > time[i][j] && cnt > 2){
                    unibottom[2] = uninum[i][j];
                    timebottom[2] = time[i][j];
                }
                cnt++;

            }
        }
    }
    for (i = 1; i <= 2; i++) {
        printf("%d %0.2f\n", unibottom[i], timebottom[i]);
    }
    return 0;
}

Measured memory_bytes: 652
#include <stdio.h>
#include <math.h>
int main(void)
{
    double r,s,l;
    scanf("%lf",&r);

    s = r*r*M_PI;
    l = 2*r*M_PI;

    printf("%.6lf %.6lf\n",s,l);
    return 0;
}

Measured memory_bytes: 652
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
using namespace std;

#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vector<int>>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define itr(v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fd(i,n)         for(int i=n-1;i>=0;i--)
#define fir(i,a,b)      for(int i=a;i<b;i++)
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);
#define MAXZ            200005
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

bool cmp(int a,int b) {return a>b;}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}

int a[200001],b[200001];

int32_t main()
{
    FIO
    int k; cin>>k;
    string s; cin>>s;
    if(s.length()>k){
        s=s.substr(0,k);
        s+="...";
    }
    cout<<s<<"\n";
    return 0;

}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve()
{
	ll n;
	cin >> n;
	ll ans = 0;
	ll ma = 0;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	for (int i = 1; i < n; ++i)
	{
		ans += max(0LL, a[i - 1] - a[i]);
		a[i] = max(a[i], a[i - 1]);
	}
	cout << ans << endl;
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin >> T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 5216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;

int main(){
	long long q,h,s,d,n;
	long long onel,twol;
	long long ans=0;
	cin>>q>>h>>s>>d>>n; 
	onel=min(4*q,min(2*h,s));
	twol=min(2*onel,d);
	if(n%2==0)
	ans=twol*(n/2);
	else
	ans=twol*(n/2)+onel;

	cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 666;
long double dp[MAXN], f[MAXN];
vector<int> edge[MAXN];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, m;
	cin >> n >> m;
	rep (i, 1, m) {
		int u, v;
		cin >> u >> v;
		edge[u].pb(v);
	}
	dp[n] = 0;
	per (i, n - 1, 1) {
		for (auto v : edge[i]) {
			dp[i] += dp[v] + 1;
		}
		dp[i] /= SZ(edge[i]);
	}
	long double res = dp[1];
	rep (i, 1, n - 1) {
		if (SZ(edge[i]) == 1) continue; 
		long double delt = 0;
		for (auto v : edge[i]) {
			delt = max(delt, dp[v]);
		}
		memcpy(f, dp, sizeof(f));
		f[i] = (f[i] * SZ(edge[i]) - delt - 1) / (SZ(edge[i]) - 1);
		per (j, i - 1, 1) {
			f[j] = 0;
			for (auto v : edge[j]) {
				f[j] += f[v] + 1;
			}
			f[j] /= SZ(edge[j]);
		}
		res = min(res, f[1]);
	}
	cout << fixed << setprecision(10) << res << endl;
	return 0;
}

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

int main() {
	int ans;
	string str;
	do {
		getline(cin,str);
		if (str=="0") break;
		for(unsigned int i=0;i<str.length();++i) {
			ans+=str[i]-'0';
		}
		cout << ans << endl;
		ans=0;
	} while(1);
	return 0;
}

Measured memory_bytes: 3144
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
#define int long long
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int N; cin>>N;
  vector<string>A(N);
  rep(i,N)cin>>A[i];
  sort(A.begin(),A.end());
  int ans=1;
  vector<int>B(N+1);
  REP(i,N){
    if(A[i]==A[i-1])ans++;
    else{
      B[i]=ans;
      ans=1;
    }
  }
  if(ans!=1)B[N-1]=ans;
  sort(B.begin(),B.end());
  reverse(B.begin(),B.end());
  ans=1;
  REP(i,N){
    if(A[i]==A[i-1])ans++;
    else{
      if(ans==B[0])cout<<A[i-1]<<endl;
      ans=1;
    }
  }
  if(ans==B[0])cout<<A[N-1]<<endl;
}

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

int main(){

 int h = 0, w = 0, i;

 while(1) {
  cin >> h >> w;

  if ((h == 0) && (w == 0)) break;

  for (h; h > 0; h--) {
   for (i = w; i > 0; i--) {
    cout << "#";
   }
   cout << endl;
  }
  cout << endl;
 }

 return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<bitset>
using namespace std;
bitset<4000006> a;
int n,s=0,x;
int main()
{
	a[0]=1;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&x);
		a=a|(a<<x);
		s+=x;
	}
	for(int i=s/2+s%2;;i++)
		if(a[i]){printf("%d\n",i);return 0;}
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <chrono>
#define fr first
#define sc second
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll md = 1000000007;
vl fac(2,1), ifac(2,1);

ll ad(ll a, ll b) {
    return (a%md + b%md + md) % md;
}

ll ml(ll a, ll b) {
    return ( (a%md) * (b%md) ) % md;
}

void cachefact(ll lim, ll mod = md) {
    for(int i = 2; i <= lim; i++) {
        ifac.push_back((ifac[mod%i] * (mod - mod/i) % mod)%mod);
    }
    for(ll i = 2; i <= lim; i++) {
        fac.push_back((fac[i-1] * i)%mod);
        ifac[i] = (ifac[i-1] * ifac[i])%mod;
    }
}

ll C(int n, int r) {
    if(n < r || r < 0) return 0;
    return ml(fac[n], ml(ifac[r], ifac[n-r]));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cachefact(2e5);
    int h, w, n, i, j;
    cin >> h >> w >> n;
    h--, w--;
    ll ans = C(h+w, h);
    vector<pair<ll,ll>> a(n);
    for(i = 0; i < n; ++i) {
    	cin >> a[i].fr >> a[i].sc;
    	a[i].fr--;
    	a[i].sc--;
    }
    sort(a.begin(), a.end());
    vl dp(n);
    for(i = 0; i < n; ++i) {
    	dp[i] = C(a[i].fr + a[i].sc, a[i].fr);
    	for(j = 0; j < i; ++j) {
    		if(a[j].fr <= a[i].fr && a[j].sc <= a[i].sc) {
    			dp[i] = ad(dp[i], - ml(dp[j], C(a[i].fr + a[i].sc - a[j].fr - a[j].sc, a[i].fr - a[j].fr)));
    		}
    	}
    }
    for(i = 0; i < n; ++i) {
    	ans = ad(ans, - ml(dp[i], C(h + w - a[i].fr - a[i].sc, h - a[i].fr)));
    }
    cout << ans << "\n";
    return 0;
}

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

int main()
{
  int a, b;
  cin >> a >> b;
  if (a >= 13)
  {
    cout << b;
  }
  else if (a >= 6 && a <= 12)
  {
    cout << b / 2;
  }
  else
  {
    cout << 0;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

int main() {
    int n;
    long long k;
    cin >> n >> k;
    // n番目の町の転移先の配列
    vector<int> a(n);
    rep(i, n) {
        cin >> a.at(i);
        // 0-indexで考える
        a.at(i)--;
    }

    // ループが発生するため、それを利用する
    // ただしループ前にk回転移することもある

    // ループ部分
    deque<int> loop;
    // 一度来た町かどうか
    vector<bool> visited(n, false);
    // 現在の町
    int current = 0;

    while (true) {
        // 現在の町が既に訪れた町であった場合
        if (visited.at(current)) {
            // ループ開始地点までloopを前から消去
            while (loop.at(0) != current) {
                k--;
                loop.pop_front();

                // ループ前にk回転移したらそこで終わり
                if (k == 0) {
                    cout << loop.at(0) + 1 << endl;
                    return 0;
                }
            }
            // ここにbreakを入れないと終わらない
            break;
        }

        // ループが見つかるまでの処理

        // 現在の町をループ部分に追加
        loop.push_back(current);
        // 現在の町を訪れたことにする
        visited.at(current) = true;
        // 次の町に転移
        current = a.at(current);
    }

    // k >= ループ開始地点までの転移回数 のとき
    // ループ開始地点から (k % loop.size) 回転移したところが答え
    cout << loop.at(k % loop.size()) + 1 << endl;
}


Measured memory_bytes: 4768
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

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

	Int N, K;
	cin >> N >> K;

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

	vector<pair<mint, mint>> count(N, pair<mint, mint>());

	Int before;
	Int after;
	for (Int i = 0; i < N; i++) {
		before = 0;
		after = 0;
		for (Int j = 0; j < N; j++) {
			if (i == j) continue;
			if ((j < i) && (a[i] > a[j]))before++;
			if ((j > i) && (a[i] > a[j]))after++;
		}
		count[i].first = before;
		count[i].second = after;
	}

	mint ans = 0;
	for (Int i = 0; i < N; i++) {
		ans += count[i].second * K + (count[i].second + count[i].first) * K * (K - 1) / 2;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter
N,M=map(int,input().split())
A=list(map(int,input().split()))
A[0] = A[0] % M
for i in range(1,N): A[i] = (A[i]+A[i-1])%M
cnt = Counter([0]+A)
print(sum(n*(n-1)//2 for n in cnt.values()))


Measured memory_bytes: 14920
A,B,C,X,Y=map(int,input().split())
if A+B <= 2*C:
	print(A*X+B*Y)
else:
	if X > Y:
		if A <= 2*C:
			print(2*C*Y+A*(X-Y))
		else:
			print(2*C*X)
	else:
		if B <= 2*C:
			print(2*C*X+B*(Y-X))
		else:
			print(2*C*Y)


Measured memory_bytes: 3060
using System;

class Program
{
    static void Main(string[] args)
    {
        int input = int.Parse(Console.ReadLine());
        int second = input % 60;
        int minute = ((input - second) / 60) % 60;
        int hour = ((input - second) / 60 - minute) / 60;

        Console.WriteLine(hour.ToString() + ':' + minute.ToString() + ':' + second.ToString());
    }
}


Measured memory_bytes: 15988
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int X, Y;

int main(void)
{
  cin >> X >> Y;
  cout << (X + Y / 2) << endl;
  return 0;
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

//------------------------------------------------------

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

    ll n;
    cin >> n;
    ll c[n];
    rep(i, n) cin >> c[i];
    ll dp[n + 1];
    dp[0] = 1;
    vector<ll> before_pos(limit, -1);
    for (ll i = 1; i <= n; ++i) {
        if (before_pos[c[i - 1]] == -1 || before_pos[c[i - 1]] == i - 1) { //初めての色or直前の色
            dp[i] = dp[i - 1] % MOD;
        } else {
            dp[i] = (dp[i - 1] + dp[before_pos[c[i - 1]]]) % MOD;
        }
        before_pos[c[i - 1]] = i;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define ull unsigned ll
#define pll pair<ll, ll>
#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout);
#define M 1000000007
#define N 200000
#define INF 101111111111111
using namespace std;
main(){
    FAST;
    ll n;
    scanf("%lld", &n);
    if(n < 10){
    	printf("Yes\n");
    	exit(0);
    }
    for(ll i = 2;i<=9;i++){
    	if(n%i == 0 && n/i < 10){
    		printf("Yes\n");
    		exit(0);
    	}
    }
    printf("No\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
  string a, b, c, s;
  cin >> a >> b >> c;

  s += a[0];
  s += b[0];
  s += c[0];

  transform(s.begin(), s.end(), s.begin(), ::toupper);
  cout << s << endl;

}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a > b)cout << a - 1 << endl;
    else cout << a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
template<class T=ll> 
T in(){T x;cin>>x;return (x);}
template<class T> 
void print(T &x){cout<<x<<"\n";}
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cerr << #x"="<< (x) << "\n"
#define dbgv(x) cerr<<#x<<"\n";reps(y,x){cerr<<y<<" ";}cerr<<"\n"
int main(){
  int n=in();
  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
  }

  sort(all(p));

  int ans=0;
  rep(i,n-1){
    ans+=p[i];
  }
  ans+=p[n-1]/2;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())

cnt = 0
if B == 1:
    cnt = 0
elif A >= B:
    cnt = 1
else:
    # A < B
    cnt = 0
    while True:
        # A -= 1
        # A += A
        # cnt += 1
        if A - cnt + (A * cnt) >= B:
            break
        cnt += 1

    cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <iostream>
#include <ctype.h>
#include <string>
typedef long long ll;
using namespace std;
#define mod 1e9+7

void count(int &cnt, vector<vector<int>>&fr, int index, vector <bool>&seen){
  if(seen[index] != true){
    seen[index] = true;
    cnt++;
    for(int i : fr[index]){
      count(cnt, fr , i , seen);
    }
  }

}

int main(){
  
  int n,m;
  cin>>n>>m;
  int a,b;
  
  vector <vector<int>> fr(n,vector<int>(0));
  rep(i,m){
    cin>>a>>b;
    fr[a-1].push_back(b-1);
    fr[b-1].push_back(a-1);
  
  }
  vector<bool> seen (n,false);

  int cnt =0 ,ans = 0;
  rep(i, n){
    count(cnt, fr , i , seen);
    if(cnt>ans) ans = cnt;
    cnt=0;
  }
  cout<<ans;


}

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

int func(int x){
    if(x<10) return x;
    return x%10 + func(x/10);
}

int main(){
    int N;
    cin >> N;
    
    if(N%func(N)==0){
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long dp[100005];
long long f(int n, vector<int>&V){
	if(n == V.size() - 1) return 0;
	if(dp[n] != -1) return dp[n];
	int ans1 = abs(V[n] - V[n + 1]);
	if(n + 2 >= V.size()) return dp[n] = ans1 + f(n + 1, V);
	int ans2 = abs(V[n] - V[n + 2]);
	return dp[n] = min(ans1 + f(n + 1, V) , ans2 + f(n + 2, V));
}
int main() {
	int n;
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<int> V(n);
	for(int i=0; i<n;i++) cin >> V[i];
	cout << f(0, V);
	return 0;
}

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

int main(){
	int n,l;
	cin >> n >> l;
	int ans = 0;
	int nokori = 0;
	int mn = 100000000;
	int a = 0;
	for(int i = 1; i <=n; i++){
		ans += l+i-1;
	}
	for(int i = 1; i <=n; i++){
		nokori = ans;
		nokori += -l-i+1;
		if(abs(ans-nokori) < mn){
			mn = abs(ans - nokori);
			a = nokori;
		}
	}
	cout << a << endl;
}

// cout << fixed << setprecision(15) <<  << endl;

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
static const int mod = 1e9+7;
int main(){
    int n, now; sc(n)
    string s1, s2;
    cin >> s1 >> s2;
    bool check;
    ll ans;
    if (s1[0] == s2[0]){
        check = true;
        ans = 3;
        now = 1;
    }else {
        check = false;
        ans = 6;
        now = 2;
    }
    while (now < n){
        if (s1[now] == s2[now]){
            if (check) ans = ans * 2 % mod;
            check = true;
            now += 1;
        }else {
            if (check) ans = ans * 2 % mod;
            else ans = ans * 3 % mod;
            check = false;
            now += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        if(a >= 13){
        	ans = b;
        }else if(a <= 13 && a >= 6){
            ans = b / 2;
        }else if(a < 6){
        	ans = 0;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
int_a, int_b, division_num = map(int, input().split())
division_count = 100
select_division = []
i = 1

while i < division_count:
    if int_a % i == 0 and int_b % i == 0:
        division_count += 1
        select_division.append(i)
    i += 1

print(select_division[-division_num])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i,y,n,inc)	for(int i=y;i<n+y;i+=inc)
#define cin(t) int t;cin>>t
#define w(t) while(t--)
#define nl cout<<endl;
#define pb push_back
#define ft(i) (i&(-1*i))
#define arrIn(arr,size)		for(int i=0;i<size;i++){cin>>arr[i];}
#define arrOut(arr,size,seperater)	for(int i=0;i<size;i++){cout<<arr[i]<<seperater;}
using namespace std;

int max(int a, int b) {
	if (a > b)
		return a;
	return b;
}

int min(int a, int b) {
	if (a < b)
		return a;
	return b;
}

void fastIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}

int n;
int arr[305];
double dp[305][305][305];

double solve(int i, int j, int k) {

	// base case
	if (i == 0 && j == 0 && k == 0) {
		return 0;
	}

	if (dp[i][j][k] != -1)	return dp[i][j][k];
	double oneProb = (double)i / (double)n;
	double twoProb = (double)j / (double)n;
	double threeProb = (double)k / (double)n;
	double zeroProb = double(n - i - j - k) / (double)n;
	double ans = 0;

	ans = 1;
	if (i > 0) ans += solve(i - 1, j, k) * oneProb;
	if (j > 0) ans += solve(i + 1, j - 1, k) * twoProb;
	if (k > 0) ans += solve(i, j + 1, k - 1) * threeProb;
	ans /= ((double)1 - zeroProb);
	return dp[i][j][k] = ans;
}


int32_t main() {

	fo(i, 0, 305, 1) {
		fo(j, 0, 305, 1) {
			fo(k, 0, 305, 1) {
				dp[i][j][k] = -1;
			}
		}
	}

	cin >> n;

	int oneCount, twoCount, threeCount;
	oneCount = twoCount = threeCount = 0;
	fo(i, 0, n, 1) {
		cin >> arr[i];
		if (arr[i] == 1) 	oneCount++;
		if (arr[i] == 2)	twoCount++;
		if (arr[i] == 3)	threeCount++;

	}

	cout << fixed << setprecision(9) << solve(oneCount, twoCount, threeCount); nl;
	return 0;
}

// cout << "Case #" << i << ": " << answer << endl;

Measured memory_bytes: 221952
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include<bits/stdc++.h>
/*#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>*/
ll z =  1000000007 ;
ll inf = 100000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;


 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	 
	ll n ;
	cin >> n ;
	ll arr[n] ;
	map<ll , ll> m ;
	vector<ll> v ;
	
	fo(i , n)
	{
		cin >> arr[i] ;
		if(m[arr[i]] == 0)
			v.pub(arr[i]) ;
		m[arr[i]]++ ;
	}
	ll ans = 0 ;
	
	fo(i , v.size())
	{
		ll a = m[v[i]] ;
		ans += (((a)*(a-1)) / 2) ;
	}
	fo(i , n)
	{
		cout << (ans - (m[arr[i]] - 1)) << '\n' ;
	}
	return 0;
}

Measured memory_bytes: 12020
#include "bits/stdc++.h"
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define int long long

int mod=1e9+7;

vector<int> adj[100001];


pair<int,int> dfs(int s,int p){
	
	int s_black=1; int s_white=1;
	for(auto c: adj[s]){

		if(c!=p){

		pair<int,int>res= dfs(c,s) ;
		
		//s is black  
		s_black=s_black*res.second % mod;
		
		//s is white  
		s_white=s_white*((res.second+res.first)%mod) % mod;
		}
	}
	
	return {s_black,s_white} ;
	
}


signed main(){

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
// online submission
#endif


int n;
cin >> n;


for(int i=0;i<n-1;i++){
	int x,y;
	cin >> x >> y;
	adj[x].push_back(y);
	adj[y].push_back(x);
}

pair<int,int> res=dfs(1,-1);

cout<< (res.first+res.second)%mod;

    return 0;
}




Measured memory_bytes: 14664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define var auto
using namespace std;
using ll = long long;
using P = pair<int, int>;
#ifdef DEBUG
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; cout << a << endl; return 1; } cout << a << endl; return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; cout << a << endl; return 1; } cout << a << endl; return 0; }
#else
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#endif
const ll INF = 1LL << 60;
const int MAX_ITEM = 10e5+10;
ll dp[MAX_ITEM][3] = {0};


int main() {
  int n; 
  cin >> n;
  int a[n],b[n],c[n];
  rep(i,n) {
    cin >> a[i] >> b[i] >> c[i];
  }
  
  // 回す
  rep(i,n) {
    chmax(dp[i+1][0], dp[i][1] + a[i]);
    chmax(dp[i+1][0], dp[i][2] + a[i]);
    chmax(dp[i+1][1], dp[i][0] + b[i]);
    chmax(dp[i+1][1], dp[i][2] + b[i]);
    chmax(dp[i+1][2], dp[i][0] + c[i]);
    chmax(dp[i+1][2], dp[i][1] + c[i]);
  }
  
  // 最大の価値は 終わりが ABC どれか？
  ll res;
  chmax(res, dp[n][0]);
  chmax(res, dp[n][1]);
  chmax(res, dp[n][2]);

  cout << res << endl;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 1000000;
LL sum[N];
int n;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++ i)
    {
        int a; cin >> a;
        sum[i] = sum[i - 1] + a;
    }
    LL ans = 1e18;
    for (int i = 1; i < n; ++ i) ans = min(ans, abs(sum[i] - (sum[n] - sum[i])));
    cout << ans << endl;
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10 ** 7)

N, A, B, C = map(int, input().split())
command = [sorted(list(input())) for _ in range(N)]

ans = []


def game(i, a, b, c, prev):
    if i == N:
        ans.append(prev)
        return True
    x, y = command[i]
    if x == "A" and y == "B":
        if b:
            bl = game(i + 1, a + 1, b - 1, c, x)
            if bl:
                ans.append(prev)
                return True
        if a:
            bl = game(i + 1, a - 1, b + 1, c, y)
            if bl:
                ans.append(prev)
                return True
    elif x == "A" and y == "C":
        if c:
            bl = game(i + 1, a + 1, b, c - 1, x)
            if bl:
                ans.append(prev)
                return True
        if a:
            bl = game(i + 1, a - 1, b, c + 1, y)
            if bl:
                ans.append(prev)
                return True
    else:
        if c:
            bl = game(i + 1, a, b + 1, c - 1, x)
            if bl:
                ans.append(prev)
                return True
        if b:
            bl = game(i + 1, a, b - 1, c + 1, y)
            if bl:
                ans.append(prev)
                return True

    return False


bl = game(0, A, B, C, "?")
if not bl:
    print("No")
else:
    print("Yes")
    ans.pop()
    for x in ans[::-1]:
        print(x)

Measured memory_bytes: 114820
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
using namespace std;
string S;
string tmp;
string ans = "Yes";

int main() {
	cin >> S;
	int l = S.length();
	for (int i = 0;i < l;i++) {
		tmp = S[i];
		if ((i % 2 == 0 && tmp == "L") || (i % 2 == 1 && tmp == "R")) {
			ans = "No";
			break;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long ans = 0;
        long mons = 1;
        while (h > 0) {
            ans += mons;
            mons *= (long) 2;
            h /= 2;
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 24020
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N, x int

func main() {
	sc.Split(bufio.ScanWords)
	//X: 最初のマス
	N, x = nextInt(), nextInt()

	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = nextInt()
	}

	sort.Ints(a)
	ans := 0
	j := 0
	for i := 0; i < N; i++ {
		if a[i] <= x {
			ans++
			x -= a[i]
			j = i
			continue
		}
	}
	if x > 0 && j == N-1 {
		ans--
	}

	fmt.Println(maxInt(0, ans))
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

const int N = 1e5 + 5;
int in[N];
int a[N], b[N];

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> in[i];
        if(i&1) a[in[i]]++;
        else b[in[i]]++;
    }

    vector< pair< int, int> > Va, Vb;
    for(int i = 1; i < N; ++i) {
        if(a[i]) Va.emplace_back(a[i], i);
        if(b[i]) Vb.emplace_back(b[i], i);
    }

    sort(Va.rbegin(), Va.rend());
    sort(Vb.rbegin(), Vb.rend());

    if(Va.size() == 1 and Vb.size() == 1) {
        if(Va[0].second != Vb[0].second) return !printf("0");
        return !printf("%d\n", n / 2);
    }

    int res = n;
    for(int i = 0; i < (int) Va.size() and i < 10; i++) {
        for(int j = 0; j < (int) Vb.size() and j < 10; ++j) {
            if(Va[i].second == Vb[j].second) continue;
            res = min(res, n - Va[i].first - Vb[j].first);
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 2428
////////////////////////////////////
////////////////////////////////////
////                            ////
////                            ////
////     Please give me AC!     ////
////     Please give me AC!     ////
////                            ////
////                            ////
////////////////////////////////////
////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
const long long  MOD=13;
long long mod_pow(long long x,long long y){//x^yを返す//計算量は0(log(y))
  long long t=x,r=1;
  while(y){
    if(y%2){r=r*t%MOD;}
    y>>=1;
    t=t*t%MOD;
  }
  return r;
}
int main(){
  string S;
  cin>>S;
  long long dp[200020][26];
  long long dpcopy[13],mod=1e9+7;
  for(long long i=1;i<=(long long)S.size();i++){
    if(S.at(i-1)=='?'){
      for(long long j=0;j<13;j++){
        if(i==1 && j<10){
          long long w=(long long)S.size()-1;
          long long a=mod_pow(10,w)*j;
          a%=13;
          dp[1][a]=1;
        }
        else if(i>1){
          for(long long k=0;k<13;k++){
            dpcopy[k]=dp[i-1][k];
          }
          for(long long k=0;k<10;k++){
            long long w=(long long)S.size()-i;
            long long a=mod_pow(10,w)*k;
            a%=13;
            dp[i][j]+=dpcopy[(j-a+13)%13];
            dp[i][j]%=mod;
          }
          for(long long k=0;k<13;k++){
            dp[i-1][k]=dpcopy[k];
          }
        }
      }
    }
    else{
      if(i==1){
        long long w=(long long)S.size()-i;
        long long a=mod_pow(10,w)*(S.at(i-1)-'0');
        a%=13;
        dp[1][a]=1;
      }
      else{
        for(long long j=0;j<13;j++){
          dpcopy[j]=dp[i-1][j];
        }
        long long w=(long long)S.size()-i;
        long long a=mod_pow(10,w)*(S.at(i-1)-'0');
        a%=13;
        for(long long j=0;j<13;j++){
          dp[i][j]=dpcopy[(j-a+13)%13];
        }
        for(long long j=0;j<13;j++){
          dp[i-1][j]=dpcopy[j];
        }
      }
    }
  }
  cout<<dp[(long long)S.size()][5]<<endl;
}

Measured memory_bytes: 24060
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    char[] S = scanner.next().toCharArray();
    boolean[][] left = new boolean[N][10];
    boolean[][] right = new boolean[N][10];
    for (int i = 1; i < N; i++) for (int j = 0; j < 10; j++) left[i][j] = left[i - 1][j] || S[i - 1] - '0' == j;
    for (int i = N - 2; i >= 0; i--) for (int j = 0; j < 10; j++) right[i][j] = right[i + 1][j] || S[i + 1] - '0' == j;
    boolean[][][] exist = new boolean[10][10][10];
    for (int i = 0; i < N; i++) {
      int k = S[i] - '0';
      for (int j = 0; j < 10; j++) for (int l = 0; l < 10; l++) exist[j][k][l] |= left[i][j] && right[i][l];
    }
    int count = 0;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          if (exist[i][j][k]) count++;
        }
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 25312
#include<stdio.h>
int main(void){
	int _c1,_c5,_c10,_c50,_c100,_c500,a,b,c,d,e,f;
	_c1=1;
	_c5=5;
	_c10=10;
	_c50=50;
	_c100=100;
	_c500=500;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	if(_c1*a+_c5*b+_c10*c+_c50*d+_c100*e+_c500*f>=1000)
	printf("1\n");
	else
	printf("0\n");
	return 0;
}

Measured memory_bytes: 584