akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const long LMIN=-(1l<<63);
struct TAG{long* array;int size,head,tail,count;};
typedef struct TAG* DEQUE;
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline long IN(void)
{
  long x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline long Max(const long x,const long y){return x<y?y:x;}
static inline void* xmalloc(size_t size){void* p=malloc(size);if(p==NULL){exit(EXIT_FAILURE);}return p;}
static inline DEQUE CREATE(void)
{
  const int size=10000;
  struct TAG* deque=(DEQUE)xmalloc(sizeof(struct TAG));
  deque->array=(long*)xmalloc(sizeof(long)*size);
  deque->size=size;deque->head=deque->tail=deque->count=0;return deque;
}
static inline void DELETE(DEQUE deque){free(deque->array);free(deque);}
static inline int PREV(DEQUE deque,int index){return(!index)?deque->size-1:index-1;}
static inline int NEXT(DEQUE deque,int index){return(index+1)%deque->size;}
static inline void PUSH(DEQUE deque,long val,int back)
{
  //front=0,back=1;
  if(deque->count==deque->size){exit(EXIT_FAILURE);}
  if(back)deque->tail=NEXT(deque,deque->tail);else deque->head=PREV(deque,deque->head);
  deque->array[(back)?deque->tail:deque->head]=val;deque->count++;
  if(deque->count==1){if(back)deque->head=deque->tail;else deque->tail=deque->head;}
}
static inline long POP(DEQUE deque,int back)
{
  if(!deque->count){exit(EXIT_FAILURE);}
  long val=deque->array[(back)?deque->tail:deque->head];
  if(back)deque->tail=PREV(deque,deque->tail);else deque->head=NEXT(deque,deque->head);
  deque->count--;return val;
}
int main(void)
{
  int N=IN(),K=IN(),C[5000],P[5000],vis[5000]={0};long score=LMIN,vector[15000];
  rep(i,N){P[i]=IN()-1;}rep(i,N){C[i]=IN();score=Max(score,C[i]);}if(score<0){return OUT(score),0;}
  rep(i,N)
  {
    if(vis[i]){continue;}
    int len=0,now=K,sz=0,x=P[i];long high=LMIN,temp=0,y=1l*C[x];vis[i]=1;
    vector[sz++]=0,vector[sz++]=y;
    while(!vis[x]){vis[x]=1;x=P[x];y+=1l*C[x];vector[sz++]=1l*C[x];}
    if(y>0)
    {
      temp+=1l*Max(1l*now/(sz-1l)-1l,0l)*y;
      if(now>sz-1){now%=sz-1;now+=1l*sz-1l;}
    }
    len=sz;
    rep(j,len-1){vector[sz++]=1l*vector[j+1];}
    rep(j,len-1){vector[sz++]=1l*vector[j+1];}
    rep(j,sz-2){vector[j+2]+=1l*vector[j+1];}
    DEQUE dq=CREATE();PUSH(dq,0,0);
    rep(j,sz-1)
    {
      while(dq->count&&vector[dq->array[dq->head]]>vector[j+1]){POP(dq,0);}
      PUSH(dq,j+1,0);
      while(dq->count&&j+1-dq->array[dq->tail]>now){POP(dq,1);}
      if((j+1)!=dq->array[dq->tail]){high=1l*Max(1l*high,1l*vector[j+1]-1l*vector[dq->array[dq->tail]]);}
    }
    temp+=1l*high;score=1l*Max(score,temp);DELETE(dq);
  }
  return OUT(score),0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100
#define MAXW 100000
#define INF 2000000000

int w[MAXN], v[MAXN];
int n,C;
long long dp[MAXN+1][MAXW+1];

int main() {
	int i,j;
	scanf("%d %d",&n, &C);	
	for (i=0; i<n;i++) {
		scanf("%d %d",&w[i],&v[i]);
	}
	for (i=n-1; i>=0; i--) {
		for (j=0; j<=C; j++) {
			dp[i][j]=dp[i+1][j];
			if (j-w[i]>=0) {
				dp[i][j]=max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
			}
		}
	}
	printf("%lld\n",dp[0][C]);
	return 0;
}

Measured memory_bytes: 81780
#include<iostream>
using namespace std;
int main()
{
    int n,x=0,y=0;
    cin>>n;
    int ara1[n];
    int ara2[n];
    for(int h=0; h<n;h++){
        cin>>ara1[h];
    }
    for(int h=0;h<n;h++){
        cin>>ara2[h];
    }
    for(int i=0;i<n;i++){
        if(ara1[i]>ara2[i]){
            x=x+ara1[i];
            y=y+ara2[i];
        }
    }
    cout<<x-y<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	ll k;
	cin >> n >> k;
	vector<ll> a;
	a.resize(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll l = -1'000'000'000'000'000'001LL, r = 1'000'000'000'000'000'001LL, ans = -1;
	while(r - l > 1) {
		ll Mid = l + r >> 1LL;
		ll cnt = 0;
		for(int i = 0; i < n; ++i) {
			int L = i, R = n;
			while(R - L > 1) {
				int mid = L + R >> 1;
				if(a[i] * a[mid] <= Mid) {
					if(a[i] < 0) {
						R = mid;
					} else {
						L = mid;
					}
				} else {
					if(a[i] < 0) {
						L = mid;
					} else {
						R = mid;
					}
				}
			}
			if(a[i] < 0) {
				cnt += n - R;
			} else {
				cnt += L - i;
			}
		}
		if(cnt < k) {
			l = Mid;
		} else {
			r = ans = Mid;	
		}
	}
	cout << ans << '\n';
	return 0;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

vector<bool> sosuu(222221);
vector<int> used;
vector<int> four;
int n;

int main(){
  cin >> n;
  sosuu = gen_sosuu(sosuu);
  FOR(i,2,55556){
    if(used.size()==n)break;
    if(sosuu[i] && i%5==2) used.push_back(i);
  }
  REP(i,used.size()) cout << used[i] << " ";
  cout << endl;
  /*used.push_back(3);
  used.push_back(5);
  used.push_back(7);
  used.push_back(13);
  used.push_back(19);
  int cnt = used[4];
  n -= 5;
  REP(q,n){
    if(cnt >= 55555) break;
    while(true){
      cnt++;
      if(cnt >= 55555) break;
      bool flag = true;
      if(!sosuu[cnt]){
        continue;
      }
      cout << cnt << endl;
      REP(i,used.size()){
        FOR(j,i+1,used.size()){
          FOR(k,j+1,used.size()){
            FOR(l,k+1,used.size()){
              int a = used[i] + used[j] + used[k] + used[l] + cnt;
              cout << used[i] << " " << used[j] << " " << used[k] << " " <<used[l] << " " << cnt << " " << a <<endl;
              if(sosuu[a]){
                flag = false;
                break;
              }
            }
          }
        }
      }
      if(!flag) continue;
      used.push_back(cnt);
      break;
    }
  }
  REP(i,used.size()){
    cout << used[i]<< " ";
  }
  cout << endl;
  */

}


Measured memory_bytes: 256
class Dice:
    def __init__(self):
        self.eye = {}
        for k, v in zip(['top', 'front', 'right', 'left', 'back', 'bottom'], input().split()):
            self.eye[k] = int(v)


    def roll(self, dir):
        self.dir = dir
        if self.dir == 'E':
            w = self.eye['top']
            self.eye['top'] = self.eye['left']
            self.eye['left'] = self.eye['bottom']
            self.eye['bottom'] = self.eye['right']
            self.eye['right'] = w
        elif self.dir == 'S':
            w = self.eye['top']
            self.eye['top'] = self.eye['back']
            self.eye['back'] = self.eye['bottom']
            self.eye['bottom'] = self.eye['front']
            self.eye['front'] = w
        elif self.dir == 'W':
            w = self.eye['top']
            self.eye['top'] = self.eye['right']
            self.eye['right'] = self.eye['bottom']
            self.eye['bottom'] = self.eye['left']
            self.eye['left'] = w
        elif self.dir == 'N':
            w = self.eye['top']
            self.eye['top'] = self.eye['front']
            self.eye['front'] = self.eye['bottom']
            self.eye['bottom'] = self.eye['back']
            self.eye['back'] = w


dice = Dice()
for dir in input():
    dice.roll(dir)
print(dice.eye['top'])



Measured memory_bytes: 5612
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;


int main()
{
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0)
    {
        cout << "Zero" << endl;
        return 0;
    }
    if ((a > 0 && b > 0) || (b - a + 1) % 2 == 0)
    {
        cout << "Positive" << endl;
        return 0;
    }
    cout << "Negative" << endl;
    

}



















































Measured memory_bytes: 256
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


k, s = na()
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if z >= 0 and z <= k:
            ans += 1
print(ans)


Measured memory_bytes: 3444
n,x = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
a.sort()
for i in range(n):
    if x >= a[i]:
        if i == n-1:
            if a[i] == x:ans+=1
        else:
            x -= a[i]
            ans +=1
    else:break
print(ans)

Measured memory_bytes: 3060
import numpy as np
C = []
for i in range(3):
    c_horizontal = list(map(int, input().split()))
    C.append(c_horizontal)

## Ax = C
A = np.array([
    [1, 0, 0, 1, 0, 0],
    [1, 0, 0, 0, 1, 0],
    [1, 0, 0, 0, 0, 1],
    [0, 1, 0, 1, 0, 0],
    [0, 1, 0, 0, 1, 0],
    [0, 1, 0, 0, 0, 1],
    [0, 0, 1, 1, 0, 0],
    [0, 0, 1, 0, 1, 0],
    [0, 0, 1, 0, 0, 1] ])
# 拡大係数行列
Ab = np.array([
    [1, 0, 0, 1, 0, 0, C[0][0]],
    [1, 0, 0, 0, 1, 0, C[0][1]],
    [1, 0, 0, 0, 0, 1, C[0][2]],
    [0, 1, 0, 1, 0, 0, C[1][0]],
    [0, 1, 0, 0, 1, 0, C[1][1]],
    [0, 1, 0, 0, 0, 1, C[1][2]],
    [0, 0, 1, 1, 0, 0, C[2][0]],
    [0, 0, 1, 0, 1, 0, C[2][1]],
    [0, 0, 1, 0, 0, 1, C[2][2]] ])

# 係数行列と拡大係数行列のランクをそれぞれ求める
rankA = np.linalg.matrix_rank(A)
rankAb = np.linalg.matrix_rank(Ab)

if rankA == rankAb:
    print('Yes')
else:
    print('No')

# print(C)
# A = [0] * 3
# B = [0] * 3
# flgList = []
# for k in range(3):
#     flgHorizontal = [False] * 3
#     flgList.append(flgHorizontal)
# ## c(i, j) = a(i) + b(j)
# for i in range(3):
#     for a in range(101):
#         A[i] = a
#         for j in range(3):
#             B[j] = C[i][j] - A[i]
#                 if C[i][j] == A[i] + B[j]:
#                     print(C[i][j], A[i], B[j])
#                     flgList[i][j] = True
# print(flgList)
# determinantList = [False] * 3
# for m in range(3):
#     if all(flgList[m]):
#         determinantList[m] = True

# if all(determinantList):
#     print('Yes')
# else:
#     print('No')C

Measured memory_bytes: 16460
#include <iostream>
#include <string>

using namespace std;
int main()
{
    unsigned int n;
    cin>>n;
    string s;
    cin>>s;
    unsigned int k=0;
    //cout<<s.at(s.size()-1);
    for (int i=2;i<=s.size()-1;i++)
    {
        if(s.at(i)=='C')
        {
            if ((s.at(i-1)=='B') and (s.at(i-2)=='A'))
            {
                k++;
            }
        }
    }
    cout<<k;
    return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $N);
$xs = array();

$xs = explode(' ', fgets(STDIN));
$ys = $xs;
sort($ys);

$cnt = 0;
foreach(range(0,$N-1) as $i) {
    if($xs[$i] !== $ys[$i]) $cnt++;
}

echo ($cnt === 0 || $cnt === 2 ? "YES" : "NO") . "\n";

?>

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll n, k;
  cin >> n >> k;
  
  //vector<int> a(n);  rep(i, 0, n) cin >> a.at(i);
  
  cout << n -k +1 << "\n";
  
  //cout << fixed << setprecision(10) << n << "\n";

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>


int main(){
  std::string N;
  std::cin >> N;
  long sum=0;
  for(long i=0; i<N.length(); i++){
    sum+=N[i]-'0';
  }
  if(sum%9==0){
    std::cout << "Yes" << std::endl;
  }else{
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3408
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	double d1,x,ans=0.0;
	scanf("%d%lf%lf",&n,&d1,&x);
	d1-=x;
	while(n)
	{
		ans+=(d1*2+x+2*n*x)*0.5;
		d1=d1+d1/n+3*x*0.5/n;
		x=x+2*x/n;
		n--;
	}
	printf("%.15lf",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

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

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }

template <typename T> inline T read(){
    T sum = 0;
    int fl = 1,ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') fl = -1;
    for(; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
    return sum * fl;
}

const int maxn = 3000 + 5;

int book[maxn][maxn];
int dp[maxn][maxn];

string a,b;

void print(int i,int j){
	if(i == 0 || j == 0) return;
	if(book[i][j] == 0){
		print(i - 1,j - 1);
		cout << a[i - 1];
	}else if(book[i][j] == 1){
		print(i - 1,j);
	}else print(i,j - 1);
}

inline void Solve (){
	int len1 = a.size(),len2 = b.size();
	for(int i = 1; i <= len1; i++){
		for(int j = 1; j <= len2; j++){
			if(a[i - 1] == b[j - 1]){
				Chkmax(dp[i][j],dp[i - 1][j - 1] + 1);
				book[i][j] = 0;
			}else if(dp[i - 1][j] > dp[i][j - 1]){
				dp[i][j] = dp[i - 1][j];
				book[i][j] = 1;
			}else{
				dp[i][j] = dp[i][j - 1];
				book[i][j] = -1;
			}
		}
	}
	print(len1,len2);
}

inline void Input (){
	cin >> a >> b;
}

int main(){
	Input();
	Solve();
	return 0;
}

Measured memory_bytes: 70912
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    double w, h, n;
    cin >> w >> h >> n;
    double x1 = 0;
    double x2 = w;
    double y1 = 0;
    double y2 = h;

    rep(i, n)
    {
        double x, y, a;
        cin >> x >> y >> a;
        if (a == 1)
        {
            x1 = max(x1,x);
        }
        else if (a == 2)
        {
            x2 = min(x2,x);
        }
        else if (a == 3)
        {
            y1 = max(y1,y);
        }
        else
        {
            y2 = min(y2,y);
        }
    }
    if ((x2 - x1) <= 0 || (y2 - y1) <= 0){
        cout << 0 << endl;
        return 0;
    }
    cout << (x2 - x1) * (y2 - y1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100

int main(){

  int num,i,j,array[MAX],tem,count=0;

  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&array[i]);
  }

  for(i=0;i<=num-1;i++){
    for(j=num-1;j>i;j--){
      if(array[j]<array[j-1]){
	tem = array[j];
	array[j] = array[j-1];
	array[j-1] = tem;
	count++;
      }
    }
  }
  for(i=0;i<num-1;i++){
    printf("%d ",array[i]);
      }
  printf("%d\n",array[num-1]);
      

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


}

Measured memory_bytes: 2716
s = input()
t = input()

m = len(s)
n = len(t)

dp = [[None] * (n+1) for i in range(m+1)]

for i in range(m+1):
    for j in range(n+1):

        if i == 0 or j == 0:
            dp[i][j] = 0

        elif s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1

        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])



final = dp[m][n]

lcs = [""] * (final + 1)
lcs[final] = ""

i = m
j = n

while i > 0 and j > 0:
    if s[i-1] == t[j-1]:
        lcs[final-1] = s[i-1]
        i -= 1
        j -= 1
        final -= 1

    elif dp[i-1][j] > dp[i][j-1]:
        i -= 1
    else:
        j -= 1


print("".join(lcs))


Measured memory_bytes: 286884
#include <iostream>
using namespace std;
typedef long long ll;
ll n[3];
int K;
ll ans = 0;
void dfs (int i) {
    if (i == K) {
        ans = max(ans, n[0] + n[1] + n[2]);
        return ;
    }
    for (int j = 0; j < 3; j++) {
        n[j] *= 2;
        dfs(i + 1);
        n[j] /= 2;
    }
}
int main (void) {
    for (int i = 0; i < 3; i++) {
        cin >> n[i];
    }
    cin >> K;

    dfs(0);

    cout << ans << endl;

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int keta = 1;
    double temp = double(N);
    while(temp>=10){
        temp /= 10;
        keta++;
    }
    int count = 0;
    if(keta%2==1) count += N - pow(10,keta-1) + 1;
    for(int i=0;i<keta-1;i++){
        if(i%2==0){
            count += pow(10,i+1) - pow(10,i);
        }
    }
    cout << count << endl;
    return 0;
}

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

// Contest: AtCoder Beginner Contest 143 (https://atcoder.jp/contests/abc143)
// Problem: D

using namespace std;

using ll = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;

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

    int n; cin >> n;
    vector<int> l(n);
    for (auto& li : l) cin >> li;
    sort(begin(l), end(l));
    array<int, 2001> c{};
    int res = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = l[i] + 1; j <= 2000; ++j)
            res += c[j];
        for (int j = 0; j < i; ++j)
            c[l[i] + l[j]]++;
    }

    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
A,V = input().split()
B,W = input().split()
T = input()
Q = 0
try:
  Times = abs(int(A)-int(B))/(int(V)-int(W))
except:
  Times = 0
  Q = 1
if int(V)<=int(W):
  print("NO")
  Q = 1
elif int(T) >= Times:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 9180
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)
	n := N
	SN := 0
	for i := 0; i < 10; i++ {
		SN += n % 10
		n /= 10
	}
	fmt.Printf("%s\n", map[bool]string{true: "Yes", false: "No"}[N%SN == 0])
	return
}


