akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <assert.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int tmp = 0, k;
	for (int i = 1; tmp < n; i++)
	{
		tmp += i;
		k = i + 1;
	}
	if (n != tmp)
	{
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	cout << k << endl;
	vector<vector<int>> s(k);
	int next = 1;
	for (int i = 0; i < k; i++)
		for (int j = i + 1; j < k; j++)
		{
			s[i].push_back(next);
			s[j].push_back(next);
			next++;
		}
	int size = s[0].size();
	for (int i = 0; i < k; i++)
	{
		cout << size << " ";
		for (int j = 0; j < size; j++)
			cout << s[i][j] << (j == size - 1 ? "" : " ");
		cout << endl;
	}

	return 0;
}


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

int main() {
  int X[5]; for (int i = 0; i < 5; i++) cin >> X[i];
  for (int i = 0; i < 5; i++) {
    if (X[i] == 0) {
      cout << i+1 << endl;
    }
  }
}

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


int main(){
    ll x;
    cin >> x;

    if((x%11)==0) cout << x/11*2 << endl;
    else if(x%11==6) cout << x/11*2+x%11/6 << endl;
    else cout << x/11*2+x%11/6+1 << endl;
}

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

int main(){
  int a;
  cin >> a;
  a %= 10;
  if(a==3){
    cout << "bon" << endl;
  } else if(a==0||a==1||a==6||a==8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3588
#include <cstdio>
#include <deque>
#include <utility>
using namespace std;
typedef pair<int,int> P;
deque<P> que;
deque<P> removeCard(int x) {
	deque<P> res;
	while(1) {
		P p=que.front();que.pop_front();
		x-=(p.second-p.first+1);
		if(x<=0) {
			if(x!=0) {
				que.push_front(P(p.second+x+1,p.second));
				p.second+=x;
			}
			res.push_back(p);
			break;
		}
		res.push_back(p);
	}
	return res;
}
void shuffle(int x,int y) {
	deque<P> A=removeCard(x),B=removeCard(y-x);
	for(int i=0;i<B.size();i++)que.push_back(B[i]);
	for(int i=0;i<A.size();i++)que.push_back(A[i]);
}
int main() {
	int n,m,p,q,r,x,y;
	while(scanf("%d",&n),n) {
		que.clear();
		que.push_back(P(1,n));
		scanf("%d",&m);
		scanf("%d %d %d",&p,&q,&r);
		for(int i=0;i<m;i++) {
			scanf("%d %d",&x,&y);
			shuffle(x,y);
		}
		removeCard(p-1);
		deque<P> rem=removeCard(q-p+1);
		int ans=0;
		for(int i=0;i<rem.size();i++) {
			if(rem[i].first<=r) {
				if(rem[i].second>=r) {
					ans+=(r-rem[i].first+1);
				}else {
					ans+=(rem[i].second-rem[i].first+1);
				}
			}
		}
		printf("%d\n",ans);
	}
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define loop(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

int main(){
  int n,k;cin >> n >> k;
  k=k*2+1;
  string s;cin >> s;

  vint v;int now=1,cnt=0;
  
  rep(i,n){
    if(now==ctoi(s[i])) cnt++;
    else {
      now^=1;
      v.push_back(cnt);
      cnt=1;
    }
  }
  if(now==ctoi(s.back())) v.push_back(cnt);
  if((int)v.size()%2==0) v.push_back(0); 

  int ans=0;
  for(int i=0;i<v.size();i+=2){
    int sum=0;
    int left=i,right=min(i+k,(int)v.size());
    for(int j=left;j<right;++j)
      sum+=v[j];
    chmax(ans,sum);
  }

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


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

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

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

	cin >> N >> M >> K;
	cout << K / N * M << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <vector>
#include <climits>
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> X(M);
	for (auto i = 0; i < M; ++i)
	{
		cin >> X[i];
	}

	sort(X.begin(), X.end());

	priority_queue<int, std::vector<int>, greater<int>> q;
	for (auto i = 1; i < M; ++i)
	{
		q.push(X[i] - X[i - 1]);
	}

	auto sum = 0;
	auto remain = M - N;
	for (auto i = 0; i < remain; ++i)
	{
		sum += q.top();
		q.pop();
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,n;
	cin>>n>>m;
	vector<int> ve[n+2];
	for(int i=0;i<m;i++)
	{
		int u,v;
                cin>>u>>v;
		ve[u].push_back(v);
		ve[v].push_back(u);
	}
	for(int i=1;i<=n;i++){
		cout<<ve[i].size()<<endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T U;
L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
  d=I->first,!Z[d]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L a,L i){for(a=M(i++G i);i<2e5;i+=i&-i)B[i]+=a;}
L K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;
       for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:(A[a]+=b,S(H[a],O[a]),S(a,O[a]-1)));}

Measured memory_bytes: 38100
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
ans = 0
if N % 2 == 0:
    ans = 2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2 - 1])) + A[N // 2] - A[N // 2 - 1]
else:
    x = 2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2 - 1])) - A[N // 2] - A[N // 2 - 1]
    y = 2 * (sum(A[N // 2 + 2:]) - sum(A[:N // 2])) + A[N // 2] + A[N // 2 + 1]
    ans = max(x, y)
print(ans)

Measured memory_bytes: 7516
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int i,c=0;
    cin>>s;
    if(s=="Sunny")
    {
        cout<<"Cloudy"<<endl;
    }
    if(s=="Cloudy")
    {
        cout<<"Rainy"<<endl;
    }
    if(s=="Rainy")
    {
        cout<<"Sunny"<<endl;
    }


}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <map>

using namespace std;

long long f[1000010];


int main()
{
    int n,w;scanf("%d%d",&n,&w);int ans=0;
    for (int i=1;i<=1e6;++i)
        f[i]=1LL*w+1;
    // f[i][j]= f[i-1][j] / f[i-1][j-w[i]]+v[i];
    for (int i=0;i<n;++i){
        int ww,vv;scanf("%d%d",&ww,&vv);
        for (int j=1e6;j>=vv;--j){
            if (f[j-vv]+ww<f[j])
                f[j]=f[j-vv]+ww;
            if (f[j]<=w && j>ans)
                ans=j;
        }
    }
    printf("%d\n",ans);

}











Measured memory_bytes: 7936
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	 	int h = sc.nextInt();
 		int w = sc.nextInt();
		char[][] s = new char[h][w];
		boolean flag = true;

		for (int i = 0; i < h; i++) {
			String l = sc.next();
			for (int j = 0; j < w; j++) {
				s[i][j] = l.charAt(j);
			}
		}

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (s[i][j] == '.') {
					continue;
				}
				boolean up = false;
				boolean down = false;
				boolean left = false;
				boolean right = false;

				if (i > 0 && s[i - 1][j] == '#') {
					up = true;
				}
				if (i < h - 1 && s[i + 1][j] == '#') {
					down = true;
				}
				if (j > 0 && s[i][j - 1] == '#') {
					left = true;
				}
				if (j < w - 1 && s[i][j + 1] == '#') {
					right = true;
				}

				if (!up && !down && !left && !right) {
					flag = false;
					break;
				}
			}
			if (!flag) {
				break;
			}
		}

		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
  }
}


