akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using namespace std;

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    ll ans = 0;

    map<int, ll> cnt;
    rep(i, N) {
        ans += cnt[i - A[i]];
        cnt[A[i] + i]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 26576
# coding: utf-8
def getLnInputs():
    return input().split()


def getLnIntInputs():
    return list(map(int, getLnInputs()))


def is_next_sheep(isCurrentSheep, response, isPreviousSheep):
    isNextSame = not (isCurrentSheep ^ response)
    return not (isNextSame ^ isPreviousSheep)


def resolve_hypothesis(firstIsSheep, lastIsSheep, responseArray):
    res_str = "S" if firstIsSheep else "W"

    isCurrentSheep = firstIsSheep
    isPreviousSheep = lastIsSheep

    for i in range(len(responseArray) - 1):
        isNextSheep = is_next_sheep(isCurrentSheep, responseArray[i], isPreviousSheep)
        res_str += "S" if isNextSheep else "W"
        isCurrentSheep, isPreviousSheep = isNextSheep, isCurrentSheep

    if isCurrentSheep != lastIsSheep or is_next_sheep(isCurrentSheep, responseArray[-1], isPreviousSheep) != firstIsSheep:
        return -1

    return res_str


def main():
    input()
    s = input()

    responseArray = list(map(lambda c: c == "o", list(s)))

    for i in range(2):
        for j in range(2):
            firstIsSheep = bool(i)
            lastIsSheep = bool(j)
            res = resolve_hypothesis(firstIsSheep, lastIsSheep, responseArray)

            if res == -1:
                continue

            print(res)
            return

    print(-1)
    return


main()


Measured memory_bytes: 4852
require "pp"
def rifuru(cards)
  c = []
  n = cards.size
  n.times do |i|
    c << cards[(n / 2) * (i % 2) + i / 2]
  end
  c
end

def cut(cards, k)
  n = cards.size
  top = cards.slice(0, k)
  buttom = cards.slice(k, n - k)
  c = []
  buttom.each { |num| c << num }
  top.each { |num| c << num }
  c
end

n = STDIN.readline.chomp.to_i
m = STDIN.readline.chomp.to_i

cards = (1..(2*n)).to_a

m.times do
  k = STDIN.readline.chomp.to_i
  if k == 0
    cards = rifuru(cards) 
  else
    cards = cut(cards, k)
  end
end

cards.each do |num|
  puts num
end

Measured memory_bytes: 8252
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  ll a, b, x; cin >> a >> b >> x;
  ll result = b/x - a/x; if (a%x==0) result++;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 768
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
s = input()
print(s[::2])


Measured memory_bytes: 10140
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }

int main(){
    int r;
    cin >> r;
    double ans;
    ans = r*2*3.1415926535;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3776
N=input()
A=map(int,input().split())
B=map(int,input().split());B=list(B)
C=map(int,input().split());C=list(C)
ans=0; temp=30

for i in A:
    ans+=B[i-1]
    if i-1==temp:
        ans+=C[i-2]
    temp=i
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int sx,sy,tx,ty;

struct threeElements{
int _1st,_2nd,_3rd;
};
vector<vector<int>>adj(10);
int sum,n,m,visited[11];
void dfs(int i){
    visited[i]=1;
    int flag=1;
    for(int j=1;j<=n;++j){
        if(!visited[j]){
            flag=0;
        }
    }
    if(flag){
        sum++;
        return;
    }
    for(auto x:adj[i]){
        if(!visited[x]){
            dfs(x);
            visited[x]=0;
        }
    }
}
int main()
{
   // freopen ("jumping.in","r",stdin);
   _IOS();
   //18:17
   int n;
   cin>>n;
   ll ans=1;
   for(int i=1;i<=n;i++)
   {
       ans*=i;
       ans%=mod;
   }
   cout<<ans;

}


Measured memory_bytes: 3576
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

static const long long MOD = ((1e9) + 7);

static vector<long long> xs;
static vector<long long> ys;

int32_t main()
{
  uint32_t n, m;
  cin >> n >> m;

  xs.push_back(0);
  for (uint32_t i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    xs.push_back(x);
  }

  ys.push_back(0);
  for (uint32_t i = 1; i <= m; i++) {
    long long y;
    cin >> y;
    ys.push_back(y);
  }

  long long sum_x = 0;
  for (uint32_t k = 1; k <= n; k++) {
    sum_x += (k - 1) * xs[k] - (n - k) * xs[k];
    sum_x = (sum_x + MOD) % MOD;
  }

  long long sum_y = 0;
  for (uint32_t k = 1; k <= m; k++) {
    sum_y += (k - 1) * ys[k] - (m - k) * ys[k];
    sum_y = (sum_y + MOD) % MOD;
  }

  long long ans = (sum_x * sum_y) % MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2548
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());

		List<String> s = new ArrayList<String>();

		for(int i = 0;i<N;i++){
			s.add(br.readLine());
		}

		int M = Integer.parseInt(br.readLine());

		ArrayList<String> t = new ArrayList<String>();

		for(int i = 0;i<M;i++){
			t.add(br.readLine());
		}
		s.sort(null);
		t.sort(null);
		ArrayList<String> seen = new ArrayList<String>();
		int sum = 0;
		for(int i= 0;i<s.size();i++){
			if(!seen.contains(s.get(i))){
				seen.add(s.get(i));
				int point = 0;
				for(int p = 0;p<s.size();p++){
					if(s.get(i).equals(s.get(p))){
						point++;
					}
				}
				for(int m = 0;m<t.size();m++){
					if(s.get(i).equals(t.get(m))){
						point--;
					}
				}

				if(point>0 && sum<point)sum=point;
			}
		}

		System.out.println(sum);

	}

}