Measured memory_bytes: 512
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static int through[];
    static int answer = 0;

    static void plusAnswer(){
        answer++;
    }

    static boolean checkToBeAbleToGo(int num){
        return through[num] == 0;
    }

    static void markPoint(boolean isThrough, int num){
        if(isThrough)
            through[num] = 1;
        else
            through[num] = 0;
    }

    static boolean isAllThroughed() {
        for(int i = 0; i < through.length; i++) {
            if(through[i] == 0)
                return false;
        }
        return true;
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        answer = 0;
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        int M = scan.nextInt();
        through = new int[N];
        Arrays.fill(through, 0);
        Tree tree[] = new Tree[N];
        for(int i = 0; i < N; i++) {
            tree[i] = new Tree();
            tree[i].children = new ArrayList<>();
        }

        for (int i = 0; i < M; i++) {
            int a = scan.nextInt() - 1;
            int b = scan.nextInt() - 1;
            tree[a].children.add(tree[b]);
            tree[a].number = a;
            tree[b].children.add(tree[a]);
            tree[b].number = b;
        }

        tree[0].checkGoNext();

        os.println(answer);
    }

}

class Tree {
    public void Tree(){}
    int number;
    List<Tree> children;

    public void checkGoNext() {
        boolean isWentNext = false;
        Main.markPoint(true, number);
        for (Tree child : children){
            if(Main.checkToBeAbleToGo(child.number)) {
                isWentNext = true;
                child.checkGoNext();
            }
        }
        if(!isWentNext) {
            if(Main.isAllThroughed())
                Main.plusAnswer();
        }
        Main.markPoint(false, number);
    }
}

