akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.at(i) = a - i - 1;
  }
  sort(A.begin(), A.end());
  
  ll b = A.at(N / 2);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += abs(A.at(i) - b);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
using namespace std;
struct cal {
	int a; 
	char c;  
	int  d; 
};
cal sk[100005],ca[100005],g;
int m;
int div(int d,int m) {
	int i,a[16],b,c;
	if (m==2) return d % m;
	for (i=0;i<16;i++) { a[i]=d % m; d=(d*d) % m;}
	c=m-2; b=1;
	for (i=15;i>=0;i--) if ((c & (1 << i))>0) b=(b*a[i]) % m;
	return b;    
 }  
int calc(char *c) {
	int s,r,y[256],sp1=0,sp2=0,p=0;
	sk[0].a=-2;  g.c='!';	
	y['(']=4;y[')']=0; y['*']=y['/']=2; y['+']=y['-']=1; y['\0']=-1;
	while(g.c!='\0') {
		if (c[p]==' ') { p++; continue;}
		if (c[p]>='0' && c[p]<='9') { 
			s=0; while(c[p]>='0' && c[p]<='9') {s*=10;s+=c[p]-'0'; p++; }
			g.a=3; g.d=s; g.c='0';
			} else { g.a=y[(int)c[p]]; g.c=c[p]; p++;}
	    while(g.a<=sk[sp2].a && sk[sp2].c!='(') {
			   if (sk[sp2].a==3) { sp1++; ca[sp1]=sk[sp2];} else {
				switch(sk[sp2].c) {
				case '+': ca[sp1-1].d=(ca[sp1-1].d+ca[sp1].d) % m; sp1--; break; 	
			    case '-': ca[sp1-1].d=(m+ca[sp1-1].d-ca[sp1].d) % m; sp1--; break;
			    case '*': ca[sp1-1].d=(ca[sp1-1].d*ca[sp1].d) % m; sp1--; break;
			    case '/':
			             r=div(ca[sp1].d,m); if (r % m ==0) return m+1; 
			             ca[sp1-1].d=(ca[sp1-1].d*r) % m; sp1--; break;
			     }
			   }
			   sp2--;
			}
		if (g.c!=')')  sk[++sp2]=g; else sp2--;
		}
	return ca[1].d;
}


int main() {
 int a,p1,p2;	
 char e,c1[100005],c2[100005];
 while(cin >> m >> e && m>0) {
  gets(c1); p1=p2=0;
  while(c1[p1]!='\0') { if (c1[p1]!=' ') c2[p2++]=c1[p1]; p1++;} c2[p2]='\0';  
  a=calc(c2);
  if (a==m+1) cout << "NG" << endl; else { cout << c2 << " = " << a << " (mod " << m << ')' << endl;}  
  }
 return 0;
 } 

Measured memory_bytes: 1320
#include<iostream>
using namespace std;
int main()
{
	int n, a, i, s[14], h[14], c[14], d[14];
	char suite;
	for ( i = 0; i < 14; i++)s[i] = 0;
	for ( i = 0; i < 14; i++)h[i] = 0;
	for ( i = 0; i < 14; i++)c[i] = 0;
	for ( i = 0; i < 14; i++)d[i] = 0;
	cin >> n;
	for( i = 0; i < n; i++ )
	{
		cin >> suite >> a;
		if ( suite == 'S' )s[(a - 1)] = 1;		
		if ( suite == 'H' )h[(a - 1)] = 1;
		if ( suite == 'C' )c[(a - 1)] = 1;
		if ( suite == 'D' )d[(a - 1)] = 1;
	}
	for ( i = 0; i < 13; i++ )
	{
		if ( s[i] == 0 )cout << "S " << (i + 1) << endl;
	}
	for ( i = 0; i < 13; i++ )
	{
		if ( h[i] == 0 )cout << "H " << (i + 1) << endl;
	}
	for ( i = 0; i < 13; i++ )
	{
		if ( c[i] == 0 )cout << "C " << (i + 1) << endl;
	}
	for ( i = 0; i < 13; i++ )
	{
		if ( d[i] == 0 )cout << "D " << (i + 1) << endl;
	}
return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;

namespace atcoder_ABC065B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
			int buttonCount = int.Parse(Console.ReadLine());
			Dictionary<string, string> lightPatterns = new Dictionary<string, string>();
			for (int i = 0; i < buttonCount; i++)
			{
				lightPatterns[(i + 1).ToString()] = Console.ReadLine();
			}

			int pushCount = 0;
			string lightingButton = "1";
            while (true)
			{
				if (!lightPatterns.ContainsKey(lightingButton)) {
					Console.WriteLine("-1"); 
					return;	
				}

				string pushedButton = lightingButton;

				lightingButton = lightPatterns[lightingButton];
				lightPatterns.Remove(pushedButton);

				pushCount++;

				if (lightingButton == "2") {
					Console.WriteLine(pushCount); 
					return;	
				}
			}
        }
    }
}


