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

#define ll long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

void kekek()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef EBUCHKA
        freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
    #endif
}

const int MAXN = 2e5 + 10000;

void solve() {

}

int main() {
    kekek();
    solve();
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b});
}


Measured memory_bytes: 256
#include<iostream>
#include<cassert>
using namespace std;
#define N 8
#define FREE -1
#define NOT_FREE 1
int row[N],col[N], dpos[2*N-1],dneg[2*N-1];
bool X[N][N];
void initialize(){
  for(int i=0;i<N;i++){row[i]=FREE,col[i]=FREE; }
  for(int i=0;i<2*N-1;i++){dpos[i]=FREE;dneg[i]=FREE;}
}
void printBoard(){
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(X[i][j]){
	if(row[i]!=j) return;
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cout << ((row[i]==j)?"Q":".");
    }
    cout << endl;
  }
}
void recursive(int i){
  if(i==N){
    printBoard();return;
  }
  for(int j=0;j<N;j++){
    if(NOT_FREE == col[j] ||
       NOT_FREE == dpos[i+j] ||
       NOT_FREE == dneg[i-j+N-1])continue;
    row[i]=j; col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    recursive(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}
int main(){
  initialize();
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++) X[i][j] = false;
  int k; cin >> k;
  for(int i=0;i<k;i++){
    int r,c; cin >> r >> c;
    X[r][c] = true;
  }
  recursive(0);
  return 0;
}
    



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

int main() {
    long long int a, b, c;
    cin>>a>>b>>c;
    if(a + b < c){
        cout<<b + a + b + 1<<endl;
    } else {
        cout<<b + c <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M,a=0;
    double b=0;
    cin>>N>>M;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        b+=A[i];
    }
    double c=b/(4*M);
    for(int i=0;i<N;i++){
        if(A[i]>=c){
            a++;
        }
    }
    if(a>=M){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define ull unsigned long long

using namespace std;

int main() {
    ull N, A, B;
    cin >> N >> A >> B;

    ull patternLen = A+B;
    ull multiplier = N / (patternLen);
    ull remainder = N % (patternLen);
    cout << multiplier * A + min(remainder, A);

    return 0;
}


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

#define INX(x) (cin >> x)
#define INXV(vec, cnt) for(ll i; i < cnt; i++) INX(vec[i])
#define OUTX(x) (cout << x << endl)
#define OUTXV(vec) for(ll i; i < (ll)vec.size(); i++) OUTX(vec[i])

#define ADD emplace_back
#define MP make_pair

int main()
{
    ll N;
    cin >> N;
    ll pow10_18 = pow(10,18);


    bool isOK = true;
    bool skip = false;
    ll multi = 1;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> A[i];
        if(A[i] == 0)
        {
            multi = 0;
            skip = true;
            break;
        }
    }

    if(!skip)
    {
        for (ll i = 0; i < N; i++)
        {
            if(pow10_18 / A[i] < multi)
            {
                isOK = false;
                break;
            }
            multi *= A[i];
        }
    }

    OUTX((isOK ? multi : -1));    


    return 0;
}


Measured memory_bytes: 3996
/*
       ()       ()()()()     ()        ()       ()        ()        ()
      ()()      ()     ()    ()()      ()      ()()       ()()      ()
     ()  ()     ()      ()   ()  ()    ()     ()  ()      ()  ()    ()
    ()()()()    ()      ()   ()    ()  ()    ()()()()     ()    ()  ()
   ()      ()   ()     ()    ()      ()()   ()      ()    ()      ()()
  ()        ()  ()()()()     ()        ()  ()        ()   ()        ()

*/
#include <bits/stdc++.h>
#define MOD  (int)(1e9+7)
#define SIZE (int)(1e5+5)
#define all(x) x.begin(),x.end()
#define si(i)  scanf("%d",&i)
#define sf(f)  scanf("%f",&f)
#define pi(i)  printf("%d",i)
#define pd(d)  printf("%lf",d)
#define deb(x) cout<<#x<<" is "<<x<<"\n";
#define lb     lower_bound
#define ub     upper_bound
#define pb     push_back
#define prDouble(x) cout<<fixed<<setprecision(10)<<x;
#define IOfast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

int64_t exponentiation(int64_t base,int exp)
{
    if (exp == 0)
        return 1;

    if (exp == 1)
        return base;

    int64_t t = exponentiation(base, exp / 2);

    t = (t * t);

    if (exp % 2 == 0)
        return t;
    else
        return base * t;
}
int64_t dp[3001][3001];

int64_t solve(vector<int64_t>& arr,int start,int end)
{   
  if(start > end)
    return 0;

  if(dp[start][end] != -1)
  
    return dp[start][end];
  
  
  dp[start][end] = max( arr[start] + min( solve(arr,start+2,end ), solve(arr,start+1,end-1 )) 
                      , arr[end] + min( solve(arr,start,end-2 ), solve(arr,start+1,end-1 )) );

  return dp[start][end];  
}


int main()
{
  IOfast;
  int q=1;
  //cin>>q;
  memset(dp,-1,sizeof(dp));
  while(q--)
  {
    int n,k;
    cin>>n;
    vector<int64_t> arr(n);
    for(auto &item:arr) cin>>item;

    int64_t X = solve(arr,0,n-1); //taro started this game ;  
    int64_t sum = accumulate(all(arr),(int64_t)0);
    cout<<2*X - sum;
    //out<<"X is "<<X<<"\nY is "<<sum-X;
  }
  return 0;
}


Measured memory_bytes: 70784
#include<stdio.h>
int a,b,c,x,i,j,k,srx;
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&x);
    for(i=0;i<=a;++i)
    for(j=0;j<=b;++j)
    for(k=0;k<=c;++k)
    if(i*500+j*100+k*50==x)
    srx++;
    printf("%d\n",srx);
    return 0;
}