Measured memory_bytes: 24020
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long 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;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

/* -- template -- */

int dp[200001];//dp[i] : iを作ることができるか？

int main() {
    int N, K; cin >> N >> K;
    ll ans = 0;
    for(ll i = K; i <= N + 1; ++i) {
        ans = (ans + i * (N - i + 1) + 1) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = vec![];
    let mut b: Vec<i64> = vec![];

    for _ in 0..n {
        let ai = read();
        a.push(ai);
    }
    for _ in 0..n {
        let ai = read();
        b.push(ai);
    }

    let mut maxv = 0;

    for i in 0..n {
        let mut ans = 0;
        for j in 0..i + 1 {
            ans += a[j];
        }

        for j in i..n {
            ans += b[j];
        }
        if ans > maxv {
            maxv = ans;
        }
    }
    println!("{}", maxv);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    sort(all(a));
    reverse(all(a));

    ll ans = a[0];

    ll cnt = 0;
    ll id = 1;

    if(n == 2){
        cout << ans << endl;
        return 0;
    }

    while(1){
        rep(i,2){
            ans += a[id];
            cnt++;
            if(cnt == n-2){
                cout << ans << endl;
                return 0;
            }
        }
        id++;
    }



}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  int n,k;
  string s;
  cin>>n>>k>>s;

  int ans=0;
  int cnt=0;
  repo(i,n){
    if(s[i]==s[i-1]) cnt++;
    else {
      ans+=cnt;
      cnt=0;
    }
  }
  ans+=cnt;

  cout << min(ans+2*k,n-1) << endl;

}

