akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"

using namespace std;

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

void Main()
{
	char a;
	cin >> a;
	//cout << int('a') << int('A') << endl;
	if(int(a) <= int('Z')){
		cout << 'A' << endl;
	}else{
		cout << 'a' << endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int max = sc.nextInt();
		int answer = sc.nextInt();
		int count=0;
		for(int a=0;a<=max;a++){
			for(int b=0;b<=max;b++){ 
				if(answer-a-b<=max && answer-a-b>=0) count++;
			}
		}
		System.out.println(count);;
		
		sc.close();
	}
}

Measured memory_bytes: 9684
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <iostream>

using std::cin;
using std::cout;
using std::endl;
typedef long long ll;
const int N = 100010;
int _w;

int gcd( int a, int b ) {
	return b ? gcd(b, a%b) : a;
}

int n, a[N];
ll s;

bool solve() {
	int cnt = 0;
	for( int i = 1; i <= n; ++i )
		cnt += a[i] & 1;
	if( cnt > 1 ) return false;
	for( int i = 1; i <= n; ++i )
		if( a[i] & 1 ) {
			if( a[i] == 1 ) return false;
			--a[i];
			break;
		}
	int g = a[1];
	for( int i = 2; i <= n; ++i )
		g = gcd( g, a[i] );
	for( int i = 1; i <= n; ++i )
		a[i] /= g;
	ll s = 0;
	for( int i = 1; i <= n; ++i )
		s += a[i];
	if( s & 1 ) {
		return !solve();
	} else {
		return false;
	}
}

int main() {
	cin >> n;
	for( int i = 1; i <= n; ++i ) {
		cin >> a[i];
		s += a[i];
	}
	if( n == 1 ) {
		puts( a[1] == 1 ? "Second" : "First" );
	} else if( n & 1 ) {
		if( s & 1 ) {
			puts( solve() ? "First" : "Second" );
		} else {
			puts("First");
		}
	} else {
		puts( s % 2 ? "First" : "Second" );
	}
	return 0;
}


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

int main() {
	string s,ans;
	int i;
	cin >> s;
	for (i = 0; i < s.size(); i++) {
		switch (s[i]) {
		case '1':
			ans.push_back(s[i]);
			break;
		case '0':
			ans.push_back(s[i]);
			break;
		case 'B':
			if (ans.size()==0) {
				continue;
			}
			else {
				ans.pop_back();
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;



ll sadness(ll b, const vector<ll> & a) {
  ll s = 0;
  for (ll x: a)
    s += abs(x-b);
  return -s;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(20);
  int n;
  cin >> n;
  vector<ll> a(n);
  ll tot = 0;
  for (int i = 0; i< n; i++) {
    cin >> a[i];
    a[i] -= i+1;
    tot += a[i];
  }
  ll cmin = -1e9, cmax = 1e9;
  while (cmax-cmin > 2) {
    ll lt = cmin + (cmax-cmin)/3;
    ll rt = cmax - (cmax-cmin)/3;
    if (sadness(lt, a) < sadness(rt, a))
      cmin = lt;
    else
      cmax = rt;
  }
  cout << -max(sadness(cmin+1,a), max(sadness(cmin, a), sadness(cmax, a))) << endl;
}



Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		List<Integer> dicevalue = new ArrayList<>();
		int top, front;
		int q;

		int[][] line = {
				{ 2, 3, 5, 4 },
				{ 1, 4, 6, 3 },
				{ 1, 2, 6, 5 },
				{ 1, 5, 6, 2 },
				{ 1, 3, 6, 4 },
				{ 2, 4, 5, 3 },
		};

		Scanner stdIn = new Scanner(System.in);

		for (int i = 0; i < 6; i++) {
			dicevalue.add(stdIn.nextInt());
		}
		stdIn.nextLine();

		Map<Integer, int[]> dicemap = new HashMap<>();

		for (int i = 0; i < 6; i++) {
			dicemap.put(dicevalue.get(i), line[i]);
		}
		q = stdIn.nextInt();
		stdIn.nextLine();

		for (int j = 0; j < q; j++) {
			top = stdIn.nextInt();
			front = stdIn.nextInt();
			stdIn.nextLine();

			int[] tempary = dicemap.get(top);

			int frontindex = dicevalue.indexOf(front) + 1;
			int leftindex = 0;
			;

			for (int i = 0; i < 4; i++) {
				if (tempary[i] == frontindex) {
					if (i == 3) {
						leftindex = tempary[0];
					} else {
						leftindex = tempary[i + 1];
					}
				}
			}
			System.out.println(dicevalue.get((leftindex) - 1));
		}

		stdIn.close();
	}
}

Measured memory_bytes: 26260
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n;cin>>n;
    vector<ll> l(n);
    rep(i,n) cin>>l[i];

    sort(ALL(l));
    ll ans=0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            ll x=l[i]+l[j];
            auto ite=upper_bound(ALL(l),x-1);
            ll idx=(ite-l.begin());
            ans+=(max(0ll,idx-j-1));
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ll a, b;
	cin>>a>>b;
	cout<<a*b<<endl;

	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define itn int
typedef long long ll;
typedef pair<int,int> p;


int main()
{
  int a, b;
  cin >> a >> b;
  int count = 0;
  for (int i = 1; i <= b - a; i++){
    count += i;
  }
  cout << count - b << endl;
}

Measured memory_bytes: 256
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;



/* Name of the class has to be "Main" only if the class is public. */
public class Main
 
 
{
    static Scanner in = new Scanner(System.in);
   
    public static void solve()
    {
        int n=in.nextInt();
        
        int x=n%10;
        
        if(x==2 ||x==4 ||x==5 ||x==7 ||x==9)
        {
            System.out.println("hon");
        }
        else if(x==0 ||x==1 ||x==6 ||x==8 )
        {
            System.out.println("pon");
        }
        else
        {
            System.out.println("bon");
        }
        
    }
    

    
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		
		int t=1;
		//in.nextLine();
		
		while(t>0)
		{
		    
		    solve();
		    t--;
		}
		
		
	
	//	System.out.println(x);
	}
}


Measured memory_bytes: 35752
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}
 

 
int main(){

  int a,b;
  cin >> a >> b;

  a += b;
  a %= 24;
  cout << a << endl;
}