Measured memory_bytes: 21844
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	string s;
	getline(cin, s);

	transform(s.begin(), s.end(), s.begin(), ::toupper);

	cout << s << endl;
}


Measured memory_bytes: 3116
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, K;
int A[100010], B[100010];
int rec[35];

signed main() {
    cin >> N >> K;
    rep(i,0,N) cin >> A[i] >> B[i];

    int M = 0;
    rep(i,0,32) if(K >> i & 1) M = i;

    rep(i,0,N) repq(j,0,M) {
        if(!( K >> j & 1 )) continue;
        int S = ((K >> (j + 1)) << (j + 1)) | ( (1 << j) - 1 );
        // printf("i = %lld, S = %lld, or = %lld\n", i+1, S, S | A[i]);
        if((S | A[i]) == S) rec[j] += B[i];
    }
    rep(i,0,N) if((K | A[i]) == K) rec[M+1] += B[i];
    cout << *max_element(rec, rec+35) << endl;
    return 0;
}

Measured memory_bytes: 1792
a,b,c = (int(x) for x in input().split())

if a>b :
    s1 = b
    s2 = a
else:
    s1 = a
    s2 = b

if s2 > c :
    s3 = s2
    s2 = c
    
    if s1 >s2:
        s2 = s1
        s1= c
else:
    s3 = c

print(s1,s2,s3)






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

int main(){
  int K,N;
  cin >> K >> N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int ans=0;
  vector<int>B(N);
  for(int i=0;i<N;i++){
    if(i==0){
      B[0]=A[0]+(K-A[N-1]);
      ans=B[0];
    }
    else{
      B[i]=A[i]-A[i-1];
      ans=max(B[i],ans);
    }
  }
  cout << K-ans << endl;
}


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

using ll = long long;
using ii = pair<int, int>;

const int maxn = 1e3 + 3;
const int mod = 1e9 + 7;

inline int mul() { return 1; }
template <typename... V>
inline int mul(int a, V... v) {
#if !defined(_WIN32) || defined(_WIN64)
	return (int) ((long long) a * mul(v...) % mod);
#endif
	unsigned long long x = (long long) a * mul(v...);
	unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
	asm(
		"divl %4; \n\t"
		: "=a" (d), "=d" (m)
		: "d" (xh), "a" (xl), "r" (mod)
	);
	return m;
}
inline int add() { return 0; }
template<typename... V>
inline int add(int x, V... v) {
	x += add(v...); if(x >= mod) x -= mod; return x;
}
inline int sub() { return 0; }
template<typename... V>
inline int sub(int x, V... v) {
	x -= sub(v...); if(x < 0) x += mod; return x;
}
template<typename... V>
inline void mulwith(int &a, V... v) {
	a = mul(a, v...);
}
template<typename... V>
inline void addto(int &a, V... v) {
	a = add(a, v...);
}
template<typename... V>
inline void subfrom(int &a, V... v) {
	a = sub(a, v...);
}

