akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include <cmath>
using namespace std;
int main(){
    int a,b;
    scanf("%d%d",&b,&a);
    int ta=a-1;
    int tb=b-1;
    a=a-1;
    b=b-1;
    printf("%d %d\n",2+int(ceil(a/50.0))*2+int(ceil(b/50.0))*2,100);
    for(int i=1;i<=100;i++)
        printf(".");
    printf("\n");
    for(int i=1;i<=int(ceil(a/50.0));i++){
        for(int j=1;j<=100;j++){
            if(j%2==1&&ta){
                printf("#");
                ta--;
            }
            else
                printf(".");
        }
        printf("\n");
        for(int j=1;j<=100;j++)
            printf(".");
        printf("\n");
    }
    for(int i=1;i<=100;i++)
        printf("#");
    printf("\n");
    for(int i=1;i<=int(ceil(b/50.0));i++){
        for(int j=1;j<=100;j++){
            if(j%2==1&&tb){
                printf(".");
                tb--;
            }
            else
                printf("#");
        }
        printf("\n");
        for(int j=1;j<=100;j++)
            printf("#");
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>

int main()
{
  int n, hmax, h;
  scanf("%d %d", &n, &hmax);
  int ans = 1;
  for (int i = 1; i < n; ++i)
  {
    scanf("%d", &h);
    if (hmax <= h)
    {
      hmax = h;
      ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

void solve(long long N, long long M, std::vector<long long> s, std::vector<long long> c)
{
    vector<int> a(N,-1);
    for(int i=0;i<M;i++)
    {
        if(a[s[i]-1]==-1)
            a[s[i]-1]=c[i];
        else if(a[s[i]-1]!=c[i])
        {
            cout<<-1<<endl;
            return;
        }
    }
    if(N==1&&a[0]<=0)
    {
        cout<<"0"<<endl;
        return;
    }
    if(N>1&&a[0]==0)
    {
        cout<<-1<<endl;
        return;
    }
    cout<<max(a[0],1);
    for(int i=1;i<N;i++)
        cout<<max(a[i],0);
    cout<<endl;
}

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


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int X,A,B;
  int N,O;
  
  scanf("%d %d %d",&X,&A,&B);
  
  N = X - A;
  O = N / B;
  N = N - B * O;
  
  printf("%d",N);
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<stdio.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main(){
  int n;
  std::cin >> n;
  std::vector<int> a(n+1);
  rep(i,n)std::cin >> a[i+1];
  std::vector<int> b(n+1);
  for (int i = n; i >=1; --i) {
    int sum=0;
    for (int j = i+i; j <=n; j+=i) {
      sum^=b[j];
    }
    b[i]=sum^a[i];
  }

  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (b[i]) ans.push_back(i);
  }
  cout << ans.size() << endl;
  rep(i,ans.size()) {
    printf("%d%c", ans[i], i+1==ans.size()?'\n':' ');
  }

  return 0;
}


Measured memory_bytes: 3064
n, k = list(map(int, input().split()))
s = list(input())

start = []
end = []
flag = True

m = 0

for i in range(n):
    if flag and s[i] == "1":
        flag = False
        start.append(i)
    elif not flag and s[i] == "0":
        flag = True
        end.append(i-1)

if len(start) <= 0 or start[0] != 0:
    start = [0] + start
    end = [0] + end

end.append(n-1)

#print(start, end)

if len(end) <= k:
    print(n)
else:
    m = 0
    for i in range(len(end)-k):
        m = max(m, end[i+k] - start[i] + 1)
    print(m)

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

int main(){
    string S;
    cin >> S;
    bool c=false,f=false;
    int ci=0,fi=0;
    rep(i,S.size()){
        if(!c && S[i] == 'C'){c = true; ci = i;} 
        if(S[i] == 'F'){f = true; fi = i;}
    }
    cout << (c & f && ci < fi ? "Yes" : "No") << endl;
    return 0;
}

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

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

string S;

int main(){
    cin >> S;
    rep(i,S.length())cout << "x";
    cout << endl;
    return 0;
}

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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) &= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  cin >> N;
  vec a(N);
  int cont[110];
  m0(cont);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    cont[a[i]]++;
  }

  sort(ALL(a));
  reverse(ALL(a));

  if (a[0] % 2 == 0) {
    if (cont[a[0] / 2] != 1) {
      cout << "Impossible" << endl;
      return 0;
    }
  } else {
    int mid = (a[0] + 1) / 2;
    if (cont[mid] != 2) {
      cout << "Impossible" << endl;
      return 0;
    }
  }

  for (int i = a[0]; i * 2 > a[0]; i--) {
    if (cont[i] < 2) {
      cout << "Impossible" << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long n,max1=-10000000000;
    long long r[200000];
    
    cin >> n;
    for (int i=0;i<n;i++)
        cin >> r[i];
    
    long long minj = 10000000000;
    for (int i=0;i<n;i++){
        max1 = max(r[i]-minj, max1);
        minj = min(r[i], minj);
    }
    
    cout << max1 <<endl;
}



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

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

int main(void) {
    int h, w;
    string c[100];

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    REP(i, h) {
        cin >> c[i];
    }

    REP(i, h) {
        REP(k, 2) {
            cout << c[i] << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, m, l, i, j, k;

	long long  a[100][100], b[1000][100], c[100][100] = { 0 };

	scanf("%d %d %d", &n, &m, &l);

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			
			scanf("%lld", &a[i][j]);
		}
	}

	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) {

			scanf("%lld", &b[i][j]);
		}
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			for (k = 0; k < l; k++) {

				c[i][k] += a[i][j] * b[j][k];
			}
		}
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			printf("%lld", c[i][j]);

			if (j < l - 1)
			{
				printf(" ");
			}
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n; sc(n)
    int A[n];
    for (int i = 0; i < n; i++) sc(A[i])
    ll cnt1 = 0, cnt2 = 0, sum = 0;
    for (int i = 0; i < n; i++){
        sum += A[i];
        if (i % 2 == 0){
            if (sum <= 0){
                cnt1 += abs(sum) + 1;
                sum += abs(sum) + 1;
            }
        }else {
            if (sum >= 0){
                cnt1 += abs(sum) + 1;
                sum -= abs(sum) + 1;
            }
        }
    }
    sum = 0;
    for (int i = 0; i < n; i++){
        sum += A[i];
        if (i % 2 == 1){
            if (sum <= 0){
                cnt2 += abs(sum) + 1;
                sum += abs(sum) + 1;
            }
        }else {
            if (sum >= 0){
                cnt2 += abs(sum) + 1;
                sum -= abs(sum) + 1;
            }
        }
    }
    cout << min(cnt1,cnt2) << endl;
    return 0;
}

Measured memory_bytes: 640
//in the name of god
#include <bits/stdc++.h>
using namespace std;
int a,b,x,y,n;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
        cin>>n;
        for(int i=0;i<n;++i){
             cin>>x>>y;
             if(x>a) a=x,b=y;
        }
        cout<<a+b;
	return cout<<endl,0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<class T> class Dijkstra {
public:
	int N;
	T inf;
	vector<T> cost;
	vector<vector<pair<T, int>>> edge;

	Dijkstra(const int N, T inf) : N(N), inf(inf),cost(N), edge(N) {
	}

	void make_edge(int from, int to, T w) {
		edge[from].push_back({ w,to });
	}

	void solve(int start) {
		for(int i = 0; i < N; ++i) cost[i] = inf;

		priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
		cost[start] = 0;
		pq.push({ 0,start });

		while (!pq.empty()) {
			T v = pq.top().first;
			int from = pq.top().second;
			pq.pop();
			for (auto u : edge[from]) {
				T w = v + u.first;
				int to = u.second;
				if (w < cost[to]) {
					cost[to] = w;
					pq.push({ w,to });
				}
			}
		}
		return;
	}
};

void solve(){
    vector<double> x, y, r;
    REP(i,2){
        double a, b;
        cin >> a >> b;
        x.emplace_back(a);
        y.emplace_back(b);
        r.emplace_back(0);
    }
    int N;
    cin >> N;
    REP(i,N){
        double a, b, c;
        cin >> a >> b >> c;
        x.emplace_back(a);
        y.emplace_back(b);
        r.emplace_back(c);
    }
    Dijkstra<double> dijk(N+2, LINF);
    REP(i,N+2) REP(j,N+2) if(i != j){
        dijk.make_edge(i, j, max(0.0, hypot(x[i]-x[j], y[i]-y[j]) - (r[i] + r[j])));
    }
    dijk.solve(0);
    printf("%.12lf\n", dijk.cost[1]);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 22256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for i in range(A + 1):
  for j in range(B + 1):
    for k in range(C + 1):
      if i * 500 + j * 100 + k * 50 == X:
        ans += 1
print(ans)

Measured memory_bytes: 3060
n = int(input())
xs = [int(x) for x in input().split()]
M = 10**9 + 7
r = 0
for i in range(61):
    k = 0
    for x in xs:
        k += (x >> i) % 2
    r = (r + ((n-k) * k % M) * pow(2, i) )% M

print(r)


Measured memory_bytes: 122876
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        for(int i = 0; i <1000000; i++){
            if(a <= b*i){
                System.out.print(i);
                break;
            }
        }
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#include <iostream> 
#include <stdio.h>
#define MAX 200005
typedef long long ll; 
using namespace std; 
int main () 
{

    int k; 
    cin >> k; 
    string s; 
    cin >> s;
    string ans;  

    string dots("...");

    if (k >= s.length())
    {
        cout << s << endl; 
    }
    else 
    {
        cout << s.substr(0,k) << "..." << endl; 
    }
     
    return 0; 
}


Measured memory_bytes: 3648
//E.H//
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,k;
ll arr[100005];
ll ps[100005],psposi[100005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        ps[i]=ps[i-1] + arr[i];
        psposi[i]=psposi[i-1] + max(0LL,arr[i]);
    }
    ll temp=0;
    int awal=-1;
    for(int i=k;i<=n;i++){
        ll x=max(0LL,ps[i]-ps[i-k]);
        x+=psposi[i-k];
        x+=(psposi[n]-psposi[i]);
        if(x>temp){
            temp=x;
            awal=i-k+1;
        }
    } 
    cout<<temp<<endl;

}

Measured memory_bytes: 5992
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int n,sum;
    while(~scanf("%d",&n))
    {

        if(n>2)
        {
            sum=n/3;
        }

        else
        {
            sum=0;
        }

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

    }
    return 0;
}