Measured memory_bytes: 31068
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int change_to_i(string s){
   stringstream ss; int k;
   ss<<s; ss>>k;
   return k;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s = to_string(n);
    int l = s.size();
    int ans = 0;
    while(n > 0){
        ans += n % 10;
        n /= 10;
    }
    rep(i, 1, l + 1){
        if(s[i - 1] == '0') continue;
        string t = s.substr(0, i);
        // cout << t << endl;
        t[i - 1] = (char)('0' + (t[i - 1] - '0' - 1));
        rep(j, 0, l - i){
            t += '9';
        }
        // cout << t << endl;
        int tmp = change_to_i(t);
        int sum = 0;
        while(tmp > 0){
            sum += tmp % 10;
            tmp /= 10;
        }
        chmax(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
N = len(S) + 1
ans = [0] * N
for i in range(N - 1):
    if S[i] == "<":
        if ans[i] < ans[i + 1]:
            continue
        else:
            ans[i + 1] = ans[i] + 1

for i in range(N - 1, 0, -1):
    if S[i - 1] == ">":
        if ans[i - 1] > ans[i]:
            continue
        else:
            ans[i - 1] = ans[i] + 1

print(sum(ans))


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

int main() {
    int m, n; cin >> m >> n;
    int ins[m];
    vector<int> outs[m];
    for (int i=0; i<m; i++) ins[i] = 0;
    
    for (int i=0; i<n; i++) {
        int xi, yi; cin >> xi >> yi;
        ins[yi-1]++;
        outs[xi-1].push_back(yi-1);
    }
    
    queue<int> q;
    vector<int> ans;
    
    for (int i=0; i<m; i++) {
        if (ins[i]==0) q.push(i);
    }
    
    while (q.size()) {
        int v = q.front(); q.pop();
        ans.push_back(v);
        
        for (auto nv : outs[v]) {
            ins[nv]--;
            if (ins[nv]==0) q.push(nv);
        }
    }
    
    for (int i=0; i<m; i++) {
        if (ans[i]==1) continue;
        cout << ans[i]+1 << endl;
    }
    
    cout << 2 << endl;
}


Measured memory_bytes: 3164
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int K = sc.nextInt();
        String S = sc.next();
        char[] ch = S.toCharArray();
        boolean[] b = new boolean[N];
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            b[i] = ch[i] == 'L';
        }
        int ans = 0;
        do {
            // System.out.println(cnt + Arrays.toString(b));
            if (!(cnt < K))
                break;

            for (int i = 0; i < N - 1; i++) {
                if (b[i] && !b[i + 1]) {
                    cnt++;
                    for (int p = i + 1; p < N && !b[p]; p++) {
                        b[p] = !b[p];
                    }
                } else if (!b[i] && b[i + 1]) {
                    cnt++;
                    for (int p = i + 1; p < N && b[p]; p++) {
                        b[p] = !b[p];
                    }
                }
                if (!(cnt < K))
                    break;
            }
        } while (false);
        System.err.println(cnt + Arrays.toString(b));
        for (int i = 1; i < N; i++) {
            if (b[i - 1] && b[i])
                ans++;
        }
        for (int i = 0; i < N - 1; i++) {
            if (!b[i] && !b[i + 1])
                ans++;
        }
        System.out.println(ans);
    }
}

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

using namespace std;

#define PB push_back
#define SZ(a) (int)a.size()
#define MP make_pair

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;

char in[25];

int main() {

	fgets(in, 25, stdin);

	in[3] = 0;

	printf("%s\n", in);


	return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    string s;
    cin>>n>>s;
    for(int i=0;i<s.length();i++){
        s[i]+=n;
        if(s[i]>'Z')s[i]-=26;
    }
    cout<<s<<endl;
    return 0;
}

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

int main() {
    int a, b, x;
    char op;
    while(1){
        cin >> a >> op >> b;
        if ( op == '+' ){
            x = a + b;
        } else if ( op == '-' ){
            x = a - b;
        } else if ( op == '*' ){
            x = a*b;
        } else if ( op == '/' ){
            x = a/b;
        } else {
            break;
        }
        cout << x << endl;
    }

    return 0;
}


Measured memory_bytes: 3068
import java.util.Scanner;
class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int A=sc.nextInt();
int B=sc.nextInt();
if(A==1)A=14;
if(B==1)B=14;
if(A==B){
System.out.println("Draw");
}else if(A>B){
System.out.println("Alice");
}else{
System.out.println("Bob");
}
}
}

Measured memory_bytes: 9812
require 'pp'
n = gets.to_i

xl = []
n.times do
  xl << gets.split.map(&:to_i) # x, l
end

xl.sort_by!{|z|z[0] + z[1]}
line = xl[0][0] + xl[0][1]
# p xl

cnt = 0
i = 1
while i < n
  break if xl[i].nil?
  if line > (xl[i][0] - xl[i][1])
    cnt += 1
    i += 1
    next
  end
  line = xl[i][0] + xl[i][1]
  i += 1
end


p n - cnt
# 3 1 5


