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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


const int MOD = 1000000007;
const int MAX = 200100;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll pow(int x, int n){
    if(n == 0) return 1;
    ll res = pow(x*x%MOD, n/2);
    if(n%2 == 1) res *= x;
    return res;
}



int main()
{
    int n, k; cin >> n >> k;
    if(n<k) k=n;

    ll res = 0;

    COMinit();

    rep(i,k+1){
        ll ans = 1;
        ans *= COM(n-1,i);
        ans %= MOD;
        ans *= COM(n,i);
        res += ans;
        res %= MOD;
    }

    cout << res << endl;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main() {
    int n,m;
    cin>>n>>m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

int main(){
    char a;
    scanf("%c",&a);
    if(isupper(a)) printf("A");
    else printf("a");
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 3760
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
S = read()[:-1]

accum_ten = [0]
accum_sha = [0]
for i, s in enumerate(S):
    if s == '.':
        accum_ten.append(accum_ten[-1] + 1)
        accum_sha.append(accum_sha[-1])
    else:
        accum_ten.append(accum_ten[-1])
        accum_sha.append(accum_sha[-1] + 1)

ans = float('inf')

for i in range(N+1):
    left = accum_sha[i]
    right = accum_ten[-1] - accum_ten[i]
    ans = min(ans, left + right)
    # print(ans)

print(ans)


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

int main()
{
  string cl[9];
  int res[9], num[9];
  int n, m;
  for (int i = 0; i < 9; i++){
    cin >> cl[i] >> n >> m;
    num[i] = n + m;
    res[i] = n * 200 + m * 300;
  }

  for (int i = 0; i < 9; i++){
    cout << cl[i] << ' ' << num[i] << ' ' << res[i] << endl;
  }
  return (0);
}

Measured memory_bytes: 1204
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int a[7368792];
int main(){
    while(1){
        int m,n;

        scanf("%d%d",&m,&n);
        if(m == 0 && n == 0)
            break;

        REP(i,7368792)
            a[i] = 1;
 
        int start = m;

        int cou = 0;
        for(int i = start;cou < n;i++){
            if(a[i] == 1){
                cou++;
                for(int j = i;j <= 7368791;j+=i){
                    a[j] = 0;
                }
            }
        }
        int b;
        for(b = start;true;b++){
            if(a[b] == 1)
                break;
        }
        printf("%d\n",b);
    }
}

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

int main(void){
  int n, m;
  cin >> n >> m;

  vector<bool> flag(n + 1, false);
  vector<int> size(n + 1, 1);
  size[0] = 0;
  flag[1] = true;

  int x, y, cnt = 1;
  for(int i = 0; i < m; i++){
    cin >> x >> y;
    // もしxに赤ボールが入ってる可能性があって、
    // yがまだ赤ボールの可能性0だった場合
    if(flag[x] && !flag[y]){
      // 赤ボール入ってる可能性がある箱カウントを1増やす
      ++cnt;
      flag[y] = true;
    }
    if(size[x] != 0){
      ++size[y];
      --size[x];
      // 箱の中のボールが尽きたら、赤いボールが入ってる可能性を消す
      if(flag[x] && size[x] == 0){
        flag[x] = false;
        --cnt;
      }
    }
  }

  // 出力
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 640
#pragma warning (disable:4996)
#include"bits/stdc++.h"
#include<cassert>
#define int long long
#define MRE assert(0);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const long long mod = 1000000007;
const long long inf = 1e17;
typedef pair<int, int> P;
int a[3005], x[3005], y[3005];
int table[3005][3005];

int modpow(int a, int x) {
	int res = 1;
	while (x) {
		if (x & 1)res = res*a%mod;
		a = a*a%mod;
		x >>= 1;
	}
	return res;
}

const int inv2 = modpow(2, mod - 2);

signed main() {
	int n, q; cin >> n >> q;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, q) {
		cin >> x[i] >> y[i];
		x[i]--; y[i]--;
	}

	rep(i, n)rep(j, n)if (a[i] < a[j])table[i][j]++;

	rep(k, q) {
		//x[i]とy[i]をswap
		rep(l, n) {//(x,l)->(y,l)
			if (x[k] == l || y[k] == l)continue;
			table[x[k]][l] = table[x[k]][l] * inv2 % mod;
			table[y[k]][l] = table[y[k]][l] * inv2 % mod;
			table[l][x[k]] = table[l][x[k]] * inv2 % mod;
			table[l][y[k]] = table[l][y[k]] * inv2 % mod;
			int p1 = table[x[k]][l], p2 = table[y[k]][l], p3 = table[l][x[k]], p4 = table[l][y[k]];
			table[x[k]][l] = (table[x[k]][l] + p2) % mod;
			table[y[k]][l] = (table[y[k]][l] + p1) % mod;
			table[l][x[k]] = (table[l][x[k]] + p4) % mod;
			table[l][y[k]] = (table[l][y[k]] + p3) % mod;
		}
		table[x[k]][y[k]] = table[x[k]][y[k]] * inv2 % mod;
		table[y[k]][x[k]] = table[y[k]][x[k]] * inv2 % mod;
		int p1 = table[y[k]][x[k]], p2 = table[x[k]][y[k]];
		table[x[k]][y[k]] = (table[x[k]][y[k]] + p1) % mod;
		table[y[k]][x[k]] = (table[y[k]][x[k]] + p2) % mod;
	}
	int r = 0;
	rep(k, n) {
		for (int l = 0; l < k; l++) {
			r += table[k][l];
			r %= mod;
		}
	}

	cout << r*modpow(2, q) % mod << endl;
}

Measured memory_bytes: 70784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC121 {
	class ABC121_B {
		static void Main(string[] args) {
			var NMC = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
			var N = NMC[0];
			var M = NMC[1];
			var C = NMC[2];

			var B = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
			var Ai = new List<int[]>();
			for (int i = 0; i < N; i++) {
				Ai.Add(Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray());
			}

			var count = 0;
			foreach (var A in Ai) {
				var currentSum = 0;
				for (int i = 0; i < M; i++) {
					currentSum += A[i] * B[i];
				}
				if(currentSum+C > 0) {
					count++;
				}
			}

			Console.WriteLine(count);
		}
	}
}


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

using namespace std;

int main() {
	long long N;
	cin >> N; 
	long long N_2 = N;
	
	vector<long long> x; 
	for (long long i = 2; i*i <= N; i++) {
		int m = 0;
		while (N%i == 0) { // 素数で割り切れなくなるまで割っていく
			m++;//割った個数を配列に足す
			N /= i;
		}
		if (0 != m) {
			x.push_back(m);
		}
		if (1 == N) {
			break;
		}
	}
	if (1 != N) {
		x.push_back(1);
	}


	int nAns = 0;
	for (long long n = 0;n<x.size();++n) {
		int m = sqrt(2 * x[n]) - 1;
		int l = x[n] - ((1 + m) * m) / 2; 
		nAns += m;
		m++;
		while (m <= l){
			l -= m;
			m++;
			nAns += 1;
		}
	}

	std::cout <<nAns << endl;
	return 0;
}



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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	//何セット入るかを考える
	ll n ;
	cin >> n ;
	ll a, b; 
	cin >> a>> b; 
	ll chi = a + b;
	ll set = n / chi ;
	ll ans = set * a;
	n -= set * chi;
	
	//後n個おける
	ans += min(n,a);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    int h[100100];

    for(int i=0; i<n; i++) cin>>h[i];
    vector<long long> cost(n,0);
    cost[0]=0;

    for(int i=1; i<n; i++){
        long long tmp=INF;
        for(int j=1; j<=k; j++){
            if (i-j>=0) tmp=min(tmp,cost[i-j]+abs(h[i]-h[i-j]));
            else continue;
        }
        cost[i]=tmp;
    }
    cout<<cost[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 4496
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans=0;
  ll sum=0;
  ll sumx=0;
  for(ll i=0,j=0;i<n;i++){
    sum+=a[i];
    sumx^=a[i];
    while(sum!=sumx){
      sum-=a[j];
      sumx^=a[j];
      j++;
    }
    ans+=i-j+1;
  }
  cout << ans << endl;
}

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

using namespace std;

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

    int h[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", h + i);
    }

    int dp[n+1];
    dp[0] = 0;

    for(int i = 1; i < n; i++) {
        int m = dp[i-1] + abs(h[i] - h[i-1]);
        if(i > 1) {
            m = min(m, dp[i-2] + abs(h[i] - h[i-2]));
        }
        dp[i] = m;
    }

    printf("%d\n", dp[n-1]);
}

Measured memory_bytes: 1024
N = int(input())
if N % 2 == 1:
    print (0)
    exit()

B = N

#10の倍数が何個出てくるか-->純粋に0の数を数えている
count = N // 10
# print (count)

a = 50
while B >= a:
    count += B // a
    a *= 5

print (count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int N; 
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  int max = A.at(0);
  long long ans = 0;
  for(int i = 1; i < N; i++){
    if(A.at(i) < max){
      ans += max - A.at(i);
    }
    else{
      max = A.at(i);
    }
  }
 
    cout << ans << endl;
}

Measured memory_bytes: 4032
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s.at(0)!='A'){
		cout<<"WA"<<endl;
		return 0;
	}
	int m;
	m=0;
	for(int i=2;i<s.size()-1;i++){
		if(s.at(i)=='C'){
			m++;
		}
	}
	if(m!=1){
		cout<<"WA"<<endl;
		return 0;
	}
	int n;
	n=0;
	for(int i=0;i<s.size();i++){
		if(isupper(s.at(i))){
			n++;
		}
	}
	if(n!=2){
		cout<<"WA"<<endl;
		return 0;
	}
	cout<<"AC"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n,d;
    cin >> n >> d;
    d = 2 * d + 1;
    int ans = int(n /d);
    if(n %d != 0) ans ++;
    cout << ans << endl; 
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

// 0:R????????°????????§???, 1:L????????°????????§???
int dp[2001][2001][2];
const string LR="LR";

void calc(string s, int K)
{
    int S=s.size();
    memset(dp,0,sizeof(dp));
    rep(i,S)rep(j,K+1)rep(k,2)
    {
        // ??????????????????
        dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]+(s[i]==LR[(j%2+k+1)%2]));

        if(j<K)
        {
            // ????????????
            dp[i+1][j+1][k] = max(dp[i+1][j+1][k], dp[i][j][k]+(s[i]==LR[(j%2+k)%2]));
        }
    }
}

