akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;

int *g;
int par(int x) { return g[x] == x ? x : g[x] = par(g[x]); }
void merge(int a, int b) {
    g[par(a)] = par(b);
}

int main(){
    int n, m, a, b;
    cin >> n >> m;
    int p[n], q[n], idx[n+1];
    g = new int[n];
    for(int i = 0; i < n; i++){
        cin >> p[i];
        g[i] = i;
        idx[p[i]] = i;
    }
    for(int i = 0; i < n; i++) q[i] = i+1;
    while(m--){
        cin >> a >> b;
        a--; b--;
        merge(a, b);
    }
    int r = 0;
    for(int i = 0; i < n; i++){
        if(p[i] != q[i]){
            if(par(idx[q[i]]) == par(i)){
                r++;
            }
        } else r++;
    }
    cout << r << '\n';
    delete[] g;
}


Measured memory_bytes: 1792
// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}

using namespace std;

typedef long long ll;
inline int in(){int x;scanf("%d",&x);return x;}

int way[999][999];

const int INF = 1 << 28;

int W, H;

struct Info {
  int x, y;
  int cost;
  Info(int x, int y, int cost) : x(x), y(y), cost(cost) {}
  bool operator<(const Info& rhs) const {
    return make_pair(x, y) < make_pair(rhs.x, rhs.y);
  }
  bool operator==(const Info& rhs) const {
    return make_pair(x, y) == make_pair(rhs.x, rhs.y);
  }
  int index() const {
    return y * W + x;
  }
  bool inBounds() const {
    return 0 <= x && x < W && 0 <= y && y < H;
  }
};

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

int bfs()
{
  const Info goal(W - 1, H - 1, -1);
  queue<Info> Q;
  Q.push(Info(0, 0, 1));
  set<Info> vis;
  while (!Q.empty()){
    queue<Info> nQ;
    while (!Q.empty()){
      auto& info = Q.front();
      Q.pop();
      if (info == goal) return info.cost;
      for (int d = 0; d < 4; d++){
        Info nxt = info;
        nxt.x += dx[d];
        nxt.y += dy[d];
        nxt.cost++;
        if (!nxt.inBounds()) continue;
        if (!way[info.index()][nxt.index()]) continue;
        if (vis.count(nxt)) continue;
        vis.insert(nxt);
        nQ.push(nxt);
      }
    }
    swap(Q, nQ);
  }
  return 0;
}

int main()
{
  while (W = in(), H = in()){
    memset(way, 0, sizeof(way));
    for (int x = 0; x < W - 1; x++){
      if (in() == 0) way[x][x + 1] = way[x + 1][x] = 1;
    }
    for (int y = 1; y < H; y++){
      for (int x = 0; x < W; x++){
        if (in() == 0) way[y * W + x][y * W + x - W] = way[y * W + x - W][y * W + x] = 1;
      }
      for (int x = 0; x < W - 1; x++){
        if (in() == 0) way[y * W + x][y * W + x + 1] = way[y * W + x + 1][y * W + x] = 1;
      }
    }
    cout << bfs() << endl;
  }
  return 0;
}

Measured memory_bytes: 5168
import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,k=INTM()
    a=LIST()
    vst=[0]*n
    vst[0]=1
    loop=[]
    temp=1
    for i in range(k):
        temp=a[temp-1]
        if vst[temp-1]==0:
            vst[temp-1]=1
        elif vst[temp-1]==1:
            loop.append(temp)
            vst[temp-1]=2
        else:
            temp=loop[-1]
            cost=k-i
            break
        if i==k-1:
            cost=0
    if cost!=0:
        print(loop[(cost-1)%len(loop)])
    else:
        print(temp)
                    
                
if __name__ == '__main__':
    do()

Measured memory_bytes: 51020
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

class P
{
    static void Main()
    {
        int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] h = Enumerable.Repeat(0, nk[0]).Select(_ => int.Parse(Console.ReadLine())).OrderBy(x => x).ToArray();

        int min = int.MaxValue;
        for (int i = 0; i <= nk[0] - nk[1]; i++)
        {
            min = Min(min, Abs(h[i] - h[i + nk[1] - 1]));
        }
        Console.WriteLine(min);
    }
}

Measured memory_bytes: 18652
#include <stdio.h>
int main(){
  char a[4],b[4];
  scanf("%s\n%s",a,b);
  for(int i=0;i<3;i++){
    if(a[i]!=b[2-i]){
      printf("NO");
      return 0;
    }
  }
  printf("YES");
  return 0;
}


Measured memory_bytes: 128
#include <string>
#include <iostream>
using namespace std;
  
void itom(int num){
  int a=num/1000;
  if(a>1)cout<<a;
  if(a>0)cout<<'m';
  num%=1000;
 
  a=num/100;
  if(a>1)cout<<a;
  if(a>0)cout<<'c';
  num%=100;
 
  a=num/10;
  if(a>1)cout<<a;
  if(a>0)cout<<'x';
  num%=10;
 
  a=num;
  if(a>1)cout<<a;
  if(a>0)cout<<'i';
 
  cout<<endl;
}

