akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() 
{
    int k,b;
    cin>>k>>b;
    int a[2*k-1];
    for(int i=0;i<2*k-1;i++)
    {
        a[i]=b-k+1+i;
    }
    for(int i=0;i<2*k-1;i++)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}











Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
using namespace std;

int main()
{
    ll n, k;
    cin >> n >> k;

    ll i;

    vector <ll> v(n);
    for(i = 0; i < n; i ++)
    {
    	cin >> v[i];
    }
    sort(v.begin(), v.end(), greater <ll> ());

    ll sum = 0;
    for(i = k; i < n; i ++)
    {
    	sum += v[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define NMAX 100000
int K = 1;
int PtoE[NMAX+1];//parent -> edge
int nextE[NMAX+1];//now edge -> next edge
int EtoC[NMAX+1];//double meaning. edge -> child | color

void dfs(int p, int p_color){
	int color = 1;
	for (int e = PtoE[p]; e; e = nextE[e]) {
		dfs(EtoC[e], color==p_color? ++color: color);
		K = max(K, EtoC[e] = color++);
	}
}

int main(){
	int N; cin>>N;
	rp(e, 1, N){
		int p,c; scanf("%d%d",&p,&c);
		EtoC[e] = c;
		nextE[e] = PtoE[p];
		PtoE[p] = e;
	}
	dfs(1, 0);
	printf("%d\n", K);
	rp(i, 1, N) printf("%d\n", EtoC[i]);
}

Measured memory_bytes: 3840
import java.util.Scanner;
public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long A=sc.nextLong();
		long B=sc.nextLong();
		long N=sc.nextLong();
		if(B-1>N) {
			System.out.println((A*N)/B);
		}else {
		System.out.println((A*(B-1))/B);
		}

		}
}

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

using namespace std;
#define intMax 2147483647
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repp(i, a, b) for (int i = a; i >= b; i--)
#define be(a) (a.begin(), a.end())
#define rbe(p) (p.rbegin(), p.rend())
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    rep(i, 0, n)
    {
        cin >> A[i];
    }
    vector<int> dp(n, intMax);
    dp[0] = 0;
    rep(i, 1, n)
    {
        repp(j, i - 1, max(0, i - k))
        {
            dp[i] = min(dp[i], dp[j] + abs(A[i] - A[j]));
        }
    }
    cout << dp[n - 1];
}

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

#define pb push_back
#define mk make_pair
#define sc second
#define fr first

using namespace std;


int main () {
       int n, c, k;
       cin >> n >> c >> k;

       deque <int> v(n);
       for(int i = 0;i < n;i ++)
           cin >> v[i];

       sort(v.begin(), v.end());
       int cnt = 0;
       while(1)
       {
             int r = v.front() + k, t = 1;
             while(!v.empty() && v.front() <= r)
             {
                  v.pop_front();
                  t ++;
                  if(t > c) break;
             }
             cnt ++;
             if(v.empty()) break;
       }
       cout << cnt;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    reverse(t.begin(), t.end());
    if (s == t) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define eps 1e-6
typedef long long ll;
using namespace std;

int n, a[200010], ans[200010];

int main(){

	cin >> n;
	for(int i = 2; i <= n; i++)
		cin >> a[i], ans[a[i]]++;
	for(int i = 1; i <= n; i++)
		cout << ans[i] << "\n"; 

	return 0;
}


Measured memory_bytes: 5196
#include <stdio.h>
 
char c1[11];
char c2[11];
char c3[11];
int a,b;
 

int main(void){
scanf("%s %s", c1, c2 );
scanf("%d %d", &a, &b);
scanf("%s", c3);
 
if(strcmp(c1,c3) == 0){
  a-=1;
}
if(strcmp(c2,c3) == 0){
  b-=1;
}
 
printf("%d %d",a, b);

return 0;  
}


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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; ++i) {
        cout << v[i];
        if (i < n - 1)
            cout << " ";
    }
    cout << "\n";

    for (int i = 0; i < n; ++i) {
        if ((1 << i + 1) > n) {
            cout << (i * (1 << i) + (n - (1 << i)) * (i + 2)) << "\n";
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 4584
#include <stdio.h>
int main(void){
    int a,b,x;
    char op;
    
    while(scanf("%d %c %d ",&a,&op,&b) !=EOF){
        if(op =='+'){
        x =a+b;
        
        printf("%d\n",x);}
        
        else if(op == '-'){
        x =a-b;
        
        printf("%d\n",x);}
        
        else if(op == '*'){
        x =a*b;
        
        printf("%d\n",x);}
        
         else if(op == '/'){
        x=a/b;
        
        printf("%d\n",x);}
        
        else if(op == '?'){
        
        break;}
    }// Your code here!
    return(0);
}



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

int main () {
    int H,W;
    cin >> H >> W;
    char mat[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> mat[i][j];
        }
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cout << mat[i][j];
        }
        cout << '\n';
        for(int j=0; j<W; j++){
            cout << mat[i][j];
        }
        cout << '\n';
    }
}



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