Measured memory_bytes: 512
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int i,j,h,w;
    
    while(1) {
        
        scanf("%d %d",&h,&w);
        
        if (h == 0 && w == 0) {
            break;
        }
        
        for (i = 0; i < h; i++) {
            for (j = 0; j < w; j++) {
                
                if (i%2 == 0) {
                    if (j%2 == 0) {
                        printf("#");
                    } else {
                        printf(".");
                    }
                } else {
                    if (j%2 == 0) {
                        printf(".");
                    } else {
                        printf("#");
                    }
                }
            }
            printf("\n");
        }
        
        printf("\n");
    }
    return 0;
}

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

#define ll long long
#define ar array

int h, n, a[1000], b[1000];
int dp[10001];

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

	cin >> h >> n;
	memset(dp, 0x3f, sizeof(dp));
	dp[0]=0;
	for(int i=0; i<n; ++i) {
		cin >> a[i] >> b[i];
		for(int j=0; j<h; ++j)
			dp[min(j+a[i], h)]=min(dp[min(j+a[i], h)], dp[j]+b[i]);
	}
	cout << dp[h];
    return 0;
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n ;
    cin >> n ;
    if ( (n & 1) == 0 ) {
        cout << -1 << endl;
        return 0 ;
    }
    int cur = 0 ;
    for(int i = 1; i < (int)1e7; i++){
        cur = cur * 10 ;
        cur %= n ;
        cur += 7 ; 
        cur %= n ;
        if ( cur == 0 ) {
            cout << i << endl;
            return 0 ;
        }
    }
    cout << -1 << endl;
    return 0; 
}


Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