Measured memory_bytes: 14968
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
  [sx, sy, tx, ty] <- readInts
  replicateM_ (tx-sx) $ putStr "R"
  replicateM_ (ty-sy) $ putStr "U"
  replicateM_ (tx-sx) $ putStr "L"
  replicateM_ (ty-sy+1) $ putStr "D"
  replicateM_ (tx-sx+1) $ putStr "R"
  replicateM_ (ty-sy+1) $ putStr "U"
  putStr "L"
  putStr "U"
  replicateM_ (tx-sx+1) $ putStr "L"
  replicateM_ (ty-sy+1) $ putStr "D"
  putStrLn "R"

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


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

int main(){
	string s, t;
	cin >> s >> t;
	auto count = 0;
	for(int i = 0; i < 3; i++){
		if (s[i] == t[i]){
			count = count + 1;
		}
	}

	cout << count << endl;

}

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

const long long MAX = 10000000;  // TLEならば小さくする
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (long long i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	
	ll s; cin >> s;
	COMinit(); // 前処理
	ll n = s / 3;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ll x = s - 3 * i;
		ans += COM(x + i - 1, x);
		ans %= MOD;
	}
	cout << ans << endl;	
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}


using D=double;
using P=complex<D>;
const D EPS=1e-8;

inline D dot(P a,P b){
    return real(a)*real(b)+imag(a)*imag(b);
}

inline D cross(P a,P b){
    return real(a)*imag(b)-imag(a)*real(b);
}

const int MAXN=100;

int N;
P ps[MAXN];

inline P cc(P A,P B,P C){
    const D a=dot(C-B,C-B);
    const D b=dot(A-C,A-C);
    const D c=dot(B-A,B-A);

    const D x=a*(b+c-a);
    const D y=b*(c+a-b);
    const D z=c*(a+b-c);

    return (A*x+B*y+C*z)/(x+y+z);
}

inline D calc(P c){
    D ret=0.0;
    rep(i,N)chmax(ret,dot(ps[i]-c,ps[i]-c));
    return ret;
}

signed main(){
    cin>>N;
    rep(i,N){
        int x,y;
        cin>>x>>y;
        ps[i]=P(x,y);
    }

    D ans=1e20;
    rep(i,N)rep(j,N)if(i!=j){
        P c=(ps[i]+ps[j])*0.5;
        chmin(ans,calc(c));
    }

    rep(i,N)rep(j,N)rep(k,N)if(i!=j&&j!=k&&k!=i){
        if(abs(cross(ps[j]-ps[i],ps[k]-ps[i]))<EPS)continue;
        P c=cc(ps[i],ps[j],ps[k]);
        chmin(ans,calc(c));
    }

    printf("%.20f\n",sqrt(ans));
    return 0;
}


Measured memory_bytes: 256
ret = "Yes"
Array.new(gets.to_i){gets.split.map(&:to_i)}.each{ |arr|
    t = arr[0]
    x = arr[1]
    y = arr[2]
    xpy = x + y
    if (t.even? ? xpy.even? : xpy.odd?) && xpy <= t then
        next
    else
        ret = "No"
        break
    end
}
puts ret

Measured memory_bytes: 9596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
void insertionSort(vector<int> A, int N) // N個の要素を含む0-オリジンの配列A
{
  for (int i = 1; i < N + 1; i++)
  {
    rep(k, N)
    {
      if (k == N - 1)
      {
        cout << A[k];
      }
      else
      {
        cout << A[k] << " ";
      }
    }
    cout << "\n";

    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v)
    {
      A[j + 1] = A[j];
      j--;
      A[j + 1] = v;
    }
  }
}
int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N)
  {
    cin >> A[i];
  }
  insertionSort(A, N);
  return 0;
}


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

int main() {
  int R;
  cin >> R;
  if(R<1200)
    cout << "ABC" << endl;
  else if(R<2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
  return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimization ("O3,unroll-loops")
#pragma GCC target ("avx,avx2,fma")
using namespace std;

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, m, k; cin >> n >> m >> k;
    vector<int64_t> a(n), b(m);
    for (auto &it : a) cin >> it;
    for (auto &it : b) cin >> it;
    vector<int64_t> prefA(n + 1), prefB(m + 1);
    for (int i = 1; i <= n; i++) prefA[i] = prefA[i - 1] + a[i - 1];
    for (int i = 1; i <= m; i++) prefB[i] = prefB[i - 1] + b[i - 1];
    int64_t tot = 0;
    for (int i = 0; i <= n; i++) {
        int64_t tim = prefA[i], cnt = 0;
        if (tim <= k) {
            auto it = lower_bound(prefB.begin(), prefB.end(), k - tim);
            int j = it - prefB.begin();
            if (prefB[j] > k - tim || j > m) j--;
            cnt = i + j;
        }
        tot = max(tot, cnt);
    }
    cout << tot;
    return 0;
}

Measured memory_bytes: 9528
from collections import Counter
from math import factorial


def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))


n = int(input())
S = [''.join(sorted(input())) for _ in range(n)]
S_c = Counter(S)

ans = 0
for i in list(S_c.values()):
    if i != 1:
        ans += combinations_count(i, 2)