using namespace std;

const int N = 100010;

int a[N], b[N];

int main() {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &a[i], &b[i]);
	}
	long long cnt = 0;
	for (int i = n-1; i >= 0; --i) {
		if((cnt+a[i])%b[i] != 0) {
			cnt += (b[i] - (cnt+a[i])%b[i]) % b[i];
		}
	}
	printf("%lld\n", cnt);
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
//  int  a, b, c, d, X, Y;
//  double  c;
  long long  a, b, c, d, X, Y;
  int N, K;
  //char s[101][101]={};
  char sv[101]={};
  char ss[101]={};
  char t[12]={};
//  char s[10000000000000000001]={};
  char s[2][100001]={};
  int len=0;
  long long A[1000001]={};
//  long long  A[101]={};
  long long  B[101]={};
  long long  C[101]={};
  int i,j,k;
  int flag=0;
  long long tmp=0;
  long long min=10000000000;
  int cnt=0;
  double ans=1000;
  int max=-1;
  
  //  int ans=0;
  int str_len=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//  scanf("%lld %lld", &a, &b);
  scanf("%d %d", &N, &K);
  for(i=0;i<N;i++){
    scanf("%lld", &A[i]);
//    printf("%lld\n" ,A[i]);
  }
  qsort(A, N, sizeof(long long), compare_int);
  for(i=0;i<N;i++){
    scanf("%lld", &A[i]);
//    printf("%lld\n" ,A[i]);
  }
  for(i=0;i<(N-K+1);i++){
    tmp=A[i+K-1]-A[i];
//    printf("%lld\n" ,tmp);
    if(min>tmp) min=tmp;
//    printf("%lld\n" ,min);
    
  }
  
    printf("%lld\n" ,min);
return 0;
}


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

