akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define elif else if
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define mod 100000007
#define elif else if
#define str string

signed main(){
  int N,M,O,P=0,count=0,count2=0,crash=0,nowtab=1;
  double d;
  char C,c;
  str S,T;
  vint v(0);
  cin>>S;
  if(S=="SUN")cout<<7<<endl;
  if(S=="MON")cout<<6<<endl;
  if(S=="TUE")cout<<5<<endl;
  if(S=="WED")cout<<4<<endl;
  if(S=="THU")cout<<3<<endl;
  if(S=="FRI")cout<<2<<endl;
  if(S=="SAT")cout<<1<<endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a[]=new int [n];
		
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
		}
		Arrays.sort(a);
		
		System.out.println(a[n-1]-a[0]);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {
    string s;
    cin>>s;
    bool N=0,W=0,S=0,E=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='N')
            N=1;
        if(s[i]=='W')
            W=1;
        if(s[i]=='S')
            S=1;
        if(s[i]=='E')
            E=1;
    }
    if(N&&W&&S&&E)
        cout<<"Yes"<<"\n";
    else if(N&&S&&W==0&&E==0)
        cout<<"Yes"<<"\n";
    else if(N==0&&S==0&&W&&E)
        cout<<"Yes"<<"\n";
    else
        cout<<"No"<<"\n";
    
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

if N==0:
    A0 = A[0]
    if A0 == 1:
        print(1)
    else:
        print(-1)
else:
    max_forward = [1]
    now = 1
    flag = 0
    for i in range(N):
        now = (now - A[i])*2
        if now <= 0:
            flag = -1
            break
        max_forward.append(now)
    
    max_backward = [A[-1]]
    now = A[-1]
    for i in range(N):
        ind = N-i-1
        now = now + A[ind]
        max_backward.append(now)
    
    if flag == -1:
        print(-1)
    else:
        if max_forward[-1] < A[-1]:
            print(-1)
        else:
            ans = 0
            for i in range(N+1):
                temp = min(max_forward[i], max_backward[N-i])
                #print(temp)
                ans += temp
            print(ans)
        

Measured memory_bytes: 680080
import java.util.*;
public class Main { 

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int cnt = 0;
        if(n % 2 == 1)
            cnt++;
        
        System.out.println((n/2 + cnt) / (n * 1.0));
    }

}

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

#define endl '\n'

using namespace std;

typedef long long ll;

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

	ll n, x;
	cin >> n >> x;
	cout << 3 * (n - __gcd(n, x)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);++i)

int w,h;
int ans;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool visit[10][10];


inline bool check(int y,int x){
	return 0<=y&&y<h&&0<=x&&x<w;
}
int neighbor(int y,int x,char color,char panel[10][10]){
	int res=0;
	if(!check(y,x) || visit[y][x])return 0;
	if(panel[y][x]!=color){
		if(panel[y][x]=='R')return 1;
		if(panel[y][x]=='G')return 2;
		if(panel[y][x]=='B')return 4;
	}
	visit[y][x] = true;
	rep(i,4){
		res |= neighbor(y+dy[i],x+dx[i],color,panel);
	}
	return res;
}
void change(int y,int x,char from,char to,char panel[10][10]){
	if(!check(y,x) || from!=panel[y][x])return;
	panel[y][x] = to;
	rep(i,4){
		change(y+dy[i],x+dx[i],from,to,panel);
	}
}
bool find;
bool search(int depth,int limit,char panel[10][10]){
	memset(visit,false,sizeof(visit));
	int diff = neighbor(0,0,panel[0][0],panel);
	if(diff==0){
		return true;;
	}
	if(limit <= depth)return false;
	char buf[10][10];
	rep(i,3){
		if((diff&1<<i)==0)continue;
		memcpy(buf,panel,sizeof(buf));
		change(0,0,buf[0][0], (i==0?'R':(i==1?'G':'B')),buf);
		if(search(depth+1,limit,buf))return true;
	}
	return false;
}
int main(){
	char panel[10][10];
	while(cin>>w>>h,w|h){
		rep(i,h)rep(j,w)cin>>panel[i][j];
		int l=0,r=10000,m;
		while(l<r){
			m=(l+r)/2;
			if(search(0,m,panel))r=m;
			else l=m+1;
		}
		cout<<r<<endl;
	}
}