int n, k;
int a[maxn];
int C[maxn][maxn];
int dp[21][maxn];

int main(int argc, char const *argv[])
{
#ifdef LOCAL
	freopen("in", "r", stdin);
#endif
	for(int i = 0; i < maxn; i++) {
		C[i][i] = C[i][0] = 1;
	}
	for(int i = 1; i < maxn; i++) {
		for(int j = 1; j < i; j++) {
			C[i][j] = add(C[i-1][j], C[i-1][j-1]);
		}
	}
	cin >> n >> k;
	for(int i = 1; i <= k; i++) {
		cin >> a[i];
	}
	dp[0][0] = 1;
	for(int i = 1; i <= k; i++) {
		dp[i][0] = mul(dp[i-1][0], C[n][a[i]]);
		for(int j = 1; j <= n; j++) {
			for(int tek = 0; tek <= j and tek <= a[i]; tek++) {
				addto(dp[i][j], mul(dp[i-1][j-tek], C[j][tek], C[n-tek][a[i]-tek]));
			}
		}
	}
	cout << dp[k][n] << endl;
	return 0;
}

Measured memory_bytes: 4224
import Control.Monad
import Data.List
import Text.Printf

main :: IO ()
main = do
    cs <- getContents
    putStr $ unlines $ map solve (lines cs)

solve :: String -> String
solve s = (floatFormat $ sign x) ++ " " ++ (floatFormat $ sign y)
    where ns = map read (words s)
          a = ns !! 0
          b = ns !! 1
          c = ns !! 2
          d = ns !! 3
          e = ns !! 4
          f = ns !! 5
          x = (e*c-b*f)/(a*e-b*d)
          y = (a*f-d*c)/(a*e-b*d)

sign :: Float -> Float
sign x = if x == 0.0 then 0.0 else x

floatFormat :: Float -> String
floatFormat x = printf "%.3f" x

Measured memory_bytes: 4416
#include <iostream>
 
using namespace std;
 
int main()
{
    int n, sum = 0, x;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
    	cin >> x;
    	sum += x;
    }
    cout << sum-n << "\n";
    return 0;
}

Measured memory_bytes: 256
x = gets.to_i
a = [false]*102
gets.split.each do |s|
  a[s.to_i] = true
end
mi = Float::INFINITY
ans = p
(0...102).each do |i|
  next if a[i]
  b = (x-i).abs
  next if mi <= b
  mi = b
  ans = i
end
p ans


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

#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define endl        '\n'
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

namespace InOp{
template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
}
using namespace InOp;

namespace ModOp{
template<class x,class y,class z> z add(x a,y b,z m){return (a+b)%m;}
template<class x,class y,class z> z sub(x a,y b,z m){return (a-b+m)%m;}
template<class x,class y,class z> z mul(x a,y b,z m){return ((ll)a*b)%m;}
template<class y,class z> z expo(ll b,y e,z m){ll a=1;b%=m;while(e!=0){if((e&1)==1){a=a*b;a=a%m;}b=b*b;b%=m;e>>=1;}return a%m;}
template<class x,class z> z inv(x b,z m){return expo(b,m-2,m);}
template<class x,class y> x invGeneral(x a,y b){if(a==0)return b==1?0:-1;x m=invGeneral(b%a,a);return m==-1?-1:((1-(ll)b*m)/a+b)%b;}
template<class x,class y,class z> z div(x a,y b,z m){ll c=inv(b,m);return mul(a,c,m);}
}
using namespace ModOp;

namespace Debug{
template<class x> void deb(x a){cerr<<"a"<<": "<<a<<endl;}
template<class x,class y> void deb(x a,y b){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<endl;}
template<class x,class y,class z> void deb(x a,y b,z c){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<" | "<<"c"<<": "<<c<<endl;}
template<class x,class y,class z,class xy> void deb(x a,y b,z c,xy d){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<" | "<<"c"<<": "<<c<<" | "<<"d"<<": "<<d<<endl;}
}
using namespace Debug;

#define N  1000005

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l,r,x,y,m,n;
        cin>>n;
        if(n>=30)
        {

            cout<<"Yes";
        }
        else
            cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3632
s=str(input())
s=list(s)
counta=0
countb=0
for i in range(len(s)):
  if(i%2==0):
    if(s[i]=="R" or s[i]=="U" or s[i]=="D"):
      counta+=1
  elif(i%2==1):
    if(s[i]=="L" or s[i]=="U" or s[i]=="D"):
      countb+=1
if(counta+countb==len(s)):
  print("Yes")
  
else:
  print("No")

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

