akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld=long double;
ld eps=1e-9;

bool check(vector<int>&v) {
	if(v[0]<0)return false;

	int a=v[0]+v[5];
	int b=v[1]+v[4];
	int c=v[2]+v[3];

	if(a+c+1<b)return false;
	if(a+b+1<c)return false;
	if(b+c<a)return false;

	return true;
}
int sum;
bool flag=false;
int max_e_num=0;
int now_e_num;
void solve(string& ans,vector<int>&v) {
	if(ans.size()==sum)return ;
	string way="ENSW";

	{
		vector<int>nv(v);;
		nv[0]=v[1];
		nv[1]=v[5];
		nv[5]=v[4];
		nv[4]=v[0];
		nv[0]--;
		if (check(nv)) {
			ans+=way[0];
			now_e_num+=1;
			solve(ans,nv);
			return ;
		}
	}
	if (!flag&&max_e_num < now_e_num) {
		max_e_num=now_e_num;
	}
	else if (!flag&&max_e_num > now_e_num) {
		ans.clear();
		return ;
	}
	flag=true;
	{
		vector<int>nv(v);;
		nv[0] = v[2];
		nv[2] = v[5];
		nv[5] = v[3];
		nv[3] = v[0];
		nv[0]--;
		if (check(nv)) {
			ans += way[1];
			solve(ans,nv);
			return;
		}
	}
	{
		vector<int>nv(v);;
		nv[0] = v[3];
		nv[3] = v[5];
		nv[5] = v[2];
		nv[2] = v[0];
		nv[0]--;
		if (check(nv)) {
			ans += way[2];
			solve(ans, nv);
			return;
		}
	}
	{
		vector<int>nv(v);;
		nv[0] = v[4];
		nv[4] = v[5];
		nv[5] = v[1];
		nv[1] = v[0];
		nv[0]--;
		if (check(nv)) {
			ans += way[3];
			solve(ans, nv);
			return;
		}
	}
	
}