int main()
{
    cin.tie(0);ios::sync_with_stdio(false);
    
    string s;
    int K;
    cin >>s >>K;

    string x="",y="";
    rep(i,s.size())
    {
        if(s[i]=='L' || s[i]=='R') x+=s[i];
        else y+=(s[i]=='U')?'L':'R';
    }

    int X=x.size(), Y=y.size();
    // 0:R????????°????????§???, 1:L????????°????????§???
    int dx[2001]={};
    // 0:D????????°????????§???, 1:U????????°????????§???
    int dy[2001]={};

    calc(x,K);
    rep(i,K+1) dx[i]=max(2*dp[X][i][0]-X, 2*dp[X][i][1]-X);
    calc(y,K);
    rep(i,K+1) dy[i]=max(2*dp[Y][i][0]-Y, 2*dp[Y][i][1]-Y);

    int ans=0;
    rep(i,K+1)rep(j,K+1)if(i+j<=K) ans=max(ans,dx[i]+dy[j]);

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

Measured memory_bytes: 34468
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
struct sta { int x, y, d; };
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
int main() {
	int n, m; cin >> n >> m;
	char fie[52][52];
	sta now;
	rep(i, 52) {
		rep(j, 52) {
			fie[i][j] = '#';
		}
	}
	string s;
	P che;
	rep1(i, n) {
		cin >> s;
		rep1(j, m) {
			fie[i][j] = s[j - 1];
			if (fie[i][j] == 'G') {
				che = { i,j };
			}
			if (fie[i][j] == '^')now = { i,j,0 };
			if (fie[i][j] == '>')now = { i,j,1 };
			if (fie[i][j] == 'v')now = { i,j,2 };
			if (fie[i][j] == '<')now = { i,j,3 };
		}
	}
	int cnt = 0; int used[52][52] = {}; used[now.x][now.y] = 1;
	while (cnt < 50000) {
		cnt++; int nd = now.d;
		int nx = now.x+dx[(1+nd)%4]; int ny = now.y+dy[(1+nd)%4];
		if (fie[nx][ny] != '#') {
			used[nx][ny] = 1;
			now = { nx,ny,(1 + nd) % 4 };
			if (che == P{ nx,ny })break;
			continue;
		}
		nx = now.x + dx[nd]; ny = now.y + dy[nd];
		if (fie[nx][ny] != '#') {
			used[nx][ny] = 1;
			now = { nx,ny,nd };
			if (che == P{ nx,ny })break;
			continue;
		}
		nx = now.x + dx[(nd + 3) % 4]; ny = now.y + dy[(nd + 3) % 4];
		if (fie[nx][ny] != '#') {
			used[nx][ny] = 1;
			now = { nx,ny,(3 + nd) % 4 };
			if (che == P{ nx,ny })break;
			continue;
		}
		nx = now.x - dx[nd]; ny = now.y - dy[nd];
		if (fie[nx][ny] != '#') {
			used[nx][ny] = 1;
			now = { nx,ny,(nd+2)%4 };
			if (che == P{ nx,ny })break;
			continue;
		}
	}
	if (che == P{ now.x,now.y }) {
		int cnt = 0;
		rep(i, 52) {
			rep(j, 52) {
				if (used[i][j])cnt++;
			}
		}
		cout << cnt << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3140
let max l =
  let rec loop l res els =
    match l with
    | []      -> (res, els)
    | x :: xs -> if x > res then loop xs x (res :: els)
    else loop xs res (x :: els)
  in match l with
  | []      -> (0, [])
  | x :: xs -> loop xs x []
  ;;

let sort l =
  let rec loop l les =
    match l with
    | [] -> les
    | _  -> let (m, e) = max l in loop e (m :: les)
  in loop l []
  ;;

let rec print_list l =
  match l with
  | []      -> print_string "\n"
  | x :: xs -> print_int x; if xs <> [] then print_string " "; print_list xs
  ;;

let make_list a b c = a::(b::(c::[]));;

let () =
  Scanf.sscanf(read_line()) "%d %d %d" (
    fun a b c -> print_list (sort (make_list a b c))
    )
    ;;



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

int main(void) {
  int N, sum=0;
  cin >> N;
  int A[N], B[N], C[N-1];
  
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) cin >> B[i];
  for(int i=0; i<N-1; i++) cin >> C[i];
  
  for(int i=0; i<N-1; i++){
    bool flag=false;
    
    if(A[i+1]-A[i] == 1) flag=true;
    
    if(flag==true)
      sum += B[A[i]-1] + C[A[i]-1];
    else
      sum += B[A[i]-1];
  }
  
  sum += B[A[N-1]-1];
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
import math
from collections import deque
from collections import defaultdict

import bisect

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

q = readInt()
lr = []

maxNumber = 100000

for i in range(q):
	lr.append(readInts())


pri = get_sieve_of_eratosthenes(maxNumber)
simi = [0 for i in range(maxNumber+1)]
simi[3] = 1
for i in range(4,len(pri)):
	x = pri[i]
	if x!=0 and pri[(x+1)//2]!=0:
		simi[i] = simi[i-1]+1
	else:
		simi[i] = simi[i-1]

#print(simi[:10])

for item in lr:
	print(simi[item[1]]-simi[item[0]-1])

Measured memory_bytes: 31780
#include<cstdio>
#include<cstring>
#include<algorithm>
#define RI register int
#define CI const int&
using namespace std;
const int N=105;
int n,k; long long ans1,ans2; char s[N*3],t[N*3];
int main()
{
	RI i; for (scanf("%s%d",s+1,&k),n=strlen(s+1),i=1;i<=n;++i)
	s[i+n]=s[i+(n<<1)]=t[i]=t[i+n]=t[i+(n<<1)]=s[i];
	if (k==1)
	{
		for (i=2;i<=n;++i) if (s[i]==s[i-1]) s[i]='%',++ans1;
	} else
	{
		for (i=2;i<=(n<<1);++i) if (s[i]==s[i-1]) s[i]='%',++ans1; ans1*=(k>>1);
		if (s[n<<1]==s[1]) ans1+=(k>>1)-1; if (k&1) for (i=(n<<1)+1;i<=3*n;++i)
		if (s[i]==s[i-1]) s[i]='%',++ans1;
	}
	reverse(t+1,t+3*n+1);
	if (k==1)
	{
		for (i=2;i<=n;++i) if (t[i]==t[i-1]) s[i]='%',++ans2;
	} else
	{
		for (i=2;i<=(n<<1);++i) if (t[i]==t[i-1]) t[i]='%',++ans2; ans2*=(k>>1);
		if (t[n<<1]==t[1]) ans2+=(k>>1)-1; if (k&1) for (i=(n<<1)+1;i<=3*n;++i)
		if (t[i]==t[i-1]) t[i]='%',++ans2;
	}
	return printf("%lld",ans1<ans2?ans1:ans2),0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)

ll binpow(ll a, ll b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    cin>>s;
    if (s==to_lower(s))
        cout<<"a";
    else
        cout<<"A";
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int data[100],cnt=0,n,mini;
  cin >> n;
  for(int i=0;i<n;i++) cin >> data[i];
  for(int i=0;i<n;i++){
    mini = i;
    for(int j=i;j<n;j++){
      if(data[j]<data[mini]){
	mini = j;
      }
    }
    if(mini != i){
      cnt++;
      swap(data[i],data[mini]);
    }
  }
  for(int i=0;i<n;i++){
    cout << (i!=0?" ":"") << data[i];
  }
  cout << endl << cnt << endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;

constexpr ll INF = 1e18;

struct node {
    ll n;
    ll c;
    node (ll n, ll c) : n(n), c(c) {}
};

ll N, M;
vector<unordered_map<ll, vector<node> > > G;
vector<unordered_map<ll, ll> > dist;
queue<node> que;

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

    cin >> N >> M;

    G = vector<unordered_map<ll, vector<node> > >(N + 1);
    dist = vector<unordered_map<ll, ll> >(N + 1);

    for (ll i = 0; i < M; i++) {
        ll p, q, c;
        cin >> p >> q >> c;
        // move in same campanies
        G[p][c].push_back(node(q, c));
        G[q][c].push_back(node(p, c));

        // exit and enter
        G[p][c].push_back(node(p, 0));
        G[p][0].push_back(node(p, c));
        G[q][c].push_back(node(q, 0));
        G[q][0].push_back(node(q, c));

        dist[p][0] = INF;
        dist[q][0] = INF;
        dist[p][c] = INF;
        dist[q][c] = INF;
    }

    dist[N][0] = INF;

    que.push(node(1, 0));
    dist[1][0] = 0;
    while (!que.empty()) {
        auto token = que.front(); que.pop();
        
        for (auto r : G[token.n][token.c]) {
            ll newcost = dist[token.n][token.c];
            if (token.c == 0) {
                newcost++;
            }

            if (newcost < dist[r.n][r.c]) {
                dist[r.n][r.c] = newcost;
                que.push(node(r.n, r.c));
            }
        }
    }
    
    ll ans = dist[N][0];
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}



Measured memory_bytes: 95056
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
 
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long N, std::vector<long long> A, std::vector<long long> B){
  vector<pair<ll, ll>> C(N);
  REP(i, N) {
    C[i].first = -(A[i] + B[i]);
    C[i].second = i;
  }
  sort(ALL(C));
  ll ans = 0;
  REP(i, N) {
    if (i % 2 == 0) {
      ans += A[C[i].second];
    } else {
      ans -= B[C[i].second];
    }
  }
  std::cout << ans << std::endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 3328
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;




int main() {
 string t;
 int a;
 cin>>a;
 cin>>t;
 vector<char> s(30);
 s.at(0)='A';s.at(1)='B';s.at(2)='C';s.at(3)='D';s.at(4)='E';s.at(5)='F';s.at(6)='G';s.at(7)='H';s.at(8)='I';s.at(9)='J';s.at(10)='K';s.at(11)='L';s.at(12)='M';s.at(13)='N';s.at(14)='O';s.at(15)='P';s.at(16)='Q';s.at(17)='R';s.at(18)='S';s.at(19)='T';s.at(20)='U';s.at(21)='V';s.at(22)='W';s.at(23)='X';s.at(24)='Y';s.at(25)='Z';
int num;
rep(i,t.size()){
  rep(j,26){
    if(s.at(j)==t.at(i)){
      if(j+a<=25){
        cout<<s.at(j+a);
      }
      else{
        cout<<s.at(j+a-26);
      }
    }
  }
}
  cout<<endl;
}


Measured memory_bytes: 256
a = input()
b = input()
l = len(a)
aa = []
for i in range(l):
    aa.append(a[-1] + a[:-1])
for i in range(l):
    b = b[-1] + b[:-1]
    for j in aa:
        if b==j:
            print('Yes')
            break
    else:
        continue
    break
else:
    print('No')


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

int print_arr(vector<int> a, int n){
    for(int j=0; j<n; j++){
        cout << a[j];
        if(j<n-1){
            cout << " ";
        }
    }
    cout << endl;
    return 0;    
}

int insertion_sort(vector<int> a, int n){
    for(int i=1; i<n; i++){
        print_arr(a, n);
        int v = a[i];
        int j = i - 1;
        while(j>=0 and a[j]>v){
            a[j+1] = a[j];
            j--;
            a[j+1] = v;
        }
    }
    print_arr(a, n);
    return 0;
}

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    insertion_sort(a, n);
    return 0;
}


Measured memory_bytes: 3144
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int sum = 0;
        for(int i = 0; i < s; i++){
            int a = sc.nextInt();
            sum += a;
        }
        System.out.println(sum-s);
    }
}

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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

class UnionFind {
    vector<int> par, Size;

  public:
    UnionFind(int n) : par(n), Size(n) {
        rep(i, n) {
            par[i] = i;
            Size[i] = 1;
        }
    }

    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    bool same(int x, int y) { return root(x) == root(y); }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(Size[x] > Size[y]) {
            Size[x] += Size[y];
            par[y] = x;
        } else {
            Size[y] += Size[x];
            par[x] = y;
        }
    }

    int size(int x) { return Size[root(x)]; }
};

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

    int n, m, k;
    cin >> n >> m >> k;
    UnionFind UF(n + 1);
    int cnt[n + 1] = {};
    vector<int> x[n + 1];
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        UF.unite(a, b);
        cnt[a]++;
        cnt[b]++;
    }
    rep(i, k) {
        int a, b;
        cin >> a >> b;
        if(UF.same(a, b)) cnt[a]++, cnt[b]++;
    }
    FOR(i, 1, n + 1) cout << UF.size(i) - 1 - cnt[i] << " ";
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int A, B, C;
        public Dictionary<Tuple<int, int, int>, int> Dic;
        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                A = line[0];
                B = line[1];
                C = line[2];
            }
            
            Console.WriteLine(Solve());
        }

        public int Solve()
        {
            int count = 0;
            Dic = new Dictionary<Tuple<int, int, int>, int>();
            while (true)
            {
                // Judge & Memo
                var tpl = Tuple.Create(A, B, C);
                if (Dic.ContainsKey(tpl)) return -1;
                if ((A % 2 == 1) || (B % 2 == 1) || (C % 2 == 1)) return count;
                Dic.Add(tpl, 0);

                // Action
                int a = B / 2 + C / 2;
                int b = A / 2 + C / 2;
                int c = A / 2 + B / 2;
                A = a;
                B = b;
                C = c;
                count++;

            }
        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13396
#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>;

int main() {
	string s;
	cin >> s;
	string ans;
	rep(i, s.size()) ans += 'x';	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	char n;
	int a=0,b=0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='A')
		a++;
		else
		b++;
		
	}
	if(a==3||b==3)
	printf("No");
	else 
	printf("Yes");
} 

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