print(ans)


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VLL a(n);
  rep(i,n) cin >> a[i];
  ll x = 0;
  rep(i,n){
    if(i%2 == 0 ) x += a[i];
    else x -= a[i];
  }
  VLL ans(n,0);
  ans[0] = x;
  FOR(i,1,n){
    ans[i] = 2*(a[i-1] - ans[i-1]/2);
  }
  rep(i,n){
    if(i != n-1) cout << ans[i] << " ";
    else cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define pb push_back

typedef long long ll;

int main() {
	string s; cin >> s;
	
	int ans1 = 0;
	int ans2 = 0;

	// first is 0
	// 偶数 is 0
	if (s[0] == '1') {
		++ans1;
	}
	if (s[1] == '0') {
		++ans1;
	}


	if (s.size() > 1){
		FOR(i,2, s.size()){
			if (i % 2 == 0) {
				if (s[i] == '1') {
					++ans1;
				}
			// 奇数
			} else {
				if (s[i] == '0') {
					++ans1;
				}
			}
		}
	}
	
	// first is 1
	// 奇数 is 0
	if (s[0] == '0') {
		++ans2;
	}

	if (s[1] == '1') {
		++ans2;
	}


	if (s.size() > 1){
		FOR(i,2, s.size()){
			if (i % 2 == 0) {
				if (s[i] == '0') {
					++ans2;
				}
			// 奇数
			} else {
				if (s[i] == '1') {
					++ans2;
				}
			}
		}
	}

	cout << min(ans1, ans2) << endl;

	return 0;
}

Measured memory_bytes: 512
package main

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

func gcd(a, b int64) int64 {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func abs(a int64) int64 {
	if a < 0 {
		a = -a
	}
	return a
}

func pow(x, n, m int64) int64 {
	if n == 0 {
		return 1
	}
	ret := pow(x, n/2, m)
	ret *= ret
	ret %= m
	if n%2 == 1 {
		ret *= x
		ret %= m
	}
	return ret
}

type pair [2]int64

func inv(p pair) pair {
	if p[0] == 0 {
		return pair{1, 0}
	}
	if p[1] == 0 {
		return pair{0, 1}
	}
	if p[1] < 0 {
		return pair{-p[1], p[0]}
	}
	return pair{p[1], -p[0]}
}

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	a := make([]int64, n)
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a[i], &b[i])
	}

	m := make(map[pair]int64)
	var x int64
	for i := 0; i < n; i++ {
		if a[i] == 0 && b[i] == 0 {
			x++
		} else if a[i] == 0 {
			m[pair{0, 1}]++
		} else if b[i] == 0 {
			m[pair{1, 0}]++
		} else {
			g := gcd(abs(a[i]), abs(b[i]))
			a1, b1 := a[i]/g, b[i]/g
			if a[i] < 0 {
				a1, b1 = -a1, -b1
			}
			m[pair{a1, b1}]++
		}
	}

	var ans int64 = 1
	var M int64 = 1000000007
	for k := range m {
		k2 := inv(k)
		y := pow(2, m[k], M) - 1
		y += pow(2, m[k2], M) - 1
		y++
		delete(m, k2)
		ans *= y % M
		ans %= M
	}
	ans += x
	ans--
	if ans < 0 {
		ans += M
	}
	ans %= M
	fmt.Println(ans)
}


Measured memory_bytes: 22044
import sys
input=sys.stdin.readline
def main():
    N, K = map(int, input().split())
    lst_a = list(map(int, input().split()))
    # 石の個数が残りi個の局面で勝ちTrue 負け False　
    dp = [False] * (K+1)
    for i in range(1, K+1):
        for j in range(N):
            if i - lst_a[j] >= 0:
                dp[i] |= not(dp[i - lst_a[j]])
    
    if dp[K]:
        print('First')
    else:
        print('Second')
main()

Measured memory_bytes: 3828
#include<iostream>
using namespace std;
int main(void)
{
  int i,j,k,l,n,left[26],right[26],same,ans;
  string s,sl,sr;
  cin>>n;
  cin>>s;
  ans=0;
  for(i=1;i<n-1;i++)
  {  
    same=0;
   for(j=0;j<26;j++)
   {
     left[j]=0;right[j]=0;
   }
    
   for(j=0;j<n;j++)
   {
     if(j<i)
     {
       left[s[j]-'a']=1;
     }
     else
     {
       right[s[j]-'a']=1;
     }
   }
   for(j=0;j<26;j++)
   {
     if(left[j]==1&&right[j]==1){same++;}
   }
   if(same>ans){ans=same;}
  }
  
  cout<<ans;
  
  
}

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

int main()
{
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if (u == s)
    {
        a--;
    }
    else
    {
        b--;
    }
    cout << a << " " << b << endl;
}


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

vector<int> to[200005];
vector<int> ans;

void bfs (int v) {
    queue<int> q;
    for (int u : to[v]) {
        q.push(u);
        ans[u] = v+1;
    }
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (int u : to[x]) {
            if (ans[u] != -1) continue;
            q.push(u);
            ans[u] = x+1;
        }
    }

    return;
}

int main() {
    int n, m;
    cin >> n >> m;
    ans.resize(n);
    rep(i, n) ans[i] = -1;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    bfs(0);
    bool ok = true;
    for (int i = 1; i < n; i++) {
        if (ans[i] == -1) {
            ok = false; 
            break;
        }
    }
    if (ok) {
        cout << "Yes" << endl;
        for (int i = 1; i < n; i++) {
            cout << ans[i] << endl;
        }
    } else {
        cout << "No" << endl;
    }
    
    
    return 0;
}

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

