akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>

using namespace std;

#define INF 100000000

int main(){
    int H, W;
    cin >> H >> W;
    string S[H];
    for(int i=0 ;i<H; i++){
        cin >> S[i];
    }
    pair<int, int> move[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    int m = 0;
    for(int s = 0; s<H*W; s++){
        for(int g=s+1; g<H*W; g++){
            if(S[s/W][s%W] == '#') continue;
            if(S[g/W][g%W] == '#') continue;
            bool visited[H][W];
            int dist[H][W];
            for(int i=0; i<H; i++){
                for(int j=0; j<W; j++){
                    visited[i][j] = false;
                    dist[i][j] = INF;
                }
            }
            queue<int > q;
            dist[s/W][s%W] = 0;
            visited[s/W][s%W] = true;
            q.push(s);
            while(!q.empty()){
                int v = q.front(); q.pop();
                for(auto m : move){
                    int i= v/W + m.first;
                    int j= v%W + m.second;
                    if(0<=i && i<H && 0<=j && j<W){
                        if(!visited[i][j] && S[i][j] == '.'){
                            q.push(W*i+j);
                            dist[i][j] = dist[v/W][v%W] + 1;
                            visited[i][j] = true;
                        }
                    }
                }
            }
            m = max(m, dist[g/W][g%W]);
        }
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
M,K=[int(i) for i in input().split()]
#M,K=1,0
if K>=2**M:
    print(-1)
    sys.exit()
    
if M==1:
    if K==0:
        print(*[0,0,1,1])
        sys.exit()
    else:
        print(-1)
        sys.exit()
L=[]
l=[int(i) for i in range(2**M) if i !=K]
L.extend(l)
L.append(K)
L.extend(l[::-1])
L.append(K)

print(*L)

Measured memory_bytes: 16276
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int a, b, mul;
		Scanner scanner = new Scanner(System.in);
		a = scanner.nextInt();
		b = scanner.nextInt();
		mul = a * b;
		if(mul % 2 == 0) {
			System.out.println("No\n");
		}else
			System.out.println("Yes\n");
	}

}


Measured memory_bytes: 23380
import java.util.Scanner;


public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = 0;
        int n = sc.nextInt();
        int a[] = new int[n];
        while(i<n){
        a[i] = sc.nextInt();
        i++;
        }
        while(i-1>=0){
             if (i==1){
        System.out.print(a[i-1]);
        break;
        }
        System.out.print(a[i-1]+" ");
         
        i--;
        }
        System.out.println();
}
}



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

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FOR(i, 1, n + 1)
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

ll junretu(int n, int k)
{
	ll result = 1;
	REP(i, k)
	{
		result *= n;
		result %= MOD;
		--n;
	}
	return result;
}