// ------------------
// Integer modulo MOD
// ------------------
const int64_t MOD = 998244353;
struct mint
{
    int64_t x;
    mint(int64_t 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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(int64_t n) const
    {
        if (n == 0)
            return 1;
        mint t = pow(n >> 1);
        t *= t;
        if (n & 1)
            t *= *this;
        return t;
    }
    mint inv() const { return pow(MOD - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

int main()
{
    int N;
    cin >> N;
    vector<int> D(N);
    vector<int> n_D(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> D.at(i);
        n_D.at(D.at(i)) += 1;
    }

    if (D.at(0) != 0 || n_D.at(0) != 1)
    {
        cout << 0 << endl;
        return 0;
    }
    mint res = 1;
    for (int i = 1; i < N; i++)
    {
        if (n_D.at(i) == 0)
        {
            continue;
        }
        res *= mint(n_D.at(i - 1)).pow(n_D.at(i));
    }
    cout << res.x << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
	ll k,x;
	cin>>k>>x;
	if(500*k>=x) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
template <typename T, typename U>ostream &operator<<(ostream &out, const pair<T, U> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>void print(const ContainerType<ValueType, Args...> &c){for (const auto &v : c)cout << v << ' ';cout << '\n';} void print(){cout<<'\n';}
template <typename T, typename... Args>void print(T a, Args... args){cout << a << " ";print(args...);}
lli llipower(lli x, lli y, lli p = LLONG_MAX){lli res = 1;x = x % p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}

//8====================================D
int a, b, c, d;
int main(){
    int h,w,k;
    cin>>h>>w>>k;
    vector<string> a(h);
    fori(h) cin>>a[i];
    int x=0;
    int ans=0;
    while(x<(1<<(h+w))){
        bitset<13> t(x);
        int count=0;
        fori(h){
            forj(w){
                if(a[i][j]=='#' && t[i]==0 && t[j+h]==0) count++;
            }
        }
        if(count==k) ans++;
        x++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline

def print_ans(N):
    """Test Case
    >>> print_ans("redcoder")
    1
    >>> print_ans("vvvvvv")
    0
    >>> print_ans("abcdabc")
    2
    """
    ans = 0
    length = len(N)
    for i in range(length // 2):
        if N[i] != N[length -1 - i]:
            ans += 1
    print(ans)

    

if __name__ == '__main__':
    N = input().rstrip()
    print_ans(N)




Measured memory_bytes: 2940
/*
Author : N_o_o_B
Created : December 03 2019 23:34:24 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;
ll dp[53][53][2533];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;
    int n,A;
    cin >> n >> A;
    vi x(n);
    fori(i,n) cin >> x[i];
    fori(i,n+1){
        fori(j,2533){
            dp[n][i][j] = 0;
        }
    }
    dp[n][0][0] = 1;
    ford(i,n){
        fori(j,n+1){
            fori(k,2533){
                dp[i][j][k] = dp[i+1][j][k];
                if(j and k >= x[i]){
                    dp[i][j][k] += dp[i+1][j-1][k-x[i]];
                }
            }
        }
    }
    ll ans = 0;
    rep(j,1,n){
        ans += dp[0][j][A*j];
    }
    cout << ans << endl;
    time_taken();
    return 0;
}


Measured memory_bytes: 55552
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y)
{
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y)
{
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y)
{
  return x / gcd(x, y) * y;
}

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

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

  ll sum = 0;
  for (int i = 0; i < n; i++)
  {
    int d = min(b[i], a[i]);
    b[i] -= d;
    a[i] -= d;
    sum += d;
    d = min(b[i], a[i + 1]);
    b[i] -= d;
    a[i + 1] -= d;
    sum += d;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())

AB = []
for _ in range(N):
	A, B = map(int, input().split())
	AB.append([A, B])
AB.sort()

import heapq
Q = []
ABidx = 0
ans = 0

for lastday in range(M + 1):
	while(ABidx < len(AB) and AB[ABidx][0] <= lastday):
		heapq.heappush(Q, -1*AB[ABidx][1])
		ABidx += 1
	if(len(Q) > 0):
		ans += -1 * heapq.heappop(Q)
print(ans)

Measured memory_bytes: 24200
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int n;

int main(){
  int h,w;
  char flag[1111][1111];
  char emb[5][5];
  char mas[] = {'J','O','I'};
  int dx[] = {-1,-1,0,0};
  int dy[] = {-1,0,-1,0};
  int cnt = 0;
  int ans = 0;
  cin >> h >> w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> flag[i][j];
    }
  }
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      cin >> emb[i][j];
    }
  }
  for(int i=0;i<h-1;i++){
    for(int j=0;j<w-1;j++){
      if(flag[i][j] == emb[0][0] && flag[i][j+1] == emb[0][1] && flag[i+1][j] == emb[1][0] && flag[i+1][j+1] == emb[1][1]){
	cnt++;
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int z=0;z<3;z++){
	if(flag[i][j] == mas[z]) continue;
	char tmp = flag[i][j];
	flag[i][j] = mas[z];
	int ret = 0;
	for(int k=0;k<4;k++){
	  int nx = j + dx[k];
	  int ny = i + dy[k];
	  if(flag[ny][nx] == emb[0][0] && flag[ny][nx+1] == emb[0][1] && flag[ny+1][nx] == emb[1][0] && flag[ny+1][nx+1] == emb[1][1]){
	    ret++;
	  }
	}
	ans = max(ans,cnt+ret);
	flag[i][j] = tmp;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2252
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int main(){
  const int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};

  int w,h;
  int tate[50][50], yoko[50][50];
  int dis[50][50];

  while(cin >> w >> h, w){
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++){
	tate[i][j] = yoko[i][j] = 1;
	dis[i][j] = 0;
      }	
    }

    for(int i=0;i<2*h-1;i++){
      if(i%2 == 0){
	for(int j=0;j<w-1;j++)cin >> tate[i/2+1][j+1];
      }else{
	for(int j=0;j<w;j++)cin >> yoko[i/2+1][j+1];
      }
    }

    dis[1][1] = 1;
    queue<pii> q;
    q.push(pii(1,1));

    while(q.size()){
      int y = q.front().first, x = q.front().second; q.pop();

      for(int i=0;i<4;i++){
	int ny = y+dy[i], nx = x+dx[i];
	if(ny<1 || nx<1 || ny>h || nx>w)continue;
	if(dis[ny][nx] != 0)continue;

	bool f = true;
	if(i==0 && yoko[y-1][x])f = false;
	if(i==1 && tate[y][x])f = false;
	if(i==2 && yoko[y][x])f = false;
	if(i==3 && tate[y][x-1])f = false;
	if(f){
	  dis[ny][nx] = dis[y][x] + 1;
	  q.push(pii(ny,nx));
	}
      }
    }

    cout << dis[h][w] << endl;
  }
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> A(n);
	rep(i, n) cin >> A[i];
	sort(A.begin(), A.end());
	auto itr = lower_bound(A.begin(), A.end(), 0);
	int k = distance(A.begin(), itr);
	//cout << k << endl;
	ll ans = 0;
	if (itr == A.end() && n % 2 != 0) {
		rep(i, n) {
			if (i == n - 1) ans += A[i];
			else ans -= A[i];
		}
		cout << ans << endl;
		return 0;
	}
	if (k % 2 == 0) {
		rep(i, n) {
			if (i <= k - 1) ans -= A[i];
			else ans += A[i];
		}
		cout << ans << endl;
		return 0;
	}
	else {
		ll res1 = 0, res2 = 0;
		rep(i, n) {
			if (i <= k - 2) res1 -= A[i];
			else res1 += A[i];
		}
		rep(i, n) {
			if (i <= k) res2 -= A[i];
			else res2 += A[i];
		}
		ans = max(res1, res2);
		cout << ans << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

#include<string.h>

int main(void)

{

   int sum;

   char str[1100];

   int i;

   for(i=0;i<1100;i++){

      str[i]=0;

   }

   while(1){

      scanf("%s",str);

      if(strcmp(str,"0")==0){

         break;

      }

      sum=0;

      for(i=0;str[i]!='\0';i++){

         sum+=str[i]-'0';

      }

      printf("%d\n",sum);

   }

   return 0;

}

Measured memory_bytes: 536
#!/usr/bin/env python3
import sys

def solveChild(S: str, start: int, N: int):
    # return the final position of this child after 10^100 times moves
    # same == 1: stop at same as start
    # same == 0: stop at different with starts
    if S[start] == 'L':
        i = start - 1
        for i in range(start - 1, -1, -1):
            if S[i] == 'R':
                lastL = i+1
                # firstR = i
                break
        if (start - lastL) % 2 == 1: # start - lastL is odd
            same = False
            return lastL - 1, same
        else: # start - lastL is even
            same = True
            return lastL, same
    else: # S[start] == 'R'
        for i in range(start + 1, N):
            if S[i] == 'L':
                lastR = i - 1
                # firstL = i
                break
        if (lastR - start) % 2 == 1: # start - lastR is odd
            same = False
            return lastR + 1, same
        else: # start - lastR is even
            same = True
            return lastR, same

def solve(S: str):
    N = len(S)
    num_child = [0] * N
    # first 
    stop, same = solveChild(S, 0, N)
    num_child[stop] += 1
    for start in range(1, N):
        if S[start] == 'L' and S[start - 1] == 'L':
            if same:
                stop -= 1
                num_child[stop] += 1
                same = False
            else:
                stop += 1
                num_child[stop] += 1
                same = True
        elif S[start] == 'R' and S[start - 1] == 'R':
            if same:
                stop += 1
                num_child[stop] += 1
                same = False
            else:
                stop -= 1
                num_child[stop] += 1
                same = True
        else:
            stop, same = solveChild(S, start, N)
            num_child[stop] += 1

    print(' '.join(map(str, num_child)))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10740
#include<cstdio>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==5&&b==7&&c==5||a==7&&b==5&&c==5||a==5&&b==5&&c==7)printf("YES\n");
        else printf("NO\n");
    return 0;
}

Measured memory_bytes: 128
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
P p[ohara];
ll dp[ohara];
bool vi[ohara];

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

  cin >> h >> w >> d;
  rep(i, h) {
    rep(j, w) {
      cin >> a;
      p[a] = m_p(i, j);
    }
  }
  rrrep(i, h * w, 1) {
    if (vi[i]) continue;
    ll now = i;
    vi[now] = true;
    while (1) {
      y = p[now].fi, x = p[now].se;
      now -= d;
      if (now <= 0) break;
      ll af_x, af_y;
      af_y = p[now].fi, af_x = p[now].se;
      dp[now] += dp[now + d] + abs(x - af_x) + abs(y - af_y);
      vi[now] = true;
    }
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    ans = dp[b];
    ans -= dp[c];
    Cout(ans);
  }
  return 0;
}

Measured memory_bytes: 3968
#include<iostream>

using namespace std;

void swap(int& a, int& b){
    a = a ^ b; b = a ^ b; a = a ^ b;
}

int selectSort(int a[], int n){
    int cnt = 0;
    for(int i = 1; i <n; ++i){
        a[0] = i;
        for(int j = i + 1; j <= n; ++j){
            if(a[j] < a[a[0]]) a[0] = j;
        }
        if(a[0] != i) { swap(a[a[0]], a[i]); ++cnt; }
    }
    return cnt;
}

int main(){
    int n, cnt = 0;
    cin >> n;
    int a[n + 1];
    for(int i = 1; i <= n; ++i) cin >> a[i];
    cnt = selectSort(a, n);
    for(int i = 1; i < n; ++i) cout << a[i] << " ";
    cout << a[n] << endl << cnt << endl;
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
   vector<pair<pair<string,int>,int>> K;
   vector<int>p;
   for(int i=0;i<n;i++){
        string p;
       cin>>p;
       int s;
       cin>>s;
      
       K.push_back(make_pair(make_pair(p,-s),i));
   }
   sort(K.begin(),K.end());
   for(int i=0;i<n;i++){
      cout<<( K[i].second)+1<<endl;
   }

   return 0;


    
}


Measured memory_bytes: 256
n,m=map(int,input().split())
mlist=[i for i in range(1,m+1)]
ans=0

li=[]
for i in range(n):
  temp=list(map(int,input().split()))
  del temp[0]
  li.append(temp)

for i in(mlist):
  judge=0
  for x in(li):
    if i not in x:
      judge=1
  if judge==0:
    ans+=1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

/**
 * https://abc066.contest.atcoder.jp/tasks/abc066_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		
		int ans = 0;
		for(int i=1; i<s.length(); i++){
			int l = s.length()-i;
			if(l%2==1) continue;
			String s1 = s.substring(0,l/2);
			String s2 = s.substring(l/2,l);
			if(s1.equals(s2)){
				ans = l;
				break;
			}
		}
		
		System.out.println(ans);

	}

}

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


int main() {


	int a, b, k;

	cin >> a >> b >> k;

	for (int i = 0; i < k; i++) {
		cout << a << endl;
		if (a == b) return 0; 
		a++;
	}
	a--;

	int start = b-k+1;
	if (b-k+1 <= a) { start = a +1; };
	for (int i = 0; i < k; i++) {
		cout << start << endl;
		if (start == b)break;

		start++;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int h,w;
	int i,t;
	while(1){
		scanf("%d %d", &h, &w);
		if(h==0 && w==0)break;
		for(i = 0;i < h;i++){
			for(t = 0;t < w;t++){
				if((i+t)%2)
					printf(".");
				else
					printf("#");
			}
			puts("");
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 588
ARGF.each_line do |line|
  break if line =~ /\?/
  a, op, b = line.split
  a, b = [a, b].map(&:to_i)
  case op
  when "+"
    puts a + b
  when "-"
    puts a - b
  when "*"
    puts a * b
  when "/"
    puts a / b
  end
end

Measured memory_bytes: 6092
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int N;
    static int M;
    static Edge[] edges;
    static long[] d;
    static long INF = Long.MAX_VALUE;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        M = scanner.nextInt();

        edges = new Edge[M];
        for(int i = 0; i < M; i++) {
            int from = scanner.nextInt() - 1;
            int to = scanner.nextInt() - 1;
            long cost = -scanner.nextLong();
            Edge e = new Edge(from, to, cost);
            edges[i] = e;
        }

        d = new long[N];
        Arrays.fill(d, INF);

        scanner.close();
    }

    private static void bellmanFord(int s) {
        d[s] = 0;
        for(int i = 0; i < N; i++) {
            boolean update = false;
            for(int j = 0; j < M; j++) {
                Edge e = edges[j];
                if(d[e.from] != INF && d[e.from] + e.cost < d[e.to]) {
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                }
            }
            if(!update) break;
        }
    }

    public static void main(String args[]) {
        init();
        bellmanFord(0);
        long ans = -d[N - 1];

        bellmanFord(0); // もう1回bellmanFord回して、Nの頂点の結果が変わって入ればスコアに関わる閉路がある
        if(ans == -d[N - 1]) {
            System.out.println(ans);
        } else {
            System.out.println("inf");
        }
    }
}

class Edge {
    int from;
    int to;
    long cost;

    public Edge(int from, int to, long cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }
}

Measured memory_bytes: 29900
#include<iostream>
using namespace std;
int i,n,m,a,c[20];
int main()
{
	for(cin>>n;i++<n;cin>>a,c[a/400]++);
	for(i=0;i<8;i++)m+=c[i]>0;
	cout<<(m?m:1)<<" "<<m+c[8]+c[9]+c[10]+c[11]+c[12];
}


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

int main(){
    char S[3];

    rep(i,3) cin>>S[i];
    if (S[1]=='B'){
        cout<<"ARC"<<endl;
    }else{
        cout<<"ABC"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;

#define rep(i,N) for(int (i)=0; (i)<(N); (i)++)
#define revrep(i,N) for(int (i)=(N)-1; (i)>=0; (i)--)
#define dump(vec) for(int i = 0; i < (vec).size(); i++){cout << vec.at(i) << ",";}cout << endl

typedef long long ll;

int main(void)
{
    int N = 0;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) {
        cin >> A.at(i);
    }

    vector<ll> keta(1001,0);
    rep(k,61){
        ll s = 0;
        ll t = 0;
        rep(i,N) {
            if (((A.at(i) >> k )& 0x01) == 1) {
                t++;
            } else {
                s++;
            }
        }
        ll u = s*t;
        keta.at(k) = u;
    }
    //dump(keta);

    rep(k,keta.size()-1){
        keta.at(k+1) += (keta.at(k)/2);
        if(keta.at(k) % 2 == 1) {
            keta.at(k) = 1;
        } else {
            keta.at(k) = 0;
        };
    }

    //dump(keta);

    ll ret = 0;
    rep(k,keta.size()){
        if (keta.at(k)) {
            ll temp = 1;
            rep(i,k){
                temp *= 2;
                temp %= (1000000000+7);
            }
            ret += temp;
            ret %= (1000000000+7);
        }        
    }

    cout << ret << endl;
    

    return 0;
}


Measured memory_bytes: 2560
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static class UnionFind {
		int[] param;
		int[] rank;
		int N;
		int xlen;
		
		public UnionFind(int n) {
			N=n;
			param = new int[N];
			rank = new int[N];
			for(int i=0; i<N; i++)
				param[i] = i;
		}
		
		public void init() {
			for(int i=0; i<N; i++)
				param[i] = i;
			Arrays.fill(rank, 0);
		}
		
		public UnionFind(int x, int y) {
			this(x*y);
			xlen=y;
		}
		
		public boolean same(int a, int b) {
			return getRoot(a)==getRoot(b);
		}
		
		public boolean same(int x1, int y1, int x2, int y2) {
			return same(x1*xlen+y1, x2*xlen+y2);
		}
		
		public int getRoot(int a) {
			if(param[a]==a) return a;
			else return (param[a] = getRoot(param[a]));
		}
		
		public void unite(int a, int b) {
			a = getRoot(a);
			b = getRoot(b);
			if(a==b)
				return;
			
			if(rank[a] < rank[b]) {
				param[a] = b;
			} else {
				param[b] = a;
				if(rank[a]==rank[b])
					rank[a]++;
			}
		}
		
		public void unite(int x1, int y1, int x2, int y2) {
			unite(x1*xlen+y1, x2*xlen+y2);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int L = sc.nextInt();
		
		UnionFind ufRoad = new UnionFind(N);
		for(int i=0; i<K; i++) {
			ufRoad.unite(sc.nextInt()-1, sc.nextInt()-1);
		}

		UnionFind ufRail = new UnionFind(N);
		for(int i=0; i<L; i++) {
			ufRail.unite(sc.nextInt()-1, sc.nextInt()-1);
		}
		
		HashMap<Long, Integer> count = new HashMap<>();
		for(int i=0; i<N; i++) {
			long key = ((long)ufRoad.getRoot(i))<<20 | (long)ufRail.getRoot(i);
			Integer value = count.get(key);
			count.put(key, value==null ? 1 : value+1);
		}
		
		for(int i=0; i<N; i++) {
			long key = ((long)ufRoad.getRoot(i))<<20 | (long)ufRail.getRoot(i);
			pw.print(count.get(key) + (i==N-1 ? "\n" : " "));
		}
		
		sc.close();
		pw.close();
	}
}


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

const int N = 39;

string solve(int n){
  n = n %N;
  if(n==0)n = N;
  return "3C" + (n<10?"0"+to_string(n):to_string(n));
}

int main(){
  int n;
  while(cin>>n){
    cout<<solve(n)<<endl;
  };
  
}

Measured memory_bytes: 1224
import sys

x = input()
X = int(x)

if X < 100:
	print(0)
	sys.exit()
elif X >= 100 and X <= 105:
	print(1)
	sys.exit()
elif X % 105 == 0:
	print(1)
	sys.exit()

x1 = int(x[:-2])
x2 = int(x[-2:])

c = int(x2 // 5) + 1

if x1 >= c:
	print(1)
else:
	print(0)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int b[1000005];

int main()
{
	
	int n;
	memset(b,0,sizeof(b));	
	cin >> n;
	int a[n],max = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		
		if(max < a[i])
			max = a[i];//求出数组里最大值，防止下面循环次数过多
		b[a[i]]++;
		b[a[i]-1]++;
		b[a[i]+1]++;
	
	}
	
	int max1 = 0;
	for(int i = 0;i <= max + 1;i++){
		if(max1 < b[i])
			max1 = b[i];
	}
	cout << max1;
	return 0;
}


Measured memory_bytes: 7956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    int a, b, c;
    cin>>a>>b>>c;
    if(a==b&&b!=c&&a!=c)cout<<"Yes\n";
    else if(b==c&&b!=a&&c!=a)cout<<"Yes\n";
    else if(a==c&&b!=a&&c!=b)cout<<"Yes\n";
    else cout<<"No\n";   
}
int main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)foo();
}

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

#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)

struct num{
	int a;
	int b;
	int rank;
};

int main(void){
	struct num data[200];
	int indata[200];
	struct num w;
	
	char c;
	int i=0,rank=0;
	while(cin>>data[i].a>>c>>data[i].b,data[i].a+data[i].b)i++;
//	cout<<i<<endl;
	loop(j,0,i-1){
		loop(k,j,i){
			if(data[j].b<data[k].b){
				w=data[j];data[j]=data[k];data[k]=w;
			}
		}
		if(data[j].b==data[j-1].b)data[j].rank=rank;
		else data[j].rank=++rank;
	}
	if(data[i-2].b==data[i-1].b)data[i-1].rank=rank;
	else data[i-1].rank=++rank;
	int d=0;
	while(cin>>indata[d++]);
	
	for(int j=0;j<d;j++){
		for(int k=0;k<i;k++){
			if(indata[j]==data[k].a)cout<<data[k].rank<<endl;
		}
	}

	
	
//	for(int j=0;j<i;j++)cout<<data[j].a<<" "<<data[j].b<<" "<<data[j].rank<<endl;
	
	
}

Measured memory_bytes: 1160
n = int(input().strip())
count = 0
for i in range(n):
  a,b = map(int,input().strip().split())
  if count == 3:
    print('Yes')
    exit(0)
  elif a == b:
    count += 1
  elif(a != b):
    count = 0
if count == 3:
	print('Yes')
else:
	print('No')


Measured memory_bytes: 9104
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	X := sc.nextInt()
	ans := 1
	for i := 2; i*i < X; i++ {
		power := 2
		num := i
		for pow(i, power) <= X {
			num = pow(i, power)
			power++
		}
		if ans < num {
			ans = num
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 640
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cost_list = [a, b, c, d, e]

min_val = 100
idx = 0
for i, cost in enumerate(cost_list):
    val = cost % 10
    if val == 0:
        continue

    if val < min_val:
        min_val = val
        idx = i

ans = cost_list[idx]
for i, cost in enumerate(cost_list):
    if i == idx:
        continue

    wait_next_order = 0
    if cost%10 != 0:
        wait_next_order = 10 - cost%10

    ans += cost + wait_next_order

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int dp[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	printf("%d\n",dp[n]);
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define srt(a) sort(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define vplli vector <pair <lli,lli> >
#define vpulli vector <pair <ulli,ulli> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pair <int,int>> >
#define vvb vector <vector <bool> >
#define fr(i,n) for (int i = 0; i < (n); i++)
#define frbig(i,n) for (lli i = 0; i < (n); i++)
#define fra(i,a,n) for (lli i = a; i < (n); i++)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
const lli MOD = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    string s,t;
    cin >> s >> t;
    if(s.size()==t.size()-1){
    fr(i,s.size()){
        if(s[i]!=t[i]){ cout << "No"; return 0;}
    }
    cout << "Yes";
    }
    else cout << "No"; 
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;
const int N_MAX = 100001;
const int modint = 1000000007;

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }
int ceil(int a,int b){
  // a/bの切り上げを考える
  return (a+b-1)/b;
}

int main(){
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  rep(i,n)cin >> a[i] >> b[i] >> c[i];

  int dp[3][n];

  memset(dp, 0, sizeof(dp));
  dp[0][0] = a[0];
  dp[1][0] = b[0];
  dp[2][0] = c[0];

  for(int i = 1;i < n;i++){
    dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + a[i];
    dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + b[i];
    dp[2][i] = max(dp[0][i-1], dp[1][i-1]) + c[i];
  }
  int temp = max(dp[0][n-1],dp[1][n-1]);
  int ans = max(temp, dp[2][n-1]);
  cout << ans << endl;
}

Measured memory_bytes: 5940
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B) {
    cout << C << "\n";
  } else if (A == C) {
    cout << B << "\n";
  } else {
    cout << A << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2


int n, M[N][N];
int color[N], d[N], f[N], tt;


void dfs_visit(int u) {
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for (v=0; v < n; v++) {
    if (M[u][v] == 0) continue;
    if (color[v] == WHITE) {
      dfs_visit(v);
    }
   }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs() {
  int u;

  for (u=0; u < n; u++) color[u] = WHITE;
  tt = 0;


  for (u=0; u < n; u++) {

    if (color[u] == WHITE) dfs_visit(u);
  }
  for (u=0; u < n; u++) {
   printf("%d %d %d\n", u+1, d[u], f[u]);
  }
}

int main() {
  int u, v, k, i, j;

  scanf("%d", &n);
  for (i=0; i < n; i++) {
   for (j=0; j < n; j++) M[i][j] = 0;

  }

  for (i=0; i < n; i++) {
   scanf("%d %d", &u, &k);
   u--;
   for (j=0; j < k; j++) {
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
     }
  }

  dfs();

  return 0;
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

int N;
string  str;

string hoge(string ans){
	for(int i = 2; i < str.size(); i++){
		if(str[i-1] == 'o'){
			if(ans[i-1] == 'S'){
				ans += ans[i-2];
			} else {
				ans += (ans[i-2]=='S'?'W':'S');
			}
		} else {
			if(ans[i-1] == 'S'){
				ans += (ans[i-2]=='S'?'W':'S');
			} else {
				ans += ans[i-2];
			}
		}
	}
	if(ans[N-1] == 'S'){
		if(str[N-1] == 'o'){
			if(ans[0] != ans[N-2]) ans = "-1";
		} else {
			if(ans[0] == ans[N-2]) ans = "-1";
		}
	} else {
		if(str[N-1] == 'o'){
			if(ans[0] == ans[N-2]) ans = "-1";
		} else {
			if(ans[0] != ans[N-2]) ans = "-1";
		}
	}
	
	if(ans[0] == 'S'){
		if(str[0] == 'o'){
			if(ans[1] != ans[N-1]) ans = "-1";
		} else {
			if(ans[1] == ans[N-1]) ans = "-1";
		}
	} else {
		if(str[0] == 'o'){
			if(ans[1] == ans[N-1]) ans = "-1";
		} else {
			if(ans[1] != ans[N-1]) ans = "-1";
		}
	}
	return ans;
}

signed main(){
	cout<<fixed<<setprecision(7);

	string  ans[4] = {"SS","SW","WW","WS"};
	
	cin>>N>>str;
	
	for(int i = 0; i < 4; i++){
		string temp = hoge(ans[i]);
		if(temp != "-1"){
			cout<<temp<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 640
def main():
    n, maxW, weight, value = getInputs()

    accumulatedValue = [0] * (maxW + 1)

    possible = [False] * (maxW + 1)
    possible[0] = True

    used = []
    for i in range(maxW + 1):
        used.append([0] * n)

    for x in range(min(weight), maxW + 1):
        for w in range(n):
            weightW = weight[w]

            if (x - weightW >= 0) and possible[x - weightW] and used[x - weightW][w] == 0:
                newValue = accumulatedValue[x - weightW] + value[w]

                if newValue > accumulatedValue[x]:
                    accumulatedValue[x] = newValue
                    used[x] = used[x - weightW].copy()
                    used[x][w] = 1
                    possible[x] = True

    print(max(accumulatedValue))

def getInputs():
    n, maxW = map(lambda x: int(x), input().split())

    weight, value = [], []
    for i in range(n):
        w, v = map(lambda x: int(x), input().split())
        weight.append(w)
        value.append(v)

    return n, maxW, weight, value

main()


Measured memory_bytes: 239608
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
typedef pair<int, int> P;

int get_score(const vector<P> & vc, const vector<bool> & flg) {
  int x = 0, y = 0;
  rep(i, vc.size()) {
    if (flg[i]) {
      x += vc[i].first;
      y += vc[i].second;
    }
  }
  return x - y;
}

bool dfs(const vector<P>& vc, vector<bool> flg, int* pAns) {
  if (flg.size() == vc.size()) {
    int score = get_score(vc, flg);
    *pAns = max(*pAns, score);
    return true;
  }

  flg.push_back(false);
  if (dfs(vc, flg, pAns)) {
    flg.pop_back();
  }

  flg.push_back(true);
  if (dfs(vc, flg, pAns)) {
    flg.pop_back();
  }

  return true;
}

int main(void) {
  int n;
  cin >> n;
  vector<P> vc(n);
  rep(i, n) cin >> vc[i].first;
  rep(i, n) cin >> vc[i].second;
  vector<bool> flg;
  int ans = 0;
  dfs(vc, flg, &ans);
  cout << ans << endl;
  return 0;
}


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

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

    int n;
    string s;
    cin >> n >> s;

    vector<vector<int>> a(26), memo(n, vector<int>(n));
    rep(i, 0, n) {
        a[s[i] - 'a'].emplace_back(i);
    }
    int ans = 0;
    rep(c, 0, 26) {
        if (a[c].empty())
            continue;
        int m = a[c].size();
        rep(i, 0, m) rep(j, i + 1, m) {
            int res = 1, sub = 0;
            int x = a[c][i], y = a[c][j];
            while (y + 1 < n && x + res < y && s[x + res] == s[y + res]) {
                if (memo[x + res][y + res]) {
                    sub = res;
                    res += memo[x + res][y + res];
                    res = min(res, y - x);
                    break;
                }
                res++;
                sub = res;
            }
            rep(l, 0, sub) memo[x + l][y + l] = res - l;
            ans = max(ans, res);
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define testcases ll t;cin>>t;while(t--)
#define queries ll q;cin>>q;while(q--)
#define ll long long 
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define ff first
#define ss second
#define elif else if
#define flush cout<<endl;
#define pb push_back;
#define mod 1000000007




int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//testcases{
		long long int n,x,y,z,k,p,q,r,ct=0,sum=0,e=0;;
		cin>>n;
		
		x = sqrt(n);

		for(long i=x;i>=1;i--){

			if(n%i==0){
				y=i;
				break;
			}
		}

		z = n/y;

		cout<< y+z-2;
		flush;

				
	//}
	
}

Measured memory_bytes: 256