Measured memory_bytes: 256
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Threading;
using System.Runtime.CompilerServices;
using System.IO.Pipes;

namespace AtCoder
{
    class Program
    {

        struct Point
        {
            public int x;
            public int y;

            public Point(int x, int y)
            {

                this.x = x;
                this.y = y;

            }

        }


        const int BiggestMod = 1000000007;

        public static void Main()
        {

            var num = int.Parse(Console.ReadLine());
            var lines = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var ans = 0;

            Array.Sort(lines);

            for (int i = 0, l = num - 2; i < l; ++i)
                for (int j = i + 1, m = num - 1; j < m; ++j)
                    if (lines[i] != lines[j])
                        for (int k = j + 1; k < num; ++k)
                            if (lines[j] != lines[k])
                                if (lines[k] < lines[i] + lines[j])
                            ans++;

            Console.WriteLine(ans);

        }

    }

}

Measured memory_bytes: 28012
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<utility>
#include<limits>
using namespace std;
typedef pair<int, int> Edge;
int main()
{
	int n; cin >> n;
	vector< vector< Edge > > lists;

	for (int i = 0; i < n; i++)
	{
		vector<Edge> list;
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++)
		{
			Edge edge;
			cin >> edge.second >> edge.first;
			list.push_back(edge);
		}
		lists.push_back(list);
	}

	vector<int> costs(n, -1);
	costs[0] = 0;
	priority_queue<Edge,vector<Edge>,greater<Edge> > queue;
	queue.push(Edge(0, 0));

	while (!queue.empty())
	{
		Edge edge = queue.top(); queue.pop();
		int dest = edge.second;
		int cost = edge.first;
		if (costs[dest]<cost)continue;
		for (Edge next : lists[dest])
		{
			next.first += cost;
			if (costs[next.second] > next.first||costs[next.second]==-1)
			{
				costs[next.second] = next.first;
				queue.push(next);
			}
		}
	}
	for (int i = 0; i < n; i++)
		cout << i << " " << costs[i] << endl;

	char c;
	cin >> c;

	return 0;
}


Measured memory_bytes: 6976
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;
long long n,k,tmpl;
vector<vector<int>> G;
vector<long long> l;

bool dfs(int u){
    if(l[u]<=k/2)tmpl++;
    for(int v:G[u]){
        if(l[v]==-1){
            l[v]=l[u]+1;
            dfs(v);
        }
    }
    return 0;
}