const int64_t small = 1000000;

int f(int b, int64_t n)
{
    int ret = 0;
    while (n > 0) {
        ret += n % b;
        n /= b;
    }
    return ret;
}

int main()
{
    int64_t n, s;
    cin >> n >> s;

    for (int b = 2; b < small; b++) {
        if (s == f(b, n)) {
            cout << b << endl;
            return 0;
        }
    }

    // if (small > n) {
    //     cout << -1 << endl;
    //     return 0;
    // }

    int64_t ans = -1;
    if (n == s) ans = n + 1;

    for (int64_t msb = 1; msb * msb <= n; msb++) {
        int64_t hi_b = n / msb;
        int64_t lo_b = n / (msb + 1) + 1;

        if (hi_b < small) break;
        if (s - msb < 0) break;

        int64_t st_s = n % hi_b;
        int64_t ed_b = n % lo_b;

        // [msb + st_s, .. msb + st_s + msb, ... msb + ed_b]

        if ((s - msb - st_s) % msb == 0 &&
            (s - msb) >= st_s && (s - msb) <= ed_b) {
            // cerr << "** ok: " << hi_b - ((s - msb - st_s) / msb) << endl;
            ans = hi_b - ((s - msb - st_s) / msb);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define int long long int
#define pb push_back
#define M 1000000007
#define inf 10000000000
#define ff first
#define ss second
#define deb(x) cout< #x< " "< x< endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<=n;i++)
#define FORR(a,b,c) for(int a= b;a>=c;a--)
#define fa(arrr) for(auto x:arrr)
#define iPair pair<int, pair<int,int>>
#define sz size()
// #define mp make_pair
#define mxm3(a,b,c) max(a, max(b,c))
#define mi3(a,b,c) min(a, min(b,c))
#define mxn 500005
#define PII pair<int,int>
#define all(v) v.begin(), v.end()
#define endl "\n"
// #define N 1000
#define C 4
#define nfs ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
// Ordered Set Tree
// typedef tree<PII, null_type, less<PII>,
//         rb_tree_tag,
//         tree_order_statistics_node_update>
//         oset;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

// int fact[1005];




// int N;
// int dx[] = { -1, 0, 1, 0};
// int dy[] = {0, 1, 0, -1};
int vis[1000][1000];


// int dp[] = { -1};
// int n, k;
// int dp[1001][100005];
int dp[3003][3003];
string lcs(string s, string t, int n, int m) {

    for(int i = 0;i<=n;i++){
        for(int j = 0;j<=m;j++){
            if(i==0|| j==0) dp[i][j] = 0;
            else if(s[i-1]==t[j-1]){
                dp[i][j] = 1+ dp[i-1][j-1];
            }
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    int idx = dp[n][m];
    string ans = "";
    int i = n;
    int j = m;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            ans+=s[i-1];
            i--;
            j--;
        }
        else if(dp[i][j-1] > dp[i-1][j])
            j--;
        else i--;
    }
    reverse(all(ans));
    return ans;

}

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) dp[i][j] = -1;
    }
    // cout << lcs(s, t, n, m) << endl;
    cout << lcs(s, t, n, m) << endl;
    // string ans = "";
    // int i = n;
    // int j = m;
    // while(i>=0 && j>=0){
    //     if(s[i]==t[j]){
    //         ans+=s[i];
    //         i--;
    //         j--;
    //     }
    //     else if(dp[i-1][j] > dp[i][j-1]){
    //         i--;
    //     }
    //     else j--;
    // }
    // reverse(all(ans));
    // cout << ans << endl;
}