typedef bool B;
typedef long double D;
typedef complex<D> P;
typedef vector<P> VP;
typedef struct {P s,t;} L;
typedef vector<L> VL;
typedef struct {P c;D r;} C;
typedef vector <C> VC;

const D eps=1.0e-10;
const D pi=acos(-1.0);
template<class T> bool operator==(T a, T b){return abs(a-b)< eps;}
template<class T> bool operator< (T a, T b){return a < b-eps;}
template<class T> bool operator<=(T a, T b){return a < b+eps;}
template<class T> int sig(T r) {return (r==0||r==-0) ? 0 : r > 0 ? 1 : -1;}
#define X real()
#define Y imag()

D ip(P a, P b) {return a.X * b.X + a.Y * b.Y;}
D ep(P a, P b) {return a.X * b.Y - a.Y * b.X;}
D sq(D a) {return sqrt(max(a, (D)0));}
P vec(L l){return l.t-l.s;}
inline void input(P &p){D x,y;cin >> x >> y;p={x,y};}
// ???????????¬????????¨???

// ccw
enum CCW{
	LEFT = 1,
	RIGHT = 2,
	BACK = 4,
	FRONT = 8,
	MID = 16,
	ON=FRONT|BACK|MID
};

inline int ccw(P base, P a, P b) {              //???a??¨???b???????????????????????????
	a -= base; b -= base;
	if (ep(a, b) > 0)
		return LEFT;    // counter clockwise
	if (ep(a, b) < 0)
		return RIGHT;   // clockwise
	if (ip(a, b) < 0)
		return BACK;    // b--base--a on line
	if (norm(a) < norm(b))
		return FRONT;   // base--a--b on line
	// otherwise
	return MID;      // base--b--a on line  a??¨b????????????????????????
}

B iver(L a, L b) {return ip(vec(a),vec(b) )== 0.0;}
B ipar(L a, L b) {return ep(vec(a),vec(b) )== 0.0;}


// ??????
P pLL(L a,L b){ return a.s+vec(a)*ep(vec(b),b.s-a.s)/ep(vec(b),vec(a));}


// ?????¨??´?????¨????????¢??£???????????????

B iLL(L a,L b){return !ipar(a,b);}
B eqL(L a,L b){return !iLL(a, b) && ep(vec(a), b.s - a.s)==0;}
B iLS(L a,L b){return sig(ep(vec(a),b.s-a.s))*sig(ep(vec(a),b.t-a.s)) <= 0;}
B iLSs(L a,L b){return sig(ep(vec(a),b.s-a.s))*sig(ep(vec(a),b.t-a.s)) < 0;}
B iSS(L a,L b){
	int cwa = ccw(a.s,a.t, b.s) | ccw(a.s,a.t, b.t);
	int cwb = ccw(b.s,b.t, a.s) | ccw(b.s,b.t, a.t);
	return ((cwa | cwb) & MID) || ((cwa & cwb) == (LEFT | RIGHT));
}
B iSSs(L a,L b) {
	int cwa = ccw(a.s,a.t, b.s) | ccw(a.s,a.t, b.t);
	int cwb = ccw(b.s,b.t, a.s) | ccw(b.s,b.t, a.t);
	return (cwa & cwb) == (LEFT | RIGHT);
}

// ?????¨??´?????¨????????¢??£????????¢

D dLP(L l,P p){return abs( ep(vec(l),p-l.s) )/abs(vec(l));}
D dSP(L s,P p){
	if (sig( ip( vec(s), p - s.s)) <= 0) return abs(p - s.s);
	if (sig( ip(-vec(s), p - s.t)) <= 0) return abs(p - s.t);
	return dLP(s,p);
}
D dLL(L a,L b){ return iLL(a,b)?0:dLP(a,b.s);}
D dLS(L a,L b){ return iLS(a,b)?0:min(dLP(a, b.s),dLP(a, b.t));}
D dSS(L a,L b){ return iSS(a,b)?0:
	min({ dSP(a,b.s),dSP(a,b.t),dSP(b,a.s),dSP(b,a.t)});}