Measured memory_bytes: 128
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        xs: [isize; 5]
    }

    let mut r: usize = 0;
    for (i, x) in xs.iter().enumerate() {
        if *x == 0 {
            r = i
        }
    }

    println!("{}", r + 1)
}


Measured memory_bytes: 2136
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
int dc=100000;
#define MAX 100010
int p[MAX], comp[MAX], height[MAX]={};

int root(int v){
  if(comp[v]==v)return v;
  int u=root(comp[v]);
  comp[v]=u;
  return u;
}

void uf(int u,int v);

int main(){
  if(df)printf("*** debug mode ***\n");
  int n,m,i;
  scanf("%d%d",&n,&m);
  for(i=1;i<=n;i++){
    scanf("%d",&p[i]);
    comp[i]=i;
  }
  for(i=0;i<m;i++){
    int u,v;
    scanf("%d%d",&u,&v);
    uf(u,v);
  }
  int count=0;
  for(i=1;i<=n;i++){
    if(root(p[i])==root(i))count++;
  }

  printf("%d",count);
  return 0;
}

void uf(int u,int v){
  u=root(u);v=root(v);
  int w=height[u]<height[v]?u:v;
  comp[u+v-w]=comp[w];
  height[w]++;
}

/// confirm df==0 ///


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

int main(){

  int S;
  int h, m, s;

  cin >> S;

  h = S / 3600;
  m = (S % 3600) / 60;
  s = (S % 3600) % 60;

  cout << h <<":"<< m <<":"<< s << endl;

  return 0;
}

Measured memory_bytes: 3084
MOD = 10 ** 9 + 7

# MODを法とした階乗、組み合わせ
class ModCombination
  attr_reader :fac, :inv, :finv, :mod
 
  def initialize(n, mod: MOD)
    @mod = mod
    @fac = [1, 1]
    @inv = [1, 1]
    @finv = [1, 1]
 
    (2..n).each do |i|
      @fac[i] = fac[i - 1] * i % mod
      @inv[i] = mod - inv[mod % i] * (mod / i) % mod
      @finv[i] = finv[i - 1] * inv[i] % mod
    end
  end
 
  def combination(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0
 
    fac[n] * (finv[k] * finv[n - k] % mod) % mod
  end
  
  def repeated_combination(n, k)
    combination(n + k - 1, k)
  end
end

MC = ModCombination.new(300000)

n,k = gets.split.map &:to_i

# <=> 0の個数がk個以下
# 0の個数がi個の時の場合の数
# nCi : ゼロの選び方
# n - i の箱に、n個の球を配る、1以上
# <=> n - i個の箱に、n - (n-i)個の球を配る、0個以上
# n-1Hi

k = [k, n-1].min

ans = 0
0.upto(k) do |i|
  ans = (ans + MC.combination(n,i) * MC.repeated_combination(n-i, i)) % MOD 
end

puts ans

Measured memory_bytes: 9184
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=100005;

int dist[MAX_N];
vector<int> graph[MAX_N];
bool used[MAX_N];

int search(int me,int enemy){
  //自分の領地と相手との領域を探索する
  fill(used,used+MAX_N,false);
  stack<P> st;
  st.push(P(me,0));
  int cnt=0;
  while(!st.empty()){
    P p = st.top();
    int x=p.first;
    st.pop();
    if(used[x]||x==enemy||dist[x]<=p.second) continue;
    used[x]=true;
    dist[x]=p.second;
    cnt++;
    for(auto y:graph[x]) st.push(P(y,p.second+1));
  }
  return cnt;
}

int main(){
  int N;
  cin >> N ;
  fill(dist,dist+MAX_N,INF);
  rep(i,N-1){
    int a,b;
    scanf("%d%d",&a,&b);
    a--; b--;
    graph[a].pb(b);
    graph[b].pb(a);
  }
  int b,w;
  search(0,N-1);
  w=search(N-1,0); //白の領地
  b=N-w;
  //cout << b << "," << w << endl;
  if(b>w) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
  return 0;
}

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

int main() {
	int n,x,t,tem,tem1;
	cin>>n>>x>>t;
	if(n%x==0)
	{
	    cout<<(n/x)*t;
	}
	else{
	    cout<<((n/x)+1)*t;
	}
	
}


Measured memory_bytes: 3628
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    c = [0]*5
    for a in A:
        c[a%4]+=1
    if N//2<=c[0]:
        print("Yes")
        return 
    N-=c[0]*2
    print(["No","Yes"][N<=c[2]])
if __name__ == '__main__':
    main()

Measured memory_bytes: 17472
n = int(input())
dif = []
sumb = 0
for i in range(n):
    a, b = map(int, input().split())
    sumb += b
    dif.append(a+b)
dif.sort(reverse=True)
ans = -sumb
for i in range(n):
    if i%2 == 0:
        ans += dif[i]
print(ans)


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

bool has3(int x){
	while(x){
		if ( x % 10 == 3) return true;
		x /= 10;
		}
		return false;
	}

void call(int n){
	for ( int x = 1; x <= n; x++){
		if (x % 3 == 0 || has3(x) ){
			cout << " " << x;
		}
	}
	cout << endl;
}
	

int main() {
	int n;
	cin >> n ;
	call(n);
	return 0;
}

Measured memory_bytes: 3084
import qualified Data.ByteString.Char8 as C
import Data.List


r' :: IO [Int]
r'  = unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine

main :: IO ()
main = do
    [n,x] <- r'
    ls <- r'
    print $ solve x 1 0 ls

solve x ac d [] = ac
solve x ac d (l:ls)
    | d+l > x = ac
    | otherwise = solve x (ac+1) (d+l) ls

Measured memory_bytes: 380
#include<iostream>
#include<stack>
using namespace std;
static const int N = 100; 
static const int WHITE = 0;
static const int GRAY = 1; 
static const int BLACK = 2;

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

int next(int u) {
	for(int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
	    if(M[u][v]) return v;
	}
	return -1;
}

void dfs_visit(int r) {
	for(int i = 0; i < n; i++) nt[i] = 0;
	
	stack<int> S;
	S.push(r);
	color[r] = BLACK;
	d[r] = ++tt;
	
	while(!S.empty()) {
		int u = S.top();
		int v = next(u);
		if(v != -1) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   d[v] = ++tt;
			   S.push(v);	
			}
		} else {
			S.pop();
			color[u]  = BLACK;
			f[u] = ++tt;
		}
	}
}