Measured memory_bytes: 21204
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s = show $ 800 * n - ((n `div` 15) * 200) where n = read s :: Int

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
a=gets.to_i
b=gets.to_i
c=gets.to_i
d=gets.to_i
e=gets.to_i
f=gets.to_i
ans=a+b+c+d
if a<=b&&a<=c&&a<=d then
	ans-=a
elsif b<=a&&b<=c&&b<=d then
	ans-=b
elsif c<=a&&c<=b&&c<=d then
	ans-=c
else
	ans-=d
end
if e>f then
	ans+=e
else
	ans+=f
end
puts(ans)


Measured memory_bytes: 6868
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {

	var s string
	fmt.Scan(&s)

	slice := strings.Split(s, "")

	cnt := 0

	for i := 0; i < len(s)-1; i++ {
		if slice[i] != slice[i+1] {
			cnt++
		}

	}

	fmt.Println(cnt)
}


Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
#define rep(i, n) for ( int i = 0; i < (int)n; i++ )
#define MAX 500

class Point{
   public:
   int x, y;
   Point(int x=0, int y=0):x(x), y(y){}
};

int R;

bool isClose(Point p1, Point p2 ){
   return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) <= 16*R*R;
}

main(){
   int AN, BN;
   vector<Point> A[MAX][MAX];
   vector<Point> B[MAX][MAX];
   const int di[13] = {0, 1, 1, 0, -1, -1, -1, 0, 1, 2, 0, -2, 0};
   const int dj[13] = {0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 2, 0, -2};
   int x, y;
   while(1){
       cin >> AN >> BN >> R;
       if ( AN == 0 && BN == 0 && R == 0 ) break;

       rep(i, MAX) rep(j, MAX) {
           A[i][j].clear();
           B[i][j].clear();
       }
       rep(i, AN){
           scanf("%d %d", &x, &y); A[x/20][y/20].push_back(Point(x, y));
       }
       rep(i, BN){
           scanf("%d %d", &x, &y); B[x/20][y/20].push_back(Point(x, y));
       }

       int sum = 0;

       rep(i, MAX) rep(j, MAX){
           rep(k, A[i][j].size()){
               Point s = A[i][j][k];
               int ni, nj;
               for ( int ti = -2; ti <= 2; ti++ ) for ( int tj = -2; tj <= 2; tj++ ){
                   ni = i + ti;
                   nj = j + tj;
                   if ( ni < 0 || nj < 0 || ni >= MAX || nj >= MAX ) continue;
                   rep(l, B[ni][nj].size()){
                       Point t = B[ni][nj][l];
                       if ( isClose(s, t) ) sum++;
                   }
               }
           }

       }

       cout << sum << endl;
   }


}

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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    if(B<=C) cout << 0 << endl;
    else if(A<=C && C<=B && B<=D) cout << B-C << endl;
    else if(A<=C && D<=B) cout << D-C << endl;
    else if(C<=A && B<=D) cout << B-A << endl;
    else if(C<=A && A<=D && D<=B) cout << D-A << endl;
    else if(D<=A) cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans=0;
	string s,a="CODEFESTIVAL2016";
	cin>>s;
	for(int i=0;i<16;i++)
		if(s[i]!=a[i])
		    ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int h,w;
  cin >> h >> w;
  int n;
  cin >> n;
  int a[n+1];
  a[0] = 0;
  REP(i,n){
    int b;
    cin >> b;
    a[i+1]=b;
  }
  int colornum = 1;
  int cells_left = a[1];
  int c[h][w];
  REP(i,h){
    REP(j,w){
      if(i%2==0){
        c[i][j]=colornum;
      }else{
        c[i][w-1-j]=colornum;
      }
      cells_left--;
      if(cells_left==0){
        colornum++;
        cells_left = a[colornum];
      }
    }
  }
  REP(i,h){
    REP(j,w){
      cout << c[i][j] << " ";
    }
    cout << endl;
  }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

ll n, k, c[5005], p[5005], ans = LLONG_MIN;
bool flag[5005] = {0};

void reset()
{
}

void input()
{
	cin>>n>>k;
	UU(i,1,n) cin>>p[i];
	UU(i,1,n) cin>>c[i];
}

void add(ll now, ll life, ll value)
{
	ans = max(ans, value);
	if(life == 0)
	{
		return ;
	}
	add(p[now], life - 1, value + c[p[now]]);
	return;
}

void dfs(ll now, ll step, ll value)
{
	if(step > 0)
	{
		ans = max(ans, value);
	}
	if(flag[now])
	{
		ll mul = max(k/step - 1, 1LL);
		ll other = k - (mul * step);
		
		add(now, other,mul * value);
		return ;
	}
	if(step == k)
	{
		return ;
	}
	
	flag[now] = 1;
	dfs(p[now], step + 1LL, value + c[p[now]]);
	flag[now] = 0;
	return ;
}