int main(void){
	int q;
	cin >> q;
	cout.precision(10);
	rep(loop,q){
		L line[2];
		rep(i,2){
			input(line[i].s);
			input(line[i].t);
		}
		int ans=0;
		if(iSS(line[0],line[1])) ans=1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
#include <stdio.h>

int main(void){
	int a,b,c,ex;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a > b){
		ex = a;
		a = b;
		b = ex;
		
	}
	if(b > c){
		ex=b;
		b=c;
		c=ex;
	}
	if(a > b){
		ex=a;
		a=b;
		b=ex;
	}
	
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  
  int ans = 0;
  int c,d;
  for(int i = 0; i < n; i++){
    cin >> c >> d;
    if(c >= a && d >= b) ans++;
  }
  cout << ans << endl;
}


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

int arr[300] = {};
int index = 0;

void build(int n){
	if(n > 100)
		return;
	arr[index++] = n;
	build(n+4);
}

void build2(){
	for(int i = 0; i < 100; i += 7){
		build(i);
	}
}

int main(){
	build2();
	int n;
	cin >> n;
	for(int i = 0; i < 300; i++){
//		cout << arr[i] << " ";
		if(n == arr[i]){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	string s;
	int K;
	cin >> s >> K;
	REP(i, s.length() - 1) if (s[i] != 'a' && 'z' + 1 - s[i] <= K) {
		K -= 'z' + 1 - s[i];
		s[i] = 'a';
	}
	REP(i, K % ('z' - 'a' + 1)) {
		if (s[s.length() - 1] == 'z') s[s.length() - 1] = 'a';
		else ++s[s.length() - 1];
	}
	cout << s << endl;
	return 0;
}


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

using namespace std;

#define bug(x) cerr << #x << " = " << x << '\n'
#define ll     long long
#define maxn

int main() {
        //freopen(".inp","r",stdin);
        ll n, d;
        cin >> n >> d;

        int cnt = 0;
        for(int i = 1; i <= n; ++ i) {
            ll x, y;
            cin >> x >> y;
            ll p = x*x + y*y;
            if(p <= d*d) cnt ++;
        }
        cout << cnt;
}



Measured memory_bytes: 3540
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    k = int(input())
    a,b = map(int, input().split())
    for i in range(a,b+1):
        if i%k==0:
            print("OK")
            exit()
    print("NG")






if __name__=="__main__":
    main()


Measured memory_bytes: 62476
using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        int n = s.Length;


        int count1 = 0;
        {
            for (int i = 0; i < n; i++)
            {
                if (i % 2 == 0 && s[i] == '0')
                {
                    count1++;
                }
                else if (i % 2 == 1 && s[i] == '1')
                {
                    count1++;
                }
            }
        }

        int count2 = 0;
        {
            for (int i = 0; i < n; i++)
            {
                if (i % 2 == 0 && s[i] == '1')
                {
                    count2++;
                }
                else if (i % 2 == 1 && s[i] == '0')
                {
                    count2++;
                }
            }
        }
        Console.WriteLine(Math.Min(count1, count2));
    }
}


Measured memory_bytes: 13116
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<tuple>
#define lson (now<<1)
#define rson ((now<<1)|1)
#define mid ((nl+nr)>>1)
#define maxn 100005
using namespace std;
typedef long long ll;
int a[maxn];
int main()
{
	ll n,x,t;
	cin>>n>>x>>t;
	printf("%lld\n",(n%x!=0)*t+(n/x)*t);
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
int main() {
    // 入力は32bit整数に収まりません
    long long N, M;
    cin >> N >> M;
    // {S} より {c,c} の方が同じか多いかとき
    if (N <= M/2) {
        // N個は確実に作ることが出来て、c はM-2*N個余る
        // 余りを使って出来るだけSccを作る(c 4つで Scc 1つ)
        cout << N+(M-2*N)/4 << endl;
    }
    // {S} より {c,c} の方が少ないとき
    else {
        // c,c からSを作るという操作は無意味
        // ccのセット分以上のSがあるので作れるだけ作る
        cout << M/2 << endl;
    }
    return 0;
}


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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> p(N);
	for (int i = 0; i < N; ++i)
		cin >> p[i];
	sort(p.begin(), p.end());
	int sum = 0;
	for (int i = 0; i < K; ++i)
		sum += p[i];
	cout << sum;

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D,N;
  cin >> D >> N; 
  int Ans=0;
  if(N==100)
  Ans=std::pow(100,D)*(N+1);
  else Ans=std::pow(100,D)*N;
  cout << Ans << endl;
}

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

int main(){
  string s, zeihan, kouhan, condition;
  int n;
  cin >> s;
  n= s.size();
  
  for (int i=0; i<(n-1)/2; i++){
    if(s[i] != s[n-i-1]){
      cout << "No" << endl;
      return 0;
    }
  }
  
  zeihan = s.substr(0,(n-1)/2);
  kouhan = s.substr((n+1)/2,n-1);
  
  int k;
  
  if (((n-1)/2)%2 ==1){
    k=(((n-1)/2)-1)/2;
  } else{
    k= ((n-1)/2)/2;
  }
  
  for (int i=0; i< k; i++){
    if (zeihan[i] != zeihan[(n-1)/2-i-1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
)

func hasStr(S string, str string) bool {
        if len(str) <= len(S) {
                if S[len(S)-len(str):len(S)] == str {
                        return true
                }
        }
        return false
}

func main() {
        var S string
        fmt.Scan(&S)

        list := []string{"dream", "dreamer", "erase", "eraser"}
        for {
                tmp := S
                for _, v := range list {
                        if hasStr(S, v) {
                                S = S[:len(S)-len(v)]
                        }
                }
                if tmp == S {
                        break
                }
        }
        if len(S) == 0 {
                fmt.Println("YES")
                return
        }
        fmt.Println("NO")
}


Measured memory_bytes: 1280
fun main() {
    val k = nextLongList()[2]
    val a = nextLongList()
    val b = nextLongList()

    val aS = LongArray(a.size+1)
    aS[0] = 0
    for (i in 1..a.size) {
        aS[i] = a[i-1]+aS[i-1]
    }
    val bS = LongArray(b.size+1)
    bS[0] = 0
    for (i in 1..b.size) {
        bS[i] = b[i-1]+bS[i-1]
    }

    var max = 0
    var bIdx = b.size
    for (i in aS.indices) {
        if (aS[i] > k) break
        while (aS[i]+bS[bIdx] > k) {
            bIdx--
        }
        max = Math.max(max, i+bIdx)
    }

    println(max)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(' ')
fun nextIntList() = nextList().map { it.toInt() }
fun nextLongList() = nextList().map { it.toLong() }
fun nextDoubleList() = nextList().map { it.toDouble() }


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

using namespace std;

#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x) 
#define N 100005
#define MOD 1000000007
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;


int main() 
{
    fastIO;
    string s;
    int ans=700;
    cin>>s;
    for(int i=0;i<3;i++)
        if(s[i]=='o')
            ans+=100;
    cout<<ans<<"\n";
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define all(v,a,b) v.begin(a),v.end(b)
#define in cin>>
#define out cout<<
#define end <<endl
#define INF 1000000000000000

int main()
{
	int N;
	in N;
	vector<int> h(N);
	rep(i, N)
	{
		in h.at(i);
	}
	vector<long> ans(N);
	rep(i, N)
	{
		ans.at(i) = INF;
	}
	rep(i, N)
	{
		if (i == 0)
		{
			ans.at(i) = 0;
			continue;
		}
		else if (i == 1)
		{
			ans.at(i) = abs(h.at(i) - h.at(i - 1));
		}
		else
		{
			int a = ans.at(i - 2) + abs(h.at(i) - h.at(i - 2));
			int b = ans.at(i - 1) + abs(h.at(i) - h.at(i - 1));
			if (a < b)
			{
				ans.at(i) = a;
			}
			else
			{
				ans.at(i) = b;
			}
		}
	}
	out ans.at(N - 1) end;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int a,b;
int main() {
	scanf("%d%d",&a,&b);
	printf("%d\n",(a+b-3)/(a-1));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin>>a>>b>>c;
    if (a+b==c || a+c==b ||a==b+c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
a,b,m = map(int,input().split())
l_a = list(map(int,input().split()))
l_b = list(map(int,input().split()))
l_x = []
for i in range(m):
  l_x.append(list(map(int,input().split())))

#何も持っていないときの最小値
sonomama = min(l_a)+min(l_b)

#割引券を使ったときの最小値
l_warine = [sonomama]
for i in l_x:
  l_warine.append( l_a[ i[0]-1 ] + l_b[ i[1]-1 ] -i[2] )
print(min(l_warine))

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

void solve(long long X){
  long long sum = 0;
  long long i;
  for(i = 1; sum < X; i++){
    sum += i;
  }

  cout << (i-1) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
  scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N, R;
    cin >> N >> R;
    if(N >= 10){
        cout << R << endl;
    }
    else{
        cout << R + 100 * (10 - N) << endl;
    }

    return 0;
}

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

from collections import defaultdict
d = defaultdict(int)
for _ in range(n):
    d[int(input())] += 1

# 数字が奇数回現れたら残り、偶数回なら消える
ans = 0
for v in d.values():
    if v%2 == 1:
        ans += 1
print(ans)

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

// typedef long long ll;
int main() {
  int N;
  cin >> N;
  int H[N];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
    H[0]-=1;
  for (int i = 1; i < N; i++) {
    if (H[i-1] > H[i]) {
      cout << "No" << endl;
      return 0;
    } else {
      if (H[i] != H[i-1]) {
        H[i] = H[i]-1;
      }
    }
  }

  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[100100];
int n;

ll count(ll sum){
    ll num = 0;
    for(int i = 1; i < n; i++){
        ll a = A[i];
        if(sum > 0){
            sum += a;
            if(sum >= 0){
                num += (sum + 1);
                sum = -1;
            }
        }else{
            sum += a;
            if(sum <= 0){
                num += (-sum + 1);
                sum = 1;
            }
        }
    }
    return num;
}

int main(){
    ll num = 0;
    cin >> n;

    REP(i,n){
        ll a;
        cin >> a;
        A[i] = a;
    }

    if(A[0] != 0){
        if(A[0] > 0)
            num = min(count(A[0]), count(-1) + A[0] + 1);
        else
            num = min(count(A[0]), count(1) - A[0] + 1);
    }else{
        num = 1 + min(count(1), count(-1));
    }

    cout << num << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

#define LENGTH 25000

int mennseki(char *ascii,int length,int p,int q) {
	int hukami = 0,i;
	double a =0;
	
	for(i = p; i < q; i++) {
		if(ascii[i] == '/') {
			a += (double)hukami - 0.5;
			hukami--;
		} else if (ascii[i] == '\\') {
			a +=(double)hukami + 0.5;
			hukami++;
		} else if(ascii[i] =='_') {
			a += hukami;
		}
	}
	return a;
}

int main(void) {
	char ascii[LENGTH];
	int i,length,dis;
	int sum=0,num=0,alt=0,j=0;
    int height[LENGTH] = {0};
	int width[LENGTH] = {0};
	scanf("%s",ascii);
	
	for(length = 0; ; length++) {
		height[length] = alt;
		if(ascii[length] =='/') {
			alt++;
		} else if(ascii[length] == '\\') {
			alt--;
		} else if(ascii[length] == '\0') {
			break;
		}
	}
	    
	
	while(num < length) {
		while(ascii[num] != '\\' && num < length) {
			num++;
		}
		dis= num + 1;
		while(dis <= length && height[dis] != height[num]) {
			dis++;
		}
		if(dis <= length) {
			width[j++] = mennseki(ascii,length,num,dis);
			num = dis;
		} else {
			num++;
		}
	}
	
	for(i = 0; i <j; i++) {
		sum += width[i];
	}
	
	
	printf("%d\n%d", sum, j);
 
  for(i = 0; i < j; i++){
    printf(" %d", width[i]);
  }
  printf("\n");
 
  return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

ll calc(vvll& c, ll i, unordered_set<ll>& seen) {
  if(i == 1) {
    return 0;
  }
  
  //追加コスト最小を探す
  ll mcost = LLINF;
  rep(j, 10) {
    if(seen.find(j) == seen.end()) {
      seen.emplace(j);
      chmin(mcost, c[i][j] + calc(c, j, seen));
      seen.erase(j);
    }
  }
  
  return mcost;
}

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

  ll H, W;
  cin >> H >> W;
  
  vvll c(10, vll(10));
  rep(i, 10) {
    rep(j, 10) {
      cin >> c[i][j];
    }
  }
  
  vvll A(H, vll(W));
  rep(i, H) {
    rep(j, W) {
      cin >> A[i][j];
    }
  }
  
  vll mincost(10);  
  for(int i=0; i<=9; i++) {
    //if(i == 1) continue;
    unordered_set<ll> seen;
    seen.emplace(i);
    
    mincost[i] = calc(c, i, seen);
    //memo[i] = mincost[i];
  }

  ll totalcost = 0;
  rep(i, H) {
    rep(j, W) {
      if(A[i][j] != -1) {
        totalcost += mincost[A[i][j]];
      }
    }
  }
  
  fin(totalcost);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using P = pair<int, int>;
void prp(P& p) {cout << p.first << " " << p.second << endl;}
int dy[] = {-1, 1, 0, 0, 1, 1, -1, -1};
int dx[] = {0, 0, -1, 1, 1, -1, 1, -1};
int h, w;
int dist[22][22];
vector<string> s;

int bfs(int x, int y){
    dist[x][y] = 0;
    queue<P> que;
    que.push({x, y});

    int d = 0;
    int md = 0;
    while(!que.empty()){
        queue<P> n_que;
        d++;
        while(!que.empty()){
            int a, b;
            tie(a, b) = que.front(); que.pop();
            rep(i, 4){
                int da = a + dx[i];
                int db = b + dy[i];
                if(da < 0 || da >= h || db < 0 || db >= w) continue;
                if(s[da][db]=='#') continue;
                if(dist[da][db] <= d) continue;
                dist[da][db] = d;
                md = d;
                n_que.push({da, db});
            }
        }
        que = n_que;
    }


    return md;
}

int main()
{
    cin >> h >> w;
    s.resize(h);
    rep(i, h) cin >> s[i];

    int ans = 0;
    rep(i, h) rep(j, w){
        if(s[i][j]=='#') continue;
        rep(ii, h)rep(jj, w) dist[ii][jj] = INF;
        chmax(ans, bfs(i, j));
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 3564
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int, n)

	sum := 0
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
		sum += aa[i]
	}

	sort.Ints(aa)
	ans := sum

	if ans%10 == 0 {
		for i := 0; i < n; i++ {
			if aa[i]%10 == 0 {
				continue
			}
			ans -= aa[i]
			break
		}
		if ans%10 == 0 {
			ans = 0
		}
	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s;
  cin >> s;
  for (int i = 0; i < 26; ++i) {
    if (s.find('a'+i)==string::npos) {
      cout << (char)('a'+i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;
// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};
int main() {
    int n,q;
    cin >> n >> q;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i]--;
    vector<int> vec(n,-1);
    vector<vector<int>> range(n);
    rep(i,n) {
        int last = vec[a[i]];
        if (last != -1) range[last].push_back(i);
        vec[a[i]] = i;
    }
    vector<vector<P>> qs(n);
    rep(qi,q) {
        int l,r;
        cin >> l >> r;
        l--; r--;
        qs[l].emplace_back(r,qi); //x軸で走査するのでxをindexにとる。出力のためにクエリ番号を残す。上のrangeも構造を合わせた。
    }
    BIT<int> d(n);
    vector<int> ans(q);
    for (int x = n-1; x>=0 ; x--) {
        for (int y : range[x]) d.add(y,1);
        for (P query : qs[x]) {
            int qy = query.first, qn = query.second;
            ans[qn] = (qy-x+1) - d.sum(qy);
        }
    }
    rep(i,q) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 59988