void dfs() {
	for(int i = 0; i < n; i++){
		color[i] = WHITE; nt[i] = 0;
	}
	tt = 0; 
	
	for(int j = 0; j < n; j++) {
		if(color[j] == WHITE) {
			dfs_visit(j);
		}
	}
	
	for(int i =0; i < n; i++ ) {
    	cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
}


int main() {
	int u, k,v;
	cin >> n;
	for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
      	M[i][j] = 0;
      }	
	}
	for(int i = 0; i < n; i++) {
	    cin >> u >> k ;
	    u--;
	    for(int i = 0; i < k; i++ ) {
	       cin >> v;
	       v--;
	       M[u][v] = 1;	
	    }		
	}
	
	
	dfs();
	
	return 0;
}  

Measured memory_bytes: 3112
object Main {
  def main(args: Array[String]) {
    val input = io.Source.stdin.getLines().mkString("\n");
    println(solve(input).trim());

  }

  def solve(input: String): String = {
    Stream.iterate(input.split("\n")(1).split(" ").map(_.toInt))(_.map(_/2)).takeWhile(_.forall(_%2==0)).size.toString
  }
}

Measured memory_bytes: 27220
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] arr = new long[n];
    long[] arr1 = new long[n];
    for(int i=0;i<n;i++){
      arr[i]=sc.nextLong();
      arr1[i]=arr[i];
    }
    Arrays.sort(arr1);
    int flag=0;
    for(int i=0;i<n;i++){
      if(Math.abs(arr[i]-arr1[i])>1){
        flag=1;
        break;
      }
    }
    if(flag==1){
      System.out.println("No");
    }
    else{
      System.out.println("Yes");
    }
   
  }
}

Measured memory_bytes: 51052
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(string S, long long w){
  for (int i = 0; i < S.size(); i+=w) {
    std::cout << S[i];
  }
  std::cout << std::endl;
}

int main(){
  long long w;
  string S;
  cin >> S;
  scanf("%lld",&w);
  solve(S, w);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a,b,x,y;
int main()
{
    cin>>a>>b;
    for (int i=1;i<=999;i++)
    {
        x+=i;
        y=x+(i+1);
        if ((x-a)==(y-b))
        {
            cout<<x-a;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
f_i = stdin

A, B = map(int, f_i.readline().split())

def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

G = gcd(A, B)
L = (A // G) * (B // G) * G
print(L)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // Atcoder
    // template: cpp
    ll n, m;
    cin >> n >> m;

    cout << pow(2, m) * (1900 * m + 100 * (n - m));
}


Measured memory_bytes: 256
import itertools
n=int(input())
s=[input() for i in range(n)]
cnt=[0]*5
for t in s:
  if t[0]=='M':
    cnt[0]+=1
  elif t[0]=='A':
    cnt[1]+=1
  elif t[0]=='R':
    cnt[2]+=1
  elif t[0]=='C':
    cnt[3]+=1
  elif t[0]=='H':
    cnt[4]+=1
ans=0
for v in itertools.combinations([0,1,2,3,4],3):
  ans+=cnt[v[0]]*cnt[v[1]]*cnt[v[2]]
print(ans)

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

struct Dice {
  int s1, s2, s3, s4, s5, s6;
  int turnN() {
    int tmp = s1;
    s1 = s2; s2 = s6; s6 = s5; s5 = tmp;
  }
  int turnS() {
    int tmp = s1;
    s1 = s5; s5 = s6; s6 = s2; s2 = tmp;
  }
  int turnW() {
    int tmp = s1;
    s1 = s3; s3 = s6; s6 = s4; s4 = tmp;
  }
  int turnE() {
    int tmp = s1;
    s1 = s4; s4 = s6; s6 = s3; s3 = tmp;
  }
};

int main() {
  
  int S1, S2, S3, S4, S5, S6; cin >> S1 >> S2 >> S3 >> S4 >> S5 >> S6;
  
  Dice d = {S1, S2, S3, S4, S5, S6};
  
  string S; cin >> S;
  
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'N') d.turnN();
    if (S.at(i) == 'S') d.turnS();
    if (S.at(i) == 'W') d.turnW();
    if (S.at(i) == 'E') d.turnE();
  }
  
  cout << d.s1 << endl;
  
}


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

using namespace std;

int main(){
    int n;
    cin >>n;
    int ans=n;
    string s;
    cin >> s;

    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            ans=ans-1;
        }
    }
    cout << ans<<endl;
}

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, L: "List[int]"):
    L.sort()
    if L[-1] < sum(L[:-1]):
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


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

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;