int main(int argc, char const *argv[]) {
    cin>>n>>k;
    G = vector<vector<int>>(n,vector<int>(0));
    vector<int> us(n-1),vs(n-1);
    for(int i=0;i<n-1;++i){
        int u,v;cin>>u>>v;
        u--;v--;
        G[u].push_back(v);
        G[v].push_back(u);
        us[i]=u;
        vs[i]=v;
    }
    long long res = n;
    if(k%2==0){
        for(int i=0;i<n;++i){
            tmpl = 0;
            l = vector<long long>(n,-1);
            l[i] = 0;
            dfs(i);
            res = min(res,n-tmpl);
        }
    }
    else{
        for(int i=0;i<n-1;++i){
            tmpl = 0;
            l = vector<long long>(n,-1);
            l[us[i]] = 0;
            l[vs[i]] = 0;
            dfs(us[i]);
            dfs(vs[i]);
            res = min(res,n-tmpl);
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int N, E, T;
	while(cin >> N >> E >> T){
		long long res = E;
		vector<int> x(N);
		for(int i=0;i<N;i++) cin >> x[i];
		vector<long long> dp(N+1);
		vector<long long> dp2(N);
		dp[N-1] = E+T; dp[N] = E;
		dp2[N-1] = dp[N] + 2*x[N-1];
		int thr = N-1;
		for(int i=N-2;i>=0;i--){
			while(2*(x[thr] - x[i]) > T) --thr;
			dp[i] = T+dp[thr+1];
			if(thr+1 < N) dp[i] = min(dp[i], dp2[thr+1]-2*x[i]);
			dp2[i] = min(dp2[i+1], dp[i+1] + 2*x[i]);
		}
		cout << dp[0] << endl;
	}
}



Measured memory_bytes: 2176
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b > c + d) {
        cout << "Left" << endl;
    }
    else if (a + b < c + d) {
        cout << "Right" << endl;
    }
    else {
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.length();
  int ans = 0;
  for (int i = 0; i < N / 2; i++) ans += S[i] != S[N - 1 - i];
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>

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

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

void solve() {
    int n, a, b;
    cin >> n >> a >> b;

    while(1){
        if(a < b-1){
            a++;
        }else{
            cout << "Borys" << endl;
            return;
        }
        if(b > a+1){
            b--;
        }else{
          cout << "Alice" << endl;
          return;
        }
    }
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

struct que {
	int st, lim, c;

	que() {
		st = lim = c = 0;
	}
} req[MAXN];

vector<int> adj[MAXN];

int cover[MAXN];

int col[MAXN];

int u[MAXN];

int d[MAXN];

int n, m, q;

void solve() {                   
	scanf("%d %d", &n, &m);

    for (int i = 1, u, v; i <= m; ++i) {
		scanf("%d %d", &u, &v);
		adj[u].pb(v);
		adj[v].pb(u);    
    }

    scanf("%d", &q);

    for (int i = 1; i <= q; ++i) {
    	scanf("%d %d %d", &req[i].st, &req[i].lim, &req[i].c);    	    		
    }

    for (int i = 1; i <= n; ++i) {
    	cover[i] = -1;
    }

    queue<int> Q;

    for (int i = q; i > 0; --i) {
    	int st = req[i].st, lim = req[i].lim, c = req[i].c;        

		Q.push(st);
    	d[st] = 0;
    	u[st] = i;

    	while (!Q.empty()) {
			int v = Q.front();
			Q.pop();

			if (!col[v]) {
				col[v] = c;
			}

			if (lim - d[v] <= cover[v]) {
				continue;
			}

			cover[v] = lim - d[v];

			if (d[v] != lim) {
    			for (int to : adj[v]) {
    				if (u[to] != i) {
    					u[to] = i;
    					d[to] = d[v] + 1;
    					Q.push(to);
    				}
    			}
    		}
    	}    	
    }

    for (int i = 1; i <= n; ++i) {
    	printf("%d\n", col[i]);
    }
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 9592
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;

int main(void)
{
	ll a, b, c;
	cin >> a >> b >> c;

	int flg = 0;

	if (a >= c) {
		a = a-c;
		flg = 1;
	} else {
		c = c-a;
		a = 0;
	}

	if (flg == 0) {
		if (b >= c) {
			b = b-c;
		}else {
			b = 0;
		}
	}

	cout << a << " " << b << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define mod 1000000007
#define INF 1000000000000000000
/****************************/
ll a[200020];
int main()
{
	ll n,k;
	cin>>n>>k;
	rep(i,k)
	{
		cin>>a[i];
	}
	ll ans=INF;
	rep(i,k)
	{
		if(i==0)
		{
			ans=min(ans,min(a[k-1]-a[0],n-(a[1]-a[0])));
		}
		else
		{
			if(i==k-1)
			{
				ans=min(ans,min(a[k-1]-a[0],n-(a[k-1]-a[k-2])));
			}
			else
				ans=min(ans,min(n-(a[i]-a[i-1]),n-(a[i+1]-a[i])));
		}
	}
	cout<<ans;
	return 0;
}

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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;


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

    int N;
    cin >> N;

    vector<int> h(N);
    REP(i, N) cin >> h[i];

    int dp[100005];
    FOR(i, 0, N) {
        dp[i] = INF;
    }

    dp[0] = 0;
    REP(i, N) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[N - 1] << endl;

    return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	cout << a * b - a - b + 1 << endl;
}

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

int main()
{
    int N;
    std::string s;
    std::cin >> N;
    std::cin >> s;

    int R_count, B_count;
    R_count = 0;
    B_count = 0;

    for (auto it : s)
    {
        if (it == 'R') {++R_count;}
        else if (it == 'B') {++B_count;}
    }

    if (B_count < R_count) {std::cout << "Yes" << std::endl;}
    else {std::cout << "No" << std::endl;}

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 500000
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	string s,t;
	cin>>s>>t;
	vector<int> a[26];
	REP(i,SZ(s)){
		a[s[i]-'a'].push_back(i);
	}
	ll ans=0;
	int tmp=-1;
	bool f=true;
	REP(i,SZ(t)){
		if(SZ(a[t[i]-'a'])==0){
			f=false;
			break;
		}
		int k=upper_bound(ALL(a[t[i]-'a']),tmp)-a[t[i]-'a'].begin();
		if(k==SZ(a[t[i]-'a'])){
			ans++;
			k=0;
		}
		tmp=a[t[i]-'a'][k];
	}
	ans=(ll)SZ(s)*(ans)+tmp+1;
	if(!f)ans=-1;
	OUT(ans);
	return 0;
}

Measured memory_bytes: 1216
#include<vector>
#include<iostream>
#include<algorithm>

#define	mp(a,b)		make_pair(a,b)
#define	mt(a,b,c)	mp(mp(a,b),c)
#define	_1st	first.first
#define	_2nd	first.second
#define	_3rd	second

using namespace std;

typedef	pair<int,int> pii;
typedef pair<pii,int> tiii;

vector<int> city;

int UF_Root(int i)
{
	if (city[i]==-1)	return i;
	return city[i]=UF_Root(city[i]);
}

bool UF_Find(int i,int j)
{
	return UF_Root(i)==UF_Root(j);
}

void UF_Union(int i,int j)
{
	i=UF_Root(i);
	j=UF_Root(j);
	if(i!=j)	city[j]=i;
}

int main()
{
	for(int n,m;cin>>n>>m,n;){
		city=vector<int>(n,-1);

		vector<tiii> data(m);
		while(m--){
			int a,b,c;	cin>>a>>b>>c;
			data[m]=mt(c,a,b);
		}
		sort(data.begin(),data.end());

		int totalcost=0;
		for(int i=0;i<data.size();i++){
			if(!UF_Find(data[i]._2nd,data[i]._3rd)){
				UF_Union(data[i]._2nd,data[i]._3rd);
				totalcost+=data[i]._1st;
			}
		}
		cout<<totalcost<<endl;
	}

	return 0;
}

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

int main() {
  string S, T;
  int A, B;
  string U;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  
  if(S == U) {
    cout << A - 1 << " " << B << endl;
  }
  if(T == U) {
    cout << A << " "  << B - 1 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int n;
    cin >> n;

    if(n%2 == 0)
    {
        cout << fixed << setprecision(15) << 0.5 << endl;
    }
    else {
        int m = n/2 + 1;
        cout << fixed << setprecision(15) << (double)m/n << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from fractions import gcd

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a



N, X = map(int, input().split())		# 5 7
A = list( map(int, input().split()) )	# 1 2 3 4 5 ...(ソート付き)

#print(A)

A = A + [X]
A.sort()

B=[]
for i in range(N):
	B.append(A[i+1]-A[i])

#print(A)
#print(B)


a = B[0]
for b in B:
	a = gcd(a, b)

print(a)
exit(0)



Measured memory_bytes: 16276
#include <iostream>

using namespace std;

//ifstream cin("/home/mihai/Documents/C++/ATCoder/Beginer_097/B/B.in");
//ofstream cout("/home/mihai/Documents/C++/ATCoder/Beginer_097/B/B.out");

int main()
{
	int a;
	cin >> a;
	int sol = 1;
	for(int i = 2; i * i <= a; i++)
	{
		int p = i;
		while(p * i <= a)
			p *= i;
		if(p > sol)
			sol = p;
		if(p == a)
		{
			cout << a;
			return 0;
		}
	}
	cout << sol;
}

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

int main(){
    int A, B;
    cin >> A >> B;
    if (A > B){
        int tmp = B;
        B = A;
        A = tmp;
    }
    if (A == 1 && B == 2){
        cout << 3 << endl;
    }else if(A == 1 && B == 3){
        cout << 2 << endl;
    }else{
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a , b;
	cin >> a >> b;
	int p = a + a - 1;
	int s = b + b - 1;
	int t = a + b;
	int d = max(p , s);
	cout << max(d , t) << endl;
	return 0;
}

Measured memory_bytes: 256
K,N=map(int,input().split())
A=list(map(int,input().split()))
dis=[]
for i in range(N):
    if i<N-1:
        dis.append(A[i+1]-A[i])
    else:
        dis.append(A[(i+1)%N]-A[i]+K)
dis=sorted(dis)[::-1]
print(K-dis[0])

Measured memory_bytes: 26060
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    houses=[]
    k,n=map(int,input().split())
    houses=list(map(int,input().split()))
    distance=[]
    
    for i in range(1,n):
        distance.append(houses[i]-houses[i-1])
    distance.append(k-(houses[-1]-houses[0]))

    max_length=max(distance)    
    print(sum(distance)-max_length)

if __name__=="__main__":
    main()

Measured memory_bytes: 31572
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n,m;
    cin>>n>>m;
    int Max=m/n;
    for(int i=Max;i>=1;i--){
        if(m%i==0){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    long long N, P, A[51], B[51], i, ans=1, count1=0;

    cin >> N >> P;

    for(i=1; i<=N; i++){
        cin >> A[i];

        B[i] = A[i] % 2;

        if(B[i] == 0){
            ans *= 2;
        }

        else{
            count1++;
        }
    }

    if(count1 >= 1){
        ans *= pow(2, count1-1);
    }

    else{
        if(P==1){
            ans = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
H=[int(h) for h in input().split()][::-1]
A="Yes"
for i in range(N-1):
    if H[i+1]-H[i] > 1:
        A="No"
        break;
    elif H[i+1]-H[i] == 1:
        H[i+1] -= 1
print(A)

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

using namespace std;

const int N = 2007;

int m, n, q, v[N][N], f[N][N], e[N][N], x, y, X, Y;
int u[N][N], l[N][N];
char a[N][N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> m >> n >> q;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++){
            cin >> a[i][j];
            if (a[i][j] == '1'){
                f[i][j] += (a[i - 1][j] == '1') + (a[i][j - 1] == '1');
            }
            v[i][j] = v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1] + (a[i][j] == '1');
        }
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++){
            e[i][j] = e[i - 1][j] + e[i][j - 1] - e[i - 1][j - 1] + f[i][j];
            u[i][j] = u[i][j - 1];
            l[i][j] = l[i - 1][j];
            if (a[i][j] == '1'){
                u[i][j] += (a[i - 1][j] == '1');
                l[i][j] += (a[i][j - 1] == '1');
            }
        }
    for (int i = 1; i <= q; i++){
        cin >> x >> y >> X >> Y;
        int V = v[X][Y] - v[x - 1][Y] - v[X][y - 1] + v[x - 1][y - 1];
        int E = e[X][Y] - e[x - 1][Y] - e[X][y - 1] + e[x - 1][y - 1];
        cout << V - E + u[x][Y] - u[x][y - 1] + l[X][y] - l[x - 1][y] << endl;
    }
}


Measured memory_bytes: 84352
#include<bits/stdc++.h>
using namespace std;
main()
{
 long long int x, y,i, j;
 cin >> x >> y;
 for(i=0;i<=100;i++)
 for(j=0;j<=100;j++)
 {
 	if((i*4+2*j) == y && i+j == x)
 	{
 		cout << "Yes" << endl;
 		return 0;
	 }
	 }	
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int Ccheck = 0, bigcount = 0;
  string s;
  cin >> s;
  for (int i = 2; i < s.length()-1; i++) {
    if (s[i]=='C') {
      Ccheck++;
      continue;
    }
  }
  for (int i = 0; i < s.length(); i++) {
    if ((char)s[i]>='A' && (char)s[i]<='Z') {
      bigcount++;
    }
  }
  if (s[0]=='A' && Ccheck==1 && bigcount==2) {
    printf("AC\n");
  } else {
    printf("WA\n");
  }
}

Measured memory_bytes: 256
h, w, d = gets.split.map(&:to_i)
a = {}

1.upto(h) do |i|
  line = gets.split.map(&:to_i)
  line.each_with_index do |v, j|
    # 0-indexedなので+1
    a[v] = [i, j + 1]
  end
end

q = gets.to_i

lr = []
q.times do
  lr.push gets.split.map(&:to_i)
end

cost = Hash.new(1)

(d + 1).upto(h * w) do |i|
  cost[i] = cost[i - d] + (a[i][0] - a[i - d][0]).abs +
            (a[i][1] - a[i - d][1]).abs
end

lr.each do |x|
  puts cost[x[1]] - cost[x[0]]
end


Measured memory_bytes: 27900
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>
#include <sstream>
#include <iomanip>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;

class CT
{
public:
	pair<int, int> py;
	int index;

	bool operator<(CT other) {
		return py < other.py;
	}
};

int main()
{
	int N;

	cin >> N;

	vector<int> As(N);

	int min_v = 1e9;
	int min_index = 0;
	for (int ni = 0; ni < N; ni++) {
		cin >> As[ni];
		if (As[ni] < min_v) {
			min_v = As[ni];
			min_index = ni;
		}
	}


	int mod;
	int new_min_v = min_v;
	int new_min_index;
	while (1) {
		vector<int> new_As;
		for (int ni = 0; ni < As.size(); ni++) {
			if (ni == min_index){
				new_As.push_back(As[ni]);
			}
			else {
				mod = As[ni] % min_v;
				if (mod != 0) {
					if (mod < new_min_v) {
						new_min_v = mod;
						new_min_index = new_As.size();
					}
					new_As.push_back(mod);
				}
			}
		}
		if (new_As.size() == 1) break;
		As = new_As;
		min_v = new_min_v;
		min_index = new_min_index;
	}


	//printf("%d %d %lld", xi, yi, H + gap);

	cout << min_v;
	

	return 0;
}



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

typedef long long LL;

void setIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

int main() {
    setIO();
    LL n;
    cin>>n;
    LL mod = 1e9+7;
    LL fa=0,fb=0,ga0=0,gb0=0,ga9=0,gb9=0,ha=1,hb=1;
    for (int i = 1; i <= n; i++) {
        fb=(10*fa+2*gb0)%mod;
        gb0=(9*ga0+ha)%mod;
        gb9=(9*ga9+ha)%mod;
        hb=(8*ha)%mod;
        fa=fb; ga0=gb0; ga9=gb9; ha=hb;
    }
    cout<<fb<<endl;
    return 0;
}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Main {
    int n;
    long[] fac, iFac;
    int MOD = 1000000007;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        solve();
    }

    void solve() {
        fac = new long[n + 1];
        iFac = new long[n + 1];
        fillFactorials();
        long ans = 0;
        long prevWays = 0;
        if (n == 2) {
            ans = 1;
        } else if (n == 3) {
            ans = 4;
        } else {
            int start = (n % 2 == 0) ? n / 2 : (n + 1) / 2;
            for (int k = start; k < n; k++) {
                long ways = (combination(k - 1, n - 1 - k) * fac[k] % MOD) *
                        fac[n - 1 - k] % MOD;
                ans = (ans + (ways - prevWays + MOD) % MOD * k % MOD ) % MOD;
                prevWays = ways;
            }
        }
        System.out.println(ans);
    }

    long combination(int n, int r) {
        if (n < r) return 0;
        if (n < 0) return 0;
        return fac[n] * iFac[n - r] % MOD * iFac[r] % MOD;
    }

    void fillFactorials() {
        fac[0] = 1;
        iFac[0] = 1;
        for (int i = 1; i < fac.length; i++) {
            fac[i] = i * fac[i - 1] % MOD;
            //iFac[i] = (new BigInteger(Long.toString(fac[i]))).modPow(
            //        new BigInteger(Long.toString(MOD - 2)),
            //                new BigInteger(Integer.toString(MOD))).longValue();
            iFac[i] = power(fac[i], MOD - 2, MOD);
        }
    }

    long power(long a, long b, long mod) {
        long x = 1;
        long y = a;
        while (b > 0) {
            if (b % 2 == 1) {
                x = x * y % mod;
            }
            y = y * y % mod;
            b /= 2;
        }
        return x % mod;
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "YES"
#define NO  "NO"

using namespace std;

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int a, b, c; cin >> a >> b >> c;
  if (b - a == c - b) flag = true;

  // cout << num << endl;
  cout << (flag ? YES : NO) << endl;
  
  return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define vi vector<int>

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}


int main() {
ll a,b;
cin>>a>>b;
cout<<(a*b)/__gcd(a,b)<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> mp;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
その時点で受けれる一番報酬の高いものを取り続ける
*/

ll n,m,ans=0;
vector<ll> v[100010];
mp w[100010];

void init(){
	cin>>n>>m;
	rep(i,n){
		ll a,b;
		cin>>a>>b;
		w[i]={b,a};
		v[a].push_back(b);
	}
	sort(w,w+n);
}

int main(void){
	init();
	ll d=0;
	priority_queue<ll> Q;
	ireg(i,0,m){
		rep(j,v[m-i].size()){  // 受けれるやつ
			Q.push(v[m-i][j]);
		}
		if(!Q.empty()){
			ll p = Q.top();Q.pop();
			ans+=p;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int cnt[1000001];
vector<bool> valid(1000001, true);

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	memset(cnt, 0, sizeof(cnt));
	int n;
	cin >> n;
	ll tmp;
	for(int i = 1; i <= n; i++){ 
		cin >> tmp;
		cnt[tmp]++;
	}
	int ans = 0;
	for(ll i = 1; i <= 1000001; i++) {
		if (valid[i] && cnt[i] == 1) ans++;
		if (cnt[i] > 0) {
			for(int j = i + i; j <= 1000001; j += i)
				valid[j] = 0;
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 7672
n=int(input())
p=list(map(int, input().split()))
i=0
for x in range(0,n-2):
    if p[x]>p[x+1] and p[x+1]>p[x+2]:
        i=i+1
    if p[x]<p[x+1] and p[x+1]<p[x+2]:
        i=i+1
    if p[x]==p[x+1] and p[x+1]<p[x+2]:
        i=i+1
    if p[x]>p[x+1] and p[x+1]==p[x+2]:
        i=i+i
print(i)


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

int main()
{
	int a[4][4];
	bool b[4][4]={false};
	for(int i=1;i<=3;i++)
	  for(int j=1;j<=3;j++)
	    cin>>a[i][j];
	
	int n,x;
	cin>>n;
	for(int k=1;k<=n;k++)
	{
		cin>>x;
		for(int i=1;i<=3;i++)
		  for(int j=1;j<=3;j++)
		    if(a[i][j]==x) 
			  b[i][j]=true; 
	}
	
    if(b[1][1]&&b[1][2]&&b[1][3])
    {
    	cout<<"Yes";
    	return 0;
	}
	if(b[2][1]&&b[2][2]&&b[2][3])
    {
    	cout<<"Yes";
    	return 0;
	}
	if(b[3][1]&&b[3][2]&&b[3][3])
    {
    	cout<<"Yes";
    	return 0;
	}
	if(b[1][1]&&b[2][1]&&b[3][1])
    {
    	cout<<"Yes";
    	return 0;
	}
	if(b[1][2]&&b[2][2]&&b[3][2])
    {
    	cout<<"Yes";
    	return 0;
	}
	if(b[1][3]&&b[2][3]&&b[3][3])
    {
    	cout<<"Yes";
    	return 0;
	}
	if(b[1][1]&&b[2][2]&&b[3][3])
    {
    	cout<<"Yes";
    	return 0;
	}
	if(b[1][3]&&b[2][2]&&b[3][1])
    {
    	cout<<"Yes";
    	return 0;
	}
	cout<<"No";
	return 0;
	
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >>N;
vector<int> X(N),Y(N), A(N), B(N);
int a1,a2,b1,b2;
for(int i = 0 ; i < N ; i++){
cin >> X.at(i) >>Y.at(i);
A.at(i) = X.at(i)  - Y.at(i), B.at(i) = X.at(i)  + Y.at(i);

}
a1 = a2 = A.at(0);
b1 = b2 = B.at(0);
for(int i = 0 ; i < N ; i++){
if(a1 < A.at(i)){
a1 = A.at(i);
}
if(a2 > A.at(i)){
a2 = A.at(i);
}
if(b1 < B.at(i)){
b1 = B.at(i);
}
if(b2 > B.at(i)){
b2 = B.at(i);
}
}
int e = a1 - a2, f = b1- b2,g;
g = max(e,f);
cout << g <<endl;
}

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

ll a,b,c;
vector<ll>v;

int main(){
    cin >> a >> b >> c;
    ll ans = 0;
    if(a+b>=c)ans= b + c;
    else ans = a + 2 * b + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

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

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int a,b,c;
	cin >> a >> b >> c;
	cout << (min(b/a,c)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int; // 多倍長整数（任意精度）


void dfs(int i, const int size, const int range_start, const int range_end, vector<int> &A, int &max, vector<int> a, vector<int> b, vector<int> c, vector<int> d)
{
    if (i == size) {
      // for(int i = 0; i < A.size(); ++i){
      //   cout << A[i] << " ";
      // }
        
      int sum = 0;

      for(int i = 1; i < a.size(); ++i){
        if(A[b[i]-1] - A[a[i]-1] == c[i]){
          sum += d[i];
        }
      }

      if(max < sum){
        max = sum;
      }
    }
    else{
      for(int j = range_start; j <= range_end; ++j){
        A[i] = j;
        dfs(i + 1, size, j, range_end, A, max, a, b, c, d);
      }
    }
}

int main(){
  int N, M, Q;

  cin >> N >> M >> Q;

  vector<int> a(Q+1), b(Q+1), c(Q+1), d(Q+1);

  for(int i = 1; i <= Q; ++i){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  vector<int> A(N);
  int max = -1;

  int size = N;
  int range_start = 1;
  int range_end = M;
    
  dfs(0, size, range_start, range_end, A, max, a, b, c, d);
  
  cout << max << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
  int H, W;
  int i, j;

  while (1) {
    scanf("%d %d", &H, &W);
    if (H == 0 && W == 0) break;

    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++) {

        if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
          putchar('#');
        } else {
          putchar('.');
        }

      }
      putchar('\n');
    }
    putchar('\n');
  }

  return 0;
}

Measured memory_bytes: 572
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        int H,W;
        while(true){
          H=sc.nextInt();
          W=sc.nextInt();
          if(H==0 && W==0){
              break;
          }
          for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                if(i%2!=0){
                    if(j%2!=0){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                    
                }else{
                    if(j%2!=0){
                        System.out.print(".");
                    }else{
                        System.out.print("#");
                    }
                    
                }
                
            }
            System.out.println("");
          }  
          System.out.println("");
        }
        
    }
}


Measured memory_bytes: 32464
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define forit(it, st) for(auto it : st)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);

bool used[N];

vector<int> g[N];

int deg[N];

map<pair<int, int>, int> xx, w;

int cnt[N];

void solve(){
	char c;
	cin >> c;
	if(c == 'a' || c == 'e' || c == 'o' || c == 'i' || c == 'u') cout << "vowel";
	else cout << "consonant";
}	

 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}


Measured memory_bytes: 27392
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;

template <typename T> void output(T, int);
template <typename T> T max(T, T);
int gcd(int a, int b);

bool is_prime(int n){
    if(n==2){
        return true;
    }

    for(int i=2;i<sqrt(n)+1;i++){
        if(n%i==0){
            return false;
        }
    }

    return true;
}

int main() {
    // source
    int n;
    cin >> n;
    int temp=n;
    vector<int> ans;
    int num=11;
    while (temp > 0) {
        if(is_prime(num)){
            ans.push_back(num);
            temp--;
        }

        num+=5;
    }

    rep(i, n) { cout << ans[i] << " "; }
    cout << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T max(T a, T b) {

    if (a > b) {
        return a;
    } else {
        return b;
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
from time import perf_counter
t0 = perf_counter()


import sys
sys.setrecursionlimit(300000)
from collections import defaultdict
from random import randint

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


D = I()
C = LMI()
S = [LMI() for _ in range(D)]


# 初期解の生成
ans0 = []
for d in range(D):
    ans0.append(d % 26)
#
# last = defaultdict(int)
# ans0 = []
# for d in range(D):
#     m = -INF
#     ans = -1
#     for i in range(26):
#         lans = S[d][i]
#         for j in range(26):
#             if i == j:
#                 lans -= C[j] * (d + 1 - d - 1)
#             else:
#                 lans -= C[j] * (d + 1 - last[j])
#         if lans > m:
#             m = lans
#             ans = i
#     ans0.append(ans)



T = ans0
last = [[i + 1] * 26 for i in range(D)]
for d in range(D):
    i = T[d]
    j = 0
    for dd in range(d, D):
        last[dd][i] = j
        j += 1

def eval(d, q):
    i = T[d]
    val = S[d][q] - S[d][i]

    contrib = 0
    if d == 0:
        j = 1
    else:
        j = last[d - 1][i] + 1
    for dd in range(d, D):
        if dd > d and last[dd][i] == 0:
            break
        contrib += j - last[dd][i]
        j += 1
    val -= contrib * C[i]

    contrib = 0
    j = 0
    for dd in range(d, D):
        if last[dd][q] == 0:
            break
        contrib += last[dd][q] - j
        j += 1
    val += contrib * C[q]

    return val

def apply(d, q):
    i = T[d]

    if d == 0:
        j = 1
    else:
        j = last[d - 1][i] + 1
    for dd in range(d, D):
        if dd > d and last[dd][i] == 0:
            break
        last[dd][i] = j
        j += 1

    j = 0
    for dd in range(d, D):
        if last[dd][q] == 0:
            break
        last[dd][q] = j
        j += 1

    T[d] = q


# TLまで焼きなましで1点更新
i = 0
while perf_counter() - t0 < 1.8:
    d = randint(0, D - 1)
    q = randint(0, 25)
    if eval(d, q) > 0:
        apply(d, q)
    else:
        if randint(0, (i + 1) ** 2) == 0:
            apply(d, q)
    i += 1

for t in T:
    print(t + 1)

Measured memory_bytes: 83028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    int n,a(0),b(0),c(0);
    cin >> n;
    int x[n],y[n],t[n];
    rep(i,n){
        cin >> t[i] >> x[i] >> y[i];
    }

    rep(i,n){
        int d = abs(x[i]-a)+abs(y[i]-b);
        c = t[i] - c;
        if(d>c){
            puts("No");
            return 0;
        }else if(abs(c-d)%2!=0){
            puts("No");
            return 0;
        }else{
            a = x[i];
            b = y[i];
            c = t[i];
        }
    }

    puts("Yes");

    return 0;
}

Measured memory_bytes: 1408