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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, k, x, y;

int main() {
	cin >> n >> k >> x >> y;
	cout << min(n,k)*x + max(n-k,0)*y << ln;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	while(1){
		int H,W;
		cin >> H >> W;
		if(H==0){
			if(W==0) break;
		}
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i%2==0){
					if(j%2==0){
						cout << '#';
					}else{
						cout << '.';
					}
				}else{
					if(j%2==0){
						cout << '.';
					}else{
						cout << '#';
					}
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}
		


Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n, -1){}

    void init(int n){
        par.assign(n, -1);
    }

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

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

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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

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

    int n, k, l;
    cin >> n >> k >> l;
    UnionFind ar = UnionFind(n);
    UnionFind br = UnionFind(n);
    vector<int> res(n, 1);

    rep(i, k){
        int p, q; cin >> p >> q;
        p--; q--;
        ar.merge(p, q);
    }
    vector< pair<int, int> > city(l);
    rep(i, l){
        int r, s; cin >> r >> s;
        r--; s--;
        city[i] = pair<int, int>(r, s);
        br.merge(r, s);
    }

    map<pair<int, int>, int> m;
    rep(i, n){
        m[pair<int, int>(ar.root(i), br.root(i))]++;
    }

    rep(i, n){
        cout << m[pair<int, int>(ar.root(i), br.root(i))] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 15104
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
int p[33][214514]={};
signed main(){
    int n,c;cin>>n>>c;
    rep(i,0,n){
        int s,t,f;cin>>s>>t>>f;
        p[f-1][2*s]++,p[f-1][2*t+2]--;
    }
    int ans=0;
    rep(i,1,200050){
        int count=0;
        rep(j,0,c){
            p[j][i]+=p[j][i-1];
            if(p[j][i])count++;
        }
        if(i==0)ans=count;
        else ans=max(ans,count);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 51328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	static int[] student;
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		student=new int[N];
		for(int i=0; i<N; i++) {
			student[i]=sc.nextInt();
		}
		for(int i=1; i<=M; i++) {
			for(int j=0; j<N-1; j++) {
				if(student[j]%i > student[j+1]%i) {
					swap(j,j+1);
				}
				else {
					//
				}
			}
		}
		for(int i=0; i<N; i++) {
			pl(student[i]);
		}
	}

	public static void swap(int i,int j) {
		int a=student[i];
		int b=student[j];
		student[i]=b;
		student[j]=a;
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 24356
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	int H, W; cin >> H >> W;
	char S[51][51];
	char T[51][51];

	rep(i, 0, H) {
		cin >> S[i];
	}
	int w[8] = { 1,1,1,0,0,-1,-1,-1 };
	int h[8] = { 0,1,-1,1,-1,0,1,-1 };
	rep(i, 0, H) {
		rep(j, 0, W) {
			if (S[i][j] == '#') {
				T[i][j] = '#';
				continue;
			}

			int bomb = 0;
			rep(k, 0, 8) {
				if (i + h[k] >= 0 && j + w[k] >= 0 && i + h[k] < H && j + w[k] < W) {
					if (S[i + h[k]][j + w[k]] == '#') bomb++;
				}
			}
			T[i][j] = bomb;
		}
	}

	rep(i, 0, H) {
		rep(j, 0, W) {
			if (T[i][j] == '#') {
				cout << T[i][j];
			}
			else {
				cout << (int)T[i][j];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char a[50];
int f,tot,alen,k;
int main()
{
	scanf("%s",a);
	alen=strlen(a);
	if(a[0]!='A')
		f=1;
	for(int i=2;i<=alen-2;i++)
		if(a[i]=='C')
		{
			tot++;
			k=i;
		}
	for(int i=1;i<alen;i++)
	{
		if(!(a[i]>='a'&&a[i]<='z')&&i!=k)
			f=1;
	}
	if(tot!=1)
		f=1;
	if(f)
		printf("WA\n");
	else
		printf("AC\n");
	return 0;
}


Measured memory_bytes: 256
using System.Collections.Generic;
using static System.Console;
using static System.Math;

class Program {
	static void Main() {
		var A = NextInt();
		var B = NextInt();
		var C = NextInt();
		var D = NextInt();

		WriteLine(Max(0, Min(B, D) - Max(A, C)));
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}


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

int main() {
    string s;
    cin >> s;
    if((s.at(5)-'0')*10 + (s.at(6)-'0') >= 5){
        cout << "TBD";
    }
    else{
        cout << "Heisei";
    }
}

Measured memory_bytes: 256
n = (int)(input())
plus = [input() for i in range(n)]
m = (int)(input())
minus = [input() for i in range(m)]

maxi = 0
words = ""
for i in list(set(plus)):
  temp = plus.count(i) - minus.count(i)
  if maxi < temp:
    maxi = temp
    words = i
print(maxi)

Measured memory_bytes: 9196
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def get_yakusu_list(N):
    yakusu = []
    for i in range(1, int(math.sqrt(N)) + 1):
        if N % i == 0:
            yakusu.append(i)
            if N // i != i:
                yakusu.append(N//i)
    yakusu = sorted(yakusu)
    return yakusu

def main():
    N, M = LI()
    yakusu = get_yakusu_list(M)
    for ko in yakusu[::-1]:
        if M // ko >= N:
            break
    print(ko)

main()



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

int main() {
  ll A = 0, B = 0,ans = 0;
  cin >> A >> B;
  rep(i,10000){
    if(i * 8 / 100 == A && i / 10 == B){
      cout << i;
      return 0;
    }
  }
    cout << "-1";
}

Measured memory_bytes: 256
def main():
    from math import hypot
    import sys
    input = sys.stdin.readline

    inf = 1 << 60

    xs, ys, xt, yt = map(int, input().split())
    N = int(input())

    def dist(p1, p2):
        d = hypot(p1[0] - p2[0], p1[1] - p2[1])
        return max(0, d - (p1[2] + p2[2]))

    ps = [(xs, ys, 0)]
    ps += (tuple(map(int, input().split())) for _ in range(N))
    ps += [(xt, yt, 0)]

    adj = [[inf] * (N + 2) for _ in range(N + 2)]

    for i, p1 in enumerate(ps):
        for j, p2 in enumerate(ps):
            if i <= j: break  # 自己辺なし
            adj[i][j] = adj[j][i] = dist(p1, p2)

    def dijkstra(s):
        dist = [inf] * (N + 2)
        dist[s] = 0
        det = [0] * (N + 2)

        c, v = 0, s
        det[s] = 1
        for _ in range(N + 1):
            for u, dc in enumerate(adj[v]):
                nc = c + dc
                if dist[u] <= nc: continue
                dist[u] = nc

            c, v = -1, -1
            for u, d in enumerate(dist):
                if det[u]: continue
                if ~v and c <= d: continue
                c, v = d, u
            det[v] = 1

        return dist

    print(dijkstra(s=0)[N + 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 23156
#include<cstdio>
int main(){
	int n,y;
	scanf("%d%d",&n,&y);
	int p=0;
	y=y/1000;
	for(int a=0;a<=y/10;a++){
		for(int b=0;b<=(y-a*10)/5;b++){
			if(y-9*a-4*b==n){
				printf("%d %d %d\n",a,b,y-10*a-5*b);
				p=1;
				break;
			}
		}
		if(p==1)break;
	}
	if(p==0)printf("-1 -1 -1\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
long long n,m,i,t;
int main(){
	cin>>n; m=sqrt(n); t=n;
	for(i=1;i<=m;++i)
		if(n%i==0){
			if(i+n/i-2<t)
				t=i+n/i-2;
		}
	cout<<t;
	return 0;
} 

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	s := strconv.Itoa(a) + strconv.Itoa(b)
	n, _ := strconv.Atoi(s)

	f := true
	for i := 1; i < 10000; i++ {
		if i * i == n {
			fmt.Println("Yes")
			f = false
			break
		}
	}

	if f {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,k;
int main()
{
	cin>>a>>b>>c>>k;
	if(abs(a-b)>1e18)cout<<"Unfair"<<endl;
	else if(k%2==0)cout<<a-b<<endl;
	else cout<<b-a<<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
	Scanner sc	= new Scanner(System.in);
	String[] a = sc.next().split("",0);
	String[] b = sc.next().split("",0);
	String[] c = sc.next().split("",0);

	if (a[a.length-1].equals(b[0])) {
		if (b[b.length-1].equals(c[0])) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	} else {
		System.out.println("NO");
	}
	}
}


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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

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

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  map <string, int> mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(all(s));
    mp[s]++;
  }
  ll ans = 0;
  for (auto pp: mp) {
    ll cnt = pp.second;
    ans += cnt * (cnt - 1) / 2;
  }
  cout << ans << '\n';
  return (0);
}


Measured memory_bytes: 11264
# import fractions
# import sys
from sys import stdin

n, m = map(int, stdin.readline().rstrip().split())
xy = [list(map(int, stdin.readline().rstrip().split())) for i in range(m)]

num = [1] * n
red = [False] * n
red[0] = True
for i in range(m):
    if red[xy[i][0] - 1]:
        red[xy[i][1] - 1] = True
    num[xy[i][0] - 1] = num[xy[i][0] - 1] - 1
    num[xy[i][1] - 1] = num[xy[i][1] - 1] + 1
    if num[xy[i][0] - 1] == 0:
        red[xy[i][0] - 1] = False

print(sum(red))

Measured memory_bytes: 28860
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

int powM(int x, int n){
    if(n == 0){
        return 1;
    }
    if(n % 2 == 0){
        return powM(x * x % MOD, n / 2);
    }
    return powM(x, n-1) * x % MOD;
}

int factM(int n){
    static vector<int> t = {1};

    if((int)t.size() > n){
        return t[n];
    }

    for(int i = t.size(); i <= n; i++){
        t.push_back(t[i-1] * i % MOD);
    }
    return t[n];
}

class Combination{
    private:
        vector<int> t;

    public:
        Combination(int n): t(n+1){
            t[n] = powM(factM(n), MOD-2);

            for(int i = n-1; i >= 0; i--){
                t[i] = t[i+1] * (i+1) % MOD;
            }
        }

        int comb(int n, int k){
            if(n < k || n < 0 || k < 0){
                return 0;
            }
            return factM(n) * t[k] % MOD * t[n-k] % MOD;
        }

        int getInv(int n){
            return t[n];
        }
};

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

    int n, a, b, c;
    cin >> n >> a >> b >> c;

    Combination com(200000);

    int r = 100 * powM(a + b, MOD - 2) % MOD;
    int ap = a * powM(a + b, MOD - 2) % MOD;
    int bp = b * powM(a + b, MOD - 2) % MOD;

    int ans = 0;
    for(int i = n - 1; i <= (n - 1) * 2; i++){
        int p = com.comb(i, n - 1);

        ans += (i + 1) * r % MOD * powM(ap, n) % MOD * powM(bp, i + 1 - n) % MOD * p % MOD;
        ans %= MOD;
        ans += (i + 1) * r % MOD * powM(bp, n) % MOD * powM(ap, i + 1 - n) % MOD * p % MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1<<1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1<<2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1<<3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1<<4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1<<5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1<<6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1<<7) // 0000 0000 1000 0000

int main(){
    int s,w;
    cin >> s >> w;
    if(s>w) cout << "safe" << endl;
    else cout << "unsafe"  << endl;
    return 0;   
}

Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	long long n, a, b;
	cin >> n >> a >> b;

	if (a + b == 0)cout << 0 << endl;
	else cout << (n / (a + b)) * a + min(n % (a + b), a) << endl;



	return 0;
}

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

int main() {
  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  int a[N], b[N], c[N], dp[401][401], ans = INF;
  for (int i=0; i<N; i++)
    cin >> a[i] >> b[i] >> c[i];
  for (int j=0; j<=400; j++)
    for (int k=0; k<=400; k++)
      dp[j][k] = INF;
  dp[0][0] = 0;
  for (int i=0; i<N; i++) {
    int ai = a[i], bi = b[i], ci = c[i];
    for (int j=400; j>=ai; j--) {
      for (int k=400; k>=bi; k--) {
        dp[j][k] = min(dp[j][k], dp[j-ai][k-bi]+ci);
      }
    }
  }
  for (int i=1; i*Ma<=400 && i*Mb<=400; i++)
    ans = min(ans, dp[i*Ma][i*Mb]);
  if (ans == INF)
    ans = -1;
  cout << ans << endl;
  return 0;
}

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

int main(){
    int x; cin>>x;
    int ans=1;
    for(int i=2;i<=sqrt(x);i++){
        for(int j=2;j<=10;j++){
            int tmp = pow(i, j);
            if(tmp<=x && tmp>ans) ans = tmp; //cout<<ans<<endl;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main ()
{ long long n;
  scanf("%lld",&n);
  long long  i=0;
    long long sum=100;
 while(1)
 {   if(sum>=n) {printf("%lld",i);return 0;}
    sum*=1.01;
    //printf("%lld\n",sum);
    i++;
 }
}

Measured memory_bytes: 1732
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [n, m] = input[0].map(Number);

  return (n - 1) * (m - 1);
};

console.log(main(read()));


Measured memory_bytes: 29660
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <utility>

#define INF 1000000000000000

using namespace std;

typedef long long int lli;
typedef pair<int, int> P;

struct edge{
	int from, to, cost;
};

int V, E, r;
edge e[2000];
lli d[1000];

bool solve(int s){
	fill(d, d+V, INF);
	d[s] = 0;
	for(int i = 0;i < V;i++){
		bool update = false;
		for(int j = 0;j < E;j++){
			if(d[e[j].from] != INF && d[e[j].to] > d[e[j].from] + e[j].cost){
				d[e[j].to] = d[e[j].from] + e[j].cost;
				update = true;
			}
		}
		if(!update) break;
		if(i == V-1 && update){
			return false;
		}
	}
	return true;
}

int main(void){
	cin >> V >> E >> r;
	for(int i = 0;i < E;i++){
		cin >> e[i].from >> e[i].to >> e[i].cost;
	}
	if(solve(r)){
		for(int i = 0;i < V;i++){
			if(d[i] != INF)
				cout << d[i] << endl;
			else
				cout << "INF" << endl;
		}
	}else{
		cout << "NEGATIVE CYCLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char s[20];
  scanf("%s", s);
  s[5] = ' ';
  s[13] = ' ';
  printf("%s\n", s);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
using namespace std;
int N,T,L,B;
int n[101];
double dp[101][101];

double solve(int num,int turn){
	double res = 0;
	int next;
	//if(turn < 0)return 0;
	if(num == N)return 1;
	if(turn <= 0)return 0;
	if(dp[num][turn] != -1)return dp[num][turn];
	for(int i = 1;i <= 6;i++){
		next = num + i;
		if(next > N){
			next = N - (next - N);
		}
		if(n[next] == 1){
			res += solve(next,turn-2);
		}
		else if(n[next] == 2){
			res += solve(0,turn -1);
		}
		else{
			res += solve(next,turn -1);
		}
	}
	return dp[num][turn] = res / 6;
}
int main(){
	int x;
	while(1){
		cin >> N >> T >> L >> B;
		if(N == 0)break;
		for(int i = 0;i <= N;i++)n[i] = 0;
		for(int i = 0;i < L;i++){
			cin >> x;
			n[x] = 1;
		}
		for(int i = 0;i < B;i++){
			cin >> x;
			n[x] = 2;
		}
		for(int i = 0;i <= N;i++){
			for(int j = 0;j <= N;j++){
				dp[i][j] = -1;
			}
		}
		printf("%.6f\n",solve(0,T));
	}
	return 0;
}

Measured memory_bytes: 1272
#include <stdio.h>

int main(void){
  
  long int n,k;
  scanf("%ld %ld",&n,&k);
  
  long int t = n%k;
  
  int long ans = (t<k-t) ? t : k-t;
  
  printf("%ld",ans);
  
  return 0;
}

Measured memory_bytes: 1732
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

const int INF = INT_MAX / 2;

// graphs[i] means {to, dist} from vertex i
vector<vector<pair<int, int>>> graph;

vector<int> pos;

void bfs(const int start) {
    queue<int> que;
    pos[start] = 0;
    que.push(start);

    while (!que.empty()) {
        const int cur = que.front();
        que.pop();
        assert(pos[cur] != INF);

        for (auto next : graph[cur]) {
            const int next_v = next.first;
            const int next_d = pos[cur] + next.second;
            if (pos[next_v] == INF) {
                pos[next_v] = next_d;
                que.push(next_v);
            }
        }
    }
}

int main(void) {
    int N, M;
    cin >> N >> M;

    graph.resize(N);
    for (int i = 0; i < M; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        graph[l].push_back(make_pair(r, d));
        graph[r].push_back(make_pair(l, -1 * d));
    }

    pos.resize(N, INF);

    for (int i = 0; i < N; i++) {
        if (pos[i] == INF) {
            bfs(i);
        }
    }

    for (int i = 0; i < N; i++) {
        assert(pos[i] != INF);
    }

    bool ok = true;
    for (int l = 0; l < N; l++) {
        for (auto &edge : graph[l]) {
            const int r = edge.first;
            const int d = edge.second;
            if (pos[r] - pos[l] != d) {
                ok = false;
            }
        }
    }

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 12524
### main

loop do
  n, a, b = gets.split.map(&:to_i)
  break if (n | a | b) == 0
  #p [n, a, b]

  tfs = (n + 1).times.map{false}
  tfs[0] = true

  count = 0

  for i in (1..n)
    if (i >= a && tfs[i - a]) || (i >= b && tfs[i - b])
      tfs[i] = true
    else
      count += 1
    end
  end

  p count
end

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/24  Problem: code-festival-2016-final_c / Link: https://cf16-final.contest.atcoder.jp/tasks/codefestival_2016_final_c?lang=en  ----- */
/* ------問題------

ある星には M 種類の言語があり、1-M の番号が付けられています。

この星のある年のCODE FESTIVALには星中から N 人の参加者が集まりました。

i(1≦i≦N) 人目の参加者は Ki 種類の言語 Li,1,Li,2,…,Li,Ki を話すことが出来ます。

ある 2 人は以下のいずれかの条件を満たすときに限り、コミュニケーションを取ることが出来ます。

2 人ともが話すことの出来る言語が存在する。
ある人 X が存在して、 2 人ともが X とコミュニケーションを取ることが出来る。
このとき、N 人すべての参加者が他のすべての参加者とコミュニケーションを取ることが出来るかどうかを判定してください。

-----問題ここまで----- */
/* -----解説等-----

何でもかんでも繋がっていれば良い

----解説ここまで---- */

LL N,M;

LL ans = 0LL;

void dfs(int v, int p, VVI &G, VI& visit) {
	visit[v] = 1;
	FOR(i, 0, SZ(G[v])) {
		int nx = G[v][i];
		if (nx != p && !visit[nx])dfs(nx, v, G, visit);
	}
}

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

	cin >> N>>M;
	VVI G(N + M);
	FOR(i, 0, N) {
		int k;
		cin >> k;
		FOR(j, 0, k) {
			int lg;
			cin >> lg;
			lg--;
			lg += N;
			G[i].push_back(lg);
			G[lg].push_back(i);
		}
	}

	VI visit(N+M);
	dfs(0,-1,G,visit);
	ans = 1;
	FOR(i, 0, N) {
		if (!visit[i])ans = 0;
	}
	cout << (ans?"YES":"NO") << "\n";

	return 0;
}


Measured memory_bytes: 9208
#include <iostream>
#include <cstring>

using namespace std;

int main() {
    long long n, d;
    long long x[200000];
    long long y[200000];
    long long ans = 0;
    long long r = 0;

    cin >> n >> d;
    for (int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
        r = x[i]*x[i] + y[i]*y[i];
        if (d * d >= r){
            ans++;
        }
    }

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


Measured memory_bytes: 6744
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cstdint>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;
*/

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n + 1), b(n);
	rep(i, n + 1)scanf("%d", &a[i]);
	rep(i, n)scanf("%d", &b[i]);
	ll ans = 0;
	rep(i, n) {
		ll tmp = min(a[i], b[i]);
		a[i] -= tmp;
		b[i] -= tmp;
		ans += tmp;
		tmp = min(a[i + 1], b[i]);
		a[i + 1] -= tmp;
		b[i] -= tmp;
		ans += tmp;
	}
	printf("%lld\n", ans);

	Please AC;
}


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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int pow_(int a, int b) {
	int ret = 1;
	REP(i, 1, b+1) {
		ret *= a;
	}
	return ret;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a[3], k;	
    cin >> a[0] >> a[1] >> a[2] >> k;
    while(a[0] >= a[1]) {
    	a[1] *= 2;
    	--k;
    }
    while(a[1] >= a[2]) {
    	a[2] *= 2;
    	--k;
    }
    if(k >= 0) cout << "Yes\n";
    else cout << "No\n";	
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include <string>

using namespace std;

const double btc2yen = 380000.0;

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

    string type;
    double res= 0.0;
    double temp = 0.0;

    for (int i = 0; i < n; ++i) {
        cin >> temp >> type;

        // cout << "res=" << res << endl;
        // cout << "temp:type" << temp << ":" << type << endl;

        if (type == "BTC") {
            res = res + btc2yen * temp;
        } else {
            res = res + temp;
        }

    }

    cout << res << endl;

    return 0;
}

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

int main() {
	int n;
	while (scanf("%d", &n), n) {
		map<string, set<string>>mp, memo;
		string f;
		rep(i, n) {
			string s, t, p; cin >> s;
			for (auto&c : s) {
				if (c == ':') {
					p = t; t = "";
					if (!i)f = p;
				}
				else if (c == ',' || c == '.') {
					mp[p].insert(t); t = "";
				}
				else t += c;
			}
		}
		function<set<string>(string)>dfs = [&](string s) {
			if (memo.find(s) != memo.end())return memo[s];
			set<string>res;
			for (auto&t : mp[s]) {
				if (mp.find(t) == mp.end())res.insert(t);
				else {
					set<string>k = dfs(t);
					for (auto&p : k)res.insert(p);
				}
			}
			return memo[s] = res;
		};
		set<string>r = dfs(f);
		printf("%d\n", dfs(f).size());
	}
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <iterator>
#include <map>
#include <unordered_map>

const int N_MAX = 50 + 1;

struct pair_hash {
	template <class T1, class T2>
	std::size_t operator() (const std::pair<T1, T2> &pair) const
	{
		return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
	}
};

bool loop[N_MAX][N_MAX] = {};
std::unordered_map<int, std::vector<int>> m = {};

void print(std::vector<int> v)
{
  for (auto iter=v.begin(); iter!=v.end(); iter++) std::cout << *iter << ' ';
  std::cout << std::endl;
}

void print(std::map<int, std::vector<int>> m)
{
  for (auto iter=m.begin(); iter!=m.end(); iter++) {
    std::cout << iter->first << ": ";
    print(iter->second);
  }
}

void print(std::unordered_map<int, std::vector<int>> m)
{
  for (auto iter=m.begin(); iter!=m.end(); iter++) {
    std::cout << iter->first << ": ";
    print(iter->second);
  }
}

int dfs(std::vector<int> path)
{
  int ret = 0;
  int node = path.back();
  path.pop_back();
  for (auto iter=path.begin(); iter!=path.end(); iter++) {
    if (*iter==node) {
      path.push_back(node);
      while (1) {
        int u = path.back(); path.pop_back();
        int v = path.back(); path.pop_back();
        if (!loop[u][v]) {
          loop[u][v] = true;
          loop[v][u] = true;
          ret++;
        }
        if (v==node) break;
        path.push_back(v);
      }
      return ret;
    }
  }
  int prev = -1;
  if (!path.empty()) prev = path.back();
  path.push_back(node);
  for (auto iter=m[node].begin(); iter!=m[node].end(); iter++) {
    if (prev==-1 || *iter!=prev) {
      path.push_back(*iter);
      ret += dfs(path);
      path.pop_back();
    }
  }
  return ret;
}

int main()
{
  int N, M;
  std::cin >> N >> M;
  for (int i=0; i<M; i++) {
    int from, to;
    std::cin >> from >> to;
    m[from].push_back(to);
    m[to].push_back(from);
  }

  std::vector<int> visited = {};
  visited.push_back(m.begin()->first);
  int ans = dfs(visited);

  std::cout << M - ans;

  return 0;
}


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

typedef long long ll;
typedef tuple<ll, int, int> tlii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<pair<int, int>, ll> ppiil;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back
#define str to_string
#define mkp make_pair
#define mkt make_tuple
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }

template<typename T>
void print(T out) {
    cout << out << '\n';
}

template<typename T1, typename T2>
void print(pair<T1, T2> out) {
    cout << out.first << ' ' << out.second << '\n';
}

template<typename T>
void print(vector<T> A) {
    rep(i, 0, A.size()) {
        cout << A[i];
        cout << (i == A.size()-1 ? '\n' : ' ');
    }
}

ll sum(vector<ll> A) {
    ll res = 0;
    for (ll a: A) res += a;
    return res;
}

ll max(vector<ll> A) {
    ll res = -INF;
    for (ll a: A) chmax(res, a);
    return res;
}

ll min(vector<ll> A) {
    ll res = INF;
    for (ll a: A) chmin(res, a);
    return res;
}

ll max(ll A[], int len) {
    ll res = -INF;
    rep(i, 0, len) chmax(res, A[i]);
    return res;
}

ll min(ll A[], int len) {
    ll res = INF;
    rep(i, 0, len) chmin(res, A[i]);
    return res;
}

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

ll N, D;
vector<ll> A, gcds;
vvl bucket;

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

    cin >> N;
    A.resize(N);
    rep(i, 0, N) cin >> A[i];

    // 平方分割
    D = ceil(sqrt(N));
    bucket.resize(D);
    gcds.resize(D);
    rep(i, 0, N) bucket[i/D].pb(A[i]);
    // 各バケットで全体のGCDを予め取っておく
    rep(i, 0, D) {
        for (ll a : bucket[i]) {
            gcds[i] = gcd(gcds[i], a);
        }
    }

    ll ans = 0;
    rep(i, 0, D) {
        rep(j, 0, bucket[i].size()) {
            ll tmp = 0;
            // バケット内でa以外全ての要素とGCD
            rep(k, 0, bucket[i].size()) {
                if (j == k) continue;
                tmp = gcd(tmp, bucket[i][k]);
            }
            // aを含むバケット以外の全てのバケットとGCD
            rep(k, 0, D) {
                if (i == k) continue;
                tmp = gcd(tmp, gcds[k]);
            }
            ans = max(ans, tmp);
        }
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 2304
n = int(input())
t, a = list(map(int, input().split(" ")))
h = list(map(int, input().split(" ")))

ans = 100000
index = 0
for i in range(n):
    tmp = t - h[i] * 0.006
    if(ans > abs(a - tmp)):
        ans = abs(a - tmp)
        index = i + 1

print(index)

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

An = list(map(int,input().split()))

max_diff = 0
for i in range(1,n):
    if i != 0:
        max_diff = max(abs(An[i] - An[i-1]), max_diff)

max_diff = max(max_diff, k-An[n-1] + An[0])
print(k-max_diff)

Measured memory_bytes: 25836
n = int(input())
a = list(map(int, input().split()))
d = {}
ans = 0

for i in range(n):
    l = i + a[i]
    r = i - a[i]
    if l not in d:
        d[l] = 1
    else:
        d[l] += 1
    if r in d:
        ans += d[r]

print(ans)

Measured memory_bytes: 40492
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        mut a: [usize; n],
    }

    a.sort();
    a.reverse();

    let sum = a.iter().sum::<usize>();

    if sum <= 4 * m * a[m - 1] {
        println!("Yes");
    } else {
        println!("No");
    }

}


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

int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
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; }

const long long INF = 1LL << 60;

int main() {
    int n;
    long long a[100100][3];
    long long dp[100100][3] = {0};

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long res = 0;
    for (int i = 0; i < 3; i++) chmax(res, dp[n][i]);

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
int main(void){
    int h,w,n; cin >> h >> w >> n;
    int ans=0;
    if(h>w){
        ans = n/h;
        if(n%h!=0) ans++;
    }else{
        ans = n/w;
        if(n%w!=0) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
//-----------------------
// author : xyqkoala
// time : 2020-06-16
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


void solve(){
	int n;
	cin>>n;
	vector<int> nums(n);
	for(int i=0;i<n;i++) cin>>nums[i];
	int res = 0;
	int mx = -1;
	for(auto item:nums) mx = max(mx,item);
	vector<int> dp(mx+1,0);
	for(auto item:nums){
		dp[item]++;
	}
	for(int i=1;i<=mx;i++){
		if(!dp[i]) continue;
		int ad = 1;
		if(dp[i]>1) ad = 0;
		int j = 1;
		res+=ad;
		while((i*j)<=mx){
			dp[i*j] = 0;
			j++;
		}
	}
	cout<<res<<endl;
}


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

int main(){
    int n,i;
    long long pop;
    cin>> n;
    queue<long long> q;
    for(i=1;i<10;i++){
        q.push(i);
    }
    for(i=0;i<n-1;i++){
        pop = q.front();
        if(pop%10!=0) q.push(pop*10 + pop%10 -1);
        q.push(pop*10+pop%10);
        if(pop%10 != 9) q.push(pop*10 + pop%10 + 1);
        q.pop();
    }
    cout<< q.front()<<endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <map>
#include <algorithm>

using namespace std;

int main() {
  int i;
  int N;
  scanf("%d", &N);
  map<int, int> numbers;
  for (i = 0; i < N; i++) {
    int ai;
    scanf("%d", &ai);
    if (numbers.find(ai) != numbers.end()) {
      numbers[ai] += 1;
    } else {
      numbers[ai] = 1;
    }
  }
  int ans = 0;
  for (auto x : numbers) {
    if (x.first > x.second) {
      ans += x.second;
    } else if (x.first < x.second) {
      ans += x.second - x.first;
    }
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 4736
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.math.BigDecimal;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            int N = in.nextInt(); 
            int a[] = new int[N];
            for(int i=0; i<N; i++){
                a[i] = in.nextInt();
            }
            int c[][] = new int[H][W];
            int j=0;
            int i=0;
            int k=0;
            while(i<H){
                if(i%2==0){
                    c[i][j] = k;
                    a[k]--;
                    if(a[k]==0) k++;
                    j++;
                    if(j==W){
                        j--;
                        i++;
                    }
                }
                else if(i%2==1){
                    c[i][j] = k;
                    a[k]--;
                    if(a[k]==0) k++;
                    j--;
                    if(j==-1){
                        j++;
                        i++;
                    }
                }
            }
            for(int r=0; r<H; r++){
                for(int h=0; h<W; h++){
                    out.print((c[r][h]+1)+" ");
                }
                out.println();
            }
            
        }
    }


    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();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

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

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn dfs(graph: &[Vec<usize>], parents: &mut [usize], root: usize, parent: usize) {
    parents[root] = parent;
    for &v in graph[root].iter() {
        if parents[v] == 0 {
            dfs(graph, parents, v, parent)
        }
    }
}

fn main() {
    let (n, k, l) = scan!(usize, usize, usize);

    let mut graph = vec![vec![]; n + 1];
    for _ in 0..k {
        let (p, q) = scan!(usize, usize);
        graph[p].push(q);
        graph[q].push(p);
    }
    let mut parents = vec![0; n + 1];
    for i in 1..n + 1 {
        if parents[i] == 0 {
            dfs(&graph, &mut parents, i, i)
        }
    }

    let mut graph = vec![vec![]; n + 1];
    for _ in 0..l {
        let (p, q) = scan!(usize, usize);
        graph[p].push(q);
        graph[q].push(p);
    }
    let mut parents2 = vec![0; n + 1];
    for i in 1..n + 1 {
        if parents2[i] == 0 {
            dfs(&graph, &mut parents2, i, i)
        }
    }

    let mut m = HashMap::new();
    for i in 1..n + 1 {
        *m.entry((parents[i], parents2[i])).or_insert(0) += 1
    }

    for i in 1..n + 1 {
        if i != 1 {
            print!(" ")
        }
        print!("{}", m[&(parents[i], parents2[i])])
    }
    println!()
}


Measured memory_bytes: 41256