long long modinv(long long a, long long m)
{
	long long b = m, u = 1, v = 0;
	while (b)
	{
		long long t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= m;
	if (u < 0)
		u += m;
	return u;
}

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

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

//a,bの最大公約数
ll gcd(ll a, ll b)
{
	ll temp;
	while (a % b != 0)
	{
		temp = a;
		a %= b;
		b = temp;
	}
	return b;
}

//a,bの最小公倍数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

const int MAX_N = 1e5 + 10;
int n, m;
bool a[MAX_N];
ll dp[MAX_N];

int main()
{
	cin >> n >> m;
	REP(i, MAX_N)
	{
		a[i] = true;
	}
	REP(i, m)
	{
		int x;
		cin >> x;
		x;
		a[x] = false;
	}
	dp[0] = 1;
	REP(i, n + 1)
	{
		if (a[i + 1])
		{
			dp[i + 1] += dp[i];
			dp[i + 1] %= MOD;
		}
		if (a[i + 2])
		{
			dp[i + 2] += dp[i];
			dp[i + 2] %= MOD;
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1152
#input
N, M = map(int, input().split())
x = []
y = []
z = []
for i in range(N):
    x_temp, y_temp, z_temp = map(int, input().split())
    x.append(x_temp)
    y.append(y_temp)
    z.append(z_temp)

#output
#+++
a1 = [p+q+r for p, q, r in zip(x, y, z)]
a1.sort(reverse = True)
b1 = sum(a1[:M])

#++-
a2 = [p+q-r for p, q, r in zip(x, y, z)]
a2.sort(reverse = True)
b2 = sum(a2[:M])

#+-+
a3 = [p-q+r for p, q, r in zip(x, y, z)]
a3.sort(reverse = True)
b3 = sum(a3[:M])

#-++
a4 = [-p+q+r for p, q, r in zip(x, y, z)]
a4.sort(reverse = True)
b4 = sum(a4[:M])

#+--
a5 = [p-q-r for p, q, r in zip(x, y, z)]
a5.sort(reverse = True)
b5 = sum(a5[:M])

#-+-
a6 = [-p+q-r for p, q, r in zip(x, y, z)]
a6.sort(reverse = True)
b6 = sum(a6[:M])

#--+
a7 = [-p-q+r for p, q, r in zip(x, y, z)]
a7.sort(reverse = True)
b7 = sum(a7[:M])

#---
a8 = [-p-q-r for p, q, r in zip(x, y, z)]
a8.sort(reverse = True)
b8 = sum(a8[:M])

print(max(b1, b2, b3, b4, b5, b6, b7, b8))


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

string comp(string a,string b){
  if(a.size()>b.size()){
    return "GREATER";
  }else if(a.size()<b.size()){
    return "LESS";
  }else{
    for(int i=0;i<a.size();i++){
      if(a.at(i)>b.at(i))
        return "GREATER";
      else if(a.at(i)<b.at(i))
        return "LESS";
    }
    return "EQUAL";
  }
}

int main (){
  string a,b;
  cin >> a >> b;
  cout << comp(a,b) << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void){

	int W, H, x, y, r;

	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);

	if (W >= x + r&&H >= y + r&&W >= x - r&&H >= y - r&&x>=0&&y>=0)
	{
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

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

namespace abc104a
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = int.Parse(Console.ReadLine());
            if (r < 1200)
                Console.WriteLine("ABC");
            else if(r<2800)
                Console.WriteLine("ARC");
            else
                Console.WriteLine("AGC");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    string s;
    cin>>s;
    n = s.size();
    z = 0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            z+=(s[i]=='p')?-1:0;
        }
        else{
            z+=(s[i]=='g')?1:0;
        }
    }
    cout<<z;


    return 0;
}

Measured memory_bytes: 512
H, W = map(int, input().split())

def check(h, w):
	if h % 3 == 0 or w % 3 == 0:
		return 0

	else:
		block1 = w * (h // 3)
		block2 = (h - (h // 3)) * (w // 2)
		block3 = h * w - block1 - block2
		gap1 = max(block1, block2, block3) - min(block1, block2, block3)

		block4 = w * (h // 3 + 1)
		block5 = (h - 1 - (h // 3)) * (w // 2)
		block6 = h * w - block4 - block5
		gap2 = max(block4, block5, block6) - min(block4, block5, block6)

		return(min(gap1, gap2, min(w, h)))

print(min(check(H, W), check(W, H)))


Measured memory_bytes: 3064
import java.util.*;
import java.lang.reflect.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<String> strs = new ArrayList<String>();
        for(int i = 0; i < 3; i++){
            String s = sc.nextLine();
            strs.add(s);
        }
        StringBuilder a = new StringBuilder();
        StringBuilder b = new StringBuilder();
        for(int i = 0; i < 3; ++i){
            a.append(strs.get(i).charAt(i));
            b.append(strs.get(2-i).charAt(2-i));
        }
        System.out.println(a);
    }
}

Measured memory_bytes: 20820
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>


int main(void){
	char c[100024];
	char hoge[2] = "01";
	char piyo[2] = "10";
	int ans1=0;
	int ans2=0;
	
	scanf("%s",c);
	int i,j;

	for(i=0;c[i]!='\0';i++){
		if(c[i] != hoge[i%2]){
			ans1++;
		}
		if(c[i] != piyo[i%2]){
			ans2++;
		}
	}

	printf("%d\n",(ans1<ans2)?ans1:ans2);
	return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_INFO_MAX		100										// 最大情報数
#define D_RNG_S			0										// 座標範囲 - 開始
#define D_RNG_E			100										// 座標範囲 - 終了

// 内部構造体 - 情報
typedef struct Info {
	int miX, miY;												// 座標
	int miH;													// 高さ
} Info;

// 内部変数
static FILE *szpFpI;											// 入力
static Info sz1Info[D_INFO_MAX];								// 情報
static int siICnt;												// 情報数
static int siX;													// 中心座標X
static int siY;													// 中心座標Y
static int siH;													// 高さ

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 算出
int
fCalc(
)
{
	int i;

	// 座標範囲でループ
	for (siX = D_RNG_S; siX <= D_RNG_E; siX++) {
		for (siY = D_RNG_S; siY <= D_RNG_E; siY++) {

			// 高さ - セット
			for (i = 0; i < siICnt; i++) {
				if (sz1Info[i].miH > 0) {
					siH = sz1Info[i].miH + abs(siX - sz1Info[i].miX) + abs(siY - sz1Info[i].miY);
					break;
				}
			}

			// 高さ - 正当性チェック
			for (i = 0; i < siICnt; i++) {
				int liH = siH - abs(siX - sz1Info[i].miX) - abs(siY - sz1Info[i].miY);
				if (liH < 0) {
					liH = 0;
				}
				if (liH != sz1Info[i].miH) {
					break;
				}
			}
			if (i == siICnt) {
				return 0;
			}
		}
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 情報数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siICnt);

	// 情報 - 取得
	for (i = 0; i < siICnt; i++) {
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d%d", &sz1Info[i].miX, &sz1Info[i].miY, &sz1Info[i].miH);
	}
	
	// 算出
	fCalc();

	// 結果 - セット
	sprintf(lc1Out, "%d %d %d\n", siX, siY, siH);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

using namespace std;
typedef long long ll;
#define int ll
const int maxn = 2e4 + 10;
int dp[maxn];

signed main()
{
	int h, n;
	scanf("%lld%lld", &h, &n);
	memset(dp, 0x3f, sizeof dp);
	dp[0] = 0;
	for(int p = 0; p < n; p ++)
	{
		int val, cost;
		scanf("%lld%lld", &val, &cost);
		for(int i = val; i < maxn; i ++)
		{
			if(dp[i - val] != 0x3f3f3f3f3f3f3f3f)	dp[i] = min(dp[i], dp[i - val] + cost);
		}
	}
	int res = 0x3f3f3f3f3f3f3f3f;
	for(int i = h; i < maxn; i ++) res = min(res, dp[i]);
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

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

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    ll n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];

    vi s;
    vi ord(n+1, -1);
    int c = 0, l = 0;
    {
        int v = 1;
        while(ord[v] == -1) {
            ord[v] = s.size();
            s.push_back(v);
            v = a[v-1];
        }
        c = s.size() - ord[v];
        l = ord[v];
    }

    if(k < l) cout << s[k] << endl;
    else {
        k -= l;
        k %= c;
        cout << s[l + k] << endl;
    }

    return 0;
}


Measured memory_bytes: 5884
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

int main()
{
	string date;
	cin >> date;

	int year, month, day;
	year = (date[0] - '0') * 1000 + (date[1] - '0') * 100 + (date[2] - '0') * 10 + (date[3] - '0');
	month = (date[5] - '0') * 10 + (date[6] - '0');
	day = (date[8] - '0') * 10 + (date[9] - '0');

	if (year < 2019)
	{
		cout << "Heisei" << endl;
	}
	else if (year > 2019)
	{
		cout << "TBD" << endl;
	}
	else
	{
		if (month < 4)
		{
			cout << "Heisei" << endl;
		}
		else if (month > 4)
		{
			cout << "TBD" << endl;
		}
		else
		{
			if (day <= 30)
			{
				cout << "Heisei" << endl;
			}
			else
			{
				cout << "TBD" << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
p_list = list(map(int,input().split()))
ans_list = []
def E(me):
    if me == 1:
        return 1
    else:
        return ((1+me)*me/2)/me
E_list_ruisekiwa = [0,]
for i in range(N):
    E_list_ruisekiwa.append(E_list_ruisekiwa[i]+E(p_list[i]))

ans = 0
for i in range(N-K+1):
    ans = max(E_list_ruisekiwa[i+K]-E_list_ruisekiwa[i],ans)
print(ans)


Measured memory_bytes: 25604
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    # turn = A
    # while not ((a == 1 and b == 2) or (a == (n-1) and b == n)):
    #     if turn == A:
    #         if a + 1 < b:
    #             a += 1
    #         else:
    #             a -= 1
    #         turn = B
    #     else:
    #         if a + 1 < b:
    #             b -= 1
    #         else:
    #             b += 1
    #         turn = A

    if (b - a) % 2 == 1:
        print("Borys")
    else:
        print("Alice")


#    print("n")


resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


int32_t main() {

    fast
    int a, b, c, d;
    cin >>a >> b >> c >> d;

    int maxi=max({a*c,a*d,b*c,b*d});
    cout<<maxi;


    return 0;
}



Measured memory_bytes: 3648
s = input()
is_there = [False for i in range(26)]


for c in s:
    is_there[ord(c)-97] = True

if len(s) == 26:
    flag = True
    buf = []
    rep = None
    for i in range(25):
        buf.append(s[-i-1])
        for b in buf:
            if ord(b) > ord(s[-i-2]):
                rep = -i-2
                flag =False
                break
        if not flag:
            break


    if flag:
        print(-1)
    else:
        tp = s[:rep]
        tails = list(s[rep:])
        tails.sort()
        # print(rep)
        for t in tails:
            if ord(t) > ord(s[rep]):
                print(tp+t)
                break
else:
    for i in range(26):
        if not is_there[i]:
            print(s+chr(i+97))
            break

Measured memory_bytes: 61972
import java.util.Scanner;

public class Main {
	long count = 0;

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

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Card[] A = new Card[n];
		Card[] B = new Card[n];
		for (int i = 0; i < n; i++) {
			A[i] = B[i] = new Card(scanner.next().charAt(0), scanner.nextInt());
		}
		quicsort(A, 0, n - 1);
		meregsort(B, 0, n);
		boolean flag = true;
		for (int i = 0; i < n; i++) {
			if (A[i].pic != B[i].pic) {
				flag = false;
				break;
			}
		}
		System.out.println(flag ? "Stable" : "Not stable");
		for (int i = 0; i < n; i++) {
			System.out.println(A[i].pic + " " + A[i].num);
		}
	}

	private void meregsort(Card[] b, int left, int right) {
		if (left + 1 < right) {
			int mid = (left + right) / 2;
			meregsort(b, mid, right);
			meregsort(b, left, mid);
			merge(b, left, mid, right);
		}

	}

	private void merge(Card[] b, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		Card[] L = new Card[n1 + 1];
		Card[] R = new Card[n2 + 1];
		for (int i = 0; i < n1; i++) {
			L[i] = b[left + i];
		}
		for (int i = 0; i < n2; i++) {
			R[i] = b[mid + i];
		}
		L[n1] = new Card(' ', Integer.MAX_VALUE);
		R[n2] = new Card(' ', Integer.MAX_VALUE);

		int l = 0;
		int r = 0;
		for (int i = left; i < right; i++) {
			if (L[l].num <= R[r].num) {
				b[i] = L[l++];
			} else {
				b[i] = R[r++];
			}
		}
	}

	private <T> void swap(T[] cards, int a, int b) {
		T tmp = cards[a];
		cards[a] = cards[b];
		cards[b] = tmp;
	}

	private void quicsort(Card[] a, int p, int r) {
		if (p < r) {
			int q = partition(a, p, r);
			quicsort(a, q + 1, r);
			quicsort(a, p, q - 1);
		}

	}

	private int partition(Card[] a, int p, int r) {
		int i = p - 1;
		for (int j = p; j < r; j++) {
			if (a[j].num <= a[r].num) {
				i++;
				swap(a, i, j);
			}
		}
		swap(a, i + 1, r);
		return i + 1;
	}

	class Card {
		char pic;
		int num;

		public Card(char pic, int num) {
			this.pic = pic;
			this.num = num;
		}

	}
}

Measured memory_bytes: 98632
s = input()
ans = 'AC'
if s[0] != 'A':
    print('WA')
    exit()
else:
    s = s[1:]
if 'C' not in s[1:-1]:
    print('WA')
    exit()
else:
    if s.count('C') != 1:
        print('WA')
        exit()
    else:
        ss = s.replace('C','')
        if ss.islower():
            print('AC')
        else:
            print('WA')



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

int n, e, t1, t2;
vector <int> v[100005];
bool vis[100005];
deque <int> order;

void dfs(int node) {
	vis[node] = 1;
	for (int i : v[node]) {
		if (!vis[i]) {
			dfs(i);
		}
	}
	order.push_front(node);
}

int main() {
	cin >> n >> e;
	for (int i = 0; i < e; i++) {
		cin >> t1 >> t2;
		v[t1].push_back(t2);
	}
	for (int i = 0; i < n; i++) {
		if (!vis[i]) dfs(i);
	}
	while (!order.empty()) {
		t1 = order.front();
		cout << t1 << endl;
		order.pop_front();
	}
}



Measured memory_bytes: 5944
nmq = gets.chomp.split
n = nmq[0].to_i
m = nmq[1].to_i
q = nmq[2].to_i

abcd = []
q.times do
    input = gets.chomp.split
    4.times do |i|
        input[i] = input[i].to_i
    end
    abcd << input
end

nums = []
m.times do |i|
    nums << (i + 1)
end

all_paterns = nums.repeated_combination(n).to_a
sums = []
all_paterns.each do |patern|
    sum = 0
    q.times do |i|
        a = abcd[i][0] - 1
        b = abcd[i][1] - 1
        c = abcd[i][2]
        d = abcd[i][3]

        sum += d if patern[b] - patern[a] == c
    end
    sums << sum
end

puts sums.max

Measured memory_bytes: 28736
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010

int main(){
	IOS;
	
	ll n;cin>>n;
	string ans="";
	string s,t;cin>>s>>t;
	rep(i,0,n)ans+=s[i],ans+=t[i];
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,M = inpl()
xx = inpl()
nums = [0]*M
Pairs = [0]*M
ed = defaultdict(int)

for x in xx:
	nums[x%M] += 1
	if ed[x] == 0:
		ed[x] = 1
	else:
		Pairs[x%M]+=1
		ed[x] = 0

ans = 0
ans += nums[0]//2

if M%2 == 0:
	ans += nums[M//2]//2
	for i in range(1,M//2):
		a = nums[i]
		b = nums[M-i]
		if a < b:
			ans += a + min((b-a)//2,Pairs[M-i])
		else:#b < a:
			ans += b + min((a-b)//2,Pairs[i])
else:
	for i in range(1,M//2+1):
		a = nums[i]
		b = nums[M-i]
		if a < b:
			ans += a + min((b-a)//2,Pairs[M-i])
		else:#b < a:
			ans += b + min((a-b)//2,Pairs[i])

print(ans)


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

using namespace std;

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

const int N = 1e5 + 5;

vector <int> v[N];
int n,m;
priority_queue <int> q;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1 ; i <= n ; i++) {
    int a,b;
    cin >> a >> b;
    v[a].push_back(b);
  }
  ll ans = 0;
  for (int i = m ; i >= 0 ; i--) {
    for (auto j : v[m - i])
      q.push(j);    
    if (q.empty() == false) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5632
#include <stdio.h> 
#include <stdlib.h> 
#include <limits.h> 
#include <bits/stdc++.h> 
using namespace std;

int dpminCost(int a[], int n, int i){
  int d[n];
  d[0]=0;
  d[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
      d[i]=min(abs(a[i]-a[i-1])+d[i-1], abs(a[i]-a[i-2])+d[i-2]);
  }
  
  return d[n-1];
}

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

Measured memory_bytes: 1024
N = int(input())

summ = []
for i in range(1,N//2 + 1):
    A = []
    B = []
    k = N-i
    for __ in range(6):
        A.append(int(i%10))
        B.append(int(k%10))
        i /= 10
        k /= 10
    summ.append(sum(A+B))
print(min(summ))

Measured memory_bytes: 3480
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
// #include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int maxn = 1e5 + 5;
LL a[maxn], d[maxn];

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int n;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	d[1] = abs(a[1] - a[0]);
	for(int i = 2; i < n; ++i){
		d[i] = min(d[i - 1] + abs(a[i - 1] - a[i]), d[i - 2] + abs(a[i - 2] - a[i]));
	}
	cout << d[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  string s; cin >> s;
  int n = s.size();
  enum STATE {NONE, DREAM, ERASE};

  STATE state = NONE;
  int m = 0;
  bool er = false;

  const string dream = "dream", erase = "erase";

  rep(i, n) {
    char c = s[i];
    if(m == 0) {
      if (c == 'd') {
        m++;
        state = DREAM;
      }
      else if (c=='e') {
        m++;
        state = ERASE;
      }
      else {
        puts("NO");
        return 0;
      }
    }
    else {
      if (state == DREAM) {
        if(dream[m] == c) {
          m++;
          if(m==5) {
            int nokori = n-i-1;
            m = 0;
            if(nokori < 2) continue;
            if(nokori == 2) {
              if(s[i+1] =='e' && s[i+2] == 'r') {
                puts("YES");
                return 0;
              }
              else {
                puts("NO");
                return 0;
              }
            }
            else {
              if(s[i+1] !='e') {
                state=NONE;
              }
              else if(s[i+2]=='r' && s[i+3]=='a') {
                state=NONE;
              }
              else if(s[i+2]=='r') {
                state=NONE;
                i += 2;
              }
              else {
                puts("NO");
                return 0;
              }
            }
          }
        }
        else {
          puts("NO");
          return 0;
        }
      }
      else if (state == ERASE) {
        if(erase[m] == c) {
          m++;
          if(m==5) {
            m = 0;
            int nokori = n-i-1;
            if(nokori == 0) continue;
            if(s[i+1] == 'r') {
              i++;
            }
          }
        }
        else {
          puts("NO");
          return 0;
        }
      }
      else assert(false);
    }
  }
  if(m==0) puts("YES");
  else puts("NO");
}


Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <map>
#include <climits>

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

int main()
{
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  int maxd = 0;
  rep(i, n)
  {
    cin >> a[i];
  }
  rep(i, n-1)
  {
    int dist = a[i+1] - a[i];
    maxd = max(dist, maxd);
  }
  maxd = max(maxd, (k-a[n-1] + a[0]));

  cout << k - maxd << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
    int k;
    cin >> k;
    if(k % 2 == 0)
    {
        cout << (k / 2) * (k / 2) << endl;
    }else{
        cout << (k / 2) * ((k / 2) + 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# 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 rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define MSG(x) std::cout << #x << " : " << x << "\n";
using namespace std;
using lint = long long;
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; }

std::string func(std::string str, int pos, int len) {
    const int strLen = str.length();
 
    return str.substr(strLen - pos, len);
}

int main()
{
    lint X[4], Y[4];
    X[1] = Y[1] = 0;

    lint S;
    cin >> S;

    lint sqrtS = sqrt(S);

    if (sqrtS * sqrtS == S)
    {
        X[2] = Y[3] = sqrtS;
        X[3] = Y[2] = 0;
    }
    else if (S <= sqrtS*(sqrtS + 1))
    {
        X[2] = sqrtS;
        Y[3] = sqrtS + 1;
        X[3] = sqrtS*(sqrtS + 1) - S;
        Y[2] = 1;
    }
    else
    {
        X[2] = sqrtS + 1;
        Y[3] = sqrtS + 1;
        X[3] = X[2] * Y[3] - S;
        Y[2] = 1;
    }

    reps (i, 3)
    {
        cout << X[i] << " " << Y[i] << ((i!=3)?" ":"\n");
    }

    return 0;
}


Measured memory_bytes: 256
#   AtCoder Beginner Contest 119
#   problem A: Still TBD

S = input() #-> yyyy/mm/dd

date = S.split('/')

year = int(date[0])
month = int(date[1])
day = int(date[2])

if month >= 5:
    print('TBD')
else:
    print('Heisei')


Measured memory_bytes: 2940
def task_a():
    """
    https://atcoder.jp/contests/abc042/tasks/abc042_a
    """
    a, b, c = map(int, input().split())
    if (a, b, c) in [(5, 5, 7), (5, 7, 5), (7, 5, 5)]:
        print('YES')
    else:
        print('NO')

task_a()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};

bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  int a, ans = 0;
  rep(i, n) {
    cin >> a;
    if(IsPrime(a)) ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3076
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)] #複数行複数入力を多重リストに
l1=[]
l2=[]
for i in l:
  l1.append(i[0])
  l2.append(i[1])
a=max(l1)
b=min(l2)
if b-a>=0:
  print(b-a+1)
else:
  print("0")
  

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

int main() {
    int N; cin >> N;
    for(int i=1; i<=N; ++i) {
        if(i * 27 / 25 == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

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

using namespace std;

int main()
{

// long long h;
int n,k;
cin >> n >> k;
priority_queue<long int> q;
for (int i=0; i<n; i++)
    {   long int now;
        cin >> now;
        q.push(now);
    }

long long sum =0;
for (int i=0; i<n; i++)
{
    if (i<k) q.pop();
        else {sum+=q.top(); q.pop();}
}
cout << sum;
}


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

int main(){
  int n,i;
  cin >> n;
  vector<int> a(n);
  map<int,int>mp;
  for(i=0;i<n;++i){
    cin >> a[i];
    mp[a[i]]++;
  }
  int ans=0;
  for(auto p : mp){
    if(p.first<=p.second){
      ans+=(p.second-p.first);
    }else{
      ans+=p.second;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  string s;
  cin >> s;
  int cnt = 0;
  ll sum = 0;
  REP(i,s.size()){
    if(s[i] == 'W'){
      sum += (ll)i - cnt;
      cnt++;
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


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

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

int n,t[1100],a[1100],x,y;
signed main(){
  cin>>n;rep(i,n)cin>>t[i]>>a[i];
  x = t[0];y = a[0];
  repd(i,1,n){
    int xx = x, yy = y, ox = x, oy = y;
    while(x % t[i] != 0)x++;
    y = x/t[i]*a[i];
    while(yy % a[i] != 0)yy++;
    xx = yy/a[i]*t[i];
    if((ox > x || oy > y) || (x+y > xx+yy && ox <= xx && oy <= yy)){
      x = xx;y = yy;
    }
  }
  cout << x+y << endl;
}


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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int A, B, C;
	cin >> A >> B >> C;
	unsigned long long int ans = 0;
	if (B >= C)
	{
		cout << B + C << endl;
	}
	else
	{
		ans = B * 2;
		C -= B;
		B = 0;
		if (A >= C)
		{
			cout << ans + C << endl;
		}
		else
		{
			ans += A + 1;
			C -= A;
			A = 0;
			cout << ans << endl;
		}
	}

}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,j,N;
  cin >> N;
  
  for(i=1;i<10;i++){
      for(j=1;j<10;j++){
          if(j*i==N){
              cout << "Yes" << endl;
              i=10;
              break;
          }
      }
  }
  if(j==10){
      cout << "No" << endl;
  }
}

Measured memory_bytes: 256
while True:
    try:
        a=float(input())
        if a>91.00:
            print("heavy")
        elif 81.00<a<=91.00:
            print("light heavy")
        elif 75<a<=81:
            print("middle")
        elif 69<a<=75:
            print("light middle")
        elif 64<a<=75:
            print("welter")
        elif 60<a<=64:
            print("light welter")
        elif 57<a<=60:
            print("light")
        elif 54<a<=57:
            print("feather")
        elif 51<a<=54:
            print("bantam")
        elif 48<a<=51:
            print("fly")
        else:
            print("light fly")
    except EOFError:
        break
         


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int T[111111],X[111111],Y[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>T[i+1]>>X[i+1]>>Y[i+1];

    rep(i,N){
        int t=T[i+1]-T[i];
        int x=abs(X[i+1]-X[i]);
        int y=abs(Y[i+1]-Y[i]);
        if(x+y>t||(t-x-y)%2==1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 2560
N=int(input())
list_a=list(map(int, input().split()))

list_a.sort(reverse=True)

sam_a=0
sam_b=0

for i in range(N):
    if i%2 == 0:
        sam_a+=list_a[i]
    else:
        sam_b+=list_a[i]

print(sam_a-sam_b)

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int q = sc.nextInt();
        ArrayList<Event> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            long start = sc.nextInt(); long end = sc.nextInt();
            long place = sc.nextInt();
            a.add(new Event(start - place, place, true));
            a.add(new Event(end - place, place, false));
        }
        for (int i = 0; i < q; i++) {
            long d = sc.nextInt();
            a.add(new Event(d));
        }
        Collections.sort(a);
        TreeSet<Long> set = new TreeSet<>();
        for (int i = 0; i < a.size(); i++) {
            Event e = a.get(i);
            if (e.query) {
                if (set.isEmpty()) {
                    out.println(-1);
                } else {
                    out.println(set.first());
                }
            } else {
                if (e.start) {
                    set.add(e.place);
                } else {
                    set.remove(e.place);
                }
            }
        }
        out.close();
    }

    static class Event implements Comparable<Event> {
        long time; long place;
        boolean query; boolean start;
        Event(long time) {
            this.query = true;
            this.time = time;
        }
        Event(long time, long place, boolean start) {
            this.time = time; this.place = place;
            this.query = false;
            this.start = start;
        }

        @Override
        public int compareTo(Event o) {
            if (time == o.time) {
                if (query) return 1;
                else if (o.query) return -1;
                else if (place != o.place) return Long.compare(place, o.place);
                else if (start) return 1;
                else return -1;
            }
            return Long.compare(time, o.time);
        }
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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: 94324
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
const int D=80*160+10;


bitset<D*2> dp[90][90];

int main(){
  int h,w;
  cin>>h>>w;

  vector<vector<int>> a(h+1, vector<int> (w+1));
  vector<vector<int>> b(h+1, vector<int> (w+1));
  vector<vector<int>> v(h+1, vector<int> (w+1));
  rep(i,h)rep(j,w){
    cin>>a[i][j];
  }
  rep(i,h)rep(j,w){
    cin>>b[i][j];
  }
  rep(i,h)rep(j,w){
    v[i][j]=abs(a[i][j]-b[i][j]);
  }



//  bitset<D*2> dp[90][90];
//  vector <vector<vector<int>>> dp(h+5, vector<int> (w+5, 1200005));
//  int base=600000;

  dp[0][0][D-abs(v[0][0])]=1;
  dp[0][0][D+abs(v[0][0])]=1;

  //rep(i,h)rep(j,w)rep(k,1200000)dp[i][j][k]=0;
  //dp[0][0][base+v[0][0]]=1;
  //dp[0][0][base-v[0][0]]=1;

  rep(i,h)rep(j,w){
//    if (dp[i][j]){
  //a    cout<<i<<"i"<<j<<"j"<<k<<"K"<<endl;
      dp[i+1][j]|=dp[i][j]>>v[i+1][j];
      dp[i+1][j]|=dp[i][j]<<v[i+1][j];
      dp[i][j+1]|=dp[i][j]>>v[i][j+1];
      dp[i][j+1]|=dp[i][j]<<v[i][j+1];


  //    cout<<dp[1][0][3]<<"try"<<endl;
  //    cout<<dp[1][0][1]<<"try"<<endl;

  //  }
  }
//  cout<<dp[1][1][0]<<"try"<<endl;
//  cout<<dp[1][0][1]<<"try"<<endl;
  int ans=160*80+1;

  rep(i,D*2){
  //  cout<<dp[h-1][w-1][i]<<endl;
    if (dp[h-1][w-1][i]){
  //    cout<<D-i<<endl;
      ans=min(ans,abs(D-i));
    }
  }
  cout<<ans;


}


Measured memory_bytes: 24704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  
  	int n;
  	cin >> n;
	vi p(n);
  	rep(i,n) cin >> p[i];
  	int mi=p[0];
  	int x=1;
  	rep1(i,n) {if(mi>=p[i]) {mi=p[i];x++;}
              	
              }
  	cout << x << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var min = 30; // 今回はceil(log2(最大値))なら何でもいいです

            var N = cin.ReadInt;
            for (int i = 0; i < N; ++i)
            {
                var A = cin.ReadInt;
                var c = 0;
                while (A % 2 == 0 && A != 0) { A >>= 1; ++c; }
                min = Min(min, c);
            }
            WriteLine(min);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 13268
// Problem : B - Picture Frame
// Contest : AtCoder - AtCoder Beginner Contest 062
// URL : https://atcoder.jp/contests/abc062/tasks/abc062_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n,m;cin>>n>>m;
char arr[n+2][m+2];
for(int i=0;i<n+2;i++)
for(int j=0;j<m+2;j++)
arr[i][j]='#';
for(int i=1;i<=n;i++)
{
	for(int j=1;j<=m;j++)
	cin>>arr[i][j];
}
for(int i=0;i<n+2;i++){
for(int j=0;j<m+2;j++)
cout<<arr[i][j];
cout<<"\n";
}
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin>>s;
    int len=s.size();
    ll ans=0,p=1,now=0,cnt[2020]={0};
    cnt[0]=1;
    for(int i=len;i--;){
        now=(now+ll(s[i]-'0')*p)%2019;
        ans+=cnt[now]++;
        p=p*10%2019;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3740
n = int(input())
A = [int(i) for i in input().split()]
S = [0]*(n+1)
num={}
for i in range(n):
    S[i+1] = S[i] + A[i]
for i in S:
    if str(i) in num.keys():
        num[str(i)] += 1
    else:
        num[str(i)] = 1
out = [i*(i-1)//2 for i in num.values() if i>1]
print(sum(out))

Measured memory_bytes: 52496
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;

int nomal(){
	int ans=0;
	ans=5*20+5*19;
	return ans;
}
int mod3(){
	int ans=0;
	ans=20*10;
	return ans;
}

int so_nissu(){
	int ans=0;
	ans+=333*mod3()+666*nomal();
	return ans;
}

int main(){
	int n,y,m,d;
	int ans=so_nissu();
	cin>>n;
	rep(i,0,n){
		int cnt=0;
		cin>>y>>m>>d;
		if(y%3==0){
			cnt=(y/3-1)*mod3()+y*2/3*nomal();
			cnt=cnt+(m-1)*20+d-1;
		}else{
			cnt=y/3*mod3()+(y/3*2+y%3-1)*nomal();
			if(m%2==1){
				cnt=cnt+m/2*39+d-1;
			}else{
				cnt=cnt+m/2*19+(m/2-1)*20+d;
			}
		}
		print(ans-cnt);
	}
	return 0;
}


Measured memory_bytes: 3076