void solve()
{
	UU(i,1,n)
	{
		dfs(i, 0LL, 0LL);
	}
	cout<<ans<<endl;
}

void LetsRock()
{
	solve();	
}

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

	input();
	reset();
	LetsRock();
	
	return 0;
}


Measured memory_bytes: 3876
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int a, p; cin >> a >> p;
	println((a*3+p)/2);
}


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

int main(){
    int N;
    cin>>N;
    vector<tuple<long int, long int, long int>> d;

    for(int i=0;i<N;i++){
        long int A,B;
        cin>>A>>B;
        d.push_back(make_tuple(B,A,B));
    }

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

    //cout<<endl;
    //for(int i=0;i<N;i++) cout<<get<0>(d.at(i))<<' '<<get<1>(d.at(i))<<' '<<get<2>(d.at(i))<<endl;
    //cout<<endl;

    bool ans=true;
    long int count=0;

    for(int i=0;i<N;i++){
        count+=get<1>(d.at(i));
        //cout<<count<<endl;
        if(count>get<2>(d.at(i))){ans=false; break;}
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 8560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<limits.h>
using namespace std;
static const int n=1000;
static const int m=1000;

int lcs(string X,string Y){
	int i,j,c[m+1][n+1];
	int m=X.size();
	int n=Y.size();
    
	for (i=0;i<m+1;i++) c[i][0]=i;
	for (j=0;j<n+1;j++) c[0][j]=j;
	for (i=1;i<m+1;i++){
		for (j=1;j<n+1;j++){
			int min=c[i-1][j]+1;
			if (min>c[i][j-1]+1)
				min=c[i][j-1]+1;
            if ((X[i-1]==Y[j-1])&&(min>c[i-1][j-1]+1))
				min=c[i-1][j-1]+1;
			c[i][j]=min;
		}
	}
	return m+n-c[m][n];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s1,s2;
	int m,i;	cin >> m;
	
	for (i=0;i<m;i++){
	cin >> s1 >> s2;
	cout << lcs(s1,s2) << endl;
	}
	return 0;
}

Measured memory_bytes: 7092
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define int long long
#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 long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio 
    int n , k ; 
    cin >> n >> k ; 
    cout << min(n % k, k - n % k) << endl;
    return 0 ; 
}

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

int main() {
   int n;
   cin >> n;
   int sum=0,pmax=-1;
   rep(i,n){
      int p; cin >> p;
      sum+=p;
      pmax=max(p,pmax);
   }
   cout << sum-pmax/2 << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
X = []
Y = []
P = []
for _ in range(N):
    x,y,p = map(int,readline().split())
    X.append(x)
    Y.append(y)
    P.append(p)

DX = [[0]*N for _ in range(1<<N)]
DY = [[0]*N for _ in range(1<<N)]

for i,x in enumerate(X):
    for k in range(1<<N):
        d = abs(x)
        for j,xx in enumerate(X):
            if (k>>j)&1:
                d = min(d,abs(x-xx))
        DX[k][i] = d * P[i]    
for i,y in enumerate(Y):
    for k in range(1<<N):
        d = abs(y)
        for j,yy in enumerate(Y):
            if (k>>j)&1:
                d = min(d,abs(y-yy))
        DY[k][i] = d * P[i]                                                

PC = [0]*(1<<N)
for i in range(1<<N):
    PC[i] = PC[i//2] + 1 if i % 2 else PC[i//2]

RA = []
for i in range(1<<N):
    t = []
    for j in range(N):
        if i>>j & 1:
            t.append(j)
    RA.append(t)

INF = 10**31
mm = (1 << N) - 1
ANS = [INF]*(N+1)

for i in range(1<<N):
    m = i^mm
    j = m
    dxi = DX[i]
    pci = PC[i]
    while True:
        dyj = DY[j]
        ans = 0
        for k in RA[i^j^mm]:
            ans += min(dxi[k],dyj[k])
        pc = pci + PC[j]
        if ans < ANS[pc]:
            ANS[pc] = ans       
        if j == 0:
            break
        j = m & (j - 1)
print(*ANS,sep = '\n')

Measured memory_bytes: 94768
#include<bits/stdc++.h>
#define ll long long
#define N 200010
using namespace std;
template <typename T> void read(T &x){
	x=0;char c=getchar();int fh=1;
	while (!isdigit(c)){if (c=='-')fh=-1;c=getchar();}
	while (isdigit(c))x=x*10+c-'0',c=getchar();
	x*=fh;
}
int n,a[N],nb,b[N];
ll ansn=1e18,g[N],f[N];
int main(){
	read(n);
	for (int i=1;i<=n;i++)read(a[i]);
	nb=0;
	for (int i=2;i<=n;i++){
		f[i]=f[i-1];
		if (a[i-1]>=a[i]){
			ll p=a[i];
			while (p*4<=a[i-1])b[++nb]=i,p*=4;
		}else{
			ll p=a[i-1];
			while (p*4<a[i]){p*=4;if (nb==0)f[i]+=i*2-2;else{f[i]+=(i-b[nb])*2;nb--;}}
			if (nb==0)f[i]+=i*2-2;else{f[i]+=(i-b[nb])*2;nb--;}
		}
	}
	nb=0;
	for (int i=n-1;i>=1;i--){
		g[i]=g[i+1];
		if (a[i+1]>=a[i]){
			ll p=a[i];
			while (p*4<=a[i+1])b[++nb]=i,p*=4;
		}else{
			ll p=a[i+1];
			while (p*4<a[i]){if(nb==0)g[i]+=n*2-i*2;else{g[i]+=(b[nb]-i)*2;nb--;}p*=4;}
			if(nb==0)g[i]+=n*2-i*2;else{g[i]+=(b[nb]-i)*2;nb--;}
		}
	}
	for (int i=0;i<=n;i++)ansn=min(ansn,i+g[i+1]+f[i]);
	cout<<ansn<<endl;
	return 0;
}


Measured memory_bytes: 4992
N = int(input())
xy = [0] * N
for i in range(N):
  xy[i] = list(map(int, input().split()))
  
#nC2通りの選び方のうち毎回n-1個の通りを選ぶ
#合計のながさ * (N - 1) /(nC2) = 合計 * 2 / N


ans = 0

for i in range(N):
  for j in range(i + 1, N):
    ans += ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2) ** (1/2)
    
ans = ans * 2 / N

print(ans)

Measured memory_bytes: 38384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		try {
			int n = Integer.parseInt(br.readLine());
			Deque<Integer> list = new ArrayDeque<Integer>();
			for (int i = 0; i < n; i++) {
				String command = br.readLine();
				if (command.charAt(0) == 'i') {
					String[] commands = command.split(" ");
					int num = Integer.parseInt(commands[1]);
					list.push(num);
				} else if (command.charAt(6) == 'F') {
					list.removeFirst();
				} else if (command.charAt(6) == 'L') {
					list.removeLast();
				} else {
					String[] commands=command.split(" ");
					int num = Integer.parseInt(commands[1]);
					list.remove(num);
				}

			}
			sb.append(list.poll());
			while (!list.isEmpty()) {
				sb.append(" " + list.poll());
			}
			System.out.println(sb);
		} catch (NumberFormatException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}

}


Measured memory_bytes: 190828
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main()
{
  int N;
  scanf("%d", &N);
  vector<int> A(N);
  for (int i = 0; i < N; ++i)
  {
    int a;
    scanf("%d", &a);
    A[i] = a;
  }
  sort(begin(A), end(A), less<int>());
  
  ll ans = A[N-1] - A[0];
  for (int i = 1; i < N/2; ++i)
  {
    ans += A[N-i] - A[i];
    ans += A[N-i-1] - A[i-1];
  }
  if (N % 2 == 1)
  {
    ans += max(A[N/2+1] - A[N/2], A[N/2] - A[N/2-1]);
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define pll pair<ll, ll>
#define ppii pair<pii, pii>
#define pli pair<ll, int>
using namespace std;
inline int ReadInt()
{
    char c;
    while (c = getchar(), c < '0' || c > '9');
    int x = c - '0';
    while (c = getchar(), c >= '0' && c <= '9')
        x = x * 10 + c - '0';
    return x;
}
const int N=1e5+1;
int n, a[N];
main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("E.inp", "r", stdin);
    //freopen("sol.out", "w", stdout);
    cin>>n;
    bool ok=0;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        if(a[i]%2) ok=1;
    }
    if(!ok) cout<<"second"<<'\n';
    else cout<<"first"<<'\n';
}


Measured memory_bytes: 640
import itertools
h,w,n=map(int, input().split())
l=[str(input())for _ in range(h)]
ans = 0

for i in list(itertools.product([0,1], repeat= h)):
    for j in list(itertools.product([0,1], repeat= w)):
        b = 0
        for k in range(h):
            for m in range(w):
                if i[k] == 0 and j[m] == 0 and l[k][m] == '#':
                    b +=1
        if b == n:
            ans += 1
print(ans)

Measured memory_bytes: 9096
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll M, K;
  cin >> M >> K;
  // We can make only 0..(2**M-1).
  // So if K >= 2**M, it can't be made.
  if (K >= 1<<M) {
    cout << -1 << endl;
    return 0;
  }

  // Treat M=1
  if ((M == 1) && (K == 1)) {
    cout << -1 << endl;
    return 0;
  }
  if ((M == 1) && (K == 0)) {
    cout << "0 0 1 1" << endl;
    return 0;
  }

  vector<ll> tmp;
  rep(i, 1<<M) {
    if (i != K) {
      tmp.push_back(i);
    }
  }
  rep(i, (1<<M)-1) {
    cout << tmp[i] << " ";
  }
  cout << K << " ";
  rep(i, (1<<M)-1) {
    cout << tmp[tmp.size() - 1 - i] << " ";
  }
  cout << K << endl;;
}