Measured memory_bytes: 876
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if (N % 1110 < 10 || (N % 1000) % 111 == 0 ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main()
{
  int alpha[26] = {0};
  bool f = true;
  string w;
  cin >> w;

  for (int i = 0; i < w.length(); i++) {
    alpha[w[i]-'a'] += 1;
  }
  //  for (int i =0 ; i < w.length();i++) cout << alpha[i] << endl;
  for (int i = 0; i < 26; i++) {
    if (alpha[i]%2) f = false;
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9+5;
const int N = 1e5+3;
int n,arr[N][3],dp[N][3],last;




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

    //freopen("in","r",stdin);
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>arr[i][j];
        }
    }

    for(int i=0;i<3;i++)
        dp[0][i]=arr[0][i];


    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(k!=j){
                    dp[i][j]=max(dp[i-1][k]+arr[i][j],dp[i][j]);
                }

            }

        }

        // dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
        // dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
        // dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));


    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, a, b) for(auto (i)=a;i<b;i++)
#define list(i, N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

template<class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

#define MAX_N 100005

int n, q;
string s;
int ar[MAX_N];

void precompute(){
    ar[0] = 0;
    if(s[0]=='A' && s[1]=='C') ar[1] = 1;
    else ar[1] = 0;
    rep(i,2,s.length()){
        ar[i] = ar[i-1];
        if(s[i]=='C'&&s[i-1]=='A') ar[i]+=1;
    }
}

void solve(){
    int l, r; cin >> l >> r; --l; --r;
    cout << ar[r] - ar[l] << "\n";
}

int32_t main() {

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

    cin >> n; cin >> q;
    cin >> s; precompute();
    while(q--) solve();

    return 0;
}

Measured memory_bytes: 1872
import sys

n = int(input())
lines = sys.stdin.readlines()
links = [set() for _ in [0] * n]
for line in lines[:n - 1]:
    a, b = list(map(int, line.split()))
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)

ccc = list(map(int, lines[-1].split()))
ccc.sort(reverse=True)
ans = [-1] * n
ans_sum = 0
leaves = {i for i, l in enumerate(links) if len(l) == 1}

while leaves:
    v = leaves.pop()
    c = ccc.pop()
    ans[v] = c
    if not ccc:
        break
    ans_sum += c
    for u in links[v]:
        lu = links[u]
        lu.remove(v)
        if len(lu) == 1:
            leaves.add(u)

print(ans_sum)
print(*ans)


Measured memory_bytes: 8648
n=int(input())
a=sorted([int(input()) for _ in [0]*n])