int mtoi(string s){

    int res = 0;
    int mul = 1;
    for (int i=0; i<s.size(); i++) {
        if (s[i] >= '2' && s[i] <= '9') {
            mul = (int) s[i] - (int) '0';
        } else {
            switch (s[i]) {
                case 'm':
                    res += mul * 1000;
                    break;
                case 'c':
                    res += mul * 100;
                    break;
                case 'x':
                    res += mul * 10;
                    break;
                default:
                    res += mul;
            }
            mul = 1;
        }
    }
    return res; 
}

int main() {
    int n, aa, bb, cc;
    cin >> n;
    for(int i=0;i<n;i++) {
        string s1, s2;
        cin >> s1 >> s2;
        
        aa=mtoi(s1);
        bb=mtoi(s2);
        cc=aa+bb;
        
        itom(cc);
    }
    return 0;
}

Measured memory_bytes: 1212
#include "cmath"
#include "iostream"
long long dp[102][100003];
int main() {
    int N, W;
    scanf("%d%d", &N, &W);
    long long v, w;
    for(int i = 1; i <= W; i++)
        dp[0][i] = -1;
    dp[0][0] = 0;
    for(int i = 1; i <= N; i++) {
        scanf("%lld%lld", &w, &v);
        for(int j = 0; j <= W; j++) {
            dp[i][j] = dp[i - 1][j];
            if(j - w >= 0)
                dp[i][j] = std::max(dp[i][j], dp[i - 1][j - w] + v);
        }
    }
    long long answer = 0;
    for(auto i : dp[N]) answer = std::max(i, answer);
    printf("%lld", answer);
}

Measured memory_bytes: 82612
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380
int main() {
	cout << fixed << setprecision(10);
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<int> > a(h, vector<int>(w, 0));
	vector<vector<int> > s(h + 1, vector<int>(w + 1, 0));

	REP(y, h) {
		string str;
		cin >> str;
		REP(x, w) {
			a[y][x] = str[x] == '1';
		}
	}

	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] - s[i][j] + a[i][j];

	int ans = INF;

	REP(i, 1 << (h-1)) {
		vector<int> split;
		split.push_back(0);
		REP(j, h - 1) {
			if (i & (1 << j))split.push_back(j + 1);
		}
		split.push_back(h);



		int cnt = 0;
		int pre = 0;
		int idx = 1;
		while (idx <= w) {
			REP(j, split.size() - 1) {
				int all = s[split[j + 1]][idx]
					- s[split[j + 1]][pre]
					- s[split[j]][idx]
					+ s[split[j]][pre];

				if (k < all) {
					if (pre == idx - 1) {
						cnt = INF;
						idx = INF;
						break;
					}
					cnt++;
					pre = idx - 1;
					break;
				}
			}
			idx++;
		}
		chmin(ans, cnt + split.size() - 2);
	}
	cout << ans;

	return 0;
}

/**
4 10 2
1110010010
1000101110
0011101001
1101000111
*/

Measured memory_bytes: 384
N,K = map(int,(input().split()))
x = list(map(int,(input().split())))
n = [0]
p = [0]
ans = []
if 0 in x:
    K -= 1
for i in range(N):
    if x[i] < 0:
        n.append(x[i])
    if x[i] > 0:
        p.append(x[i])
n.sort(reverse=True)
for i in range(K+1):
    if i < len(n) and K-i < len(p):
        ans.append(min(abs(n[i])*2 + p[K-i], abs(n[i]) + p[K-i]*2))
print(min(ans))

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

int main(){
    int R, C, N;
    scanf("%d %d %d", &R, &C, &N);
    vector<vector<int>> po(N, vector<int>(4));
    for (int i = 0; i < N; i++) scanf("%d %d %d %d", &po[i][0], &po[i][1], &po[i][2], &po[i][3]);
    vector<pair<int, int>> ps;
    for (int i = 0; i < N; i++) {
        if (po[i][0] == 0) ps.push_back({po[i][1], i});
        else if (po[i][1] == C) ps.push_back({C+po[i][0], i});
        else if (po[i][0] == R) ps.push_back({R+2*C-po[i][1], i});
        else if (po[i][1] == 0) ps.push_back({2*C+2*R-po[i][0], i});
        if (po[i][2] == 0) ps.push_back({po[i][3], i});
        else if (po[i][3] == C) ps.push_back({C+po[i][2], i});
        else if (po[i][2] == R) ps.push_back({R+2*C-po[i][3], i});
        else if (po[i][3] == 0) ps.push_back({2*C+2*R-po[i][2], i});
    }
    sort(ps.begin(), ps.end());
    vector<bool> use(N, false), two(N, false);
    for (int i = 0; i < (int)ps.size(); i++) {
        if (use[ps[i].second]) two[ps[i].second] = true;
        else use[ps[i].second] = true;
    }
    bool check = true;
    fill(use.begin(), use.end(), false);
    stack<int> st;
    for (int i = 0; i < (int)ps.size(); i++) {
        int now = ps[i].second;
        if (!two[now]) continue;
        if (!use[now]) {
            st.push(now);
            use[now] = true;
        }
        else {
            if (st.top() != now) {
                check = false;
                break;
            }
            st.pop();
        }
    }
    printf(check ? "YES\n" : "NO\n");
    return 0;
}

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