Measured memory_bytes: 2932
#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef pair<string,int> P;
int n,qt;
vector<P> vec;


int main(void){
	scanf("%d%d",&n,&qt);
	queue<P> que;
	for(int i=0;i<n;i++){
		string s;
		int t;
		cin >> s >> t;
		que.push(P(s,t));
	}
	int now=0;
	while(que.size()){
		P q=que.front();
		que.pop();
		if(q.second<=qt){
			vec.push_back(P(q.first,now+q.second));
			now+=q.second;
		}else{
			now+=qt;
			que.push(P(q.first,q.second-qt));
		}
	}
	for(int i=0;i<n;i++){
		cout << vec[i].first << " " << vec[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 7076
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60; //仮想的な無限大の値
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // 入力
    int N, K;
    while (cin >> N >> K) {
        if(N == 0) break;
        vector<long long> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i];

        // 累積和を前計算
        vector<int> s(N+1, 0);
        for (int i = 0; i < N; i++) s[i+1] = s[i] + a[i];
        
        // 答えを求める
        long long res = -INF;
        for (int i = 0; i <= N-K; i++) {
            long long val = s[K+i] - s[i];
            if (res < val) res = val;
        }
        cout << res << endl;
    }
    return 0;
}



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

int main()
{
  int H, N;
  array<int,100000> A;
  //cout << "H A" << endl;; 
  cin >> H >> N;
  for(int in=0;in < N;++in)
  {
    cin >> A[in];
  }
  //cout << H << " " << A << endl;;

  for(int i=0;i<N;++i)
  {
    H -= A[i];
    if(H<=0) break;
  }
 
  if(H<=0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int pwmd(int a, int n)
{
	if (!n)
		return 1;
	int pt = pwmd(a, n / 2);
	pt *= pt, pt %= mod;
	if (n & 1)
		pt *= a, pt %= mod;
	return pt;
}
int pow(int a,int b)
{
	int ans=1;
	while(b>0)
	{
		if(b&1)
			ans*=a;
		a*=a;
		b=b>>1;
	}
	return ans;
}
vector<pair<int,int>> vec;
bool compare(pair<int,int> v1,pair<int,int> v2)
{
	return v1.ss<v2.ss;
}

vector<int> adj[200005];
int dis[200005];

void dfs1(int par, int u)
{
	for(int x:adj[u])
	{
		if(x==par)
			continue;
		dis[x]=dis[u]+1;
		dfs1(u,x);
	}
}

void dfs(int par, int u,bool *vis)
{
	vis[u]=true;
	for(int x:adj[u])
	{
		if(x==par)
			continue;
		dfs(u,x,vis);
		vis[x]=true;
	}
}

int32_t main()
{       
    FIO;
    int k,a,b;
    cin>>k>>a>>b;
    int flag=0;
    for(int i=k;i<=b;i+=k)
    {
        if(i>=a && i<=b)
        	flag=1;
    }

    if(flag)
    	cout<<"OK"<<endl;
    else
    	cout<<"NG"<<endl;

}

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

int main(void) {
	string s;
	cin >> s;
  int begin,end;
   	for(int i=0;i<s.size();++i){
    	if(s[i]=='A'){	
          begin = i;
          break;
        }
    }
  	for(int i=s.size()-1;i>=0;--i){
    	if(s[i]=='Z'){
          end = i;
          break;
        }
    }
  cout << end-begin+1 << endl;
return 0;
}


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

int main()
{
  int N,W;
  cin>>N>>W;
  int n=N;
  vector<int>wt(n),val(n);
  for(int i=0;i<n;i++)
  {
    cin>>wt[i]>>val[i];
  }
  
  long long int dp[N+1][W+1];
  memset(dp,0,sizeof(dp));
  
  
  for(int i=1;i<=N;i++)
  {
    for(int j=1;j<=W;j++)
    {
        if(wt[i-1]<=j)
        {
            dp[i][j]=max(dp[i-1][j], dp[i-1][j-wt[i-1]]+val[i-1] );            
        }   
        else
            dp[i][j]=dp[i-1][j];

    }
  }
  long long int ans=dp[N][W];
  cout<<ans;
  return 0;
}

Measured memory_bytes: 79104
use std::collections::HashMap;

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut map: HashMap<usize, usize> = HashMap::new();
    for i in 0..n {
        let tmp = a[i];
        let entry = map.entry(tmp).or_insert(0);
        *entry += 1;
    }
    let q = read::<usize>();
    let mut v: Vec<Vec<usize>> = Vec::new();
    for _ in 0..q {
        let bc = read_vec::<usize>();
        v.push(bc);
    }
    let mut sum: usize = a.iter().sum();
    for i in 0..q {
        let bc = &v[i];
        let bentry = map.entry(bc[0]).or_insert(0);
        let tmp = *bentry;
        *bentry = 0;
        let centry = map.entry(bc[1]).or_insert(0);
        *centry += tmp;

        if bc[0] > bc[1] {
            let d = (bc[0] - bc[1]) * tmp;
            sum -= d;
        } else {
            let d = (bc[1] - bc[0]) * tmp;
            sum += d;
        }
        println!("{}", sum);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 11716
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int counter = 1;
        while (n >= k) {
            n = n / k;
            counter++;
        }

        System.out.println(counter);
    }
}

Measured memory_bytes: 22100
package main

import "fmt"

type Dice struct {
	side [6]int
	topnum int
	rightnum, leftnum, forwardnum, backnum, bottomnum int
}
func (dice *Dice) init() {
	for i:=0; i<6; i++ {
		fmt.Scan(&(dice.side[i]))
	}
	dice.topnum, dice.rightnum, dice.leftnum, dice.forwardnum, dice.backnum, dice.bottomnum = 0, 2, 3, 4, 1, 5
}
func (dice *Dice) dtonum(d int) int {
	for i:=0; i<6; i++ {
		if dice.side[i]==d {
			return i
		}
	}
	return 0
}
func (dice *Dice) inittopback(top, back int) {
	//for i:=0; i<6; i++ {
	//	fmt.Scan(&(dice.side[i]))
	//}
	dice.topnum, dice.rightnum, dice.leftnum, dice.forwardnum, dice.backnum, dice.bottomnum = top, 2, 3, 5-back, back, 5-top
	topbackpairs := [6][4]int{{3,1,2,4},{0,3,5,2},{0,1,5,4},{1,0,4,5},{2,5,3,0},{2,1,3,4}}
	for i:=0; i<6; i++ {
		for j:=0; j<4; j++ {
			if top==topbackpairs[i][j] && back==topbackpairs[i][(j+1)%4] {
				dice.rightnum = i
				dice.leftnum = 5-i
				break
			}
		}
	}

}
func (dice *Dice) rotate(dir string) {
	temp := dice.topnum

	switch dir {
	case "N" :	
		dice.topnum = dice.backnum
		dice.backnum = dice.bottomnum
		dice.bottomnum = dice.forwardnum
		dice.forwardnum = temp
	case "E" :
		dice.topnum = dice.leftnum
		dice.leftnum = dice.bottomnum
		dice.bottomnum = dice.rightnum
		dice.rightnum = temp
	case "W" :
		dice.topnum = dice.rightnum
		dice.rightnum = dice.bottomnum
		dice.bottomnum = dice.leftnum
		dice.leftnum = temp
	case "S" :
		dice.topnum = dice.forwardnum
		dice.forwardnum = dice.bottomnum
		dice.bottomnum = dice.backnum
		dice.backnum = temp
	}
}

func main() {

	var dice Dice
	dice.init()
	var q int
	fmt.Scan(&q)
	for i:=0; i<q; i++ {
		var top, back int
		fmt.Scan(&top, &back)
		dice.inittopback(dice.dtonum(top), dice.dtonum(back))
		fmt.Println(dice.side[dice.rightnum])
	}
	  
}


Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    if (a == 1)
    {
        a = 14;
    }
    if (b == 1)
    {
        b = 14;
    }
    if (a == b)
    {
        printf("Draw\n");
    }
    else if (a > b)
    {
        printf("Alice\n");
    }
    else
    {
        printf("Bob\n");
    }
    return 0;
}

Measured memory_bytes: 128
S = input().rstrip()
flg = False
if S[0] == "A":
    flg = True
if flg:
    S_sep = S[2:-1]
    index = S_sep.find("C") + 2
    if index == 1:
        flg = False
if flg:
    for i in range(1, len(S)):
        if i != index:
            if S[i].isupper():
                flg = False

print("AC" if flg else "WA")

Measured memory_bytes: 3060
// AOJ 2028: Gather on the Clock
// 2017.11.03 bal4u@uu

#include <stdio.h>
#include <string.h>

int a[102];
int dp[102][102];

int main()
{
	int cno, n, i, j, k, s, t, v, ans;
	
	scanf("%d", &cno); while (cno--) {
		scanf("%d", &n);
		for (i = 0; i < n; i++) scanf("%d", a+i);
		memset(dp, 0, sizeof(dp));

		for (k = 1; k < n; k++) for (i = 0; i < n; i++) for (s = i, t = k-1, j = 0; j < k; j++, t--) {
			if (++s == n) s = 0;
			v = a[s] - a[i]; if (v < 0) v = -v;
			v += dp[s][t] + dp[i][j];
			if (v > dp[i][k]) dp[i][k] = v;
		}

		for (ans = 0, i = 0; i < n; i++) if (dp[i][n-1] > ans) ans = dp[i][n-1];
		printf("%d\n",ans);
	}
	return 0;
}

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

using namespace std;

#define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define DFOR(a, b, c) for (register int a = b, _n = c; a > _n; --a)
#define EREP(a, b) for (register int a = first[b]; a; a = edge[a].nxt)

int k, x;

void _main () {
    scanf ("%d%d", &k, &x);

    REP (i, max(-1000000, x - k + 1), min(1000000, x + k - 1))
        printf ("%d ", i);
}

int main () {
#ifdef LOCAL
    freopen("in.txt", "w", stdout);
#endif
    _main();   
    return 0;
}


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

int n;
int v[NMAX],dp[NMAX];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    dp[2]=abs(v[2]-v[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<dp[n];
}


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


int main()
{
	int N;	//参加者人数
	int K;	//初期ポイント
	int Q;	//問題数
	int q;	//問題の正解者
	
	cin >> N >> K >> Q;

	int challenger[100000];
	for (int i = 0; i < N; i++) {
		challenger[i] = K - Q;
	}

	for (int i = 0; i < Q; i++) {
		cin >> q;
		challenger[q-1]++;
	}
	

	for (int i = 0; i < N; i++) {
		if (challenger[i] > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	char str1[7],str2[7],str[7];
	int a,b,num;
	cin>>a>>b;
	sprintf(str1,"%d",a);
	sprintf(str2,"%d",b);
	sprintf(str,"%s%s",str1,str2);
	sscanf(str,"%d",&num);
	if(sqrt(num)==int(sqrt(num)))
	   cout<<"Yes"<<endl;
	else
	   cout<<"No"<<endl;
	return 0;
}

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

int main() {
	int n,t;cin>>n>>t;
	vector<int> a(n),min(n),max(n);

	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	min[0]=a[0];
	for(int i=1;i<n;i++){
		if(a[i]<min[i-1]){
			min[i]=a[i];
		}else{
			min[i]=min[i-1];
		}
	}
	max[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--){
		if(a[i]>max[i+1]){
			max[i]=a[i];
		}else{
			max[i]=max[i+1];
		}
	}
	int maxd=0;
	for(int i=0;i<n;i++){
		if(max[i]-a[i]>maxd){
			maxd=max[i]-min[i];
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(max[i]-a[i]==maxd){
			ans++;
		}
	}
//	for(int i=0;i<n;i++){
//		cout<<max[i]<<' ';
//	}
//	cout<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
N = int(input())
L = [int(s) for s in input().split(' ')]

while len(L) > 1:
  L.sort()
  L_new = [L[0]]
  for l in L[1:]:
    v = l % L_new[0]
    if v != 0:
      L_new.append(v)
  L = L_new
print(L[0])

Measured memory_bytes: 14252
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var N = o.getValue(0);
    var An = o.getArray(1);

    var last = 0;
    for(var j = N - 1; j > 0; j--) {
        if (An[j] > An[j - 1]) {
            last = j
            break;
        }
    }

    var result = 1000;
    var num = 0;
    for(var i = 0; N > i; i++) {
        if (last === i || An[i] > An[i + 1] && num > 0) {
            result += An[i] * num;
            num = 0;
            if (last === i) break;
        }

        if (An[i] < An[i + 1] && result >= An[i]) {
            var temp = result % An[i];
            num = (result - temp) / An[i]
            result = temp
        }
    }

    return result;
}


Measured memory_bytes: 30508
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	int c;
	cin>>a>>b;
	if(b/100==1)
		c=a*1000+b;
	else if(b/10>=1)
		c=a*100+b;
	else if(b/1>=1)
		c=a*10+b;
	int x;
	x=sqrt(c);
	if(x*x==c)	cout<<"Yes"<<endl;
	else		cout<<"No"<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (m, d) = readLine()!!.split(" ").map { it.toInt() }

    var sum = 0
    for (i in 1..m) {
        for (j in 1..d) {
            val s = j.toString()
            if (s.length > 1) {
                val d10 = s[0].toString().toInt()
                val d1 = s[1].toString().toInt()

                if (d10 >= 2 && d1 >= 2 && i == d1 * d10) {
                    sum += 1
                }
            }
        }
    }

    println(sum)

}

Measured memory_bytes: 38636
#include <bits/stdc++.h>
#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++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
//#3819151を参考にさせていただきました。

int n;
int ans = 0;

void dfs(ll x, int a, int b, int c)
{
//	cout << x << endl;
	if (x > n) return;
	if (a == 1 and b == 1 and c == 1) ans++;
	dfs(10 * x + 3, 1, b, c);
	dfs(10 * x + 5, a, 1, c);
	dfs(10 * x + 7, a, b, 1);
}

int main()
{
	cin >> n;
	dfs(0, 0, 0, 0);
	cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    /**/
    int count = 1;
    for(int i = 1;i < n;i++){
        if(s.at(i) != s.at(i - 1)){
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N, C; cin >> N >> C;
    int cnt[35][100005];
    vei s(N), t(N), c(N);
    rep(i,N) {
        cin >> s[i] >> t[i] >> c[i];
        cnt[c[i]][s[i]]++;
        cnt[c[i]][t[i]+1]--;
    }
    rep1(i,C+1) rep1(j,100005) cnt[i][j] += cnt[i][j-1];
    rep1(i,C+1) rep(j,100005) if(cnt[i][j] > 1 ) cnt[i][j] = 1;
    
    vei sum(100005,0);
    
    int ans = 0;
    
    rep(i,100005){
        rep1(j,C+1) sum[i] += cnt[j][i];
        ans = max(ans, sum[i]);
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, m;
	cin >> n >> m;

	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	vector<ll> sums(n + 1);
	for (int i = 0; i < n; i++) {
		sums[i + 1] = sums[i] + a[i];
	}

	map<ll, ll> mp;
	ll ans = 0;
	for (auto v : sums) {
		ll x = v % m;
		ans += mp[x];
		mp[x]++;
	}

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


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

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long

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

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

    (n >= 3200) ? cout << s : cout << "red";

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt(); //夏休みの日数
		int M = sc.nextInt(); //宿題の数

		int A[] = new int[M];//宿題にかかる日数
		int sum = 0; //宿題にかかる日数の合計
		int result = 0; //遊べる日数

		for(int i=0; i<M; i++) {

			A[i] = sc.nextInt();

			sum += A[i];
		}

		result = N - sum;
		if(result < 0) {
			result = -1;
		}

		System.out.print(result);
	}

}


Measured memory_bytes: 46152
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<functional>
#include<algorithm>
using namespace std;
int  sheets[3][10007], tmp[10007];



int main(){
  while(1){
    int n, r;
    int x1, y1, x2, y2, mx = 0, my = 0, menseki = 0, gaishuu = 0;
    vector<pair<int, int> > points;
    map<pair<int ,int> , int> nums;
    scanf("%d%d", &n, &r);
    memset(sheets, 0, sizeof(sheets));
    if(n == 0 && r == 0)return 0;
    for(int i = 0;i < n;i++){
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      x1++,y1++,x2++,y2++;
      points.push_back(make_pair(x1, y1));
      points.push_back(make_pair(x1, y2));
      points.push_back(make_pair(x2, y1));
      points.push_back(make_pair(x2, y2));
      if(nums.count(make_pair(x1, y1)) == 0)nums[make_pair(x1, y1)] = 0;
      if(nums.count(make_pair(x2, y1)) == 0)nums[make_pair(x2, y1)] = 0;
      if(nums.count(make_pair(x1, y2)) == 0)nums[make_pair(x1, y2)] = 0;
      if(nums.count(make_pair(x2, y2)) == 0)nums[make_pair(x2, y2)] = 0;
      nums[make_pair(x1, y1)]++;
      nums[make_pair(x2, y2)]++;
      nums[make_pair(x1, y2)]--;
      nums[make_pair(x2, y1)]--;
      mx = max(mx, x1);
      mx = max(mx, x2);
      my = max(my, y1);
      my = max(my, y2);
    }
    sort(points.begin(), points.end(), greater< pair<int, int> >());
    memset(tmp, 0, sizeof(tmp));
    for(int i = 1;i <= mx ; i++){
      for(int j = 1;j <= my + 1; j++){
	if(points.back().first == i && points.back().second == j){
	  tmp[j] += nums[points.back()];
	  pair<int, int> tmpr = points.back();
	  while(points.back() == tmpr)points.pop_back();
	}
	sheets[i % 3][j] = sheets[i % 3][j - 1] + tmp[j];
	if(sheets[i % 3][j] > 0)menseki++;
	if(r == 2){
	  if(sheets[i % 3][j] > 0 ){
	    if(sheets[(i - 1) % 3][j] == 0)gaishuu++;
	    if(sheets[i % 3][j - 1] == 0)gaishuu++;
	  }
	  if(sheets[i % 3][j] == 0 ){
	    if(sheets[(i - 1) % 3][j] > 0)gaishuu++;
	    if(sheets[i % 3][j - 1] > 0)gaishuu++;
	  }
	}
      }
    }
    printf("%d\n", menseki);
    if(r == 2){
      printf("%d\n", gaishuu);
    }
  }
}

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


int main(){
    const int mod=998244353;
    int n,k;
    cin>>n>>k;
    vector<int> dp(n+1,0),rui(n+1),l(k),r(k);
    rep(i,k){
        cin>>l[i]>>r[i];
    }
    dp[1]=1;
    rui[0]=0;
    rui[1]=1;
    for(int i=2;i<=n;i++){
        rep(j,k){
            int li=i-r[j];
            int ri=i-l[j];
            if(ri<0)continue;
            li=max(li,1);
            dp[i]+=rui[ri]-rui[li-1];
            dp[i]%=mod;
            dp[i]=(dp[i]+mod)%mod;
        }
        rui[i]=rui[i-1]+dp[i];
        rui[i]%=mod;
    }
    cout<<(dp[n]+mod)%mod<<endl;
}

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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;


int main(){
    cout << fixed << setprecision(12);
    ll n;
    string s;
    cin >> n >> s;
    ll i = n/2;
    if(n % 2 == 1){
        cout << "No" << endl;
        return 0;
    }
    if(s.substr(0, i) == s.substr(i, i)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
void swap(int *a, int *b) {
   int t;
   t = *a;
   *a = *b;
   *b = t;
}

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  int t;
  if (a > b) swap(&a, &b);
  if (a > c) swap(&a, &c);
  if (b > c) swap(&b, &c);

  printf("%d %d %d\n", a, b, c);
}


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

int main()
{
    int n; cin>>n;
    vector<int> d(n); for(auto& e: d) cin>>e;

    vector<bool> v(1000);
    for(int i=0; i<n; ++i) {
        int x=0;
        x*=10; v[x+=d[i]]=true;
        if (i+1<n) x*=10; v[x+=d[i+1]]=true;
        if (i+2<n) x*=10; v[x+=d[i+2]]=true;
    }
    int res=0;
    for(int i=0; i<1000; ++i) if (!v[i]) { res=i; break; }
    cout<<res<<endl;
}

Measured memory_bytes: 3100
N=int(input())
D = []
D += [[i,0]  for i in list(map(int,input().split()))]
D += [[i,1]  for i in list(map(int,input().split()))]
D += [[i,2]  for i in list(map(int,input().split()))]
D = sorted(D,key=lambda x: x[0])

up_count=0
up_buf = 0
down_count=N
down_buf= 0
middle_buf = 0
ans = 0
prev_val = D[0][0]
for d in D:
    if d[0]==prev_val:
        if d[1]==0:
            up_buf+=1
        if d[1]==1:
            middle_buf += 1
        if d[1]==2:
            down_buf+=1
    else:
        ans += middle_buf*(down_count-down_buf)*up_count
        up_count+=up_buf
        up_buf=0
        down_count-=down_buf
        down_buf=0
        middle_buf=0
        prev_val = d[0]
        if d[1]==0:
            up_buf+=1
        if d[1]==1:
            middle_buf += 1
        if d[1]==2:
            down_buf+=1        
print(ans)

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

int main(){
    int N,M;
    cin>>N>>M;
    int sum,sum1;
    sum=0;
    sum1=0;
    for(int i=0;i<N;i++){
        sum+=i;
    }
    for(int k=0;k<M;k++){
        sum1+=k;
    }
    cout<<sum+sum1<<endl;
    return 0;
}

Measured memory_bytes: 256