if n%2==0:
    print(2*sum(a[n//2+1:])-2*sum(a[:n//2-1])+a[n//2]-a[n//2-1])
else:
    b=abs(sum(a[n//2-1:n//2+1])+2*sum(a[:n//2-1])-2*sum(a[n//2+1:]))
    a.sort(reverse=True)
    c=abs(sum(a[n//2-1:n//2+1])+2*sum(a[:n//2-1])-2*sum(a[n//2+1:]))
    print(max(b,c))

Measured memory_bytes: 8084
h, w, a, b = map(int, input().split())

ans = [[]*w for i in range(h)]

for i in range(h):
    for j in range(w):
        if j < a and i < b:
            ans[i].append(1)
        elif j < a and i >= b:
            ans[i].append(0)
        elif j >= a and i < b:
            ans[i].append(0)
        elif j >= a and i >= b:
            ans[i].append(1)
for i in range(h):
    print("".join(map(str, ans[i])))

            

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

/*
高橋：追い出したい
追い出すには、高橋のターンで追い出す必要がある（青木は動かさない選択も可能）
Rで追い出すなら、右端にいないといけない
dp(i,j,k) = kステップ目でi,jにいたときどっちが勝つか
dp(i,j,k+1) = 
dpのサイズが大きい

勝つためには１つの方向に注目し、それ以外で動く必要はない。
*/

bool ans=false;
ll h,w,n,sx,sy;
string s,t;

void init(){
	cin>>h>>w>>n>>sy>>sx;
	cin>>s>>t;
}

int main(void){
	init();
	char tak[]={'L','R','U','D'},ao[]={'R','L','D','U'};
	ll dx[]={-1,1,0,0},dy[]={0,0,-1,1};
	rep(k,4){
		ll x=sx,y=sy;
		rep(i,n){
			if(s[i]==tak[k]){
				y+=dy[k];
				x+=dx[k];
				if(k==0 && x<=0)ans=true;
				if(k==1 && x>w)ans=true;
				if(k==2 && y<=0)ans=true;
				if(k==3 && y>h)ans=true;
			}
			if(t[i]==ao[k]){
				//貯めれないので
				if(0<y-dy[k] && y-dy[k]<=h && 0<x-dx[k] && x-dx[k]<=w){
					y-=dy[k];
					x-=dx[k];
				}
			}
			// cerr<<k<<": "<<y<<","<<x<<endl;
		}
	}
	cout<<(ans?"NO":"YES")<<endl;
	return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<cmath>

int main(){
	int ans= INT_MAX;
	int d;
	int dpSize;
	long long g;
	std::vector<int> pList;
	std::vector<int> cList;
	std::vector<int> dpList;

	std::cin>>d>>g;
	pList.resize(d);
	cList.resize(d);

	for(int i=0; i<d; i++)
		std::cin>>pList[i]>>cList[i];

	for(int i=0; i<d; i++){
		dpSize+= (i+1)*pList[i];
		dpSize+= cList[i]/100;
	}

	dpList.resize(dpSize+1, INT_MAX);
	dpList[0]= 0;

	for(int i=0; i<d; i++){
		for(int j=dpSize; j>=0; j--){
			if(dpList[j]==INT_MAX)
				continue;

			for(int k=1; k<=pList[i]; k++){
				int nextIdx= j+ k*(i+1);

				if(k==pList[i])
					nextIdx+= (cList[i]/100);

				dpList[nextIdx]= std::min(dpList[j]+k, dpList[nextIdx]);
			}
		}
	}

	for(int i=g/100; i<dpSize+1; i++)
		ans= std::min(ans, dpList[i]);

	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){
  long n, k = -1;
  int ret = scanf("%ld %ld", &n, &k);
  if(k == 1){
    n = 0;
  }else{
    n %= k;
    while(n > labs(n - k))
      n = labs(n - k);
  }
  printf("%ld", n);
  return 0;
}

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

int main()
{   
    //データ定義
    int height;
    int width;
    //データセット取得
    cin >> height >> width;

    //枠を出力
    while( height != 0 || width != 0){
        for (int i = 0; i < height; i++)
        {
            for (int j = 0; j < width; j++)
            {
                if (i == 0 || i == height - 1 || j == 0 || j == width - 1)
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
        cin >> height >> width;
    }
}


Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var LR = new List<int[]>();
            for (int i = 0; i < N; i++) LR.Add(ReadArrayInt());
            LR = LR.OrderBy(l => l[0]).ThenBy(l => l[1]).ToList();
            var first = new int[] { LR[0][0], LR[0][1] };
            var second = new int[] { LR[1][0], LR[1][1] };
            for (int i = 2; i < N; i++)
            {
                var patF = first[1] < LR[i][0] ? 0 : Math.Min(first[1], LR[i][1]) - (LR[i][0] - 1);
                var patS = second[1] < LR[i][0] ? 0 : Math.Min(second[1], LR[i][1]) - (LR[i][0] - 1);
                var patT = first[0] < second[0] ? first[1] < second[0] ? 0 : Math.Min(first[1], second[1]) - (second[0] - 1) : second[1] < first[0] ? 0 : Math.Min(second[1], first[1]) - (first[0] - 1);
                var funF = patF + second[1] - (second[0] - 1);
                var funS = first[1] - (first[0] - 1) + patS;
                var funT = patT + LR[i][1] - (LR[i][0] - 1);
                if (funT >= Math.Max(funF, funS))
                {
                    first[0] = Math.Max(first[0], second[0]);
                    first[1] = Math.Min(first[1], second[1]);
                    second[0] = LR[i][0];
                    second[1] = LR[i][1];
                }
                else if (funS >= funF)
                {
                    second[0] = Math.Max(second[0], LR[i][0]);
                    second[1] = Math.Min(second[1], LR[i][1]);
                }
                else
                {
                    first[0] = Math.Max(first[0], LR[i][0]);
                    first[1] = Math.Min(first[1], LR[i][1]);
                }
                if (first[0] > first[1])
                {
                    first[0] = 0;
                    first[1] = -1;
                }
                if (second[0] > second[1])
                {
                    second[0] = 0;
                    second[1] = -1;
                }
            }
            var fun1 = first[1] - (first[0] - 1);
            var fun2 = second[1] - (second[0] - 1);

            Console.WriteLine(fun1 + fun2);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 29104
n,W=map(int,input().split())
lst=[]
for i in range(n):
  w,v=map(int,input().split())
  lst.append([w,v])
nap=[]
for i in range(n+1):
  nap.append([0]*(W+1))
for i in range(1,n+1):
  for j in range(1,W+1):
    if lst[i-1][0]<=j:
      nap[i][j]=max(nap[i-1][j],nap[i-1][j-lst[i-1][0]]+lst[i-1][1])
    else:
      nap[i][j]=nap[i-1][j]
print(nap[n][W])
 
 
    
  


Measured memory_bytes: 120300
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

bool is_prime(ll a) {
  if (a == 2) return true;
  if (a % 2 == 0) return false;
  for (ll i = 3; i < sqrt(a); i += 2) {
    if (a % i == 0) return false;
  }
  return true;
}

int main() {
  ll x;
  cin >> x;
  ll ans;
  for (ll i = x;; i++) {
    if (is_prime(i)) {
      ans = i;
      break;
    }
  }

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

Measured memory_bytes: 256
from fractions import gcd
N,K=map(int,input().split())
A=list(map(int,input().split()))
maxi=max(A)

if K>maxi:
  ans="IMPOSSIBLE"
else:
  t=A[0]
  for i in range(1,N):
    t = gcd(t,A[i])
  if K%t==0:
    ans="POSSIBLE"
  else:
    ans="IMPOSSIBLE"
    
print(ans)

Measured memory_bytes: 16112
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.nextLine();
		
		boolean[] answer = new boolean[n];
		for(int i=0;i<n;i++) {
			answer[i] = false;
		}
		
		int[] wacount = new int[n];
		for(int i=0;i<n;i++) {
			wacount[i] = 0;
		}
		
		int wacountsum = 0;
		for(int i=0;i<m;i++) {
			int p = sc.nextInt();
			String s = sc.next();
			sc.nextLine();
			if(s.equals("AC") && !(answer[p-1])) {
				answer[p-1] = true;
				wacountsum += wacount[p-1];
			} else if(s.equals("WA") && !(answer[p-1])) {
				wacount[p-1]++;
			} else {
				
			}
		}
		
		int correctnum = 0;
		for(int i=0;i<n;i++) {
			if(answer[i]) {
				correctnum++;
			}
		}
		
		System.out.println(correctnum + " " + wacountsum);
	}
}


Measured memory_bytes: 154252
#include <bits/stdc++.h> 
using namespace std; 
int triples(int n)
{
    int count[n+1]={0};
    
    // Intializing all the items in array as zero.
    //memset(count,0,n+1);
    
    for(int x=1;x<101;x++)
    {
        for(int y=1;y<101;y++)
        {
            for(int z=1;z<101;z++)
            {
                long int val=(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
                
                if(val>n)
                continue;
                
                count[val]++;
            }
        }
    }
    
    for(int i=1;i<=n;i++)
    cout<<count[i]<<endl;
    
    return 0 ;
}
//Driver function
int main()
{
    
    int z ;
    cin>>z;
    
    triples(z);
    
    return 0;
}

Measured memory_bytes: 3688
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def main():
    high, width, k = map(int, input().split())

    for i in range(high + 1):
        for j in range(width + 1):
            now_b = i * (width - j) + j * (high - i)
            if now_b == k:
                print('Yes')
                sys.exit()
    print('No')









if __name__ == '__main__':
    main()



Measured memory_bytes: 39276
#if 0

#endif
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
class UnionFindTree {
    ll n;
    ll P[100000];
public:
    void init(ll n) {
        for (ll i = 0; i <= n; ++i) P[i] = i;
    };
    ll root(ll node) {
        if (P[node] == node) return node; // aはroot
        return (P[node] = root(P[node])); // aの親のrootを求め，aの親とする(圧縮)
    }
    bool is_group(ll node_a, ll node_b) {
        return root(node_a) == root(node_b);
    }
    void unite(ll node_a, ll node_b) {
        P[root(node_a)] = root(node_b);
    }
};
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    unique_ptr<UnionFindTree> tree(new UnionFindTree);
    ll n, q; cin >> n >> q;
    tree->init(n);
    int com, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> com >> x >> y;
        if (com == 0) tree->unite(x, y);
        else cout << tree->is_group(x, y) << endl;
    }

    return 0;
}


Measured memory_bytes: 3308
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  string s; 
  cin >> s;

  int N = s.size();

  bool R = false, L = false, U = false, D = false;
  REP(i, N){
    if(s[i] == 'N') U = true;
    if(s[i] == 'W') L = true;
    if(s[i] == 'S') D = true;
    if(s[i] == 'E') R = true;
  }

  if((U && !D) || (!U && D) || (R && !L) || (!R && L)) No;
  else Yes;

  return 0;
}

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

public class Main {
	
	static int mod = (int)1e9+7;
	static int n;
	static int[][][] memo;
	
	public static int dp(int i, int zero, int nine) {
		if(i == n) {
			if(zero == 1 && nine == 1)
				return 1;
			else
				return 0;
		}
		
		if(memo[i][zero][nine] != -1)
			return memo[i][zero][nine];
		
		int cnt = 0;
		if(zero == 0 && nine == 0) {
			cnt = (int)(((1l * dp(i + 1, 1, nine) + dp(i + 1, zero, 1)) % mod + 8l * dp(i + 1, zero, nine)) % mod);
		} else if(zero == 0) {
			cnt = (int)((1l * dp(i + 1, 1, nine) + 9l * dp(i + 1, zero, nine)) % mod);
		} else if(nine == 0) {
			cnt = (int)((1l * dp(i + 1, zero, 1) + 9l * dp(i + 1, zero, nine)) % mod);
		} else {
			cnt = (int)(10l * dp(i + 1, zero, nine) % mod);
		}
		
		return memo[i][zero][nine] = cnt;
	}
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		n = sc.nextInt();
		if(n == 1) {
			pw.println(0);
		} else {
			memo = new int[n][2][2];
			for(int[][] j : memo)
				for(int[] i : j)
					Arrays.fill(i, -1);
			pw.println(dp(0, 0, 0));
		}
		
		pw.flush();
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public int[] nextIntArray(int n) throws IOException {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++)
				array[i] = new Integer(nextInt());
			return array;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public static int[] shuffle(int[] a) {
			int n = a.length;
			Random rand = new Random();
			for (int i = 0; i < n; i++) {
				int tmpIdx = rand.nextInt(n);
				int tmp = a[i];
				a[i] = a[tmpIdx];
				a[tmpIdx] = tmp;
			}
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 193140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
unsigned gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
int main() {
  cout << fixed << setprecision(10);
  int a,b,c;
  cin >> a >> b >> c;
  if(c%gcd(a,b)==0){
    cout << "YES" << endl;
  }else{
    cout <<  "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int v[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k; cin >> k;
	cout << v[k - 1] << '\n';
	return 0;
}

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

int main(){
	int W, H;
	int x, y, r;
	cin >> W >> H >> x >> y >> r;
	
	if ( x - r < 0 ){
		cout << "No" << endl;
	}
	else if ( y - r < 0 ){
		cout << "No" << endl;
	}
	else if ( W - x < r ){
		cout << "No" << endl;
	}
	else if ( H - y < r ){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	
return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
int n;
int a[200100]; 
int b[200100];
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n;
	forn(i,1,n-1)
	{
		cin>>a[i];
		a[i]--;
	 } 
	 forn(i,1,n-1)
	 {
	 	b[a[i]]++;
	 }
	 rep(i,n)cout<<b[i]<<endl;
	return 0;
}



Measured memory_bytes: 5204
N,W=map(int,input().split())
wv = [tuple(map(int,input().split())) for _ in range(N)]

V = sum([wv[i][1] for i in range(N)])

dp = [W+1] * (V + 1)
dp[0] = 0
for i in range(N):
  w,v=wv[i]
  for j in range(V, v-1, -1):
    dp[j] = min(dp[j-v] + w, dp[j])
    
print(max(i for i in range(V+1) if dp[i] <= W))

Measured memory_bytes: 70956
n = int(input())


def isprime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= x ** 0.5:
        if x % i == 0:
            return False
        i += 2
    return True


a = n
while not isprime(a):
    a += 1
print(a)

Measured memory_bytes: 2940
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)
    elif op == '?':
        break


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

int main(){
    int n,m=0,cnt=0;
    cin>>n;

    for(int i=0; i<n; i++){
        int h;
        cin>>h;
        if(h>=m){
            m=h;
            cnt++;
        }
    }

    cout<<cnt<<endl;
}


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

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void solve() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

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

using namespace std;

#ifdef LOCAL
#define err cerr
#else
#define err if (false) cerr
#endif

typedef long long ll;

const int MAXN = 55;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    int ans = 0;
    int i = 1;
    for (int j = 0; j < n; j++)
    {
        int x;
        cin >> x;
        if (x == i)
        {
            i++;
        } else {
            ans++;
        }
    }
    if (ans == n) cout << -1; else 
    cout << ans;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n;
ll ans, x, y;
ll Max[4], Min[4];

int main() {
    for (int i = 0; i < 4; ++i) {
        Max[i] = -1e18;
        Min[i] = 1e18;
    }
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y;
        Max[0]=max(Max[0],x+y);
        Max[1]=max(Max[1],-x+y);
        Max[2]=max(Max[2],x-y);
        Max[3]=max(Max[3],-x-y);
        Min[0]=min(Min[0],x+y);
        Min[1]=min(Min[1],-x+y);
        Min[2]=min(Min[2],x-y);
        Min[3]=min(Min[3],-x-y);
    }
    for (int i = 0; i < 4; ++i) {
        ans = max(Max[i]-Min[i], ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない

#直積その 2 列挙
from itertools import product
N =input().strip()
N_int =int(N)
count =0
for i in range(3,len(N)+1):
    for tt in product(["3","5","7"], repeat=i):
        t ="".join(tt)
        if t.count("3") >=1 and t.count("5") >=1 and t.count("7") >=1 and int(t) <=N_int:
            count +=1
            #print(t,end=" ")
print(count)

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

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> G(N);
    vector<int> p(N);
    REP(i,N-1){
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    REP(i,Q){
        int pp, x;
        cin >> pp >> x;
        pp--;
        p[pp] += x;
    }

    auto dfs = [&](auto && self, int v, int pre) -> void{
        for(auto nv : G[v]){
            if(nv == pre) continue;
            p[nv] += p[v];
            self(self, nv, v);
        }
    };

    dfs(dfs, 0, -1);
    REP(i,N) cout << p[i] << " ";
    cout << endl;
}

Measured memory_bytes: 20736
#include<stdio.h>
class solution {
private:
	int n, k;
	int dp[100005];
	int ar[100005];
	int abs(int x) {
		return x < 0 ? -x : x;
	}
	int min(int a, int b) {
		if (a < b) return a;
		return b;
	}
	int serc(int x) {
		if (x == n - 1) return 0;
		if (dp[x] != -1) return dp[x];
		dp[x] = abs(ar[x] - ar[x + 1]) + serc(x + 1);
		for (int i = 2; i <= k; i++) {
			if (x + i <= n - 1) dp[x] = min(dp[x], abs(ar[x] - ar[x + i]) + serc(x + i));
		}
		return dp[x];
	}
public:
	solution() {
		scanf("%d %d", &n, &k);
		for (int i = 0; i < n; i++) {
			scanf("%d", &ar[i]);
			dp[i] = -1;
		}
		printf("%d\n", serc(0));
	}
};

#ifndef L0C4L
int main() {
	solution();
	return 0;
}
#endif


Measured memory_bytes: 7168
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}

#define STR_MAX 5000
#define BUF_SIZE (STR_MAX+50)
#define NUM_MAX (STR_MAX*10)
#define K_MAX 5

int asc(const void *a1, const void *a2) {
    char *s1 = (char*)a1;
    char *s2 = (char*)a2;
    return memcmp(s1, s2, K_MAX+1);
}

int main(void) {
    static char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    int len = strlen(str);
    int k = get_int();
    static char cands[NUM_MAX][K_MAX+1];
    int cidx = 0;

    int size, start;
    for(size = 1; size <= k; size++) {
        for(start = 0; start < len-size+1; start++) {
            memcpy(cands[cidx++], &str[start], size);
        }
    }
    int i;

    qsort(cands, cidx, sizeof(char)*(K_MAX+1), asc);
    static char s[K_MAX+1];
    for(i = 0; i < cidx; i++) {
        if(!memcmp(s, cands[i], K_MAX+1)) continue;
        // update
        memcpy(s, cands[i], K_MAX+1);
        k--;
        if(!k) break;
    }

    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 508
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int h, w, k; cin >> h >> w >> k;
    string c[h];
    rep(i, h) {
        cin >> c[i];
    }
    int ans = 0;
    for(int wbit = 0; wbit < (1 << w); ++wbit) {
        for(int hbit = 0; hbit < (1 << h); ++hbit) {
            vector<bool>www(w, false);
            vector<bool>hhh(h, false);
            rep(i, w) {
                if(wbit & (1 << i)) {
                    www[i] = true;
                }
            }
            rep(i, h) {
                if(hbit & (1 << i)) {
                    hhh[i] = true;
                }
            }
            string tmp[h];
            rep(i, h) tmp[i] = c[i];
            rep(i, h) {
                rep(j, w) {
                    if(www[j] || hhh[i]) {
                        tmp[i][j] = '.';
                    }
                }
            }
            int cnt = 0;
            rep(i, h) {
                rep(j, w) {
                    if(tmp[i][j] == '#') ++cnt;
                }
            }
            if(cnt == k) ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  long K,M=9;
  cin >> K;
  long long ans[(K>9)?K:9]={1,2,3,4,5,6,7,8,9};
  long long *adr=ans;
  while(M<K){
    for(int i=-1;i<=1;i++){
      if(*adr%10+i>9||*adr%10+i<0)
        continue;
      ans[M++]=*adr*10+*adr%10+i;
    }
    adr++;
  }
  endend:
  cout << ans[K-1] << endl;
}

Measured memory_bytes: 1024
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 5e2+1;
 
#define ll int
// typedef long long ll;
typedef long double ld;

void test_case()
{
	ll h, w, ch, cw, dh, dw;
	cin >> h >> w >> ch >> cw >> dh >> dw;
	string s[h];
	for(int i = 0; i < h; i++)
	{
		cin >> s[i];
	}
	if(s[ch-1][cw-1] == '#')
	{
		cout << -1 << '\n';
		return;
	}
	ch--, cw--, dh--, dw--;
	ll dp[h][w];
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
			dp[i][j] = INT_MAX;
	}
	priority_queue<array<ll,3>> q;
	q.push({0,ch, cw});
	dp[ch][cw] = 0;
	ll dx[] = {-2, -1, 0, 1, 2};
	ll dy[] = {-2, -1, 0, 1, 2};
	ll dxx[] = {-1, 1, 0, 0};
	ll dyy[] = {0, 0, -1, 1};
	while(!q.empty())
	{
		int x = q.top()[1], y = q.top()[2], z = -q.top()[0];
		q.pop();
		if(dp[x][y] < z)
			continue;
		for(int i = 0; i < 4; i++)
		{
			if((x + dxx[i] >= 0) && (x + dxx[i] < h) && (y + dyy[i] >= 0) && (y + dyy[i] < w))
			{
				if((s[x + dxx[i]][y + dyy[i]] != '#') && (dp[x + dxx[i]][y + dyy[i]] > dp[x][y]))
				{
					dp[x+dxx[i]][y+dyy[i]] = dp[x][y];
					q.push({-dp[x+dxx[i]][y+dyy[i]], x+dxx[i], y+dyy[i]});
				}
			}
		}
		for(int i = 0; i < 5; i++)
		{
			for(int j = 0; j < 5; j++)
			{
				if((x + dx[i] >= 0) && (x + dx[i] < h) && (y + dy[j] >= 0) && (y + dy[j] < w))
				{
					if((s[x + dx[i]][y + dy[j]] != '#') && (dp[x + dx[i]][y + dy[j]] > dp[x][y] + 1))
					{
						dp[x+dx[i]][y+dy[j]] = dp[x][y] + 1;
						q.push({-dp[x+dx[i]][y+dy[j]], x+dx[i], y+dy[j]});
					}
				}
			}
		}
	}
	if(dp[dh][dw] == INT_MAX)
		cout << -1 << '\n';
	else
		cout << dp[dh][dw] << '\n';
}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 8732
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tofile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); 
#define M 1000000007
#define ll long long
#define db double
#define pb push_back
#define fi first
#define se second
#define vl vector<ll>
#define vvl vector<vl>
#define pii pair<int,int>
#define mkp make_pair

const ll N=3010;
string dp[N],dptemp[N];

int main()
{
	string a,b; cin >> a >> b;
	ll m=(ll)a.size(), n=(ll)b.size();
	
	for(ll i=1;i<=m;i++)
	{
		for(ll j=1;j<=n;j++)
		{
			if(dptemp[j-1].size()>dp[j].size()) dptemp[j]=dptemp[j-1];
			else dptemp[j]=dp[j];
			if(a[i-1]==b[j-1])
			{
				dptemp[j]=dp[j-1]+a[i-1];
			}
		}
		for(ll j=1;j<=n;j++)
		{
			dp[j]=dptemp[j];
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 16840
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n,k; cin >> n >> k;
  ll ans = 0;

  if (k == 0) { COUT((ll)n*n); return 0; }

  for (int b = 1; b <= n; b++) {
    ans += (n / b) * max(0,b-k);
    ans += max(0, (n%b)-k+1);
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
using ll = long long;

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#define min(a, b) ((a) < (b) ? a : b)
#define abs(a) (a < 0 ? -(a) : a)

int main()
{
  char s[11];
  scanf("%s", s);
  int min = 0x10000;
  for (int i = 0; i <= strlen(s) - 3; ++i)
  {
    int n = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
    if (min > abs(753 - n))
    {
      min = abs(753 - n);
    }
  }
  printf("%d\n", min);
  return 0;
}


Measured memory_bytes: 128
IDENTIFICATION DIVISION.
 PROGRAM-ID.     TEST149.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
  01 INP      PIC X(300).
  01 S        PIC X(100).
  01 T        PIC X(100).

 PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ALL ' '
      INTO S T.

  DISPLAY FUNCTION TRIM(T) FUNCTION TRIM(S).
 STOP RUN.

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

using namespace std;

#define MAX_V 1010

int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v)
{
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(int v)
{
    used[v] = true;
    for (int i = 0; i < (int)G[v].size(); i++) {
	int u = G[v][i], w = match[u];
	if (w < 0 || (!used[w] && dfs(w))) {
	    match[v] = u;
	    match[u] = v;
	    return true;
	}
    }
    return false;
}

int bipartite_matching()
{
    int res = 0;
    memset(match, -1, sizeof(match));
    for (int v = 0; v < V; v++) {
	if (match[v] < 0) {
	    memset(used, false, sizeof(used));
	    if (dfs(v)) {
                res++;
            }
	}
    }
    return res;
}

void init()
{
    for (int i = 0; i < MAX_V; i++) {
        G[i].clear();
    }
}

int main()
{
    int N, M;
    while (cin >> N >> M, N) {
        vector<int> b(N), r(M);
        for (int i = 0; i < N; i++) {
            cin >> b[i];
        }
        for (int i = 0; i < M; i++) {
            cin >> r[i];
        }
        init();
        V = N + M;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                int gcd = __gcd(b[i], r[j]);
                if (gcd != 1) {
                    add_edge(i, j + N);
                }
            }
        }
        cout << bipartite_matching() << endl;
    }
    return 0;
}

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

int SameThree(int a,int b,int c){
	if((a==b)&&(b==c)) return 1;
	else{
		 return 0;
	}
}

int main(){
	int A[3][3];
	for(int i=0;i<3;++i){
		for(int j=0;j<3;++j){
			cin>>A[i][j];
		}
	}
	int ans=1;
	ans*=SameThree(A[0][0]-A[0][1],A[1][0]-A[1][1],A[2][0]-A[2][1]);
	for(int i=0;i<3;++i){
		for(int j=0;j<3;++j){
			ans*=SameThree(A[0][i]-A[0][j],A[1][i]-A[1][j],A[2][i]-A[2][j]);
			ans*=SameThree(A[i][0]-A[j][0],A[i][1]-A[j][1],A[i][2]-A[j][2]);
		}
	}
	if(ans==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main()
{
   int a,b,c,s,area;
   scanf("%d%d%d",&a,&b,&c);
   s = (a+b+c)/2;
   area = sqrt(s*(s-a)*(s-b)*(s-c));
   printf("%d\n", area);
   return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static int sum(int a) {
		int ans = 0;
		while(a >= 10) {
			ans += a%10;
			a /= 10;
		}
		ans += a;
		return ans;
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int n = 0;
		if(N%2 == 0) {
			n = N/2;
		}
		else {
			n = (N+1)/2;
		}
		int ans = sum(1)+sum(N-1);
		
		for(int A = 1; A <= n; A++) {
			if(sum(A)+sum(N-A) < ans) {
				ans = sum(A)+sum(N-A);
			}
		}
		System.out.println(ans);

	}

}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,l;
  cin>>n>>l;
  vector<string> v(n);
  rep(i,n) cin>>v[i];
  sort(v.begin(),v.end());
  rep(i,n){
    cout<<v[i];
  }
  cout<<endl;
  
  
  
  
}
///////////////////////////

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

int main(){
    int n; cin >> n;
    vector<int> a(200000);
    for(int i=0; i<n; i++) cin >> a[i];

    int even = n/2;
    int odd = n - even;
    if(n%2==0){ 
        for(int i= n; i>0; i-=2){
            printf("%d ", a[i-1]);
        }
        for(int i=1; i<=n; i+=2){
            printf("%d ", a[i-1]);
        }
    }else{
        for(int i=n; i>0; i-=2){
            printf("%d ", a[i-1]);
        }
        for(int i=2; i<=n; i+=2){
            printf("%d ", a[i-1]);
        }
    }
   
    printf("\n");
    return 0;
}

Measured memory_bytes: 3968