int main()
{
	vector<int>v(6);
	while (cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4] >> v[5]) {
		sum = accumulate(v.begin(), v.end(), 0);
		if(sum==0)break;
		else {
			max_e_num=0;
			sort(v.begin(),v.end());
			string answer(sum,'Z');
			do {
				flag=false;
				now_e_num=0;
				string ans;
				solve(ans,v);
				if (!ans.empty()) {
					answer=min(answer,ans);
				}
			}while(next_permutation(v.begin(),v.end()));

			int L,R;cin>>L>>R;
			if (answer[0]=='Z') {
				cout<<"impossible"<<endl;
			}
			else {

				cout << answer.substr(L - 1, R - L + 1) << endl;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 8712
using System;

namespace AOJ.Volume3
{
    class ProgrammingContest
    {
        public static int Main()
        {
            int n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ');
            var point = new int[n];
            for(int i = 0; i < n; i++) { point[i] = int.Parse(input[i]); }
            Array.Sort(point);

            int score = 0;
            for(int i = 1; i <= n; i++)
            {
                int cnt = 0;
                for(int j = 0; j < n; j++)
                {
                    if (point[j] >= i) { cnt++; }
                }
                if (cnt >= i) { score = i; }
            }
            Console.WriteLine(score);

            return 0;
        }
    }
}

Measured memory_bytes: 9292
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()

void Main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a * b > c * d)
        cout << a * b << endl;
    else
        cout << c * d << endl;

    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
H, W, M = map(int, input().split())
hw = []
sh = [0] * H
sw = [0] * W
for i in range(M):
    h, w = map(int, input().split())
    hw.append((h - 1, w - 1))

    sh[h - 1] += 1
    sw[w - 1] += 1

mh = max(sh)
mw = max(sw)

count = 0
for i in range(M):
    if sh[hw[i][0]] == mh and sw[hw[i][1]] == mw:
        count += 1

if sh.count(mh) * sw.count(mw) > count:
    print(mh + mw)
else:
    print(mh + mw - 1)

Measured memory_bytes: 109332
#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() {
    string s,t;
    int ans=0;
    cin>>s>>t;
    rep(i,s.length()){
        if(s[i]!=t[i])
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}

template<class... T>
void debug_print(T... args){
    vector<lint> tmp = initializer_list<lint>{args...};
    print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}

vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod = 

lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
    lint ret = LLONG_MAX;
    rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
    return ret;
}
lint vmaxi(vlint a, lint &index){
    lint ret = -LLONG_MAX;
    rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
    return ret;
}

lint vmin(vlint a){
    lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
    lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}

int main(){
    INT(x); int ans;
    if (x < 600){
        ans = 8;
    }
    else if (x < 800){
        ans = 7;
    }
    else if (x < 1000) ans = 6;
    else if (x < 1200) ans = 5;
    else if (x < 1400) ans = 4;
    else if (x < 1600) ans = 3;
    else if (x < 1800) ans = 2;
    else if (x < 2000) ans = 1;
    print(ans);
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w;
	cin>>h>>w;
	char a[h+1][w+1];
	for (int i=1;i<=h;i++)
	{
		string s;
		cin>>s;
		for (int j=0;j<w;j++)
		{
			a[i][j+1]=s[j];
		}
	}
	for (int i=1;i<=h;i++)
	for (int j=1;j<=w;j++)
	{
		int ans=0;
		if (a[i][j]=='.')
		{
		if (i>=2&&j>=2)
		{
			if (a[i-1][j-1]=='#')
			ans++;
		}
		if (i>=2)
		{
			if (a[i-1][j]=='#')
			ans++;
		}
		if (i>=2&&j<w)
		{
			if (a[i-1][j+1]=='#')
			ans++;
		}
		if (j>=2)
		{
			if (a[i][j-1]=='#')
			ans++;
			if (i<h)
			{
				if (a[i+1][j-1]=='#')
				ans++;
			}
		}
		if (i<h)
		{
			if (a[i+1][j]=='#')
			ans++;
			if (j<w)
			{
				if (a[i+1][j+1]=='#')
				ans++;
			}
		}
		if (j<w)
		{
			if (a[i][j+1]=='#')
			ans++;
		}
		a[i][j]=ans+'0';
	}
}
   for (int i=1;i<=h;i++)
   {
   for (int j=1;j<=w;j++)
   {
   	if (a[i][j]!='#')
   	cout<<a[i][j]-'0';
   	else
   	cout<<a[i][j];
   }
   cout<<endl;
}
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int N,a,b;
	while(scanf("%d",&N)!=EOF){
		if(N==1){
			printf("Hello World\n");
		}
		if(N==2){
			scanf("%d%d",&a,&b);
			printf("%d\n",a+b);
		}
	}
	return 0;
} 

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

int main() {
    int N, D; cin >> N >> D;
    vector<vector<int>> X(N, vector<int> (D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X.at(i).at(j);
        }
    }
    int count = 0;
    double dist;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            dist = 0;
            for (int k = 0; k < D; k++) {
                dist += pow(X.at(i).at(k) - X.at(j).at(k), 2);
            }
            dist = sqrt(dist);
            int l = (int)dist;
            if(l - dist == 0) { count++; }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
s = input()
n = int(input())

l = []
for i in range(n):
    l.append(list(map(str,input().split())))

for i in range(len(l)):
    command = l[i][0]
    a = int(l[i][1])
    b = int(l[i][2])
    c = s[a:b+1]
    if command == "replace":
        s = s[:a] + l[i][3] + s[b+1:]
    elif command == "reverse":
        s = s[:a] + c[::-1] + s[b+1:]
    elif command == "print":
        print(c)

Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  cin >> N;
  A.resize(N);
  rep(i, 0, N - 1) {
    int x;
    cin >> x;
    A[i] = x - 1;
  };
}
bool visited[MX] = {};
int ans = -1;
void dfs(int now, int cnt) {
  // debug(now);
  // debug(cnt);
  if (visited[now]) return;
  if (now == 1) {
    ans = cnt;
    return;
  }
  visited[now] = true;
  dfs(A[now], cnt + 1);
}
void solve() {
  dfs(0, 0);
  cout << ans << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1152
#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 req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
  int x;
  cin >> x ;
  if (x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M; cin >> N >> M;
    vector<pair<int, int>> A(N);
    for (int i = 0; i < N; i++) cin >> A[i].first >> A[i].second;
    sort(begin(A), end(A));
    long long ans = 0;
    for (int i = 0; M; i++) {
        ans += (long long)A[i].first * min(A[i].second, M);
        M -= min(A[i].second, M);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include<iomanip>
#include<algorithm>
#include<list>
using namespace std;

int A[1000001];
int cnt;
int G[101];

void insertionSort(int n, int g){
	for (int i = g; i < n; i++){
		int v = A[i];
		int j = i - g;
		while (j >=0 && A[j] > v){
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
}

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> A[i];
	}
	cnt = 0;
	G[0] = 1;
	int m = 0;
	while(true){
		G[m + 1] = G[m] * 3 + 1;
		m++;
		if (G[m] > n){
			break;
		}
	}
	for (int i = m - 1; i >= 0; i--){
		insertionSort(n, G[i]);
	}
	cout << m << endl;
	for (int i = m - 1; i > 0; i--){
		cout << G[i] << " ";
	}
	cout << G[0] << endl;
	cout << cnt << endl;
	for (int i = 0; i < n; i++){
		cout << A[i] << endl;
	}
	return 0;
}

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

int main(){
    int d, n;
    cin >> d >> n;
    int ans = 0;
    if(d == 0){
        ans = n;
        if(n == 100){
            ans++;
        }
    } else if(d == 1){
        ans = 100*n;
        if(n == 100){
            ans += 100;
        }
    } else {
        ans = 100*100*n;
        if(n == 100){
            ans += 10000;
        }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int c, n;
string s[1000];
int d, y, x;
int okCnt;

bool same(char a, char b, char c, char d) {
	return a == b && b == c && c == d;
}

int main() {
	int i, j;
	int ans = 0;
	
	cin >> c >> n;
	rep(i, n) cin >> s[i];
	
	rep(i, n / 2) {
		rep(j, n / 2) {
			if (same(s[i][j], s[n - 1 - i][j], s[i][n - 1 - j], s[i][j])) okCnt++;
		}
	}
	if (okCnt * 4 == n * n) ans++;
	
	rep(i, c - 1) {
		cin >> d;
		rep(j, d) {
			cin >> y >> x;
			y--; x--;
			bool res1 = same(s[y][x], s[n - 1 - y][x], s[y][n - 1 - x], s[n - 1 - y][n - 1 - x]);
			s[y][x] = (s[y][x] == '0') ? '1' : '0';
			bool res2 = same(s[y][x], s[n - 1 - y][x], s[y][n - 1 - x], s[n - 1 - y][n - 1 - x]);
			if (!res1 && res2) okCnt++;
			if (res1 && !res2) okCnt--;
		}
		if (okCnt * 4 == n * n) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4088
import numpy as np
i8 = np.int64

f = open('/dev/stdin', 'rb')
pin = np.fromstring(f.read(), i8, sep=' ')
N, M, V, P = pin[: 4]
a = pin[4:4 + N]

x = np.arange(N - P)
N -= P - 1
V -= P - 1
a = np.sort(a)[::-1][P - 1:]
top = a[0]
cumsum = np.cumsum(a)[: -1]
a = a[1:]

filter = np.logical_and(a + M >= top, (a + M) * (x + 1) - cumsum - (x + 1 - (N - V))*M >= 0)
print(np.count_nonzero(filter) + P)

Measured memory_bytes: 19988
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define S(x) (int) x.size()
#define LB lower_bound
#define UB upper_bound
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)2e5+5;
const int mod = (int)1e9+7;

int n, m, k, ans = 0;
int a[M], b[M];
int prea[M], preb[M];

void solve()
{
	cin>>n>>m>>k;
	f(i, 0, n) cin>>a[i];
	f(i, 0, m) cin>>b[i];
	f(i, 0, n) prea[i+1] = prea[i]+a[i];
	f(i, 0, m) preb[i+1] = preb[i]+b[i];
	f(i, 0, n+1)
	{
		if(prea[i] > k) break;
		ans = max(ans, i+(int)(UB(preb, preb+m+1, k-prea[i])-preb)-1);
	}
	cout<<ans<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 9900
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=10**18
for i in range(2**n):
  build=set()
  maxi=a[0]
  for j in range(n):
    if (i>>j)&1:
      build.add(j)
  cnt=len(build)
  if 0 not in build:
    cnt+=1
  s=0
  for j in range(n):
    if j==0:
      continue
    elif j in build:
      if a[j]<=maxi:
        s+=maxi-a[j]+1
        maxi+=1
      else:
        maxi=a[j]
    else:
      if a[j]>maxi:
        cnt+=1
        maxi=a[j]
  if cnt>=k:
    ans=min(ans,s)
print(ans)

Measured memory_bytes: 45292
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>


using namespace std;





int main()
{
    int n;
    cin >> n;
    vector<int> t;
    int i,ele;
    for (i = 0; i < n; ++i) {
        cin >> ele;
        t.push_back(ele);
    }
    int m;
    cin >> m;
    int a, b;
    vector<int> p, x;
    for (i = 0; i < m; ++i) {
        cin >> a >> b;
        p.push_back(a);
        x.push_back(b);
    }
    int sum = 0;
    for (i = 0; i < n; ++i) {
        sum += t[i];
    }
    for (i = 0; i < m; ++i) {
        int time = sum - t[p[i] - 1] + x[i];
        cout << time << "\n";
    }

    

}

    

Measured memory_bytes: 256
d, g = map(int, input().split(' '))
p = []
c = []
for _ in range(d):
    p_, c_ = map(int, input().split(' '))
    p.append(p_)
    c.append(c_)
 
sum_p = []
for i in range(d):
    sum_p.append((i + 1) * 100 * p[i] + c[i])
 
def ans(g, t):
    if t <= 0:
        return float('inf')
    n = min(int(g / (100 * t)), p[t-1])
    s = 100 * t * n
 
    if n == p[t-1]:
        s = sum_p[t-1]
    if g > s:
        n += ans(g - s, t - 1)
    return min(n, ans(g, t - 1))
 
print(ans(g, d))

Measured memory_bytes: 3064
N = input()
K = list(map(int,input().split()))
L = len(K)
dicta = {i:K[i] for i in range(0, L)}
count = 0
start = 0
while True:
    start = 0
    flag = 0
    for i in range(0, L):
        if dicta[i] == 0:
            if start == 0:
                pass
            elif start == 1:
                start = 0
        elif dicta[i] != 0:
            dicta[i] -= 1
            if start == 0:
                start = 1
                flag = 1
                count += 1
    if flag == 0:
        break
print(count)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 100000

typedef struct{
  char name[10];
  int time;

}Data;

typedef struct{
  Data data[N];
  int head;
  int tail;

}Pro;

void in(int *, Pro *, char *, int);
Data out(int *, Pro *);

int main(){

  int i;
  int n, q;
  char name[10], time[5];
  Pro queue;
  Data tmp;
  int time_sum = 0;

  scanf("%d%d", &n, &q);

  queue.head = 0;
  queue.tail = 0;
  for(i = 0; i < n; i++){
    queue.data[i].name[0] = ' ';
  }

  for(i = 0; i < n; i++){
    scanf("%s%s", name, time);
    in(&n, &queue, &name[0], atoi(time));
  }

  for(tmp = out(&n, &queue); tmp.name[0] != ' '; tmp = out(&n, &queue)){

    if(tmp.time - q > 0){
      in(&n, &queue, &tmp.name[0], tmp.time - q);
      time_sum += q;
    }
    else {
      time_sum += tmp.time;
      printf("%s %d\n", tmp.name, time_sum);
    }    

  }

  return 0;
}

void in(int *n, Pro *queue, char *name, int time){

  strcpy(queue->data[queue->tail].name, name);
  queue->data[queue->tail].time = time;

  if(queue->tail < *n - 1) queue->tail++;
  else queue->tail = 0;

}

Data out(int *n, Pro *queue){

  Data tmp;

  tmp = queue->data[queue->head];
  queue->data[queue->head].name[0] = ' ';

  if(queue->head < *n - 1) queue->head++;
  else queue->head = 0;

  return tmp;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)

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;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

long int jjjjj(long int n){
    long int x = 1;
    for(int i = 1; i <= n; ++i){
        x *=i;
    }
    return x;
}

struct stru{
    int c,s,f;
    void print(){
        cout << c << " " << s << " " << f << endl;
    }
};

int main(){
    int n;
    cin >> n;
    stru d[500] = {};
    for(int i = 0; i < n - 1; ++i){
        cin >> d[i].c >> d[i].s >> d[i].f;
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){
        ans = 0;
        for(int j = i; j < n - 1; ++j){
            if(ans < d[j].s){
                ans = d[j].s;
            }else if(ans % d[j].f == 0){
                ;
            }else{
                ans = ans + d[j].f - ans % d[j].f;
            }
            ans += d[j].c;
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 256
#include<stdio.h>
int car(char a){
  if(a == 'a'){
    return 0;
  }else if(a == 'b'){
    return 1;
  }else{
    return 2;
  }
}
 
int main(){
  char S[3][1000];
  int cnt[3] = {0,0,0},k = 0;
  for(int i = 0;i < 3;i++){
    scanf("%s",&S[i]);
  }
  while(1){
    if(cnt[k] == strlen(S[k])){
      if(k == 0){
        printf("A");
        return 0;
      }else if(k == 1){
        printf("B");
        return 0;
      }else{
        printf("C");
        return 0;
      }
    }
    cnt[k]++;
    k = car(S[k][cnt[k] - 1]);
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  int w,a,b;
  cin >> w >> a >> b;
  if(a<b){
    if(b-a<=w){
      cout << 0;
    } else {
      cout << b-a-w;
    }
  } else {
    if(a-b<=w){
      cout << 0;
    } else {
      cout << a-b-w;
    }
  }
  cout << endl;  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if(i+1<s.length() && s[i]=='A' && s[i+1]=='C'){
            return cout<<"Yes"<<endl,0;
        }
    }
    cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 256
# 最大公約数ごとの数を列挙
N,K=map(int,input().split())
li=[0]*(K+1)
out=0
mod=10**9+7

for i in range(K,0,-1):
    li[i]=pow(K//i,N,mod)
    for j in range(i*2,K+1,i):
        li[i]-=li[j]
    out+=li[i]*i

print(out%mod)

Measured memory_bytes: 11156
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    S = input()
    r,g,b = "R","G","B"

    def get_other(x,y):
        if x in [r,g] and y in [r,g]:
            return b
        if x in [r,b] and y in [r,b]:
            return g
        if x in [g,b] and y in [g,b]:
            return r

    rs = [0] * (N+1)
    gs = [0] * (N+1)
    bs = [0] * (N+1)

    for i in range(N):
        rs[i+1] = ((S[i] == r) + 0) + rs[i]
        gs[i+1] = ((S[i] == g) + 0) + gs[i]
        bs[i+1] = ((S[i] == b) + 0) + bs[i]

    s_dic = {r:rs,b:bs,g:gs}

    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            if S[i] != S[j]:
                not_k = 2 * j - i
                other = get_other(S[i],S[j])

                counter = s_dic[other]

                ans += counter[N] - counter[j+1]
                if not_k < len(S) and S[not_k] == other:
                    ans -= 1

    print(ans)



if __name__ == "__main__":
  main()


Measured memory_bytes: 79672
#include<stdio.h>

int main() {
	char s[80];
	int i,n,k;
	scanf("%d", &n);
	scanf("%d", &k);
	scanf("%s", s);
	i = 0;
	while (s[i]) {
		if ((i + 1) != k) {
			printf("%c", s[i]);
		} else {
			printf("%c", s[i] - 'A' + 'a');
		}		
		i++;
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
    using namespace std;
    int main()
    {
        // 整数の入力
        int X;
        cin >> X;
      
        if(X==3 || X==5 || X==7){
          cout << "YES" << endl;
        }
        else{
          cout << "NO" << endl;
        }
        return 0;
    }

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

char s[11];

int main(){
  scanf("%s",s);
  for(int i=0;i<strlen(s);i+=2){
    if(s[i]!='h'||s[i+1]!='i'){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

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

int main()
{
    stack<int> s1;
    stack<pair<int,int> > s2;
    char ch;
    int sum=0;
    for(int i=0;cin>>ch;i++){
        if(ch=='\\') s1.push(i);
        else if(ch=='/'&&!s1.empty()){
            int j=s1.top();s1.pop();
            sum+=i-j;
            int a=i-j;
            while(s2.size()>0 && s2.top().first>j){
                //水池被覆盖
                a+=s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(j,a));
        }
    }
    vector<int> ans;
    while(s2.size()>0){ans.push_back(s2.top().second);s2.pop();}
    reverse(ans.begin(),ans.end());
    cout<<sum<<endl;
    cout<<ans.size();
    for(int i = 0;i < ans.size();i++)
        cout<<" "<<ans[i];
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    int best = 1000000001;
    long long ans = 0;
    bool flag = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        ans += a[i];
        if (a[i] - b[i] > 0) {
            best = min(best, b[i]);
            flag = 1;
        }
    }
    if (!flag) {
        cout << 0 << endl;
        return 0;
    }
    cout << ans - best << endl;
}


Measured memory_bytes: 384
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

kazu, sinsuu = map(int, input().split())
print(len(Base_10_to_n(kazu, sinsuu)))

Measured memory_bytes: 2940
def comb_mod(n,r,mod):
    a,b=1,1
    r = min(r,n-r)
    for i in range(r):
        a = a*(n-i) % mod
        b = b*(r-i) % mod
    return a * pow(b, mod-2, mod) % mod

MOD = 10**9+7
s = int(input())
ans = 0

for i in range(1,s//3+1):
    rem = s-i*3
    ans += comb_mod(rem+i-1,i-1,MOD)
    ans %= MOD

print(ans)

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

using namespace std;
 
void solve() {
    int n;
    cin >> n;

    int conseq = 0;
    for (int i = 0; i < n; ++i) {
        int d1, d2;
        cin >> d1 >> d2;

        if (d1 == d2) {
            ++conseq;
        } else {
            conseq = 0;
        }

        if (conseq == 3) {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

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

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

    int t = 1;
    // cin >> t;

    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, ll> mp;
    rep(i, n) {
        mp[s[i]]++;
    }
    mint ans = 1;
    rep(i, 26) {
        ans *= (mp['a'+i]+1LL);
    }
    ans -= 1;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    LL a,b;
    cin >> a >> b;
    if(a > 9 || b > 9) cout << "-1" << endl;
    else cout << a*b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int H, W;
  while(1){
    scanf("%d %d", &H, &W);
    if (H == 0 && W == 0) break;
    int i, j;
    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++) {
        if (i % 2 ==0) {
          if (j % 2 == 0) {
            putchar('#');
          } else {
            putchar('.');
          }
        } else {
          if (j % 2 == 0) {
            putchar('.');
          } else {
            putchar('#');
          }
        }
      }
      putchar('\n');
    }
    putchar('\n');
  }
  return 0;
}



Measured memory_bytes: 2036
#include <stdio.h>
int main() {
	 
	int n,i,j,flag;
	scanf("%d",&n);
	flag = 0;
	for (i = 0; i < 100; i++) {
		for (j = 0; j < 100; j++) {
			if (4 * i + 7 * j == n) {
				
				flag = 1;
				break;
			}
		}
	}
	if (flag == 0) { printf("No"); }
	else { printf("Yes"); }
	return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
string s;
signed main() {
    cin >> N >> s;
    if (count(all(s), 'R') > count(all(s), 'B')) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }
}

Measured memory_bytes: 3600
n = list(input())
for i in range(len(n)):
         tmp = ord(n[i])
         if 65 <= tmp <= 90:
                  n[i] = chr(ord(n[i]) + 32)
         elif 97 <= tmp <= 122:
                  n[i] = chr(ord(n[i]) - 32)
ans = "".join(n)
print(ans)



Measured memory_bytes: 5572
#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second     
#define rep(i,a,b)    for(int  i=a;i<b;i++)
#define repr(i,a,b)      for(int i=b-1;i>=a;i--)
#define trav(it,v)      for(auto it=v.begin();it!=v.end();it++)
#define all(v)        v.begin(),v.end()
#define srt(v)        sort(all(v))
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define bs            binary_search
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAXN             10001

using namespace std;

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 


//int dx[4]={0,0,1,-1};
//int dy[4]={1,-1,0,0};
// vector<int>adj[100001];
// int vis[100001]={0};
// vector<int>v1;


void solve()
{
   int n;
   cin>>n;
   int rem=n%500;
   int q=n/500;
   int ans=q*1000;
   int r1=rem/5;
   ans+=5*r1;
   cout<<ans;
}   
    


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   /* #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 256
/// time is tough.....so don't stop ...keep learning ...keep growing :)

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
const int N = 1e5+5 ;
const int K = 50 ;
const ll mod =  1e9+7 ;
#define pb push_back
#define ft first 
#define sd second 
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll poww(ll a,ll b){ll res=1;while(b){if(b&1){res*=a;}a=a*a;b>>=1;}return res;}
ll poww(ll a,ll b,ll mod){ll res=1;while(b){if(b&1){res*=a;res%=mod;}a=a*a;a%=mod;b>>=1;}return res;}
const ll INF = 2e18 ;
int h[N], k, n, a[N], b[N], c[N];
int dp[N][3];

int solve(int n, int id){
	if(n == 1) return dp[n][id] ;
	int &res = dp[n][id] ;
	if(~res) return res ;
	for(int i=0;i<3;i++) {
		if(i != id) {
			int ct = 0;
			if(id == 0) ct = a[n];
			else if(id==1) ct = b[n];
			else ct = c[n];
			res = max(res, solve(n-1, i) + ct);
		}
	}
	return res;
}

int solve(int n) {
	return max(max(solve(n,0), solve(n,1)), solve(n,2)) ;
}
int main() {
    IOS;
    cin >> n;
    for(int i=1;i<=n;i++) {
    	cin >> a[i] >> b[i] >> c[i];
    }
    memset(dp, -1, sizeof dp);
    dp[1][0] = a[1] , dp[1][1] = b[1], dp[1][2] = c[1]; 
    cout << solve(n) << '\n';
	return 0 ;
}

// https://atcoder.jp/contests/dp/tasks






// // // https://codeforces.com/problemset/problem/474/E
// // // https://www.hackerrank.com/contests/codeagon/challenges/number-of-ways-1/problem
// // // https://codeforces.com/contest/475/problem/D


// https://www.spoj.com/problems/INS17M/
// https://www.codechef.com/SEPT18B/problems/ANDSQR
// 


Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <array>
#include <climits>

int main() {
  constexpr auto Aleph = 'z' - 'a' + 1;
  int n;
  std::cin >> n;
  std::array<int, Aleph> counter;
  counter.fill(INT_MAX);
  for (int i = 0; i < n; i++) {
    std::string s;
    std::cin >> s;
    std::array<int, Aleph> cnt{};
    for (char c : s)
      cnt[c - 'a']++;
    for (int i = 0; i < Aleph; i++)
      counter[i] = std::min(cnt[i], counter[i]);
  }
  std::string result;
  for (int i = 0; i < Aleph; i++)
    result += std::string(counter[i], 'a' + i);
  std::cout << result << std::endl;
}


Measured memory_bytes: 256
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])
    
x = int(input())
if x == 1:
    print(0)
else:
    print(1)

Measured memory_bytes: 65452
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  string b;
  long long int a,c=0,d=0,e,f;cin>>a>>b;
  c=count(b.begin(),b.end(),'R');
     d=count(b.begin(),b.end(),'B');
    e=count(b.begin(),b.end(),'G');
  f=c*d*e;
  rep(i,a-1){
    for(int o=i+1;o<a;o++){
      int k=2*o-i;
      if(k<a&&b[i]!=b[o]&&b[o]!=b[k]&&b[i]!=b[k])f--; 
    }
  }
  cout<<f;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>

int main(void){
    char s[255];
    int f1=0;
    int f2=0;
    scanf("%s",s);
    for(int i=0; i<(strlen(s)-1)/2; i++){
        //if(strcmp(s[i],s[(strlen(s)-1)/2-1-i])==0){
        //printf("%s\t%s\n",s[i],s[(strlen(s)-1)/2-1-i]);
        if(s[i]==s[(strlen(s)-1)/2-1-i]){
            f1++;
        }
    }
    for(int i=(strlen(s)+3)/2-1; i<strlen(s); i++){
        //if(strcmp(s[i],s[strlen(s)-1-i])==0){
        //printf("%s\t%s\n",s[i],s[strlen(s)-1-i]);
        if(s[i]==s[strlen(s)-1-i]){
            f2++;
        }
    }
    //printf("%d\t%d\n",(strlen(s)-1)/2,strlen(s)-((strlen(s)+3)/2-1));
    //printf("%d\t%d\n",f1,f2);
    if(f1==(strlen(s)-1)/2 && f2==strlen(s)-((strlen(s)+3)/2-1)){
        printf("Yes");
    }
    else{
        printf("No");
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>

using namespace std;

static inline void print(char **deck, int N, bool stable) {
    for (int i = 0; i < N - 1; ++i) {
        printf("%s ", deck[i]);
    }
    printf("%s\n", deck[N - 1]);
    printf("%s\n", stable ? "Stable" : "Not stable");
}

static inline char** newdeck(int N, char** orig = NULL) {
    char **deck = new char*[N];
    if (orig != NULL) {
        for (int i = 0; i < N; ++i) {
            deck[i] = new char[3];
            strncpy(deck[i], orig[i], 3);
        }
    }
    return deck;
}

int hashes[9];
static inline bool isstable(char** deck, int N) {
    int tmphash[9];
    memset(tmphash, 0, sizeof(int)*9);
    for (int i = 0; i < N; ++i) {
        tmphash[deck[i][1]-'0'] = tmphash[deck[i][1]-'0']*31 + deck[i][0];
    }
    for (int i = 0; i < 9; ++i) {
        if (hashes[i] != tmphash[i]) {
            return false;
        }
    }
    return true;
}

int main(void) {

    int N;
    cin >> N;

    char **deck = newdeck(N);
    for (int i = 0; i < N; ++i) {
        deck[i] = new char[3];
        cin >> deck[i];
        hashes[deck[i][1]-'0'] = hashes[deck[i][1]-'0']*31 + deck[i][0];
    }

    char **deck1 = newdeck(N, deck);
    for (int i = 0; i < N; ++i) {
        for (int j = N - 1; j >= i + 1; --j) {
            if (deck1[j][1] < deck1[j - 1][1]) {
                char* tmp = deck1[j];
                deck1[j] = deck1[j - 1];
                deck1[j - 1] = tmp;
            }
        }
    }

    char **deck2 = newdeck(N, deck);
    for (int i = 0, min; i < N - 1; ++i) {
        min = i;
        for (int j = i + 1; j < N; ++j) {
            if (deck2[j][1] < deck2[min][1]) {
                min = j;
            }
        }
        char* tmp = deck2[i];
        deck2[i] = deck2[min];
        deck2[min] = tmp;
    }

    print(deck1, N, isstable(deck1, N));
    print(deck2, N, isstable(deck2, N));

    for (int i = 0; i < N; ++i) {
        delete[] deck[i];
        delete[] deck1[i];
        delete[] deck2[i];
    }
    delete[] deck;
    delete[] deck1;
    delete[] deck2;
    return 0;
}

Measured memory_bytes: 1188
type dice = { one : int; two : int; three : int; four : int; five : int; six : int}

type direction = N | S | W | E

let move {one=a;two=b;three=c;four=d;five=e;six=f} = function
    N -> {one=b;two=f;three=c;four=d;five=a;six=e}
  | S -> {one=e;two=a;three=c;four=d;five=f;six=b}
  | W -> {one=c;two=b;three=f;four=a;five=e;six=d}
  | E -> {one=d;two=b;three=a;four=f;five=e;six=c}

let rec turn_right d = function
  | 0 -> d
  | i -> let {one=a;two=b;three=c;four=d;five=e;six=f} = d in
    turn_right {one=a;two=c;three=e;four=b;five=d;six=f} (i-1)

let () =
  let read_dice () =  Scanf.scanf "%d %d %d %d %d %d\n"
      (fun a b c d e f -> {one=a;two=b;three=c;four=d;five=e;six=f}) in
  let d1,d2 = read_dice (), read_dice () in
  let directions = [[];[S];[W];[N];[E];[S;S]] in
  let same_top = List.map (fun l -> List.fold_left
                              (fun dice direc -> move dice direc) d2 l) directions
                 |> List.filter (fun d -> if d.one=d1.one then true else false) in
  (List.fold_left
     (fun acc d -> List.map (fun t -> turn_right d t) [0;1;2;3] |> (@) acc)
     [] same_top
   |> List.filter (fun x -> x=d1)
   |> function [] ->  "No"
             | _ -> "Yes")
  |> print_endline

Measured memory_bytes: 2212
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = readline().strip()

    if N.count('7') > 0:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61956
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int ans = 0;
    for (int i = 1; i <= m / n; i++) {
        if (m % i == 0) {
            ans = i;
            if (i >= n) {
                ans = m / ans;
                break;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

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

string a,b,c;
int ab[100000],ac[100000],bc[100000];

inline int ok(char x,char y){
	return (x=='?'||y=='?'||x==y);
}

int main()
{
	cin>>a>>b>>c;
	int A=a.size(),B=b.size(),C=c.size();
	
	for(int i=0;i<A;i++)
		for(int j=0;j<B;j++)
			if(!ok(a[i],b[j]))
				ab[i-j+50000]=true;
	
	for(int i=0;i<A;i++)
		for(int j=0;j<C;j++)
			if(!ok(a[i],c[j]))
				ac[i-j+50000]=true;
	
	for(int i=0;i<B;i++)
		for(int j=0;j<C;j++)
			if(!ok(b[i],c[j]))
				bc[i-j+50000]=true;
				
	int ans=6000;
	for(int i=-4000;i<=4000;i++)
		for(int j=-4000;j<=4000;j++)
			if(!(ab[i+50000]||ac[j+50000]||bc[j-i+50000]))	
				ans=min(ans,max(A,max(B+i,C+j))-min(0,min(i,j)));
	cout<<ans<<endl;
}

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

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

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	static lint dp[200002][3];
	rep(i,n+2) rep(j,3) dp[i][j]=-INF;
	dp[0][0]=0;
	rep(i,n){
		dp[i+2][0]=dp[i][0]+a[i];
		dp[i+2][1]=dp[i][1]+a[i];
		if(i>=1) dp[i+2][1]=max(dp[i+2][1],dp[i-1][0]+a[i]);
		dp[i+2][2]=dp[i][2]+a[i];
		if(i>=1) dp[i+2][2]=max(dp[i+2][2],dp[i-1][1]+a[i]);
		if(i>=2) dp[i+2][2]=max(dp[i+2][2],dp[i-2][0]+a[i]);
	}

	lint ans;
	if(n%2==0) ans=max(dp[n][0],dp[n+1][1]);
	else       ans=max({dp[n-1][0],dp[n][1],dp[n+1][2]});
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 9596
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

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

	long long N;
	int flg, cnt = 0;

	cin >> N;

	vector<long long>A(N);

	for (long long i = 0; i < N; i++) {
		cin >> A[i];
	}

	flg = 1;
	while (flg) {
		for (long long i = 0; i < N; i++) {
			if (A[i] % 2 != 0) {
				flg = 0;
				break;
			}
		}

		if (flg) {
			for (long long i = 0; i < N; i++) {
				A[i] /= 2;
			}
			cnt++;
		}

	}

	cout << cnt << endl;

	return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

int main(){
    int N; cin >> N;
    vi A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    vi ids(N);
    for(int i=0; i<N; i++) ids[i]=i;
    sort(all(ids), [&](int i, int j){return A[i] < A[j];});
    for(int i=0; i<N; i++){
        cout << ids[i]+1;
        if(i != N-1) cout << " ";
    }
    cout << endl;
    return 0;   
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
	long long n;
	cin>>n;
	vector<long long> A(n);

	rep(i,n){
	  cin>>A[i];
	  A[i]-=i;
	 // ch(A[i],"A[i]");

	  }
	  SORT(A);
	  long long k = n/2;
	  long long b,c;
	  if(n%2==0){
		b=(A[k]+A[k-1])/2;
		c=b+1; 
		}
		else{
	  b=A[k];
	  c=A[k-1];
	 }
	  long long B,C;
	  B=0;C=0;
	  rep(i,n){
		  B +=abs(A[i]-b);
		  C +=abs(A[i]-c);
		}
		long long ans=min(B,C);
		cout<<ans<<endl;
}


Measured memory_bytes: 1792