int main() {
    cin >> n;
    if (n == 1) {
        cout << "Hello World" << endl;
    } else {
        cin >> m >> k;
        cout << m + k << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int cost = 0;
    for(int i = 0; i < K; i++){
        cost += a[i];
    }
    cout << cost << endl;
    return 0;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
list<int>ls;
void print()
{
    list<int>::iterator it;
    for(it = ls.begin();it!=ls.end();it++)
        printf("%d\n",*it);
}
int main()
{
    int q,a,b;
    list<int>::iterator it,it2;
    it = ls.begin();
    scanf("%d",&q);
    while(q--)
    {
        scanf("%d",&a);
        if(a==0)
        {
            scanf("%d",&b);
            it = ls.insert(it,b);
        }
        else if(a==1)
        {
            int i;
            scanf("%d",&b);
            if(b>0)
                for(i=0;i<b;i++,it++);
            else for(i=0;i<-b;i++,it--);
        }
        else it = ls.erase(it);
    }
    print();
    return 0;
}



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

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

using namespace std;

int main(){
	int n; cin>>n;
	int hist[100002]={};
	rep(i,n){
		int a; cin>>a; a++;
		hist[a]++;
	}

	int ans=0;
	for(int a=1;a<=100000;a++){
		ans=max(ans,hist[a]+hist[a-1]+hist[a+1]);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
using namespace std;

#define LL long long int
#define uLL unsigned long long int

#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SLL(a) scanf("%lld",&a)
#define SLL2(a,b) scanf("%lld%lld",&a,&b)
#define SLL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define SC(a) scanf("%c",&a)
#define P(a) printf("%d",a)
#define PS(a) printf("%s",a)
#define PLL(a) printf("%lld",a)
#define PCASE(kk) printf("Case %d: ",kk++)
#define PCASENL(kk) printf("Case %d:\n",kk++)
#define NL puts("")

#define pb push_back
#define mp(a,b) make_pair(a,b)
#define pi (2.0*acos(0.0))
#define pii pair<int,int>

template<typename T>inline T POW(T B,T P)
{
    if(P==0) return 1;
    if(P&1) return B*POW(B,P-1);
    else return SQR(POW(B,P/2));
}
template <typename T>inline T ModInv (T b,T m)
{
    return BigMod(b,m-2,m);
}
template<typename T>inline T ABS(T a)
{
    if(a<0)return -a;
    else return a;
}
template<typename T>inline T gcd(T a,T b)
{
    if(a<0)return gcd(-a,b);
    if(b<0)return gcd(a,-b);
    return (b==0)?a:gcd(b,a%b);
}
template<typename T>inline T lcm(T a,T b)
{
    if(a<0)return lcm(-a,b);
    if(b<0)return lcm(a,-b);
    return a*(b/gcd(a,b));
}
template <class T> inline T BMOD(T p,T e,T m)
{
    T ret=1;
    while(e)
    {
        if(e&1) ret=(ret*p)%m;
        p=(p*p)%m;
        e>>=1;
    }
    return (T)ret;
}

//for(__typeof(pp.begin()) i=pp.begin(); i!=pp.end(); i++ )

//knight and king move....



//int Dx[]={-2,-1,1,2,1,2,-2,-1};
//int Dy[]={-1,-2,2,1,-2,-1,1,2};
//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
//////////////////////////////////////////////////

int main()
{
    LL n,x;
    SLL2(n,x);

    LL ds=(n-(2*x));

    if(ds==0)
    {
        PLL((x*3LL)),NL;
    }
    else if(ds>0)
    {
        LL ans;

        ans=3LL*x+(n-x);
        LL l=x,w=ds;
        if(l<w)swap(l,w);
        while(1)
        {
            if(l%w==0)
            {
                ans+=((2LL*(l/w))-1)*w;
                break;
            }
            ans+=(2LL*(l/w))*w;
//            l=l-((2LL*(l/w))*w);
            l%=w;
            if(l==0)break;
            if(l<w)swap(l,w);

        }
        PLL(ans),NL;
    }
    else
    {
        ds=n-x;
        LL ans=x+ds;
        LL l=x,w=ds;
        if(l<w)swap(l,w);
        while(1)
        {
            if(l%w==0)
            {
                ans+=((2LL*(l/w))-1)*w;
                break;
            }
            ans+=(2LL*(l/w))*w;
//            l=l-((2LL*(l/w))*w);
            l%=w;
            if(l==0)break;
            if(l<w)swap(l,w);

        }
        PLL(ans),NL;
    }



    return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    string S; cin >> S;

    int ans = 0;
    for(int i = 1; i < N-1; i++)
    {
        string X = S.substr(0, i);
        string Y = S.substr(i, N);
        int countX = 0, countY = 0;
        REP(i, X.length()) countX |= 1 << X[i]-'a';
        REP(i, Y.length()) countY |= 1 << Y[i]-'a';
        ans = max(ans, (int)bitset<32>(countX & countY).count());
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

#define MMAX 101
const int INF=1<<10;

int gtime[MMAX+1][MMAX+1];
int gcost[MMAX+1][MMAX+1];

int n,m;
int p,q,r;

struct node{
	int st;//
	int cost;//
}typedef Node;

bool operator < (const Node n1,const Node n2){
	return n1.cost > n2.cost;
}
bool visited[MMAX];
int dijkstra(){
	fill(visited,visited+MMAX,false);
	priority_queue<Node> pq;
	Node start={p,0};
	pq.push(start);
	while(!pq.empty()){
		Node cur=pq.top();pq.pop();
		if(cur.st==q)return cur.cost;
		if(visited[cur.st])continue;
		visited[cur.st]=true;
		for(int i=1;i<=m;i++){
			if(cur.st==i||gtime[cur.st][i]==INF||gcost[cur.st][i]==INF)continue;
			if(visited[i])continue;
			if(r==1){
				Node add={i,cur.cost+gtime[cur.st][i]};
				pq.push(add);
			}
			else {//
				Node add={i,cur.cost+gcost[cur.st][i]};
				pq.push(add);
			}
		}
	}
}
void solve(){
	cout<<dijkstra()<<endl;
}
int main(){
	int a,b,cost,time,k;
	while(cin>>n>>m,(n||m)){
		for(int i=0;i<MMAX;i++){
			fill(gtime[i],gtime[i]+MMAX,INF);
			fill(gcost[i],gcost[i]+MMAX,INF);
		}
		for(int i=0;i<n;i++){
			cin>>a>>b>>cost>>time;
			if(gtime[a][b]>time)gtime[a][b]=gtime[b][a]=time;
			if(gcost[a][b]>cost)gcost[a][b]=gcost[b][a]=cost;
		}
		cin>>k;
		for(int i=0;i<k;i++){
			cin>>p>>q>>r;
			solve();
		}		
	}
	return 0;
}

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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_V = int(1e3) + 3;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    string s;
    cin >> s;
    bool C = false;
    if(s[0]=='A'){
        for(int i = 1;i<s.size();i++){
            if(s[i]<='Z'){
                if(i>1 && i<s.size()-1){
                    if(s[i]=='C' && !C){
                        C = true;
                        continue;
                    }
                }
                cout << "WA" << endl;
                return 0;
            }
        }
    }
    if(C)cout << "AC" << endl;
    else cout << "WA" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    VI b(a);
    sort(ALL(b));
    REP(i,n){
        if (a[i] == b[n - 1]) cout << b[n - 2] << endl;
        else cout << b[n - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,x,y;
main()
{
	cin>>n>>m>>x>>y;
	for(int i=0;i<n;i++)
	{
		int a;cin>>a;
		x=max(x,a);
	}
	for(int i=0;i<m;i++)
	{
		int a;cin>>a;
		y=min(y,a);
	}
	cout<<(x<y?"No ":"")<<"War"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iomanip>

#define N 7
#define INV (-1)

#define UP 0
#define RIGHT 1
#define DOWN 2
#define LEFT 3
#define DIRMAX 4

#define NA 21

using namespace std;

struct State
{
  int map[N][N];
  State(){
    //fill(&map[0][0],&map[N-1][N-1],-1);
  }
  State(int tmap[][N]){
    for(int i = 0; i < N; ++i){
      for(int j = 0; j < N; ++j){
	map[i][j] = tmap[i][j];
      }
    }
  }
  bool move(int which, int dir){
    // which = 0, upper,left
    // which != 0, bottom,right
    for(int i = (which==0?0:N-2); which==0?(i<N-1):(i>=1); which==0?++i:--i){
      for(int j = (which==0?0:N-2); which==0?(j<N-1):(j>=1); which==0?++j:--j){
	if( map[i][j] == 0 ){
	  switch(dir){
	  case UP:   if( map[i-1][j] > 0 ){swap( map[i][j], map[i-1][j] );return true;}break;
	  case RIGHT:if( map[i][j+1] > 0 ){swap( map[i][j], map[i][j+1] );return true;}break;
	  case DOWN: if( map[i+1][j] > 0 ){swap( map[i][j], map[i+1][j] );return true;}break;
	  case LEFT: if( map[i][j-1] > 0 ){swap( map[i][j], map[i][j-1] );return true;}break;
	  }
	  return false;
	}
      }
    }
  }
  int getHeuristic()const{
    static const int ti[] = {0,2,2,2,3,3,3,3,3,4,4,4};
    static const int tj[] = {0,2,3,4,1,2,3,4,5,2,3,4};
    int ret = 0;
    int max1=0,max2=0;
    for(int i = 1; i < N-1; ++i){
      for(int j = 1; j < N-1; ++j){
	if( map[i][j] > 0 ){
	  int x = abs(i-ti[map[i][j]] )+ abs(j-tj[map[i][j]]);
	  ret += x;
	  if( max1 < x ){
	    max2 = max1;
	    max1 = x;
	  }
	}
      }
    }
    return ret;
  }
  bool isComplete()const{
    static const int ti[] = {0,2,2,2,3,3,3,3,3,4,4,4};
    static const int tj[] = {0,2,3,4,1,2,3,4,5,2,3,4};
    if( map[1][3] == 0 && map[5][3] == 0 ){
      for(int i = 1; i < N - 1; ++i){
	for(int j = 1; j < N - 1; ++j){
	  if( map[i][j] > 0 ){
	    if( ti[map[i][j]] != i || tj[map[i][j]] != j ){
	      return false;
	    }
	  }
	}
      }
      return true;
    }
    return false;
  }
};

int IterativeDeepning(int depth, const State &now, int &ans)
{

  if( now.isComplete() ){
    ans = min( ans , depth );
    return ans;
  }
  int least = depth + now.getHeuristic();
  if( least >= NA ){
    return NA;
  }
  if( least >= ans ){
    return ans;
  }
  // ans = min( ans, least );
  for(int w = 0; w < 2; ++w){
    for(int dir = 0; dir < DIRMAX; ++dir){
      State next = now;
      if( next.move( w, dir ) ){
	ans = min( ans, IterativeDeepning( depth + 1, next, ans ) );
      }
    }
  }
  return NA;
}

int main()
{
  while(true){
    int map[N][N];
    int ans;
    fill(&map[0][0],&map[N-1][N],-1);
    
    const int imax[] = {1,3,5,3,1};
    const int dj[] = {2,1,0,1,2};
    for(int i = 0; i < 5; ++i){
      for(int j = 0; j < imax[i]; ++j){
	int t;
	cin >> t;
	if( t < 0 ) return 0;
	map[i+1][j+dj[i]+1]=t;
      }
    }

    /*
    for(int i = 0; i < N; ++i){
      for(int j = 0; j < N; ++j){
	cout << setw(3) << map[i][j] << ' ';
      }
      cout << endl;
    }
    cout << endl;
    */

    ans = NA;
    IterativeDeepning( 0, State(map), ans );
    if( ans >= NA ){
      cout << "NA" << endl;
    }else{
      cout << ans << endl;
    }
      
  }
  return 0;
}

Measured memory_bytes: 872
s = [*gets.chars] # 文字列 s
s1, s2 = [], [] # \の位置の配列 s1, 一番左の\の位置、各水たまりの個数と面積 s2
a = 0  # 水たまりの総面積 a

#文字列の数だけ繰り返す, 一文字(c), 繰り返し番号=文字列番号(i),
s.each.with_index do |c, i|
 
  if c == "\\"
    s1 << i # \が何文字目かを配列に入れる

  elsif c == '/' && !s1.empty? # \の位置の配列 s1 が空でなければ

    last_s1 = s1.pop # \の位置の配列の最後を一つ取り出す
    row_area = i - last_s1 # 現在の文字位置(i) - \の位置の配列の最後の要素 (行の面積)
    a += row_area # 総面積に追加

    # 一番左の\の位置と面積 s2 の要素が存在し、かつ、取り出した\の位置が、一番左の\の位置より小さい場合に繰り返す
    while s2.size != 0 && s2[-1][0] > last_s1
      row_area += s2[-1][1] 
      s2.pop
    end

    s2 << [last_s1, row_area]
  end
end

puts a
print s2.size
print " #{s2.map{|a,b|b}.join(" ")}" if s2.size > 0
print "\n"


Measured memory_bytes: 8900
function Main(input: string) {
    let splited = input.split('\n');
    let N = parseInt(splited[0]);
    let S = splited[1].split(' ')[0].split('');
    let T = splited[1].split(' ')[1].split('');

    let ans = '';

    for (let i = 0; i < N; i++) {
        ans += S[i] + T[i];
    }
    console.log(ans);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
  int v, e;
  cin >> v >> e;
  vector<int> g[v], in[v];
  vector<int> h(v,0);
  rep(i,v-1+e){
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    in[b].push_back(a);
    h[b]++;
  }
  
  queue<int> que;
  rep(i,v) if(h[i] == 0) que.push(i);
  
  vector<int> ans;
  vector<int> num(v,-1);
  while(!que.empty()) {
    int p = que.front(); que.pop();
    ans.push_back(p);
    for(auto i : g[p]) {
      h[i]--;
      if(h[i] == 0) que.push(i);
    }
  }
  rep(i,v) num[ans[i]] = i;
  vector<int> a(v,-1);
  rep(i,v) {
    int p = -1, pos = -1;
    for(auto j : in[i]) {
      if(num[j] > pos) {
        p = j;
        pos = num[j];
      }
    }
    if(p == -1) a[i] = 0;
    else a[i] = p + 1;
  }
  for(auto i : a) cout << i << endl;
  return 0;
}

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

const int maxn = 100 + 5;
const int maxm = 10000 + 5;

int v[maxn],w[maxn];
//int f[maxn][maxm];
int f[maxm];

int main()
{
    int N,W;
    scanf("%d%d",&N,&W);
    for(int i = 1;i <= N; i++)scanf("%d%d",&v[i],&w[i]);
    //二?
    /*for(int i = 1;i <= N; i++)
    {
        for(int j = 0;j <= W; j++)
        {
            if(j >= w[i])f[i][j] = max(f[i-1][j],f[i-1][j-w[i]] + v[i]);
            else f[i][j] = f[i-1][j];
        }
    }
    printf("%d\n",f[N][W]);*/
    //一?
    for(int i = 1;i <= N; i++)
    {
        for(int j = W;j >= w[i]; j--)
        {
            f[j] = max(f[j],f[j-w[i]] + v[i]);
        }
    }
    printf("%d\n",f[W]);
}

Measured memory_bytes: 3264
N = int(input())
A = list(map(int,input().split()))
L = []
H = []

for i in range(N):
  a = A[i]//400
  if a > 7:
    H.append(a)
  else:
    L.append(a)

if len(L) != 0:
  print(str(len(set(L)))+" "+str(len(set(L))+len(H)))
else:
  print("1 "+str(len(H)))

Measured memory_bytes: 8928
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N;
  cin >> N;

  while (N > 0) {
    int d = N % 10;
    if (d == 7) {
      cout << "Yes\n";
      return 0;
    }
    N /= 10;
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<ll> a(n+1),sum(n+1,0);
  map<ll,ll> cnt;
  cnt[0]++;
  FOR(i,1,n+1){
    cin>>a[i];
    sum[i]=sum[i-1]+a[i];
    cnt[sum[i]%m]++;
  }
  ll ans=0;
  for(auto itr:cnt){
    //cout<<itr.fi<<' '<<itr.se<<endl;
    ans+=itr.se*(itr.se-1)/2;
  }
  cout<<ans<<endl;
}

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

#define int int64_t
#define rep(i,a,n) for(int i=(a); i<(n); ++i)
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define re(s) reverse((s).begin(),(s).end())
#define ll long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3fLL;
const int mod = 1000000007;
using namespace std;

int a[100010];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,cnt=0;
    cin>>n;
    int x;

    rep(i,0,n){
        cin>>x;
        ++x;
        ++a[x];
        ++a[x-1];
        ++a[x+1];
        cnt = max(cnt,max(a[x],max(a[x+1],a[x-1])));
    }
    cout<<cnt<<'\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=long long;

int main() {
  int N,K; cin >>N >>K;
  int ans=0;
  if (K!=1) {
    ans=N-K;
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <map>
#include <string>

int main() {
  int N, M;
  std::cin >> N;

  std::map<std::string, int> m;

  for (int i = 0; i < N; i++) {
    std::string s;
    std::cin >> s;

    m[s]++;
  }

  std::cin >> M;

  for (int i = 0; i < M; i++) {
    std::string s;
    std::cin >> s;

    m[s]--;
  }

  int answer = 0;

  for (auto p : m) {
    answer = std::max(answer, p.second);
  }

  std::cout << answer << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int solve(int n){
	int cnt = 0;
	for(int i=1;i<n;i++){//足す数は1~ n-1。本当はn-1とか足しても無駄ｗ
		if(i+(i+1)>n){//2つ連続で足したらもうnを超える
			break;
		}
		int sum = 0;
		for(int j=0;j<n;j++){//繰り返し回数ｎはどうでもいい
			sum += i+j;
			if(sum == n){
				cnt ++;
				break;
			}else if(sum >n){
				break;
			}
		}
	}
	return cnt;
}

int main(){
	while(true){
		int n;
		cin >> n;
		if(n==0){
			break;
		}
		int result = solve(n);
		cout << result << endl;
	}
	return 0;
}
/*
等差数列の和は
項数*(初項+末項)/2
*/

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vector<double> s(n+1);
  rep(i,n){
    ll p; cin>>p;
    s[i+1]=1.0*(1+p)*p/2/p+s[i];
  }
  
  double ans=0;
  rep(i,n-k+1){
    chmax(ans, s[i+k]-s[i]);
  }
  cout<<std::setprecision(10)<<ans<<endl;
}

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

int main() {
    int N, W;
    cin>>N>>W;
    int value[100];
    int weight[100];
    for (int i = 0; i < N; ++i) {
        cin>>value[i]>>weight[i];
    }
    int dp[101][10001] = {0};

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= W; ++j) {
            if (j-weight[i] >= 0)  {
                dp[i + 1][j] = max(dp[i+1][j-weight[i]] + value[i], dp[i][j]);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    cout<<dp[N][W]<<endl;

}


Measured memory_bytes: 7052
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();

int main() {
  char s[100001];
  scanf("%s", s);
  string str = string(s);

  bool inved = false;
  string prefix = "";
  string suffix = "";

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

  int cmd;
  int f;
  char c[2];
  REP(i, q) {
    scanf("%d", &cmd);
    if (cmd == 1) {
      inved = !inved;
    } else {
      scanf("%d", &f);
      scanf("%s", c);
      if (!inved) {
        if (f == 1) {
          prefix = string(c) + prefix;
        } else {
          suffix = suffix + string(c);
        }
      } else {
        if (f == 2) {
          prefix = string(c) + prefix;
        } else {
          suffix = suffix + string(c);
        }
      }
    }
  }

  str = prefix + str + suffix;
  if (inved) {
    reverse(ALL(str));
  }

  printf("%s\n", str.c_str());
  return 0;
}


Measured memory_bytes: 1468
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int N; cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) scanf("%lld", &A[i]);
  sorti(A);

  ll res = A[N-1] - A[0];
  for (int i = 0, j = N-2; i + 1 < j; ++i, --j) res += A[j] - A[i];
  for (int i = 1, j = N-1; i + 1 < j; ++i, --j) res += A[j] - A[i];
  if (N&1) res += max(A[N/2 + 1] - A[N/2], A[N/2] - A[N/2-1]);
  printf("%lld", res);
}


Measured memory_bytes: 1024
function Main(input){
var N = input.split("\n")[0];
var a = input.split("\n")[1].split(" ");
var as = a.sort();
var dev = parseInt(as[(N-1)],10) - parseInt(as[0],10);
console.log(dev)
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
int inf = 1e9+7;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i,0,n){ cin >> a[i]; b[i] = a[i]; }
    int cnt=0;
    bool up;
    int ok = 0;
    int i = 0;
    bool hantei=true;
    for(i;i<n-1;i++){
        ok=0;
        while(ok==0 && i<n-1){
            if(a[i]<a[i+1]){up=true;ok++;i++;}
            else if(a[i]>a[i+1]){up=false;ok++;i++;}
            else i++;
        }
        hantei=false;
        while(!hantei){
        if(i==n-1) break;
        if(a[i]<a[i+1] && up==false){ hantei=true;up=true;cnt++;/*cout << i << endl;*/}
        else if(a[i]>a[i+1] && up==true){ hantei=true;up=false;cnt++;/*cout << i << endl;*/}
        else i++;
        }
    }
    cout << cnt+1 << endl;
}

Measured memory_bytes: 1024
n,a,b=gets.split.map(&:to_i)
m=1000000007
f=[1]
1000000.times do |i|
  f << f[-1]*(i+1)%m
end
def mi(a,m)
  b,u,v=m,1,0
  while b>0
    t=a/b
    a-=t*b
    u-=t*v
    a,b,u,v=b,a,v,u
  end
  u%=m
  u+=m if u<0
  return u
end
nca=1
i=n
a.times do
  nca=nca*i%m
  i-=1
end
nca=nca*mi(f[a],m)%m
ncb=1
i=n
b.times do
  ncb=ncb*i%m
  i-=1
end
ncb=ncb*mi(f[b],m)%m
nl=[2]
30.times do
  nl << nl[-1]**2%m
end
i=0
nn=1
while n>0
  if n.odd?
    nn=nn*nl[i]%m
  end
  n/=2
  i+=1
end
puts (nn-1-nca-ncb)%m


Measured memory_bytes: 22344
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-04-29 16:57
# @url:https://atcoder.jp/contests/abc162/tasks/abc162_d
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n=int(input())
    s=input()
    r=s.count('R')
    g=s.count('G')
    b=s.count('B')
    ans=r*g*b

    for i in range(n-2):
        for j in range(i+1 , n-1):
            k=2*j-i
            if k <= n-1:
                if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                    ans-=1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 69860
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int F[110][12];
int P[110][13];
int main() {
  ll N;
  cin >> N;
  REP(i, N) {
    REP(j, 10) { cin >> F[i][j]; }
  }
  REP(i, N) REP(j, 11) { cin >> P[i][j]; }
  ll ans = -1e15;
  for (int bit = 1; bit < (1 << 10); bit++) {
    ll tmp = 0;
    vector<ll> A(N, 0);
    REP(i, 10) {
      ll tk = (1 << i);
      tk &= bit;
      if (tk == 0) continue;
      REP(j, N) {
        if (F[j][i] == 1) A[j]++;
      }
    }
    REP(i, N) { tmp += P[i][A[i]]; }
    ans = max(tmp, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
def card_list()
  cards=[]
  STDIN.gets.to_i.times do |i|
    cards.push STDIN.gets.chomp
  end
  cards
end

blue_cards=card_list
red_cards=card_list

result=blue_cards.uniq.map{|i| blue_cards.count{|j| j == i} - red_cards.count{|j| j ==i}}.max
if result > 0
  puts result
else
  puts 0
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)

using LL = long long;
const int maxn = 100100;
const LL mod = 1e9+7;
char s[maxn];
int n;
LL f[maxn][4];
bool vis[maxn][4];
LL dfs(int i, int cnt) {
  if(i == n) {
    return cnt == 3;
  }
  if(f[i][cnt] != -1) return f[i][cnt];
  LL a = 0, b = 0, ret = 0;
  if(s[i] == '?') {
    if(cnt < 3) {
      a = dfs(i+1, cnt+1);
    }
    b = 3LL * dfs(i+1, cnt) % mod;
  }
  else {
    if(cnt < 3 && s[i] == 'A' + cnt) {
      a = dfs(i+1, cnt+1);
    }
    b = dfs(i+1, cnt);
  }
  return f[i][cnt] = (a + b) % mod;
}

signed main() {
  // freopen("in", "r", stdin);
  while(~scanf("%s",s)) {
    n = strlen(s);
    memset(f, -1, sizeof(f));
    printf("%lld\n", dfs(0, 0));
  }
  return 0;
}


Measured memory_bytes: 8192