struct Scc {
  const int V;
  vector<vector<int> > G, revG;
  vector<int> order;

  vector<int> vs;
  vector<bool> used;

  Scc(int v) : V(v), G(v), revG(v), order(v), used(v) { }

  void add_edge(int from, int to) {
    G[from].push_back(to);
    revG[to].push_back(from);
  }

  void dfs(int v) {
    used[v] = true;
    for(int to : G[v]) {
      if(used[to] == false) dfs(to);
    }
    vs.push_back(v);
  }

  void rdfs(int v, int k) {
    used[v] = true;
    order[v] = k;
    for(int to : revG[v]) {
      if(used[to] == false) rdfs(to, k);
    }
  }

  int compute() {
    vs.clear();
    used.assign(V, false);
    for(int i = 0; i < V; i++) {
      if(used[i] == false) dfs(i);
    }

    int k = 0;
    reverse(vs.begin(), vs.end());
    used.assign(V, false);

    for(int v : vs) {
      if(used[v] == false) rdfs(v, k++);
    }

    return k;
  }
};

int main() {
  int V, E; cin >> V >> E;
  Scc g(V);
  for(int i = 0; i < E; i++) {
    int f,t; cin >> f >> t;
    g.add_edge(f,t);
  }
  int v = g.compute();
  cout << (v != V ? 1 : 0) << endl;
}

Measured memory_bytes: 1244
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int N; cin>>N;
    vec x(N),y(N);
    rep(i,N) cin>>x[i]>>y[i];
    map<P,int> mp;
    rep(i,N){
        FOR(j,i+1,N){
            mp[(P){x[i]-x[j],y[i]-y[j]}]++;
            mp[(P){x[j]-x[i],y[j]-y[i]}]++;
        }
    }
    int ans=0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        ans=max(ans,itr->second);
    }
    cout<<N-ans<<endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;

import static java.lang.Character.isUpperCase;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int H = in.nextInt();
        int A = in.nextInt();
        if(H%A==0)
        {
            System.out.println(H/A);
        }
        else
            {
                System.out.println(H/A+1);
            }


    }


 }