using ii = pair<int,int>;
using ll = long long;

const int N = 200005;
const int mod = 924844033;

int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif

	int n;
	cin >> n;
	vector<pair<ll,ll>> vp(n);
	int mask = 0;
	for (auto & x : vp) {
		cin >> x.first >> x.second;
		mask |= (1 << ((abs(x.first) + abs(x.second)) & 1));
	}

	if (mask == 3) {
		cout << "-1\n";
		return 0;
	}

	vector<ll> v;

	for (int i = 31; i >= 0; i--)
		v.push_back(1ll << i);

	if ((abs(vp[0].first) + abs(vp[0].second)) & 1 ^ 1) {
		v.push_back(1);
	}
	cout << v.size() << '\n';
	for (auto x : v)
		cout << x << ' ';
	cout << '\n';

	for (auto & x : vp) {
		for (auto val : v) {
			if (abs(x.first) >= abs(x.second)) {
				if (x.first >= 0) {
					cout << 'R';
					x.first -= val;
				} else {
					cout << 'L';
					x.first += val;
				}
			} else {
				if (x.second >= 0) {
					cout << 'U';
					x.second -= val;
				} else {
					cout << 'D';
					x.second += val;
				}
			}
		}
		assert(max(abs(x.first),abs(x.second)) == 0);
		cout << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}


vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


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

  ll n; cin >> n;

  ll ans = 0LL;

  vector<ll> yakusu = divisor(n);

  for(auto &e: yakusu){
    //cerr << e << endl;
    ll m = e-1;
    if(m!=0 && floor(n/m) == n%m){      
      ans += m;
      //cerr << ans << endl;
    }    
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 384
from collections import deque
n,q=map(int,input().split())
tree=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a) # 無向グラフなので
ans=[0]*n
for _ in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x

stack=deque([0]) # 根の位置、現位置の元になる根
visited=[0]*n
visited[0]=1

while stack:
    cur=stack.pop()
    for i in tree[cur]:
        if visited[i]==0:
            visited[i]=1
            ans[i]+=ans[cur]
            stack.append(i)
print(*ans)

Measured memory_bytes: 126756
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);

ll mod = 1e9+7;
template<typename T> void add(T &a,T b){a=(a+b)%mod;}
template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;}