Measured memory_bytes: 384
N = int(input())
dict_s = {}
for var in range(N):
    s = input()
    if s in dict_s:
        dict_s[s] += 1
    else:
        dict_s[s] = 1

M = int(input())
for var in range(M):
    t = input()
    if t in dict_s:
        dict_s[t] -= 1

if max(dict_s.values()) < 0:
    print(0)
else:
    print(max(dict_s.values()))

Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

int main(){
  string S;
  cin >> S;
  ll N = S.length();

  ll cost[2] = {};
  rep(i, 2){
    ll first = i;
    rep(j, N){
      if(S[j] - '0' != first) cost[i]++;
      first = 1 - first;
    }
  }
  ll ans = cost[0] < cost[1] ? cost[0] : cost[1];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long int ll;
ll a[200005];
ll sum1,sum2;
ll hq;
ll mi;
int n;
int main()
{
    while(~scanf("%lld",&n))
    {
        sum1 = 0;
        sum2 = 0;
        for(int i = 0;i<n;i++)
        {
            scanf("%lld",a+i);
            sum2 += a[i];
        }
        for(int i = 0;i<n - 1;i++)
        {
            sum1 += a[i];
            sum2 -= a[i];
            mi = sum1 - sum2;
            if(mi < 0)
            {
                mi = -mi;
            }
            if(i == 0||mi<hq)
            {
                hq = mi;
            }
        }
        printf("%lld\n",hq);
    }
    return 0;
}


Measured memory_bytes: 1792
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();

void main()
{
    auto n = lread();
    bool check;
    foreach (i; iota(1, 10))
        check |= !(n % i) && (n / i < 10);
    if (check)
        writeln("Yes");
    else
        writeln("No");
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> x >> a >> b;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(x*a < b) ans = x*a;
  else ans = b;
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int isPalindrome(string s)
{
    int n=sz(s);
    for (int i=0;i<n;++i)
    {
        if (s[i]!=s[n-1-i])
        {
            return 0;
        }
    }
    return 1;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    string s,t="";
    cin>>s;
    n=sz(s);
    if (!isPalindrome(s))
    {
        cout<<"No";
        return 0;
    }
    for (int i=0;i<((n-1)/2);++i)
    {
        t+=s[i];
    }
    if (!isPalindrome(t))
    {
        cout<<"No";
        return 0;
    }
    t.clear();
    for (int i=((n/2)+1);i<n;++i)
    {
        t+=s[i];
    }
    if (!isPalindrome(t))
    {
        cout<<"No";
        return 0;
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
string S; char C;
int main() {
	while (true) {
		cin >> S >> C; string D;
		if (C == 'X')break;
		if (C == 'L') {
			for (int i = 0; i < S.size(); i++) {
				if (S[i] == '_') {
					i++; if (S[i] <= 'Z')D += S[i];
					else D += (char)(S[i] - 32);
				}
				else {
					D += S[i];
				}
			}
			if (D[0] <= 'Z')D[0] += 32;
		}
		if (C == 'U') {
			for (int i = 0; i < S.size(); i++) {
				if (S[i] == '_') {
					i++; if (S[i] <= 'Z')D += S[i];
					else D += (char)(S[i] - 32);
				}
				else {
					D += S[i];
				}
			}
			if (D[0] > 'Z')D[0] -= 32;
		}
		if (C == 'D') {
			for (int i = 0; i < S.size(); i++) {
				if (S[i] <= 'Z' && i >= 1) { D += '_'; }
				if (S[i] <= 'Z') { D += (char)(S[i] + 32); }
				else { D += S[i]; }
			}
		}
		cout << D << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n+1]={0};
  for(int i=0;i<k;i++)
  {
    int d;
    cin>>d;
    for(int j=0;j<d;j++)
    {
      int x;
      cin>>x;
      a[x]++;
    }
  }
  int ans=0;
  for(int i=1;i<=n;i++)
  {
    if(a[i]==0)
      ans++;
  }
  cout<<ans;
  return 0;
}
  


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

int main(){
  long N,K;cin>>N>>K;
  long M=(N-1)*(N-2)/2;
  if(K>M){cout<<-1;return 0;}
  vector<string>out;
  for(long i=1;i<N;i++){
    out.push_back("1 "+to_string(i+1));
  }
  for(long i=1;i<N;i++){
    for(long j=i+1;j<N;j++){
      if(M==K){
        cout<<out.size()<<endl;
        for(long i=0;i<out.size();i++)cout<<out[i]<<endl;
        return 0;
      }
      out.push_back(to_string(i+1)+" "+to_string(j+1));
      M--;
    }
  }
  
  cout<<out.size()<<endl;
  for(long i=0;i<out.size();i++)cout<<out[i]<<endl;
}

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

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define dbg(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

template <typename Arg1> ostream& operator << (ostream& out, const vector<Arg1> &a) {out<<"[ ";for(const auto &x:a)out<<x<<" ";return out<<"]";}


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

    ll n;
    cin>>n;
    ll ans = 0;
    if(n%2 == 1){
        cout<<0<<endl;
        exit(0);
    }

    ll m=5;
    n/=2;
    while(n>=m){
        ans += n/m;
        m*=5;
    }
    cout<<ans<<endl;

    timer();
    return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int down[]={'0','A'-10,'a'-36};

int getIndex(char c){
	int index;
	if(c>= '0' && c<='9'){
		index = c - down[0];
	}
	if(c>= 'A' && c<='Z'){
		index = c - down[1];
	}
	if(c>= 'a' && c<='z'){
		index = c - down[2];
	}
	return index;
}

int main(){
	int n;
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		char output[62];
		rep(i,10){
			output[i] = '0'+i;
		}
		rep(i,26){
			output[i+10] = 'A'+i;
		}
		rep(i,26){
			output[i+36] = 'a'+i;
		}

		char a,b;
		rep(i,n){
			cin >> a >> b;
			output[getIndex(a)] = b;
		}

		int m;
		cin >> m;
		string s="";
		char c;
		rep(i,m){
			cin >> c;
			s += output[getIndex(c)];
		}

		cout << s << endl;
	}
}

Measured memory_bytes: 1336
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll a,b,c,d,ans=-INFLL;
	std::cin >> a >> b;
	std::cin >> c >> d;
	ans = std::max(ans,a*c);
	ans = std::max(ans,a*d);
	ans = std::max(ans,b*c);
	ans = std::max(ans,b*d);
	std::cout << ans << std::endl;
	return 0;
}


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

int main(){
    unordered_map<int, int>  mp = unordered_map<int, int>();
    unsigned long long int sum = 0;
    int n, q, buf1, buf2;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> buf1;
        mp[buf1]++;
        sum += buf1;
    }
    cin >> q;
    for(int i=0; i<q; i++){
        cin >> buf1 >> buf2;
        sum -= (buf1 -buf2) * mp[buf1];
        mp[buf2] += mp[buf1];
        mp[buf1] = 0;
        cout << sum << endl;
    }
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int a,b;cin >>a>>b;
    string s;cin >>s;
    int n=s.size();
    bool flg=true;
    for (int i = 0; i < n; ++i) {
        if(i==a){
            if(s[i]!='-')flg=false;
        }
        else {
            if (s[i] == '-')flg = false;
        }
    }
    if(flg)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	unsigned long long int n, h;
	cin >> n >> h;
	vector<unsigned long long int> b;
	unsigned long long int max_a = 0, a_b = 0;
	for (int i = 0; i < n; ++i) {
		unsigned long long int tmpa, tmpb;
		cin >> tmpa >> tmpb;
		if (tmpa > max_a) {
			b.push_back(a_b);
			max_a = tmpa;
			a_b = tmpb;
		}
		else {
			b.push_back(tmpb);
		}
	}

	sort(b.rbegin(), b.rend());
	unsigned int count = 0;
	for (auto i : b) {
		if (i <= max_a) break;
		h -= i;
		++count;
		if (h <= a_b) {
			if (h > 0) ++count;
			cout << count << endl;
			return 0;
		}
	}

	if (max_a > a_b) {
		while (h > 0) {
			h -= max_a;
			++count;
		}
	}
	else {
		while (h > a_b) {
			h -= max_a;
			++count;
		}
		++count;
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1400
from collections import deque
def mbfs(S,H,W,d):
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    while(len(d)!=0):
        h=d[0][0]
        w=d[0][1]
        x=d[0][2]
        d.popleft()
        for di in range(4):
            nh=h+dx[di]
            nw=w+dy[di]
            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
                continue
            if(S[nh][nw]=='#'):
                continue
            S[nh][nw]='#'
            d.append([nh,nw,x+1])
    return x
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
d=deque()
for i in range(H):
    for j in range(W):
        if(A[i][j]=='#'):
            d.append([i,j,0])
print(mbfs(A,H,W,d))


Measured memory_bytes: 176092
#include <algorithm>
#include <cmath>
#include <iostream>
#include <utility>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  while (b > 0) {
    ll mod = a % b;
    a = b;
    b = mod;
  }
  return a;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll d = gcd(a, b);
  ll ans = 1;
  for (ll i = 2; i < ceil(sqrt(d)) + 1; i++) {
    if (d % i == 0) {
      ans += 1;
      while (d % i == 0) {
        d /= i;
      }
    }
  }
  if (d != 1) ans += 1;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

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

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n;
  cin >> n;
  string s;
  cin >> s;
  string s1, s2;
  s1 = s.substr(0, n);
  s2 = s.substr(n, n);
  reverse(ALL(s2));
  map<pair<string, string>, ll> left;
  map<pair<string, string>, ll> right;
  REP(i, (ll)pow(2, n))
  {
    string red = "";
    string blue = "";
    REP(j, n)
    {
      // red
      if ((i >> j) & 1 == 1)
      {
        red.push_back(s1[j]);
      }
      else
      {
        blue.push_back(s1[j]);
      }
    }
    if (left.find({red, blue}) == left.end())
    {
      left[{red, blue}] = 1;
    }
    else
    {
      left[{red, blue}]++;
    }
  }
  REP(i, (ll)pow(2, n))
  {
    string red = "";
    string blue = "";
    REP(j, n)
    {
      // red
      if ((i >> j) & 1 == 1)
      {
        red.push_back(s2[j]);
      }
      else
      {
        blue.push_back(s2[j]);
      }
    }
    if (right.find({red, blue}) == right.end())
    {
      right[{red, blue}] = 1;
    }
    else
    {
      right[{red, blue}]++;
    }
  }
  ll res = 0;
  for (auto p : left)
  {
    if (right.find(p.first) != right.end())
    {
      res += p.second * right[p.first];
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 91904
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) 
{ v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i]; }
template<class T, class U> void read_n(vector<pair<T, U>>& v, size_t n)
{ v = vector<pair<T, U>>(n); 
  for (lli i=0; i<n; ++i) cin >> v[i].first >> v[i].second; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, a, b;
vector<lli> p;
int main() {
  cin >> n >> a >> b;
  read_n(p, n);
  lli c1=0, c2=0, c3=0;
  for (auto x : p) {
    if (x <= a) c1++;
    else if (x <= b) c2++;
    else c3++;
  }
  lli ans = min({c1, c2, c3});
  cout << ans << endl;
  return 0;
}


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

int main(){
	int a,b;
    cin>>a>>b;
    float i;
   for(i=1;i<1010;i++){
        if(floor(i*0.08)==a && floor(i*0.10)==b){
       cout<<i<<endl;
        break;
    }
}
  if(i==1010){
     cout<<-1<<endl;
   }
	return 0;
}


Measured memory_bytes: 256
import Data.List
main = do
  [a, b, c', d'] <- fmap read . words <$> getLine
  let [c, d] = sort [c', d']
      ac = (a-1) `div` c
      ad = (a-1) `div` d
      acd = (a-1) ` div` lcm c d
      acd' = a - (ad + ac - acd)
      bc = b `div` c
      bd = b `div` d
      bcd = b ` div` lcm c d
      bcd' = b - (bd + bc - bcd)
  print $ bcd' - acd' + 1


Measured memory_bytes: 508
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def solve(A):
    ans = 0
    s = A[0]
    for a in A[1:]:
        prev, s = s, s + a
        if prev > 0 and s >= 0:
            ans += s + 1
            s = -1
        if prev < 0 and s <= 0:
            ans += -s + 1
            s = 1

    return ans


def main():
    N, *A = map(int, read().split())

    if A[0] > 0:
        ans1 = solve(A)
        ans2 = A[0] + 1
        A[0] = -1
        ans2 += solve(A)
        ans = min(ans1, ans2)
    elif A[0] < 0:
        ans1 = solve(A)
        ans2 = -A[0] + 1
        A[0] = 1
        ans2 += solve(A)
        ans = min(ans1, ans2)
    else:
        A[0] = 1
        ans1 = solve(A) + 1
        A[0] = -1
        ans2 = solve(A) + 1
        ans = min(ans1, ans2)

    print(ans)

    return


if __name__ == '__main__':
    main()


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

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())

typedef long long ll;

using namespace std;

int main(){
  int n, a, b;
  cin >> n;

  if(n == 1){
    cout << "Hello World" << endl;
  }else{
    cin >> a >> b;
    cout << a + b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
//#define int long long
#define ALL(x) begin(x),end(x)
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
int H, W;
char m[60][60];
/*signed*/int main(void) {   
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> m[i][j];
        }
    }
    bool ans = true;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (m[i][j] == '#') {
                if (m[i - 1][j] == '.' && m[i + 1][j] == '.' && m[i][j - 1] == '.' && m[i][j + 1] == '.') ans = false;
            }
        }
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, A, B;
  cin >> N >> A >> B;
  if (A > B) {
    cout << 0 << '\n';
  } else if (N == 1) {
    cout << (A == B ? 1 : 0) << '\n';
  } else {
    cout << ((N - 1) * B + A) - ((N - 1) * A + B) + 1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using ld = long double;

const int N = 1e5;

int n;
vi g[N];
int a[N];
int xr[1 << 15];
int dp[1 << 15];

int32_t main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//ifstream cin("in.txt");
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		g[u].pb(w);
		g[v].pb(w);
	}
	for (int u = 0; u < n; u++) {
		for (int e : g[u]) {
			a[u] ^= e;
		}
	}
	sort(a, a + n);
	int ans = n;
	vi rem;
	for (int i = 0; i < n; i++) {
		if (!a[i]) {
			ans--;
		}
		else if (i < n - 1 && a[i] == a[i + 1]) {
			ans--;
			i++;
		}
		else {
			rem.pb(a[i]);
		}
	}
	n = sz(rem);
	for (int msk = 1; msk < (1 << n); msk++) {
		dp[msk] = -n;
		for (int i = 0; i < n; i++) {
			if ((msk >> i) & 1) {
				xr[msk] ^= rem[i];
			}
		}
	}
	for (int msk = 1; msk < (1 << n); msk++) {
		for (int s = msk; s > 0; s = (s - 1) & msk) {
			if (!xr[s]) {
				dp[msk] = max(dp[msk], 1 + dp[msk ^ s]);
			}
		}
	}
	cout << ans - dp[(1 << n) - 1];
}


Measured memory_bytes: 6776
h,w= map(int, input().split())
maze= [list(input()) for i in range(h)]

# 白いマスの数
ans=0
for i in range(h):
    for j in range(w):
        if maze[i][j]=='.':
            ans+=1



import collections
from collections import deque
def clear_maze(sx, sy, gx, gy):

    INF=-10**9
    distance = [[INF for i in range(w+2)] for j in range(h+2)]
    #    distance = [[None]*field_x_length]*field_y_length
    def bfs():
        d = deque()
        d.append((sx, sy))
        distance[sx][sy] = 0

        while len(d):
            x, y = d.popleft()
            if x == gx and y == gy:
                break
            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

                if 0 <= nx<h and  0 <= ny<w:
                    if maze[nx][ny] != '#' and distance[nx][ny] == INF:
                        d.append((nx, ny))
                        distance[nx][ny] = distance[x][y] + 1

        return distance[gx][gy]

    return bfs()

v=clear_maze(0,0,h-1,w-1)
INF=-10**9
if v!=INF:
    print(ans-v-1)
else:
    print(-1)

Measured memory_bytes: 40688
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
#define mp(a, b) make_pair(a, b)
#define fir first
#define sec second
template <class T> inline void read(T &a) {
	static int ch = 0; bool f = 0; a = 0;
	while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
	while (ch >= '0' && ch <= '9') a = a * 10 + ch - '0', ch = getchar();
	if (f) a = -a;
}
//#define MULTI_CASE
#define MOD
#define N 20005
int n;
int p[N], a[N], b[N], pre[N], suf[N];

void work() {
	cin >> n;
	for (int i = 1; i <= n; i++) read(p[i]);
	for (int i = 1; i <= n; i++) a[i] = i, b[i] = n - i + 1;
	for (int i = 1; i <= n; i++) {
		pre[p[i]] += i;
		suf[p[i]] += i;
	}
	for (int i = 1; i <= n; i++) pre[i] += pre[i - 1];
	for (int i = n; i >= 1; i--) suf[i] += suf[i + 1];
	for (int i = 1; i <= n; i++) printf("%d%c", a[i] + pre[i], i == n ? '\n' : ' ');
	for (int i = 1; i <= n; i++) printf("%d%c", b[i] + suf[i], i == n ? '\n' : ' ');
}


int main() {
#ifdef MULTI_CASE
	int T;
	cin >> T;
	for (int i = 1; i <= T; i++) {
		printf("Case %d: ", i);
		work();
	}
#else
	work();
#endif
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int mod = 1e9 + 7;

ll gcd(ll x, ll y){
	while(1){
		if(x < y) swap(x, y);
		if(!y) break;
		x %= y;
	}
	return x;
}

int main(){
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll lcm = c * d / gcd(c, d);
	ll p = (a-1)/c + (a-1)/d - (a-1)/lcm;
	ll q = b/c + b/d - b/lcm;
	cout << (b - q) - (a-1 - p) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////

//　各数字を1に変えるのに必要な魔力を求めたい
//　全点対最短経路　ワーシャルフロイド O(V^3)

vector<Vl> G(10, Vl(10));

int main() {
    ll h, w; cin >> h >> w;
    rep(i, 0, 10){
        rep(j, 0, 10){
            cin >> G[i][j];
        }
    }
    Vl a(h*w);
    rep(i, 0, h*w) cin >> a[i];

    rep(k, 0, 10){
        rep(i, 0, 10){
            rep(j, 0, 10){
                chmin(G[i][j], G[i][k]+G[k][j]);
            }
        }
    }
    ll ans = 0;
    rep(i, 0, h*w){
        if(a[i] == -1) continue;
        ans += G[a[i]][1];
    }
    co(ans);

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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 int mod = MOD;
const int max_n = 2000050;
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n ) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(max_n);
int main(){
  ll h,w,r,c;cin >> h >> w >> r >> c;
  mint ans=comb(h-1+w-1,w-1);
  rep(i,r){
    mint x=comb(h-r+i+c-1,c-1);
    x*=comb(r-1-i+w-c-1,w-c-1);
    ans-=x;
  }
  cout << ans <<endl;
}

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

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; }
#define rep(i, n) for(int i = 0; i < n; i++)

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

const int INF = 1 << 29;
const ll LINF = 1LL << 60;

int main()
{
	vector<int>a(3);
	rep(i, 3)  cin >> a[i];
	sort(a.begin(), a.end());
	
	int x, y;
	x = a[2] - a[0];
	y = a[2] - a[1];

	int cnt = y;
	if ((x - y) % 2 == 1) {
		cnt += (x - y) / 2;
		cnt += 2;
	}
	else {
		cnt += (x - y) / 2;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import math
[A,B,H,M]=[int(i)for i in input().split()]
#print(A, B, H, M)
totalhun=H*60+M
zisinkakudo=totalhun/720*360
hunsinkakudo = M * 6
#print(hunsinkakudo,zisinkakudo)
aidanokakudo=min(zisinkakudo-hunsinkakudo,360-(zisinkakudo-hunsinkakudo))
c=(A**2+B**2-2*A*B*math.cos(math.radians(aidanokakudo)))**(0.5)
print(c)

Measured memory_bytes: 9504
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
char s[100010], t[100010];
int smb1[100010], smb2[100010], sma1[100010], sma2[100010];
int main(){
  int q, a, b, c, d, tp1, tp2, tmp1, tmp2;
  scanf("%s%s",s,t);
  int sz=strlen(s);
  for(int i=sz; i>0; --i){
    s[i]=s[i-1];
  }
  sz=strlen(t);
  for(int i=sz; i>0; --i){
    t[i]=t[i-1];
  }
  smb1[0]=sma1[0]=smb2[0]=sma2[0]=0;
  sz=strlen(s);
  for(int i=1; i<=sz; ++i){
    smb1[i]=smb1[i-1]+(s[i]=='B');
    sma1[i]=sma1[i-1]+(s[i]=='A');
//    cout<<i<<" "<<smb1[i]<<" "<<sma1[i]<<" "<<s[i]<<endl;
  }
  sz=strlen(t);
  for(int i=1; i<=sz; ++i){
    smb2[i]=smb2[i-1]+(t[i]=='B');
    sma2[i]=sma2[i-1]+(t[i]=='A');
  }
  cin>>q;
  for(int i=0; i<q; ++i){
    scanf("%d%d%d%d",&a,&b,&c,&d);
    tp1=smb1[b]-smb1[a-1];
    tp2=sma1[b]-sma1[a-1];
    if(tp2>tp1){
      tmp1=(tp2-tp1)%3;
    }
    else{
      tmp1=(tp1-tp2);
      tmp1+=3;
      if(tmp1%2){
        tmp1-=3;
        tmp1/=2;
      }
      else{
        tmp1/=2;
      }
      tmp1%=3;
    }
//    cout<<tp1<<","<<tp2<<"==";
    tp1=smb2[d]-smb2[c-1];
    tp2=sma2[d]-sma2[c-1];
    if(tp2>tp1){
      tmp2=(tp2-tp1)%3;
    }
    else{
      tmp2=(tp1-tp2);
      tmp2+=3;
      if(tmp2%2){
        tmp2-=3;
        tmp2/=2;
      }
      else{
        tmp2/=2;
      }
      tmp2%=3;
    }
//    cout<<tp1<<","<<tp2<<endl;
    if(tmp1==tmp2){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
  }
  return 0;
}




Measured memory_bytes: 2304
package main

import (
	"fmt"
)

func win(c int) int {
	return (c + 3 - 1) % 3
}

func main() {
	var n, k int
	var r, s, p int
	var t string
	fmt.Scan(&n)
	fmt.Scan(&k)
	fmt.Scan(&r)
	fmt.Scan(&s)
	fmt.Scan(&p)
	fmt.Scan(&t)

	toInt := map[rune]int{'r': 0, 's': 1, 'p': 2}
	points := []int{r, s, p, 0}
	robot := []rune(t)

	score := 0

	for i := 0; i < k; i++ {
		prev := win(toInt[robot[i]])
		score += points[prev]

		for j := i + k; j < n; j += k {
			c := win(toInt[robot[j]])
			if c == prev {
				prev = 3
				continue
			}
			prev = c
			score += points[prev]
		}
	}
	fmt.Println(score)
}

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

int main(int argc, char* argv[]) {

	int arr[9][4];
	int nums[5];
	int i, j, k;
	int count = 8;
	int sum;
	char str[10];
	
	scanf("%d", &nums[0]);

	nums[1] = nums[0] / 1000;
	nums[2] = (nums[0] / 100) % 10;
	nums[3] = (nums[0] / 10) % 10;
	nums[4] = nums[0] % 10;

	arr[1][1] = 1;
	arr[1][2] = 1;
	arr[1][3] = 1;

	arr[2][1] = 0;
	arr[2][2] = 1;
	arr[2][3] = 1;

	arr[3][1] = 1;
	arr[3][2] = 0;
	arr[3][3] = 1;

	arr[4][1] = 1;
	arr[4][2] = 1;
	arr[4][3] = 0;

	arr[5][1] = 0;
	arr[5][2] = 1;
	arr[5][3] = 0;

	arr[6][1] = 0;
	arr[6][2] = 0;
	arr[6][3] = 1;

	arr[7][1] = 1;
	arr[7][2] = 0;
	arr[7][3] = 0;

	arr[8][1] = 0;
	arr[8][2] = 0;
	arr[8][3] = 0;
	for(i = 1; i <= 8; i++) {
		sum = nums[1];
		for(j = 1; j <= 3; j++){
			if(arr[i][j] == 1) {
				sum += nums[1 + j];
			} else if(arr[i][j] == 0) {
				sum -= nums[1 + j];
			}
		}
		if(sum == 7) {
			for(k = 1; k <= 3; k++) {
				if(arr[i][k] == 1) {
					str[2 * k] = '+';
				} else {
					str[2 * k] = '-';
				}
			}
			str[1] = nums[1] + 48;
			str[3] = nums[2] + 48;
			str[5] = nums[3] + 48;
			str[7] = nums[4] + 48;
			str[8] = '=';
			str[9] = '7';
			str[10] = '\0';
			printf("%s", str+1);
			return 0;
		}
	}





	return 0;
}

Measured memory_bytes: 128