Measured memory_bytes: 35712
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CStringTransformation solver = new CStringTransformation();
        solver.solve(1, in, out);
        out.close();
    }

    static class CStringTransformation {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String x = in.next();
            String y = in.next();
            int xx[] = new int[26];
            int yy[] = new int[26];
            for (int i = 0; i < x.length(); i++) {
                xx[x.charAt(i) - 'a']++;
                yy[y.charAt(i) - 'a']++;
            }
            Arrays.sort(xx);
            Arrays.sort(yy);
            for (int i = 0; i < 26; i++) {
                if (xx[i] != yy[i]) {
                    out.println("No");
                    return;
                }
            }
            out.println("Yes");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 27744
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextString() string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	s := nextString()
	flag := false
	for i := 1; i < len(s); i++ {
		if s[i-1] == s[i] {
			flag = true
			break
		}
	}

	if flag {
		_, _ = fmt.Fprint(writer, "Bad")
	} else {
		_, _ = fmt.Fprint(writer, "Good")
	}
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

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

 	ll n;
 	cin >> n;
 	string a, b;
 	cin >> a >> b;
 	for(int i=0;i<n;i++) cout << a[i] << b[i];
 	cout << endl;   
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>

using namespace std;

int main(){
    int N;
    cin >> N;
    if(N==25){
        cout << "Christmas" << endl;
    }
    else if(N==24){
        cout << "Christmas Eve" << endl;
    }
    else if(N==23){
        cout << "Christmas Eve Eve" << endl;
    }
    else if(N==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int N, A[100];
  int sum=0;
  int mini;
  int i, j, k;

  //Read N and setA
  scanf("%d", &N);
  for(i=0; i<N; i++)scanf("%d", &A[i]);

  //Begin Selection Sort
  for(i=0; i<N; i++)
    {
      mini=i;
      for(j=i; j<N; j++)
	{
	  if(A[j]<A[mini])
	    mini=j;
	}
      //swap
      if(mini!=i)
	{
	  k=A[i];
	  A[i]=A[mini];
	  A[mini]=k;
	  sum++;
	}
    }

  //print
  for(i=0; i<N; i++)
    {
      if(i!=N-1)printf("%d ", A[i]);
      else printf("%d", A[i]);;
    }
  printf("\n%d\n", sum);

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

int main(){
    char w[10], t[1000];
    int i, count = 0;
    
    scanf("%s", w);
    while(scanf("%s", t)){
    	if (strcmp(t, "END_OF_TEXT") == 0) break;
        for (i = 0; i < strlen(t); i++) t[i] = tolower(t[i]);
        if (strcmp(w,t) == 0) count++;
    }
    printf("%d\n", count);
    
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1<<28;
//たどり着けたら時間まで目標地点と１歩先を行き来する
//行き来に2秒かかるのでちょうど戻れないとダメ
int main(){

    ll N, M; cin >> N >> M;

    //1000円
    for(ll i = 0; i <= N; i++){
        //5000円
        for(ll j = 0; j <= N - i; j++){
            //cout << i << " " << j << endl;
            ll zan = M - (i * 1000) - (j * 5000);
            ll k = zan / 10000;
            if(zan % 10000 != 0) continue;
            if(i + j + k == N){
                cout << k << " " << j << " " << i << endl;
                return 0;
            }
        }      
    }

    cout << "-1 -1 -1" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
using ll = long long;
using P = pair<int,int>;

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

  cout << max({a+b, a-b, a*b}) << endl;
  return 0;
}



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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    if (a < 6)
        b = 0;
    if (a < 13)
        b >>= 1;
    cout << b;            
    return 0;
}
                

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

long long int N;
long long int A;

unordered_map<long long int,long long int> mp;


bool ok(long long int val,int num){
	long long int res=1;
	long long int u=val/num;
	long long int addi=val%num;
	if(u==0)return false;
	for(int i=0;i<num;i++){
		long long int mul=u;
		if(addi){
			mul++;
			addi--;
		}
		if((N+mul-1LL)/mul<=res){
			return true;
		}
		res*=mul;
	}
	return N<=res;
}
int main(){
	cin>>N>>A;
	long long int ans=LLONG_MAX;
	for(int i=0;i<=200;i++){
		long long int tim=A*(long long int)(i);
		long long int cn=i+1;
		long long int mint=1;
		long long int maxt=N*cn;
		while(mint+1LL<maxt){
			long long int mid=(mint+maxt)/2LL;
			if(ok(mid,cn)){
				maxt=mid;
			}
			else{
				mint=mid;
			}
		}
		if(ok(mint,cn)){
			maxt=mint;
		}
		else{
			mint=maxt;
		}
		ans=min(ans,mint+tim);
		//printf("%lld\n",ans);
	}
	printf("%lld\n",ans);
	return 0;
}


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

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

typedef long long ll;
using namespace std;

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

  int A, B;
  cin >> A >> B;

  cout << max(A - 2 * B, 0) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a, b, d, r;
    double f;
    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
    printf("%d %d %f\n", d, r, f);
    return 0;
}


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

int main() {
  int64_t n;
  std::cin >> n;
  std::multiset<int64_t> a;

  for (int64_t i = 0; i < n; i++) {
    int64_t t;
    std::cin >> t;
    a.insert(t);
  }

  int64_t count = 0;
  while (a.cbegin() != a.cend()) {
    const auto v = *a.cbegin();
    const auto n = a.count(v);
    if (v <= n) {
      count += n - v;
    } else {
      count += n;
    }
    a.erase(v);
  }

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

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

using namespace std;

const long long MOD=1000000007;

long long add_mod(long long x,long long y){
	return (x+y)%MOD;
}

long long sub_mod(long long x,long long y){
	return (x-y+MOD)%MOD;
}

long long mul_mod(long long x,long long y){
	return x*y%MOD;
}

int n;
long long dp[100001][13];

void solve(){
    int i,j,k;
    string str;
    cin >> str;
    dp[0][0] = 1;
    for(i = 0;i < str.length();i++){
        if(str[i] == '?'){
            for(j = 0;j < 13;j++){
                for(k = 0;k <= 9;k++){
                    dp[i+1][(j*10+k)%13] = add_mod(dp[i+1][(j*10+k)%13],dp[i][j]);
                }
            }
        }
        else{
            k = str[i] - '0';
            for(j = 0;j < 13;j++){
                dp[i+1][(j*10+k)%13] = add_mod(dp[i+1][(j*10+k)%13],dp[i][j]);
            }
        }
    }
    long long ans = 0;
    cout << dp[str.length()][5] << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 10624
A = sorted(list(map(int, input().split())), reverse=True)

if all([i % 2 == 0 for i in A]) or all([i % 2 == 1 for i in A]):
    print((A[0] - A[1] + A[0] - A[2]) // 2)
else:
    if [i % 2 == 0 for i in A].count(True) == 2:
        for i in range(3):
            if A[i] % 2 == 0:
                A[i] += 1
        print((A[0] - A[1] + A[0] - A[2]) // 2 + 1)
    else:
        for i in range(3):
            if A[i] % 2 == 1:
                A[i] += 1
        print((A[0] - A[1] + A[0] - A[2]) // 2 + 1)

Measured memory_bytes: 8964
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	auto logN = (int)floor(log2(N));
	vector<vector<int>> parent(logN + 1, vector<int>(N, -1));

	vector<ll> x(N);
	for (auto& temp : x)
	{
		cin >> temp;
	}

	ll L;
	cin >> L;

	auto r = 0;
	for (auto l = 0; l < N; ++l)
	{
		while (r < N && (x[r] - x[l]) <= L)
		{
			++r;
		}

		parent[0][l] = r - 1;
	}

	for (auto i = 0; i < logN; ++i)
	{
		for (auto j = 0; j < N; ++j)
		{
			if (parent[i][j] >= 0)
			{
				parent[i + 1][j] = parent[i][parent[i][j]];
			}
		}
	}

	int Q;
	cin >> Q;

	vector<int> ans;
	for (auto i = 0; i < Q; ++i)
	{
		int a, b;
		cin >> a >> b;
		--a;
		--b;

		if (a > b)
		{
			swap(a, b);
		}

		auto l = 0;
		auto h = N;
		while (l <= h)
		{
			auto mid = (l + h) / 2;
			auto p = a;
			for (auto j = logN; j >= 0; --j)
			{
				if (((mid >> j) & 1) > 0)
				{
					p = parent[j][p];

					if (p < 0)
					{
						p = N;
						break;
					}
				}
			}

			if (p >= b)
			{
				h = mid - 1;
			}
			else
			{
				l = mid + 1;
			}
		}

		ans.push_back(l);
	}

	for (auto temp : ans)
	{
		cout << temp << endl;
	}

	return 0;
}

Measured memory_bytes: 11912
N = int(input())
A = list(map(int, input().split()))

# if N % 2 == 0: #偶数のとき
#     B = [0] * (N // 2 + 1)
#     W = [0] * (N // 2 + 1)
#     for i in range(N // 2):
#         B[i + 1] = B[i] + A[2 * i]
#     for i in range(N // 2 - 1, -1, -1):
#         W[i] = W[i + 1] + A[2 * i + 1]

#     # print (B)
#     # print (W)

#     ans = 0
#     for i in range(N // 2 + 1):
#         ans = max(ans, B[i] + W[i])

#     print (ans)
#     exit()

DP0 = [[-10 ** 16] * 2 for _ in range(N + 1)]
DP1 = [[-10 ** 16] * 2 for _ in range(N + 1)]
DP2 = [[-10 ** 16] * 2 for _ in range(N + 1)]

DP0[N][0] = 0 #右端の外側を0に設定してスタート

for i in range(N - 1, -1, -1):
    a = A[i]
    
    DP0[i][0] = DP0[i + 1][1]
    DP0[i][1] = DP0[i + 1][0] + a

    DP1[i][0] = max(DP1[i + 1][1], DP0[i + 1][0])
    DP1[i][1] = DP1[i + 1][0] + a

    DP2[i][0] = max(DP2[i + 1][1], DP1[i + 1][0])
    DP2[i][1] = DP2[i + 1][0] + a
    
if N % 2 == 1:
    print (max(DP1[0][0], DP2[0][1]))
else:
    print (max(DP0[0][0], DP1[0][1]))

# for i in DP0:
#     print (i)

# for i in DP1:
#     print (i)

# for j in DP2:
#     print (j)

Measured memory_bytes: 98196
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

def insertionsort(a, n, g):
    global c
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j = j - g
            c += 1
        a[j + g] = v

c = 0
g = [1]
while g[-1] * 3 + 1 < n:
    g.append(g[-1] * 3 + 1)
g.reverse()
for i in range(len(g)):
    insertionsort(a, n, g[i])
print(len(g))
print(" ".join(map(str, g)))
print(c)
for i in range(n):
    print(a[i])


Measured memory_bytes: 45508
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


int acc[1024][1001];


int main()
{
	int n, m;
	while (~scanf("%d%d", &n, &m))
	{
		int road[n][n];
		rep(i, n) rep(j, n) road[i][j] = INF;
		rep(i, m)
		{
			int a, b, c, d;
			scanf("%d,%d,%d,%d", &a, &b, &c, &d);
			road[a - 1][b - 1] = c;
			road[b - 1][a - 1] = d;
		}
		int x1, x2, y1, y2;
		scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
		rep(k, n) rep(i, n) rep(j, n)
		{
			road[i][j] = min(road[i][j], road[i][k] + road[k][j]);
		}
		cout << y1 - y2 - road[x1 - 1][x2 - 1] - road[x2 - 1][x1 - 1] << endl;
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

int w, h;

string field[100];

bool check[100][100];

string search(int y, int x){
	if(y < 0 || x < 0 || y >= h || x >= w){
		return "";
	}
	if(check[y][x]){
		return "";
	}
	if(field[y][x] != '.'){
		string ret = " ";
		ret[0] = field[y][x];
		return ret;
	}
	check[y][x] = true;
	
	return search(y - 1, x) + search(y + 1, x) + search(y, x - 1) + search(y, x + 1) + "1";
}

int main(){
	
	while(true){
		
		cin >> w >> h;
		if(w == 0 && h == 0){
			break;
		}
		
		for(int i = 0; i < h; i++){
			cin >> field[i];
		}
		
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				check[i][j] = false;
			}
		}
		
		int ans_b = 0;
		int ans_w = 0;
		
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				string ret = search(i, j);
				bool flag1 = false;
				bool flag2 = false;
				int count = 0;
				for(int k = 0; k < ret.size(); k++){
					if(ret[k] == 'B'){
						flag1 = true;
					}else if(ret[k] == 'W'){
						flag2 = true;
					}else{
						count++;
					}
				}
				if(flag1 && flag2){
					continue;
				}else if(flag1){
					ans_b += count;
				}else if(flag2){
					ans_w += count;
				}
			}
		}
		
		cout << ans_b << " " << ans_w << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    vector<int> pos(N + 1);
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        pos[a] = i;
    }

    set<int> st;
    st.emplace(-1);
    st.emplace(N);
    ll ans = 0;
    for (int i = 1; i <= N; ++i) {
        ll tmp = i;
        auto itr = st.lower_bound(pos[i]);
        tmp *= (*itr - pos[i]);
        --itr;
        tmp *= (pos[i] - *itr);
        ans += tmp;
        st.emplace(pos[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
int a[100100];
ll dp[2][100100];

int main() {
	cin >> n; rep(i, n)cin >> a[i];
	rep(i, n) {
		if (a[i] % 2 == 0) {
			if (i == 0) {
				dp[0][i] = 1;
				dp[1][i] = 2;
			}
			else {
				dp[0][i] = 3 * dp[0][i - 1] + dp[1][i - 1];
				dp[1][i] = 2 * dp[1][i - 1];
			}
		}
		else {
			if (i == 0) {
				dp[0][i] = 2;
				dp[1][i] = 1;
			}
			else {
				dp[0][i] = 3 * dp[0][i - 1] + 2 * dp[1][i - 1];
				dp[1][i] = dp[1][i - 1];
			}
		}
	}
	cout << dp[0][n - 1] << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int m,D[1401][1401]={m=0},h,w,f,i,j;
main(){
	cin>>h>>w;
	for(i=0;i<h;i++)for(j=0;j<w;j++){
		cin>>f;
		m=max(m,D[i+1][j+1]=(min(D[i][j],min(D[i+1][j],D[i][j+1]))+1)*(!f));
	}
	cout<<m*m<<endl;
}


Measured memory_bytes: 10752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    double L;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.L = sc.nextDouble();
    }
    
    //解答処理
    private double solve() {
        double volume = Math.pow(L/3, 3);
        return volume;
    }
    
    //出力
    public void show(double answer) {
        System.out.printf("%.12f",answer);
    }

}

Measured memory_bytes: 37348
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<ll,ll>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

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


int main(){
  int n, m;
  cin >> n >> m;
  vector<P> st(n);
  vector<P> ch(m);
  rep(i,n){
    ll a, b;
    cin >> a >> b;
    st[i] = make_pair(a,b);
  }
  rep(i,m){
    ll c, d;
    cin >> c >> d;
    ch[i] = make_pair(c,d);
  }
  rep(i,n){
    int ans;
    ll dis = 1e18;
    rep(j,m){
      ll now = abs(st[i].first - ch[j].first) + abs(st[i].second - ch[j].second);
      if(dis > now) {
        ans = j+1;
        dis = now;
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;
ll lim;
ll N, W[100], V[100];
ll dp[101][100001];
int main(void) {
	cin >> N>>lim;
	FOR(i, 0, N)cin >> W[i] >> V[i];
	fill(dp[0], dp[0] + 100001, INF);
	dp[0][0] = 0;
	FOR(i, 0, N) {
		for (ll k = 0; k <=100000; k++) {
			if (k < V[i]) {
				dp[i + 1][k] = dp[i][k];
			}
			else {
				dp[i + 1][k] = min(dp[i][k], dp[i][k - V[i]] + W[i]);
			}
		}
	}
	ll ans = 0;
	FOR(i, 0, 100001)if (dp[N][i] <= lim)ans = i;
	ct(ans);
	return 0;
}

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

int main() {
    int n, s[10000], q, t[500], ans=0;
    cin >> n;
    for(int i=0; i<n; i++) cin >> s[i];
    cin >> q;
    for(int i=0; i<q; i++) cin >> t[i];
    for(int j=0; j<q; j++) {
        for(int i=0; i<n; i++) {
            if(s[i]==t[j]) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3120
A = int(input())
B = int(input())
C = int(input())

X = int(input())

count = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if 500*a + 100*b + 50*c ==X:
                count += 1


print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>

#define MAX 10000000
using namespace std;


int prime[MAX];

bool is_Prime[MAX];

int ans[1010];


int main(){

  for(int i = 2 ; i < MAX ; i++){
    is_Prime[i] = true;
  }

  for(int i = 2 ; i < MAX ; i++){
    if(is_Prime[i]){
      for(int j = 2; i*j < MAX ; j++)
	is_Prime[i*j] = false;
    }
  }

  for(int i = 2,j = 0; i < MAX ; i++){
    if(is_Prime[i] ){
      prime[j] = i;
      j++;
    }
  }

  for(int i = 0; i < 100; i++){
    //  cout << prime[i] << " ";
  
  }

  int N,P;

  while(1){
    cin >> N >> P;
    if(N == -1 && P == -1 ) break;

    int i;
    for(i = 0; prime[i] <= N ;i++){}
    // prime[i] テ」ツ?ッNテ」ツつ暗」ツつ甘・ツ、ツァテ」ツ?催」ツ??、ツクツ?ァツ閉ェテ・ツーツ湘」ツ?陛」ツ?ェテァツエツ?ヲツ閉ー 
    // cout << i << " " ;



    int t,s,x = 0;

    for(int k = i,t = 0 ; t < 40 ; t++,k++){
      for(int l = k,s = k-i ; s < 40 ; s++,l++){
	ans[x] = prime[k]+prime[l];
	//		cout << ans[x] << " ";
	x++;
      }
      //     cout << endl;
    }

    sort(ans ,ans + 500);


    for(i = 0; i < 100 ; i++){
      //    cout << ans[i] << " ";
    }
    //    cout << endl;    
       cout << ans[P-1] << endl;

  }

  return 0;
}

Measured memory_bytes: 15504
#include<bits/stdc++.h>
using namespace std;
main()
{
    int t,k,l,j,m,n;
    scanf("%d",&t);
    m=t/100;
    n=t%100;
    if(m>0&&m<=12)
    {
        if(n>0&&n<=12)
            printf("AMBIGUOUS\n");
        else
            printf("MMYY\n");
    }
    else if((n>0&&n<=12))
        printf("YYMM\n");
    else
        printf("NA\n");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int W, H, K;
int gcdtbl[201][100100];

int gcd(int a, int b, bool f = false)
{
	a = max(a, -a);
	b = max(b, -b);
	if (!f && a <= 200) {
		return gcdtbl[a][b];
	}
	while (b) {
		int tmp = a % b;
		a = b;
		b = tmp;
	}
	return a;
}

bool test(int y, int dx, int x)
{
	i64 S2 = (x + dx) * (i64)H - (i64)(H - y) * dx;
	int b = gcd(dx, H) + gcd(x + dx, H - y) + gcd(x, y);
	i64 tmp = (S2 + 2 - b);
	if (tmp % 2 == 1) abort();
	return tmp / 2 <= K;
}

int solve(int dx, int y)
{
	int xlo = 0, xhi = min(W - 1 - dx, 500500 / H);
	while (xlo < xhi) {
		int mid = (xlo + xhi + 1) / 2;
		if (test(y, dx, mid)) {
			xlo = mid;
		} else {
			xhi = mid - 1;
		}
	}
	// printf("%d %d %d %d: %d\n", dx, y, W, H, xlo);
	return xlo;
}

int main()
{
	for (int i = 0; i <= 200; ++i) {
		for (int j = 0; j <= 100000; ++j) gcdtbl[i][j] = gcd(i, j, true);
	}
	scanf("%d%d%d", &W, &H, &K);
	i64 ret = 0;
	for (int t = 0; t < 2; ++t) {
		for (int dx = 0; dx <= W - 2; ++dx) {
			int ymax;
			if (dx == 0) ymax = H - 1;
			else ymax = min(500500 / dx, H - 1);
			for (int y = 1; y <= ymax; ++y) {
				ret += solve(dx, y) * (dx == 0 ? 2 : 4);
			}
		}
		swap(H, W);
	}
	printf("%lld\n", ret);
	return 0;
}


Measured memory_bytes: 81832
#if 1
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <list>
#include <unordered_map>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;

const LD eps = 1e-9;
const LD pi = acos(-1.0);
const LL inf = 1e+9;

#define mp make_pair
#define pb push_back
#define X first
#define Y second

#define dbg(x) { cerr << #x << " = " << x << endl; }

// extended template
#pragma comment(linker, "/STACK:36777216")
typedef vector<int> vi;
typedef vector<vi> vvi;

#define forn(i, n) for (int i = 0; i < n; ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<typename T> istream & operator >> (istream &, vector<T> &);
template<typename T> ostream & operator << (ostream &, const vector<T> &);

#define START clock_t _clock = clock();
#define END cerr << endl << "time: " << (clock() - _clock) / LD(CLOCKS_PER_SEC) << endl;

#define NAME "angle1"


void solve()
{
	int n;
	cin >> n;
	int sum = 0;
	int N = n;
	while (n) {
		sum += n % 10;
		n /= 10;
	}
	if (N % sum == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main()
{

	//START
	//freopen(NAME ".in", "r", stdin); freopen(NAME ".out", "w", stdout);
	//freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout);
	solve();


	//END		 
	return 0;
}
/*******************************************
*******************************************/

template<typename T> istream & operator >> (istream &is, vector<T> &v)
{
	forn(i, v.size())
		is >> v[i];
	return is;
}
template<typename T> ostream & operator << (ostream &os, const vector<T> &v)
{
	forn(i, v.size())
		os << v[i] << " ";
	return os;
}
#endif

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define isz(x) (int)(x).size()
template<typename T, typename N> 
T pow(T a, N n) {
    T r(1);
    while (n > 0) {
        if (n & 1) { r *= a; }
        a *= a;
        n >>= 1;
    }
    return r;
}
template<int mod>
struct IntMod {
    int value;
    IntMod(int value_ = 0) : value(value_) { }
    IntMod& operator+=(IntMod num) {
        value += num.value;
        if (value >= mod) value -= mod;
        return *this;
    }
    IntMod& operator-=(IntMod num) {
        value -= num.value;
        if (value < 0) value += mod;
        return *this;
    }
    IntMod operator+(IntMod num) const { return IntMod(*this) += num; }
    IntMod operator-(IntMod num) const { return IntMod(*this) -= num; }
    IntMod operator*(IntMod num) const { return IntMod(int(value * 1LL * num.value % mod)); }
    IntMod& operator*=(IntMod num) { return *this = *this * num; }
    IntMod operator/(IntMod num) const { return *this * pow(num, mod-2); }
    IntMod& operator/=(IntMod num) { return *this = *this / num; }
};
template<int mod>
std::ostream& operator<<(std::ostream& os, const IntMod<mod>& num) {
    return os << num.value;
}
const int mod = (int)1e9+7;
using Int = IntMod<mod>;
const int NMAX = 2024;
Int dp[NMAX][NMAX], sum[NMAX];
void precalc() {
    dp[0][0] = 1;
    for (int k = 1; k < NMAX; k++) {
        sum[0] = dp[k-1][0];
        for (int n = 1; n < NMAX; n++) {
            sum[n] = sum[n-1] + dp[k-1][n];
        }
        for (int n = k; n < NMAX; n++) {
            dp[k][n] = sum[n-1];
        }
    }
}
#define watch(x) std::cerr << #x << " = " << x
#define watchln(x) watch(x) << std::endl
#define cerr cerr && false && std::cerr
int main() {
    precalc();
    // Input:
    int N, K;
    std::cin >> N >> K;
    // Calculate answers:
    for (int k = 1; k <= K; k++) {
        watchln(K);
        watchln(k);
        watchln(dp[k][K]);
        std::cout << dp[k][K] * (dp[k+1][N-K] + dp[k][N-K] * 2 + dp[k-1][N-K]) << '\n';
    }
    return 0;
}

Measured memory_bytes: 16384
#include<stdio.h>
struct point {
    int t;
    int x;
    int y;
} p[100001];
int n;
int main() {
    int flag=1, np=0;
    scanf("%d", &n);
    p[0].t=p[0].x=p[0].y=0;
    for(int i=1;i<=n;i++) {
        scanf("%d %d %d", &p[i].t, &p[i].x, &p[i].y);
        int d=0;
        if(p[np].x>p[i].x) d+=p[np].x-p[i].x;
        else d+=p[i].x-p[np].x;
        if(p[np].y>p[i].y) d+=p[np].y-p[i].y;
        else d+=p[i].y-p[np].y;
        if(p[i].t-p[np].t<d) {
            flag=0;
            break;
        }
        if((p[i].t-p[np].t-d)%2) {
            flag=0;
            break;
        }
        np=i;
    }
    if(flag) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n;
    cin >> n;
    // vector<int> v(n);
    map<string, bool> mp;
    int sum = 0;
    rep(i, 0, n)
    {
        int a;
        cin >> a;
        if (a >= 1 && a <= 399)
            mp["gray"] = true;
        if (a >= 400 && a <= 799)
            mp["brown"] = true;
        if (a >= 800 && a <= 1199)
            mp["green"] = true;
        if (a >= 1200 && a <= 1599)
            mp["cyan"] = true;
        if (a >= 1600 && a <= 1999)
            mp["blue"] = true;
        if (a >= 2000 && a <= 2399)
            mp["yellow"] = true;
        if (a >= 2400 && a <= 2799)
            mp["orange"] = true;
        if (a >= 2800 && a <= 3199)
            mp["red"] = true;
        if (a >= 3200)
            sum++;        
    }
    if (mp.size() == 0 && sum != 0)
        cout << 1 << " " << sum;
    else 
        cout << mp.size() << " " << mp.size() + sum;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
long long int n;
char s;
long long int ans=0;
long long int ansn=0;
int main()
{ 
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        if(s=='I') ansn++;
        else if(s=='D') ansn--;
        ans=max(ans,ansn); 
    }
    cout<<ans;
    return 0; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int main(){
    int n;cin>>n;
    ll a[200010];
    vector<ll> v;
    for(int i=0;i<n;i++){
        cin>>a[i];
        v.push_back(a[i]-(i+1));
    }
    sort(all(v));
    ll b=v[n/2];
  ll ans=0;
    for(int i=0;i<n;i++){
        ans+=abs(a[i]-(b+i+1));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           (long long)1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigint        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(aint(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 

template <typename T>
T ceil(T a, T b){ return (a+b-1)/b; }


template<typename T>
T binpow(T a, T b, T m) {
    a %= m;
    T res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

void solve(){
    string s;
    cin>>s;
    int res=0;
    FOR(i, 0, sz(s)) {
        res += (s[i]-'0');
    }
    if(res%9) {
        cout<<"No";
    } else {
        cout<<"Yes";
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);     
    int t=1;
    //cin>>t;
    FOR(i, 1, t+1){ 
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
 
}


Measured memory_bytes: 3764