ll f(string s, string t){
    int n = s.size();
    ll dp[n+1][2][2][2]={};
    dp[0][0][0][0] = 1;
    for(int i=0;i<n;i++){
        for(int mb=0;mb<2;mb++){
            for(int y=0;y<2;y++){
                for(int x=0;x<2;x++){
                    if(mb==false && x)continue;
                    for(int p=0;p<=1;p++){
                        for(int q=0;q<=p;q++){
                            if(s[i]=='0' && p && y==false)continue;
                            if(t[i]=='1' && q==0 && x==false)continue;
                            if(mb==false && (p!=q))continue;
                            int nmb = mb|p;
                            int ny = y|((p==0)&&(s[i]=='1'));
                            int nx = x|((q==1)&&(t[i]=='0'));
                            add(dp[i+1][nmb][ny][nx], dp[i][mb][y][x]);
                        }
                    }
                }
            }
        }
    }
    return (dp[n][1][1][1]+dp[n][1][0][1]+dp[n][1][1][0]+dp[n][1][0][0])%mod;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll l,r;
    cin>>l>>r;
    //l--;
    string s,t;
    while(r){
        if(r % 2) s += '1';
        else s += '0';
        r /= 2;
    }
    while(l){
        if(l % 2)t += '1';
        else t += '0';
        l /= 2;
    }
    while(t.size() < s.size()) t += '0';
    reverse(s.begin(),s.end());
    reverse(t.begin(),t.end());
    cout << f(s,t) << endl;


    
    
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gya[200010];
ll kai[200010];
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
void nckinit(ll n){
    kai[0]=1;
    kai[1]=1;
    for(int i=2;i<=n;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    gya[n]=gyaku(kai[n]);
    for(int i=n-1;i>=1;i--){
        gya[i]=gya[i+1]*i;
        gya[i]%=mod;
    }
    gya[0]=1;
}
ll nck(ll n,ll k){
    if(k<0)return 0;
    if(k==0||n==k)return 1;
    ll ret=1;
    rep(i,0,k){
        ret*=(n-i);
        ret%=mod;
        ret*=gyaku(i+1);
        ret%=mod;
    }
    return ret;
}
ll npk(ll n,ll k){
    if(k<0)return 0;
    if(k==0)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    return ret;
}
int main(){
    ll n,m,k;cin>>n>>m>>k;
    nckinit(200010);
    ll ans=n*n*(m*(m-1)*(m+1))/3+m*m*(n*(n-1)*(n+1))/3;
    ans%=mod;
    //cout<<ans<<endl;
    ans*=nck(n*m-2,k-2);
    //cout<<nck(20,2)<<endl;
    ans%=mod;
    //cout<<ans<<endl;
    ans*=gyaku(2);
    ans%=mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main(void){
  char str[10];
  cin >> str;

  int i, j;
  int count = 0, count_;
  for(i=0; i<10; i++){
    count_ = 0;
    for(j=i; j<10; j++){
      if(str[j] == 'A' || str[j] == 'C' || str[j] == 'G' || str[j] == 'T')
	count_++;
      else
	break;
    }
    if(count < count_)
      count = count_;
  }

  cout << count << endl;
  return 0;
}


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

using namespace std;

void Main() {
    int X;
    cin >> X;
    if (X == 3 || X == 5 || X == 7) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int m,f,r;
    while(true){
        cin >> m >> f >> r;
        
        if(m == -1 && f == -1 && r == -1){
            break;
        }
        
        else if(m+f <30 || m == -1 || f == -1){
            cout << "F";
        }
        
        else if(80 <=m+f){
            cout << "A";
        }
        
        else if(65 <= m+f){
            cout << "B";
        }
        
        else if(50 <= m+f){
            cout << "C";
        }
        
        else if(30 <= m+f){
            if(50 <= r){
                cout << "C";
            }
            else if(r < 50){
                cout << "D";
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3056
#include <iostream>

using namespace std;

int main() {
    int h,w;
    cin >> h >> w;
    while(h||w) {
        for(int i=0; i<w; ++i) {
            cout << "#";
        }
        cout << endl;
        for(int i=1; i<h-1; ++i) {
            cout << "#";
            for(int j=1; j<w-1; ++j) {
                cout << ".";
            }
            cout << "#" << endl;
        }
        for(int i=0; i<w; ++i) {
            cout << "#";
        }
        cout << endl << endl;
cin >> h >> w;
    }
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
string s;
int w;
cin >> s >> w;
rep(i,s.size()){
  if(i%w==0)cout <<s.at(i);
}
cout << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

//全点対最短路問題
int N;
void warshall_floyd(vector<vector<ll>> &d) {
    for(int k = 0; k < N; k++) {
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                if(d[i][k] + d[k][j] < d[i][j]) {
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }
}

int main() {
    int M;
    ll L; // town, road, kutter
    cin >> N >> M >> L;
    // road i Ai to Bi length Ci
    vector<vector<ll>> edge(N, vector<ll>(N, INF));
    vector<vector<ll>> cnt(N, vector<ll>(N, INF));
    REP(i, N) {
        edge[i][i] = 0LL;
        cnt[i][i] = 0LL;
    }
    REP(i, M) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;
        edge[a][b] = c;
        edge[b][a] = c;
    }
    warshall_floyd(edge);
    REP(i, N) {
        REP(j, N) {
            if(i == j) {
                continue;
            }
            if(edge[i][j] <= L) {
                cnt[i][j] = 1LL;
            }
        }
    }
    warshall_floyd(cnt);
    //最短経路
    ll Q;
    cin >> Q;
    // bellmanford で最短ろ求めてから経路復元
    vector<int> sq(Q), tq(Q);
    REP(i, Q) {
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        sq[i] = s;
        tq[i] = t;
    }
    REP(i, Q) {
        int s = sq[i];
        int t = tq[i];
        if(cnt[s][t] == INF) {
            cout << -1 << endl;
        } else {
            cout << cnt[s][t] - 1 << endl;
        }
    }
    return 0;
}


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

int main() {
  int n, m; cin >> n >> m;
  bool ans = false;
  vector<int> x(n, 0);
  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    if (a == 1 && ++x[b] == 2) ans = true;
    if (b == n && ++x[a] == 2) ans = true;
  }
  cout << (ans ? "" : "IM") << "POSSIBLE" << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(void)
{
	int a[3];
	int n;
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 3; j++){
			scanf("%d", &a[j]);
		}
		
		sort(a, a + 3);
		reverse(a, a + 3);
		
		if (a[0] * a[0] == (a[1] * a[1]) + (a[2] * a[2])){
			puts("YES");
		}
		else {
			puts("NO");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+100;
char s[N],t[N],ans[N];
ll n,m;
int main(){
    scanf("%lld %lld",&n,&m);
    printf("%lld\n",n*m/__gcd(n,m));
}

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

import sys, heapq, math
sys.setrecursionlimit(300000)


def solve(N: int, M: int, S: int, U: "List[int]", V: "List[int]", A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]"):
    conns = [[] for _ in range(N)]
    for i in range(M):
        conns[U[i] - 1].append((V[i] - 1, A[i], B[i])) # cost, duration
        conns[V[i] - 1].append((U[i] - 1, A[i], B[i])) # cost, duration

    INF = float('inf')
    MAX_M = max(A) * N
    costs = [[None] * N for _ in range(N)]
    dp = [[INF] * (MAX_M + 1) for _ in range(N)]
    S = min(S, MAX_M)
    dp[0][S] = 0
    q = [(0, 0, S)] # time, idx, silver
    while q:
        t, i, m = heapq.heappop(q)
        if dp[i][m] < t:
            continue

        if m + C[i] <= MAX_M:
            if t + D[i] < dp[i][m + C[i]]:
                dp[i][m + C[i]] = t + D[i]
                heapq.heappush(q, (t + D[i], i, m + C[i]))

        for j, c, d in conns[i]:
            if m >= c:
                if t + d < dp[j][m - c]:
                    dp[j][m - c] = t + d
                    heapq.heappush(q, (t + d, j, m - c))

    for i in range(1, N):
        tmp = INF
        for v in dp[i]:
            tmp = min(tmp, v)
        print(tmp)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    U = [int()] * (M)  # type: "List[int]"
    V = [int()] * (M)  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        U[i] = int(next(tokens))
        V[i] = int(next(tokens))
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    C = [int()] * (N)  # type: "List[int]"
    D = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        C[i] = int(next(tokens))
        D[i] = int(next(tokens))
    solve(N, M, S, U, V, A, B, C, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 98376
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int K;
int dp[112345];

int main() {
	cin >> K;
	
	fill(dp, dp + K, INF);
	queue<int> que;
	que.push(1);
	dp[1] = 1;
	
	while (!que.empty()) {
		int cur = que.front(); que.pop();
		
		int nex = (cur * 10) % K;
		if (chmin(dp[nex], dp[cur])) {
			dp[nex] = dp[cur];
			que.push(nex);
		}
		
		nex = (cur + 1) % K;
		if (chmin(dp[nex], dp[cur] + 1)) {
			dp[nex] = dp[cur] + 1;
			que.push(nex);
		}
	}
	
	cout << dp[0] << endl;
	
	return 0;
}


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

using namespace std;

int main(){
    int n,m,k;
    string ans="No";
    cin >> n >> m >> k;
    for(int i=0;i<m+1;i++){
        for(int j=0;j<n+1;j++){
            if(i*n+j*m-2*i*j==k){
                ans="Yes";
                break;
            }
        }
        if(ans=="Yes"){
            break;
        }
    }

    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b0=[]
b1=[]
for i,j in enumerate(a):
    if (i+1) % 2 == 1:#奇数
        b1.append(j)
    else:#偶数
        b0.append(j)
        
if len(a) % 2 == 0:#偶数だったら逆
    for i in b0[::-1]:
        print(i,end=" ")
    for i in b1:
        print(i,end=" ")
else:
    for i in b1[::-1]:
        print(i,end=" ")
    for i in b0:
        print(i,end=" ")
    



Measured memory_bytes: 99540
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
int main(){
  int n;
  cin >> n;
  int d[110];
  rep(i,n){
    cin >> d[i];
  }
  set<int>values;
  rep(i,n){
    values.insert(d[i]);
  }
  cout << values.size();

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M), c(M);
  rep(i, M) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
  }
  vector<vector<int>> dist(N, vector<int>(N, INF));
  rep(i, N)
    dist[i][i] = 0;
  rep(i, M) {
    dist[a[i]][b[i]] = c[i];
    dist[b[i]][a[i]] = c[i];
  }
  rep(i, N) rep(j, N) rep(k, N)
    chmin(dist[j][k], dist[j][i]+dist[i][k]);
  int ans = 0;
  rep(i, M) {
    if(dist[a[i]][b[i]] < c[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define mp make_pair
#define pb push_back

using namespace std;

char s[111111], t[111111];
int ps[111111], pt[111111];
int q;

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%s%s%d",&s,&t,&q);
	int n = strlen(s);
	for(int i = 0; i < n; ++i){
		if (s[i] == 'A') ps[i + 1] = 1;
		else ps[i + 1] = 2;
		ps[i + 1] += ps[i];
	}
	n = strlen(t);
	for(int i = 0; i < n; ++i){
		if (t[i] == 'A') pt[i + 1] = 1;
		else pt[i + 1] = 2;
		pt[i + 1] += pt[i];
	}
	while (q--){
		int a, b, c, d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if ((pt[d] - pt[c - 1] - ps[b] + ps[a - 1]) % 3 == 0){
			printf("YES\n");
		}
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define ll long long

int d = 365;
int k = 0;

vector<vector<int>> s(d, vector<int>(26, 0));
vector<ll> c(26);

void init() {
    cin >> d;
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    return;
}

ll calc(vector<int> out) {
    ll score = 0;
    vector<ll> last(26, 0);
    for(int i = 0; i < out.size(); i++) {
        last[out[i]] = i+1; // タイプ番号
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i+1)-last[j]);
        }
        score += s[i][out[i]];
        //cout << "score : " << score << endl;
    }
    

    //int k = 10;
    k = 3;
    int p = min(int(out.size()+k), int(d));
    for(int i = out.size(); i < p; i++) {
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i+1)-last[j]);
            //tmp -= c[j]*((i)-last[j]);
        }
    }
    return score;
}

/*
vector<int> proc(int k) {
    vector<int> out;
    ll ans = 0;
    //ll tmp = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
    //cout << "k: " << k << endl;
    //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    return out;
}
*/

int main() {
    init();
    
    vector<int> out;
    ll ans = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
        //cout << "k: " << k << endl;
        //vector<int> out;
    for(int i = 0; i < d; i++) {
        //max_v = -100000000000;
        max_v = LLONG_MIN;
        int best = 0;
        for(int j = 0; j < 26; j++) {
            out.push_back(j);
            //for(int k = 0; k < 26; k++) {
            ll tmp = calc(out);
            if(max_v < tmp) {
                max_v = tmp;
                best = j;
            }
            //}
            out.pop_back();
        }
        out.push_back(best);
    }
    //}
    
    for(int i = 0; i < d; i++) {
        cout << out[i]+1 << endl;
    }
    //cout << max_v << endl;
    return 0;
}

Measured memory_bytes: 3700
from collections import deque

s=deque(input())
q=int(input())

rev=0
for i in range(q):
  l=list(input().split())
  if len(l)==1:
    rev+=1
  else:
    t,f,c=l[0],l[1],l[2]

    if rev%2==0:
      if f=='1':
        s.appendleft(c)
      else:
        s.append(c)
    else:
      if f=='1':
        s.append(c)
      else:
        s.appendleft(c)

if rev%2==1:
  s.reverse()
print(''.join(s))

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

int main(){
  string s;
  cin >> s;
  if (s == "AAA" || s == "BBB"){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
x = []
y = []
t = []
N.times do
  line = gets.split.map(&:to_i)
  t << line[0]
  x << line[1]
  y << line[2]
end
#ここまで入力
s = 0
while s < N
  if s == 0 #はじめの目的地かどうかで場合分け
    if x[s]+y[s] > t[s] #移動距離が足りなければNo
      puts "No"
      exit
    end
    if (x[s]+y[s])%2 != t[s]%2 #移動距離と時間の偶奇が違うならNo
      puts "No"
      exit
    end
  else
    if((x[s]-x[s-1]).abs+(y[s]-y[s-1]).abs) > t[s]-t[s-1] #移動距離が足りないならNo
      puts "No"
      exit
    end
    if(((x[s]-x[s-1]).abs+(y[s]-y[s-1]).abs)%2 != (t[s]-t[s-1])%2) #移動距離と時間の遇奇が違うならNo
      puts "No"
      exit
    end
  end
  s+=1
end
puts "Yes"

Measured memory_bytes: 4220
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <cassert>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using vb = vector<bool>;
using vvb = vector<vb>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

int blancas(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, vvi const& spref) {
	int res = spref[y1][x1];
	if (x2 >= 0) res -= spref[y2][x2];
	if (y3 >= 0) res -= spref[y3][x3];
	if (x4 >= 0 && y4 >= 0) res += spref[y4][x4];
	return res;
}

int cnec(vvi const& spref, vi const& cortes, int k) {
	int nec = 0;
	vi wh(cortes.size(), 0);
	vi whaux(cortes.size(), 0);
	vi aux(cortes.size(), 0);

	for (int j = 0; j < spref[0].size(); ++j) {
		bool pr = false;
		for (int i = 1; i < cortes.size(); ++i) {
			whaux[i] = blancas(j, cortes[i], j - 1, cortes[i], j, cortes[i-1], j - 1, cortes[i - 1], spref);
			if (whaux[i] > k) return 1000000;

			if (wh[i] + whaux[i] > k) {
				//assert(!pr);
				pr = true;
				++nec;
				wh = whaux;
			}
		}

		if (!pr) {
			for (int i = 1; i < cortes.size(); ++i) {
				wh[i] += whaux[i];
			}
		}
		else {
			wh = whaux;
		}
		whaux = aux;
	}

	return nec;
}

bool res() {
	int f, c, k;
	cin >> f >> c >> k;
	if (!cin) return false;

	vvb m(f, vb(c));
	string l;
	for (int i = 0; i < f; ++i) {
		cin >> l;
		for (int j = 0; j < c; ++j) {
			if (l[j] == '0') m[i][j] = false;
			else m[i][j] = true;
		}
	}

	vvi spref(f, vi(c, 0));
	if (m[0][0]) spref[0][0] = 1;

	for (int i = 1; i < f; ++i) {
		spref[i][0] = spref[i - 1][0];
		if (m[i][0]) ++spref[i][0];
	}
	for (int j = 1; j < c; ++j) {
		spref[0][j] = spref[0][j - 1];
		if (m[0][j]) ++spref[0][j];
	}

	for (int i = 1; i < f; ++i) {
		for (int j = 1; j < c; ++j) {
			spref[i][j] = spref[i][j - 1] + spref[i - 1][j] - spref[i-1][j-1];
			if (m[i][j]) ++spref[i][j];
		}
	}

	int mincortes = 10000000;
	for (int i = 0; i < (1 << (f - 1)); ++i) {
		vi cortes;
		cortes.push_back(-1);
		int aux = i;
		for (int j = 0; j < f; ++j) {
			if ((aux & 1) == 1) cortes.push_back(j);
			aux >>= 1;
		}
		cortes.push_back(f - 1);

		mincortes = min(mincortes, (int) (cnec(spref,cortes,k) + cortes.size() - 2));
	}

	cout << mincortes << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

typedef long long ll;

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		ll ans = 0;
		while( n-- )
		{
			int x, y, h, w;
			std::cin >> x >> y >> h >> w;

			int sz = x + y + h;

			for( int i = 0; i != 6; ++i )
			{
				if( sz <= 60 + i * 20 && w <= ( i ? i * 5 : 2 ) )
				{
					ans += 600 + i * 200;
					break;
				}
			}
		}

		std::cout << ans << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;

/*
struct Edge{
    int u,v,weight;
    bool operator<(Edge const& other) {
        return weight<other.weight;
    }
};

vector<int> parent,rank;

void make_set(int v) {
    parent[v]=v;
    rank[v]=0;
}

int find_set(int v) {
    if(v==parent[v])
        return v;
    return parent[v]=find_set(parent[v]);
}

void union_sets(int a,int b) {
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(rank[a]<rank[b])
            swap(a,b);
        parent[b]=a;
        if(rank[a]==rank[b])
            rank[a]++;
    }
}*/
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}
/*
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2; p*p<=n; p++)
        if (prime[p] == true)
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int arr[100005];
int ans[100005];
int solve(){
    int n,m;
    cin>>n>>m;
    int p=0,d=0;
	rep(i,0,m){
		int a;
		string b;
		cin>>a>>b;
		if(arr[a]==0&&b=="WA"){
			ans[a]++;
		}
		else if(b=="AC"&&arr[a]==0){
			d++;
			arr[a]=1;
		}
	}
	rep(i,1,n+1){
		if(arr[i]==1)p+=ans[i];
	}
	cout<<d<<" "<<p<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 1024
require 'set'

h, w, m = gets.chomp.split(' ').map(&:to_i)

ch = (h + 1).times.map { 0 }
cw = (w + 1).times.map { 0 }

b = Set.new
m.times do
  t = gets.chomp.split(' ').map(&:to_i)
  ch[t[0]] += 1
  cw[t[1]] += 1
  b.add(t)
end

ch_max = ch.max
can_h = ch.map.with_index { |c, i| [c, i] }.select { |c| c[0] == ch_max }.map { |c| c[1] }

cw_max = cw.max
can_w = cw.map.with_index { |c, i| [c, i] }.select { |c| c[0] == cw_max }.map { |c| c[1] }

if can_h.length * can_w.length > m
  puts ch_max + cw_max
else
  if can_h.product(can_w).all? { |x, y| b.include?([x, y]) }
    puts ch_max + cw_max - 1
  else
    puts ch_max + cw_max
  end
end


Measured memory_bytes: 88548
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<int> a(N), b(N), c(N);
  std::vector<std::vector<int> > DP(N + 1, std::vector<int> (3, 0));
  DP[0][0] = DP[0][1] = DP[0][2] = 0;
  ranges(i, 1, N + 1){
    std::cin >> a[i - 1] >> b[i-1] >> c[i-1];
    DP[i][0] = max(DP[i - 1][1], DP[i - 1][2]) + a[i-1];
    DP[i][1] = max(DP[i - 1][0], DP[i - 1][2]) + b[i-1];
    DP[i][2] = max(DP[i - 1][0], DP[i - 1][1]) + c[i-1];
  }
  cout << std::max(DP[N][0],max(DP[N][1],DP[N][2])) <<'\n' ;
  return 0;
}


Measured memory_bytes: 6912
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>

using namespace std;

vector<int> Heap;

void insert(int node)
{
	Heap.push_back(node);
}

void Max_Heapify(int node)
{
	int l = node * 2;
	int r = node * 2 + 1;

	int largest;

	if (l < Heap.size())
	{
		if (Heap[node] < Heap[l])
		{
			largest = l;
		}
		else
		{
			largest = node;
		}
	}
	else
	{
		largest = node;
	}

	if (r < Heap.size())
	{
		if (Heap[largest] < Heap[r])
		{
			largest = r;
		}
	}

	if (largest != node)
	{
		swap(Heap[largest], Heap[node]);

		Max_Heapify(largest);
	}
}

int main()
{
	int N; cin >> N; Heap.push_back(0);

	int tmp;

	for (int i = 1; i <= N; i++)
	{
		cin >> tmp;

		insert(tmp);
	}

	for (int i = N / 2; i >= 1; i--)
	{
		Max_Heapify(i);
	}

	for (int i = 1; i <= N; i++)
	{
		cout << ' ' << Heap[i];
	}

	cout << endl;
	
	return 0;
}

Measured memory_bytes: 3112