int32_t main()
{


    nfs;
    int t;
    // facto();
    // cin >> t;
    t = 1;
    while (t--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 71936
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
//#include <iomanip>
#include<cstring>
//#include<string>
#include<cmath>
//#include<queue>
//#include<stack>
#include<algorithm>
#define ll long long
#define eps 1e-10
#define endl "\n"
using namespace std;
void timediff(int hm,int mm,int hg,int mg,int *hd,int *md)
{
   *hd=hg-hm;
    *md=mg+(60-mm);
    if(*md>=60)
    {
        *hd++;
        *md=*md-60;
    }



}

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

        double d,t,s;

        cin>>d>>t>>s;
        if(s>=(d/t))
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }







    return 0;
}



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

int main() {
    int n;
    vector<int> x;

    cin >> n;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        x.push_back(temp);
    }

    sort(x.begin(), x.end());
    float val = (x[0] + x[1]) / 2.0f;
    x.erase(x.begin(), x.begin() + 2);

    while (x.size() != 0) {
        sort(x.begin(), x.end());
        val = (val + x[0]) / 2.0f;
        x.erase(x.begin());
    }

    cout << val << endl;

    return 0;
}



Measured memory_bytes: 256
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;

int main()
{
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

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

  // cout << s << endl;
  // cout << t << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 998244353;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}



int main(void) {

  ll x;
  cin >> x;
  cout << (x/500)*1000LL + ((x % 500) / 5)*5LL << endl;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
p,q = 0,0

if K % 2 == 1:
    for i in range(1, N+1):
        if i % K == 0:
            p += 1
else:
    for i in range(1, N+1):
        if i % K == 0:
            p += 1
        elif i % K == K // 2:
            q += 1
ans = p ** 3 + q ** 3 
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

int main()
{
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	int x = x2;
	int y = y2;

	int dx = x2 - x1;
	int dy = y2 - y1;

	for (int i = 0; i < 2; i++)
	{
		swap(dx, dy);
		dx = -dx;

		x += dx;
		y += dy;

		cout << x << " " << y << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
//
// Created by yamunaku on 2020/06/27.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    ll n, m, k;
    cin >> n >> m >> k;
    vl a(n), b(m);
    rep(i, n){
        cin >> a[i];
    }
    rep(i, m){
        cin >> b[i];
    }
    int ans = 0;
    ll sb = 0;
    int id = 0;
    rep(i, m){
        sb += b[id];
        id++;
    }
    id--;
    while(id >= 0){
        if(sb <= k) break;
        sb -= b[id];
        id--;
    }
    ans = id + 1;
    ll sa = 0;
    rep(i, n){
        sa += a[i];
        if(sa > k) break;
        while(id >= 0){
            if(sa + sb <= k) break;
            sb -= b[id];
            id--;
        }
        ans = max(ans, i + id + 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6408
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
using namespace std;

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

int main() {
	string _s = "MARCH";
	map<char, long long> mp;
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		for (size_t j = 0; j < _s.length(); ++j) {
			if (s[0] == _s[j]) {
				mp[s[0]]++;
				break;
			}
		}
	}

	long long ans = 1;
	if (mp.size() < 3) {
		cout << 0 << endl;
	}
	else if (mp.size() == 3) {
		for (auto iter = mp.begin(); iter != mp.end(); ++iter) {
			ans *= iter->second;
		}
		cout << ans << endl;
	}
	else {
		ans = 0;
		for (auto iter = mp.begin(); iter != mp.end(); ++iter) {
			auto iter2 = iter;
			for (iter2++; iter2 != mp.end(); ++iter2) {
				auto iter3 = iter2;
				for (++iter3; iter3 != mp.end(); ++iter3) {
					ans += iter->second * iter2->second * iter3->second;
				}
			}
		}

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

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

int main(){
  int N, a, b, c, d;
  cin >> N;
  a = N % 10;//1の位
  b = (N % 100) / 10;//10の位
  c = (N % 1000) / 100;//100の位
  d = N / 1000;//1000の位
  if((a == b && b == c) || (b == c && c == d)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    heights = [int(c) for c in input().split(" ")]
    dp1 = 0
    dp2 = abs(heights[1] - heights[0])
    for i in range(2, N):
        tmp = dp2
        dp2 = min(
            dp2 + abs(heights[i] - heights[i-1]),
            dp1 + abs(heights[i] - heights[i-2])
        )
        dp1 = tmp
    print(dp2)

solve()

Measured memory_bytes: 13924
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
using namespace std;
int main(){
    string x;
    cin>>x;
    stack<char> s;
    for(int i=0;i<x.length();i++){
        if(s.empty()){
            s.push(x[i]);
        }else if(x[i]=='S'){
            s.push('S');
        }else if(s.top()=='S'){
            s.pop();
        }else{
            s.push('T');
        }
    }
    cout<<s.size()<<endl;
}   

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(n)      (n).begin(), (n).end()
#define ll long long
#define ull unsigned long long int
void solve() {
    string s; cin >> s;
    int ans  = 0; 
    if(((s[0] == 'R') && (s[1] == 'R') ) || ((s[1] == 'R') && (s[2] == 'R'))){
        ans = 2;
        if(s[0]==s[2])ans=3;
    } else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R'){
        ans = 1;
    }else{
        ans = 0;
    }
    cout << ans << endl;
}
int main(){
        solve();
    return 0;
            
}

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

using namespace std;

int main()
{
    int x,a,acc=0;
    cin>>x;

    while(x > 5)
    {
        if((x/500) != 0)
        {
            a=(x/500);
            acc=acc+(a*1000);
            x=x-(500*a);
        }
        else
        {
            a=(x/5);
            acc=acc+(a*5);
            x=x-(5*a);
        }
    }

    cout<<acc;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int n, k;
    cin >> n >> k;

    int ans = k * pow(k - 1, n - 1);
    cout << ans << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=200010, inf=2e9;

int n, m;
bool ans[MX];
pii E[MX];

int U[MX];
int find(int x){
    return x==U[x] ? x : U[x]=find(U[x]);
}
void unite(int x, int y){
    U[find(y)]=find(x);
}

vector<int> G[1010], R[1010];
bool vis[1010];
void dfs1(int v, stack<int> &S){
    vis[v]=true;
    for(int x:G[v]) if(!vis[x]) dfs1(x,S);
    S.push(v);
}
void dfs2(int v){
    vis[v]=true;
    for(int x:R[v]){
        if(vis[x]) continue;
        unite(x,v); dfs2(x);
    }
}
void scc(){
    iota(U, U+n+1, 0);
    stack<int> stk;
    fill(vis, vis+n+1, false);
    for(int i=1; i<=n; i++) if(!vis[i]) dfs1(i, stk);
    fill(vis, vis+n+1, false);
    while(!stk.empty()){
        int v=stk.top(); stk.pop();
        if(vis[v]) continue;
        dfs2(v);
    }
}

vector<pii> GG[1010];
int D[1010][1010][2];

void dfs3(int v, int st, int idx){
    if(D[st][v][0]==0) D[st][v][0]=idx;
    else D[st][v][1]=idx;
    for(int x:G[v]){
        if(D[st][x][0]!=0 && D[st][x][1]!=0) continue;
        if(D[st][x][0]==idx || D[st][x][1]==idx) continue;
        dfs3(x,st,idx);
    }
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for(int i=1; i<=m; i++){
        int u,v; cin>>u>>v;
        E[i]={u,v};
        G[u].push_back(v);
        R[v].push_back(u);
        GG[u].push_back({v,i});
    }
    scc();

    for(int v=1; v<=n; v++){
        D[v][v][0]=D[v][v][1]=-1;
        for(pii &p:GG[v]){
            int x,idx; tie(x,idx)=p;
            if(D[v][x][0]!=0 && D[v][x][1]!=0) continue;
            dfs3(x,v,idx);
        }
    }

    for(int i=1; i<=m; i++){
        int u,v; tie(u,v)=E[i];
        // cout<<u<<' '<<v<<": "<<D[u][v][0]<<' '<<D[u][v][1]<<'\n';
        if(D[u][v][0]==i && D[u][v][1]==0) ans[i]=false;
        else ans[i]=true;
        // cout<<ans[i]<<", "<<(find(u)!=find(v))<<'\n';
        if(find(u)!=find(v)) ans[i]=!ans[i];
    }
    for(int i=1; i<=m; i++) cout<<(ans[i] ? "same" : "diff")<<'\n';
    return 0;
}

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

int main() {
  vector<int> num(3);
  for(int i=0;i<3;i++){
    cin >> num[i];
  }
  sort(num.begin(), num.end());
  cout << num[2]*10 + num[0] + num[1] << endl;
}


Measured memory_bytes: 256
import math
N=300000
L=[False]*(N+1)
for i in range(1,N):
    t=i%7
    if t==6 or t==1:
        L[i]=True
for i in range(2,int(math.sqrt(N))):
    if L[i]==True:
        j=2
        while i*j<=N:
            L[i*j]=False
            j+=1
L=[i for i in range(len(L)) if L[i]==True]

while True:
    n=input()
    if n==1:break
    ans=[str(i) for i in L[1:] if n%i==0]
    print "%d: %s"%(n," ".join(ans))

Measured memory_bytes: 16528