pair<long long, long long> ary[100010];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    ary[i].first = a;
    ary[i].second = b;
  }
  sort(ary, ary + N);
  unsigned long long res = 0;
  int cnt = M;
  for (int i = 0; i < N; i++) {
    if (cnt >= ary[i].second) {
      res += ary[i].first * ary[i].second;
      cnt -= ary[i].second;
    } else {
      res += ary[i].first * cnt;
      cnt = 0;
    }
    if (cnt == 0) break;
  }
  cout << res << endl;
}


Measured memory_bytes: 1792
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
a = 0

for s in range(1,k+1):
    for t in range(1,k+1):
        for u in range(1,k+1):
            
            a += gcd(s,t,u)

print(a)

Measured memory_bytes: 74852
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n,m;
    cin>>n>>m;
    map<ll,ll>mp;
    for(int i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        mp[x]++;
        mp[y]++;
    }
    for(int i=1;i<=n;i++)
    cout<<mp[i]<<"\n";}

Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v) {os << " [" << i++ << "]" << x; if (i % 10 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp) {os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll a, b, c, d;
  std::cin >> a >> b >> c >> d;

  ll ans = std::min(a, b) + std::min(c, d);
  print(ans);

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
typedef long long ll;
ll h,w,d[10][10],ans,a;
int main(void){
    cin>>h>>w;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>d[i][j];
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a;
            if(a!=-1)ans+=d[a][1];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
long long a[100005];
long long b[100005];
long long c[100005];
long long dp[3][100005];
int main() {
	int N; cin >> N;
	for (int i = 1; i <= N; i++) cin >> a[i] >> b[i] >> c[i];
	dp[0][1] = a[1];
	dp[1][1] = b[1];
	dp[2][1] = c[1];
	for (int i = 2; i <= N; i++) {
		dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a[i];
		dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + b[i];
		dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + c[i];
	}
	cout << max(dp[0][N], max(dp[1][N], dp[2][N])) << endl;
}


Measured memory_bytes: 4992
#include <iostream>

int main(){
    int a;
    int fi = 0, se = 0;
    for(int i=0;i<3;++i){
        std::cin>>a;
        if(a==5)fi++;
        if(a==7)se++;
    }
    if(fi==2 && se==1)std::cout<<"YES"<<std::endl;
    else std::cout<<"NO"<<std::endl;
}
    

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

using namespace std;
using ll = long long;
using pdd = pair <double, double>;

#define sf scanf
#define pf printf
#define F first
#define S second

int n;
vector <pdd> vec;

double dist(pdd a, pdd b) {
	double dx = a.F - b.F;
	double dy = a.S - b.S;
	return sqrt(dx * dx + dy * dy);
}

int main() {
	sf("%d", &n);
	for (int i = 0; i < n; i++) {
		double x, y;
		sf("%lf %lf", &x, &y);
		vec.push_back(pdd(x, y));
	}

	sort(vec.begin(), vec.end());
	double ans = 0;
	do {
		for (int i = 0; i < n - 1; i++) {
			ans += (dist(vec[i], vec[i + 1]));
		}
	} while (next_permutation(vec.begin(), vec.end()));

	for (int i = 1; i <= n; i++) {
		ans /= i;
	}

	pf("%0.10lf\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#define int long long
using namespace std;

int n, s[110], d[110];

signed main(){
	cin >> n;
	for(int i=0;i<n;i++){
		int ans = 0;
		cin >> s[i] >> d[i];
		while(1){
			if(d[i]==s[i]) break;
			if(d[i]-s[i]==1){
				ans++;
				break;
			}
			if(s[i]%2==0&&d[i]%2==0){
				s[i] /= 2;
				d[i] /= 2;
				continue;
			}
			if(s[i]%2){
				s[i]++;
				ans++;
			}
			if(d[i]%2){
				d[i]--;
				ans++;
			}
			
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
ll A,B,C;
ll GCD,LCM;
long long gcd(long long a,long long b){

    if(b%a==0) return a;

    else return gcd(b%a,a);

}
int main(void){
	ll a,b,c,d; cin>>a>>b>>c>>d;
	A=b/c-(a-1)/c; B=b/d-(a-1)/d;
	GCD=gcd(c,d);
	LCM=c*d/GCD;
	//cout<<LCM<<endl;
	C=b/LCM-(a-1)/LCM;
	ans=A+B-C;
	cout<<b-a+1-ans<<endl;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int main(){
	int a,b;
	cin>>a>>b;
	cout<<(a+b)%24;
	return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int a, b;

signed main(){
    cin >> a >> b;
    b += a * 3;
    cout << b / 2 << endl;

    return 0;
}
/*


*/

Measured memory_bytes: 764
// ABC 153-F
// 2020.1.26 bal4u

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

//typedef long long ll;
typedef int Int;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

Int in() {  // 整数の入力
	Int n = 0; int c;
	do c = gc();
	while (isspace(c));
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
}

#define INCmode   1  // 昇順ソート
//typedef long long Int;
void Usort(Int *a, int n) {
	int i, k;
#define B 8
#define BMSK 255 // (1<<8)-1
	Int t1[1 << B], t2[1 << B];
	
	Int *tmp = malloc(n * sizeof(Int));	
	for (k = 0; k < 8; ++k) {  // for 64ビット
//	for (k = 0; k < 4; ++k) {  // for 32ビット
		memset(t1, 0, sizeof(t1)), memset(t2, 0, sizeof(t2));
		for (i = 0; i < n; ++i)	t1[(a[i] >> k*B) & BMSK]++;
#if INCmode
		for (i = 0; i < BMSK; ++i) t1[i+1] += t1[i];
#else
		i = BMSK+1; while (--i) t1[i-1] += t1[i];
#endif
		i = n; while (i--) tmp[--t1[(a[i] >> k*B) & BMSK]] = a[i];
		k++;
		for (i = 0; i < n; ++i) t2[(tmp[i] >> k*B) & BMSK]++;
#if INCmode
		for (i = 0; i < BMSK; ++i) t2[i+1] += t2[i];
#else
		i = BMSK+1; while (--i) t2[i-1] += t2[i];
#endif
		i = n; while (i--) a[--t2[(tmp[i] >> k*B) & BMSK]] = tmp[i];
	}
	free(tmp);
// for (i = 0; i < n; ++i) printf("[%d] %lld\n", i, a[i]);
}

int N;
Int a[2000005];

int main()
{
	int i;
	
	N = in();
	for (i = 0; i < N; ++i) a[i] = in();
	Usort(a, N);
	out(a[0]);
	for (i = 1; i < N; ++i) pc(' '), out(a[i]);
	pc('\n');
	return 0;
}



Measured memory_bytes: 16984
//https://atcoder.jp/contests/abc065/tasks/arc076_b
//D - Built?
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}

template< typename T >
struct edge {
	int src, to;
	T cost;
	edge(int _to, T _cost) : src(-1), to(_to), cost(_cost) {}
	edge(int _src, int _to, T _cost) : src(_src), to(_to), cost(_cost) {}
	edge &operator=(const int &x) {
		to = x;
		return *this;
	}
	operator int() const { return to; }
};

template< typename T>
struct node {
	vector<edge<T>> edges;
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< node< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
bool operator<(const edge<T> &e, const edge<T> &f) { return e.cost > f.cost; }
template< typename T >
std::pair<T, Edges<T>> prim(const WeightedGraph<T> &g, int r = 0) {
  Edges<T> edges;
  T total = T();
  std::vector<int> vis(g.size());
  std::priority_queue<edge<T>> q;
  q.emplace(-1, r, 0);
  while (q.size()) {
    auto e = q.top();
    q.pop();
    if (vis[e.to]) continue;
    vis[e.to] = true;
    total += e.cost;
    if (e.src != -1) edges.emplace_back(e);
    for (auto &f : g[e.to].edges)
      if (!vis[f.to]) q.emplace(f);
  }
  return std::make_pair(total, edges);
}

int main() {
  ll N; cin>>N;
  using idp = pair<ll,ll>;
  vector<idp> xtbl, ytbl;
  FOR(i,0,N){
    ll x,y; cin>>x>>y;
    xtbl.push_back({i,x});
    ytbl.push_back({i,y});
  }
  sort(xtbl.begin(),xtbl.end(),[](auto& a, auto& b){ return a.second<b.second;});
  sort(ytbl.begin(),ytbl.end(),[](auto& a, auto& b){ return a.second<b.second;});

  WeightedGraph<ll> graph(N);
  FOR(i,0,N-1){
    const auto& s=xtbl.at(i);
    const auto& t=xtbl.at(i+1);
    graph.at(s.first).edges.emplace_back(s.first, t.first, abs(s.second-t.second));
    graph.at(t.first).edges.emplace_back(t.first, s.first, abs(s.second-t.second));
  }
  FOR(i,0,N-1){
    const auto& s=ytbl.at(i);
    const auto& t=ytbl.at(i+1);
    graph.at(s.first).edges.emplace_back(s.first, t.first, abs(s.second-t.second));
    graph.at(t.first).edges.emplace_back(t.first, s.first, abs(s.second-t.second));
  }

  auto mst = prim(graph);
  cout<<mst.first<<endl;

  return 0;
}

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

const ll INF = 1LL << 60;
ll n, s;

ll f(ll b, ll n) {
  ll res = 0;
  while (n) {
    res += n % b;
    n /= b;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> n >> s;
  if (s > n) {
    cout << -1 << endl;
    return 0;
  }
  if (s == n) {
    cout << n + 1 << endl;
    return 0;
  }
  for (ll i = 2; i * i <= n; i++) {
    if (f(i, n) == s) {
      cout << i << endl;
      return 0;
    }
  }
  ll ans = INF;
  for (ll i = 1; i * i < n; i++) {
    if (s - i < 0 || n - s + i < 0) continue;
    ll b = (n - s + i) / i;
    if (i < b && s - i < b && b > n / b && n == i * b + s - i) {
      ans = min(ans, b);
    }
  }
  cout << (ans == INF ? -1 : ans) << endl;

  return 0;
}

Measured memory_bytes: 256