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

int main() {
  int N;
  cin>>N;
  int H[N];
  for(int i=0;i<N;i++) cin>>H[i];
  int ans=1;
  for(int i=1;i<N;i++){
    for(int j=i-1;j>=0;j--){
      if(H[i]<H[j]) break;
      else if(j==0) ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    double l;
    cin >> l;

    cout << std::setprecision(12) << (l/3.)*(l/3.)*(l/3.) << endl;

    return 0;
}


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

using i64 = int64_t;

int main(){
    string s;
    cin >> s;
    int ans = s.size();
    int tmp = 0;
    for(int i=0;i<s.size();++i){
        int c = i % 2;
        if(s[i]-'0' != c)tmp++;
    }
    ans = min(ans, tmp);
    tmp = 0;
    for(int i=0;i<s.size();++i){
        int c = (i+1)%2;
        if(s[i]-'0' != c)tmp++;
    }
    ans = min(ans, tmp);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#define D(x) std::cout << __LINE__ << ' ' << #x << " = " << x << std::endl;

int main() {
#ifndef LOCAL_STJO
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
	int n, m;
	std::cin >> n;
	std::map<int, int> map;
	for(int i = 0;i < n;++ i) {
		int a;
		std::cin >> a;
		map[a] ++;
	}
	std::cin >> m;
	for(int i = 0;i < m;++ i) {
		int a;
		std::cin >> a;
		if(map[a]) {
			map[a] --;
		} else {
			std::cout << "NO\n";
			return 0;
		}
	}
	std::cout << "YES\n";
    return 0;
}



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

int main(){
    int N;
    cin >> N;
    int ans = 0;
    for(int i = N; i < 1000; i++){
        if(i%111 == 0){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
ab = []
for i in range(n):
    ab.append(tuple(map(int,input().split())))

ab.sort(key=lambda x:x[1])
s = 0
d = []
for i in ab:
    s = s + i[0]
    d.append((i[1],s))
ans = 'Yes'
for i in d:
    if i[0]<i[1]:
        ans = 'No'
print(ans)

Measured memory_bytes: 97976
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    string s, t, u;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    cin >> u;
    if(u == s) {
        cout << a-1 << " " << b << endl;
    }
    else if(u == t){
        cout << a << " " << b-1 << endl;
    }
    return 0;

}

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

int main()
{
  int N;
  cin >> N;
  int L[2*N];
  for(int i = 0; i < 2*N; i++)
    cin >> L[i];
  sort(L,L+2*N);
  int ans = 0;
  for(int i = 0; i < 2*N; i++)
    if(i % 2 == 0)
      ans += L[i];
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
if N == 0:
    print(0)
else:
    li = []
    ind = 0
    while N != 0:
        if N % 2**(ind + 1) == 0:
            li.insert(0,0)
            ind += 1
        else:
            li.insert(0,1)
            N -= (-2)**(ind)
            ind += 1            
    x = ''.join([str(li[i]) for i in range(len(li))])
    print(x)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll n, p, s[110000], a = 0, b = 0, bb = 0;
int main(){
	cin >> n >> p;
	REP(i, n) {
		cin >> s[i];
		if (s[i] % 2 == 0)a++;
		else b++;
	}
	if (p == 0) {
		for (int i = 0; i <= b; i+= 2)
		{
			ll now = 1;
			REPO(j, i) {
				now *= b - j + 1;
				now /= j;
			}
			bb += now;
		}
	}
	else {
		for (int i = 1; i <= b; i += 2)
		{
			ll now = 1;
			REPO(j, i) {
				now *= b - j + 1;
				now /= j;
			}
			bb += now;
		}
	}
	ll c = pow(2.0, a);
	cout << c * bb << endl;
}



Measured memory_bytes: 512
#include <cstdio>

int main()
{
  int a, b;
  scanf("%d %d", &a, &b);

  if (a < b) {
    printf("a < b\n");
  } else if (a > b)
  {
    printf("a > b\n");
  } else
  {
    printf("a == b\n");
  }
  
  return 0;
}


Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#include <time.h>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n,m,sz;
bool used[N] , mark[N];
vector <int> g[N] , glezu[N];
queue <int> q;

int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        int q;
        scanf("%d",&q);
        while(q--){
            int lezu;
            scanf("%d",&lezu);
            g[i].push_back(lezu);
            glezu[lezu].push_back(i);
        }
    }
    sz++;
    used[1] = true;
    q.push(1);
    while(!q.empty()){
        int mard = q.front();
        q.pop();
        for(int i=0;i<(int)g[mard].size();i++){
            int lezu = g[mard][i];
            if(mark[lezu])continue;
            mark[lezu] = true;
            for(int j=0;j<(int)glezu[lezu].size();j++){
                int Mard = glezu[lezu][j];
                if(used[Mard] == false){
                    used[Mard] = true;
                    q.push(Mard);
                    sz++;
                }
            }
        }
    }
    if(sz == n)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 8952
#include <iostream>
#include <cassert>
#include <algorithm>
#include <functional>

int main(){
    long L,R;
    std::cin>>L>>R;
    long ans = L*(L+1)%2019;
    for(auto i = L; i < R; ++i){
        for(auto j = i+1; j <= R; ++j){
            ans = std::min(ans, (i*j)%2019);
            if(ans==0){std::cout<<ans;exit(0);
            }
        }
    }
    std::cout<<ans;
}

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


int main() {
    int K, N, dist, prev = 0, mind;
    cin >> K >> N;
    vector<int> D(N);
    for (int i = 0; i < N; i++) {
        cin >> dist;
        D.at(i) = dist - prev;
        prev = dist;
    }
    D.at(0) += K - dist;
    for (int i = 0; i < N; i++) { // i番目の家からの距離
        if (i == 0) mind = K - D.at(0);
        else {
            dist = K - D.at(i);
            mind = min(dist, mind);
        }
    }
    cout << mind << endl;
    return 0;

}

Measured memory_bytes: 1024
using System;
class Program{
  static void Main(){
    string[] input = Console.ReadLine().Split(' ');
    double N = double.Parse(input[0]);
    double K = double.Parse(input[1]);
    
    double perm = 0;
    for (int i = 1; i <= N; i++){
      double times = Math.Ceiling(Math.Log(K / i, 2));
      if (times < 0)
        times = 0;
      perm += Math.Pow(0.5, times);
    }
    perm = perm / N;
    Console.WriteLine(perm);
  }
}

Measured memory_bytes: 13140
dice = list(map(int, input().split()))
dice2 = list(map(int, input().split()))
mask = {
    'N': (1, 5, 2, 3, 0, 4),
    'R': (0, 2, 4, 1, 3, 5)
    }

a, b = dice2[0], dice2[1]

find = False

for i in range(4):

    for j in range(4):
        if dice == dice2:
            find = True
            break
        dice = [dice[x] for x in mask['R']]

    if dice == dice2:
        find = True
        break
    dice = [dice[x] for x in mask['N']]

dice = [dice[x] for x in mask['R']]
dice = [dice[x] for x in mask['N']]
for j in range(4):
    if dice == dice2:
        find = True
        break
    dice = [dice[x] for x in mask['R']]

dice = [dice[x] for x in mask['N']]
dice = [dice[x] for x in mask['N']]
for j in range(4):
    if dice == dice2:
        find = True
        break
    dice = [dice[x] for x in mask['R']]

if find:

    print("Yes")
else:
    print("No")



Measured memory_bytes: 5612
#include<stdio.h> 
#include<stdlib.h>

int main()
{
	int a,b;
	char op;
	while(1){
		scanf("%d %c %d",&a ,&op ,&b);
	     if( op == '?') break;
	
	switch(op)
	{
		case '+':
			printf("%d\n",a+b);
			break;
			
		case '*':
			printf("%d\n",a*b);
			break;
		case '-':
			printf("%d\n",a-b);
			break;
		case '/':
			printf("%d\n",a/b);
			break;
			
				}
	}
	
}


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

int f[200][10];
int p[200][20];

int main() {
  int n;
  cin >> n;
  rep(i, n) rep(j, 10) cin >> f[i][j];
  rep(i, n) rep(j, 11) cin >> p[i][j];
  int mx = INT_MIN;
  rep(i, 1 << 10) {
    if (i == 0) continue;
    int ans = 0;
    rep(j, n) {
      int cnt = 0;
      rep(k, 10) {
        if ((i >> k & 1) && f[j][k] == 1) cnt++;
      }
      ans += p[j][cnt];
    }
    mx = max(mx, ans);
  }
  cout << mx << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

public class Main {
    static int MOD = 1000000007;

    public static class Mas {
        int x;
        int y;
        int step;

        Mas(int x, int y, int step) {
            this.x = x;
            this.y = y;
            this.step = step;
        }
    }

    private static final int[] vX = { 1, 0, 0, -1 };
    private static final int[] vY = { 0, 1, -1, 0 };
  

    public static void main(String[] args) {

        FastScanner fs = new FastScanner();
        String n = fs.next();
        System.out.println(n.charAt(0) == n.charAt(2) ? "Yes" : "No");
    }

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long int ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

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

int main()
{
    int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
    int diffx = tx-sx, diffy = ty-sy;
    
    REP(i,diffx) cout << 'R';
    REP(i,diffy) cout << 'U';
    REP(i,diffx) cout << 'L';
    REP(i,diffy) cout << 'D';
    //ここまでで1周

    //下に下がる
    cout << 'D';

    //右にdiffx+1
    REP(i,diffx+1) cout << 'R';

    //上にdiffy+1
    REP(i,diffy+1) cout << 'U';

    //左に+1 上に+1
    cout << 'L'; cout << 'U';

    //左にdiffx+1
    REP(i,diffx+1) cout << 'L';

    //下にdiffy+1
    REP(i,diffy+1) cout << 'D';

    //右に+1
    REP(i,1) cout << 'R';


    return 0;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

sys.setrecursionlimit(10 ** 6)

n, m = na()
xy = nan(m)

g = [[] for _ in range(n)]
for i in range(m):
    x, y = xy[i]
    x -= 1
    y -= 1
    g[x].append(y)

dp = [-1] * (n + 1)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    res = 0
    for nv in g[v]:
        res = max(res, dfs(nv) + 1)
    dp[v] = res
    return dp[v]

ans = 0
for v in range(n):
    ans = max(ans, dfs(v))

print(ans)

Measured memory_bytes: 78984
x,y,z = map(int,input().split())

ans=0
first = list(map(int,input().split()))
for i in range(x):
    num=0
    A= list(map(int,input().split()))
    for t in range(y):
        num=num + int(A[t])*int(first[t])
    if (num+z)>0:
        ans=ans+1
    else:
        ans = ans
    #print('num',num+z)

print(ans)
        


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

string Revers(string str) {
	string rev;
	for(int i = str.size() - 1; i >= 0; i--) {
		rev += str[i];
	}
	return rev;
}

int main(void) {
	int num, ans;
	string begin_train;
	string tr1, tr2;
	set<string> end_train;

	cin >> num;
	while(num--) {
		cin >> begin_train;
		for(int i = 1; i < begin_train.size(); i++) {
			tr1 = begin_train.substr(0, i);
			tr2 = begin_train.substr(i, begin_train.size() - i);
			for(int rev1 = 0; rev1 <= 1; rev1++) {
				for(int rev2 = 0; rev2 <= 1; rev2++) {
					end_train.insert((rev1 ? Revers(tr1) : tr1) + (rev2 ? Revers(tr2) : tr2));
					end_train.insert((rev2 ? Revers(tr2) : tr2) + (rev1 ? Revers(tr1) : tr1));
				}
			}
		}
		ans = end_train.size();
		printf("%d\n", ans);
		end_train.clear();
	}
	return 0;
}

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

int main(void) {
int N,D;
scanf("%d %d",&N,&D);
int array[N][D];
for (int i=0;i<N;i++){
    for (int j=0;j<D;j++){
        scanf("%d",&array[i][j]);
    }
}
int test =0;
int count= 0;
int c;
for (int i=0;i<N;i++){
    for (int j=i+1;j<N;j++){
            for ( c=0;c<D;c++){
              test += pow((array[i][c]-array[j][c]),2);

            }
            float test1=sqrt(test);
            int test2 = sqrt(test);
            if ((float)test2==test1) count++;
            test =0;
    }
}

printf("%d",count);
 return EXIT_SUCCESS;
}


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

int main() {
	ll n;
	cin>>n;
	ll a[n],dp[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	dp[i]=pri;
		
	}
	dp[0]=0;
	for(ll i=0;i<n;i++){
	if(i+1<n)	dp[i+1]=min(dp[i+1],abs(a[i+1]-a[i])+dp[i]);
	if(i+2<n)    dp[i+2]=min(dp[i+2],abs(a[i+2]-a[i])+dp[i]);
		
	}
	cout<<dp[n-1]<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B;
cin>>A>>B;
int m[3];
m[0]=A+B;
m[1]=A+(A-1);
m[2]=B+(B-1);
sort(m,m+3);
cout<<m[2];

 return 0;
}


Measured memory_bytes: 256
#![allow(dead_code)]
use crate::scanner::Scanner;
use std::cmp::min;
fn main() {
    let mut scan = Scanner::new();
    let n = scan.read::<usize>();
    let a = scan.readn::<usize>(n + 1);
    let mut l = vec![0; n + 1];
    let mut r = vec![0; n + 1];
    l[n] = a[n];
    r[n] = a[n];
    for i in (0..n).rev() {
        l[i] = a[i] + (l[i + 1] + 1) / 2;
        r[i] = a[i] + r[i + 1];
    }
    if l[0] > 1 {
        println!("-1");
        return;
    }
    let mut ret = 0;
    let mut cur = 1;
    for i in 0..=n {
        ret += cur;
        if i == n {
            break;
        }
        cur = min(r[i + 1], (cur - a[i]) * 2);
    }
    println!("{}", ret);
}
mod scanner {
    use std::io::{stdin, BufReader, Bytes, Read, Stdin};
    use std::str::FromStr;
    pub struct Scanner {
        buf: Bytes<BufReader<Stdin>>,
    }
    impl Scanner {
        pub fn new() -> Scanner {
            Scanner {
                buf: BufReader::new(stdin()).bytes(),
            }
        }
        pub fn read_next<T: FromStr>(&mut self) -> Option<T> {
            let token = self
                .buf
                .by_ref()
                .map(|c| c.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect::<String>();
            token.parse::<T>().ok()
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_next().unwrap()
        }
        pub fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read::<T>()).collect()
        }
        pub fn chars(&mut self) -> Vec<char> {
            self.read::<String>().chars().collect()
        }
    }
}



Measured memory_bytes: 4324
#!/usr/bin/env python3
#ABC141 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
dp = [[0]*(n+1) for _ in range(n+1)]
dp[-1][-1] = 1
for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(n):
    for j in range(n):
        ans = max(ans,min(i-j,dp[i][j]))
print(ans)

Measured memory_bytes: 230332
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Fri Dec 21 09:57:18 2018
//
package main

import "fmt"

type point struct {
	x, y int
}

type move struct {
	from, to point
}

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	board := make([][]int, H)
	for i := range board {
		board[i] = make([]int, W)
		for j := range board[i] {
			fmt.Scan(&board[i][j])
		}
	}

	moves := make([]move, 0)
	for i := range board {
		for j := range board[i] {
			if j+1 < len(board[i]) && board[i][j]%2 == 1 {
				board[i][j]--
				board[i][j+1]++
				moves = append(moves, move{from: point{x: i + 1, y: j + 1}, to: point{x: i + 1, y: j + 1 + 1}})
			}
		}
	}

	for i := range board {
		if i+1 < len(board) && board[i][len(board[i])-1]%2 == 1 {
			board[i][len(board[i])-1]--
			board[i+1][len(board[i])-1]++
			moves = append(moves, move{from: point{x: i + 1, y: len(board[i])}, to: point{x: i + 2, y: len(board[i])}})
		}
	}

	fmt.Println(len(moves))
	for _, m := range moves {
		fmt.Println(m.from.x, m.from.y, m.to.x, m.to.y)
	}
}


Measured memory_bytes: 21248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  int n,sum=0;
  cin>>n;
  int x=1;
  while(n>sum){
    sum+=x;
    x++;
  }
  vector<int> v;
  for(int i=x-1;i>0;i--){
    if(i==n){
      v.push_back(i);
      break;
    }else if(n>i){
      n-=i;
      v.push_back(i);
    }
  }
  for(int i=0;i<v.size();i++){
    cout<<v[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> ap(n);
    vector<int> am(n);
    rep(i,n){
        int a; cin >> a;
        //ap[i]=a+i;
        am[i]=a-i;
    }
    map<int,int> memo;
    rep(i,n){
        memo[am[i]+200000]++;
        //cout << am[i]+200000 << ' ' << memo[am[i]+200000] << endl;
    }
    ll ans=0;
    rep(i,n){
        if(memo[-(am[i]+i+i)+200000]) ans+=memo[-(am[i]+i+i)+200000];
    }
   // rep(i,7) cout << memo[i] << endl;
    cout << ans << endl;

return 0;
}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int d = max({a,b,c});
    int e = a+b+c;
    int f = 3*d-e;
    if(f%2 == 1){
        f =f+3;
        cout << f/2 << endl;
    }
    else{
        cout << f/2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int H, W, K;
    cin >> H >> W >> K;

    V(string) grid(H);
    rep(i, H) cin >> grid[i];

    int res = 1e18;
    rep(i, 1<<H-1) {
        int t = i;
        vi hcut;
        hcut.pb(0);

        int temp = 0;
        rep(j, H-1) {
            if(t&1) {
                hcut.pb(j+1);
                temp++;
            }
            t >>= 1;
        }
        hcut.pb(H);

        //rep(j, hcut.size()) cout << hcut[j] << " ";
        cout << endl;

        vi sums(hcut.size()-1, 0);
        bool ok = true;
        rep(j, W) {
            vi cnt(hcut.size()-1, 0);
            rep(k, hcut.size()-1) {
                for(int a=hcut[k]; a<hcut[k+1]; a++) {
                    if(grid[a][j]-'0') cnt[k]++;
                }
            }
            bool cut = false;
            
            rep(k, hcut.size()-1) {
                if(cnt[k] > K) ok = false;
                if(sums[k]+cnt[k] > K) cut = true;
            }
            
            if(cut) {
                temp++;
                rep(k, hcut.size()-1) {
                    sums[k] = cnt[k];
                }
            }
            else rep(k, hcut.size()-1) sums[k] += cnt[k];
        }

        if(ok) res = min(res, temp);
        
    }

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

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    static public void main(String[] av){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int cnt = 0;
	for(int i=0; i<n; i++){
	    int x = sc.nextInt();
	    int flag = 0;
	    int y = (int)Math.sqrt(x);
	    for(int j=2; j<=y; j++){
		if(x%j == 0){
		    flag = 1;
		}
	    }
	    if(flag == 0){
		cnt++;
	    }
	}
	System.out.println(cnt);
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i = 0;i<N;i++){
    cin >> A[i];
  }
  int odd = 0;//数列Aの中の奇数の個数
  int even2 = 0;//数列Aの中の2で割り切れるが、4で割り切れない数の個数
  int c4 = 0;//数列Aの中の4の倍数の個数
  
  for(int i = 0;i<N;i++){
    if(A[i]%2 ==1) odd++;
    if(A[i]%2 ==0 && A[i]%4 !=0) even2++;
    if(A[i]%4 == 0) c4++;
  }

  bool flag = false;
  
  if(odd == 0) flag = true;
  if(odd >= 1 && c4 >= odd) flag = true;
  if(odd >= 2 && c4 == odd-1 && even2 == 0) flag = true;
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b){
    cout<<c<<endl;
  }else if(a==c){
    cout<<b<<endl;
  }else{
    cout<<a<<endl;
  }
  return 0;
}

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

int main(){

  string A, B;

  cin>>A>>B;
  if(A.size()>B.size()) cout<<"GREATER"<<endl;
  else if(A.size()<B.size()) cout<<"LESS"<<endl;
  else{
    if(A>B) cout<<"GREATER"<<endl;
    else if(A<B) cout<<"LESS"<<endl;
    else cout<<"EQUAL"<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n);
	std::string a, b, c; cin >> a >> b >> c;
	
	int ans = 0;
	for(int i = 0; i < n; i++) {
		if(a[i] == b[i] and b[i] == c[i]) continue;
		else if(a[i] == b[i] and b[i] != c[i]
			 or b[i] == c[i] and c[i] != a[i]
			 or c[i] == a[i] and a[i] != b[i]
		) {
			ans++;
		} else {
			ans += 2;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i,j,k,l,m,p,r;
	scanf("%d",&r);
	scanf("%d",&m);
	scanf("%d",&l);
	for(i=1;i<=10;i++)
	{
		l=l*r-m;
		printf("%d\n",l);
	}
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _015_A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nab = ReadInts();
            long n = nab[0];
            long a = nab[1];
            long b = nab[2];
            if (b < a||(b!=a&&n==1))
            {
                Console.WriteLine(0);
                return;
            }

            long max = b * (n - 1) + a;
            long min = a * (n - 1) + b;
            Console.WriteLine(max - min + 1);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

cnt=0
for i in range(n):
  c=b[i]-a[i]
  
  #city_iのみ攻撃
  if c<=0:
    cnt+=b[i]
  
  #city_i+1も攻撃
  else:
    d=b[i]-a[i+1]-a[i]
    
    #city_i+1生き残る
    if d<=0:
      cnt+=b[i]
      a[i+1]-=c
      
    #オーバキル
    else:
      cnt+=a[i]+a[i+1]
      a[i+1]=0
      
print(cnt)

Measured memory_bytes: 24196
import java.io.*
import java.util.*

fun solve(N: Int, a: LongArray) {
    // dp[i][j] = a[i..N-j-1]から始めた時のX-Y
    val dp = Array(N) { LongArray(N) }
    for (i in N - 1 downTo 0) {
        for (j in N - 1 downTo 0) {
            if (i + j >= N) continue
            else if (i == N - 1 ) dp[i][j] = if (N % 2 == 0) -a[N-1] else a[N - 1]
            else if (j == N - 1) dp[i][j] = if (N % 2 == 0) -a[0] else a[0]
            else if ((i + j) % 2 == 0) dp[i][j] = Math.max(dp[i + 1][j] + a[i], dp[i][j + 1] + a[N - j - 1])
            else dp[i][j] = Math.min(dp[i + 1][j] - a[i], dp[i][j + 1] - a[N - j - 1])
        }
    }
    // println(dp.contentDeepToString())
    println(dp[0][0])
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val a = LongArray(N)
    for (i in 0 until N) {
        a[i] = sc.next().toLong()
    }
    solve(N, a)
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n, m;
  cin >> n >> m;
  vi k(m);
  vvi s(m, vi(n));
  re(i, m) {
    cin >> k[i];
    re(j, k[i]) {
      cin >> s[i][j];
    }
  }
  vi p(m);
  re(i, m) cin >> p[i];

  int cnt = 0;
  re(bit, (1<<n)) //スイッチのつけ方全探索
  {
    vi w(n); //スイッチ
    re(i, n) {
      if(bit>>i & 1) {
        w[i] = 1; //on
      } else {
        w[i] = 0; //off
      }
    }

    int sum = 0;
    bool turn = true;
    re(i, m) {
      sum=0;
      re(j, k[i]) {
        sum += w[s[i][j]-1];
      }
      if(sum % 2 != p[i]) {
        turn = false;
        break;
      }
    }
    if(turn) cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()


using namespace std;

const ll N = 1;
const ll big = 1e18;
const ll block = 800;
const ll mod = 1e6;

int main() {
    speed;
    ll n;
    string a;
    cin >> n >> a;
    if(n >= a.size())
    	cout << a;
    else
    	cout << a.substr(0, n) + "...";

}

/*
*/



Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main() {
    int a,b,c,d; cin >> a >> b >> c >> d;
    int ans = 0;
    for (int i = 0; i <= 100; i++) {
        if ((a <= i && i <= b) && (c <= i && i <= d)) ans++;
    }
    if (ans) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 256
def inpl(): return list(map(int, input().split()))
N, K = inpl()
A = inpl()

DP = [0]*(K+1)
for i in range(K, -1, -1):
    if DP[i]%2 == 0:
        for a in A:
            if i - a < 0:
                break
            DP[i-a] = 1
if DP[0]:
    print("First")
else:
    print("Second")


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

int main(){
    int n;
    cin >> n;
    char tmp;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        if(tmp == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll m; cin>>m;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	ll sum=0;
	REP(i,n){
		sum+=a[i];
	}
	sort(a.begin(),a.end());
	REP(i,m){
		if(a[n-1-i]*4*m<sum){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if (a<=8 && b<=8) cout<<"Yay!";
	else cout<<":(";
    return 0;
}

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

int main(){
	int n,m,l,i,j,k;
	cin >> n >> m >> l;
	long int a[n][m],b[m][l],c[n][l];

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			a[i][j]=0;
		}
	}

	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			b[i][j]=0;
		}
	}

	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			c[i][j]=0;
		}
	}

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

	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			cin >> b[i][j];
		}
	}

	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			for(k=0;k<m;k++){
				c[i][j]+=a[i][k]*b[k][j];
			}
		}
	}

	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			cout << c[i][j];
			if(j!=l-1)cout << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 1392
k = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 8, 8, 11, 11, 11, 11, 14, 14, 32, 32, 35, 35, 35, 35, 42, 42, 42, 42, 49, 49, 49, 49, 49, 49, 75, 75, 86, 86, 86, 86, 86, 86, 123, 123, 131, 131, 131, 131, 148, 148, 153, 153, 170, 170, 170, 170, 170, 170, 227, 227, 227, 227, 227, 227, 250, 250, 323, 323, 324, 324, 324, 324, 354, 354, 354, 354, 384, 384, 384, 384, 384, 391, 491, 491, 529, 529, 529, 529, 529, 529, 543]
a = int(input())
print(k[a])

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define endll puts("")
#define mod 1000000007
#define ll long long
#define mp3(a,b,c) mp(a,mp(b,c))
#define sol (root+root)
#define sag (sol+1)
#define ort ((son+bas)/2)
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;
const int N=1e5+3;
double n,m,x,y,z,h[N],hh[N],k,l,i,j,ii,jj,t,s;
void f(double sum,int x,int y)
{
//	cout<<sum<<' '<<x<<endl;
	if(x==pow(2,n)-1)
	{
	//	cout<<".  "<<sum<<" "<<z<<endl;
		s++;t+=sum;return;
	}
	for(int i=0;i<n;i++)
		if((x&(1<<i)) == 0)
		{
			f(sum+sqrt(pow(h[y]-h[i],2)+pow(hh[y]-hh[i],2)),x+(1<<i),i);
		}
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>h[i]>>hh[i];
	for(int i=0;i<n;i++)
		f(0,(1<<i),i);
	printf("%lf", t/s);

}

Measured memory_bytes: 384
N, Y = map(int, input().split())
ansX = -1
ansY = -1
ansZ = -1
for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if 10000*x + 5000*y + 1000*z == Y:
            ansX = x
            ansY = y
            ansZ = z
            
print(ansX, ansY, ansZ)

Measured memory_bytes: 9056
integer a(4)
integer ans
read*,a(1),a(2),a(3),a(4)
ans=0
do i=1,4
  if(a(i)==1)then
    ans=ans+1
    exit
  end if
end do
do i=1,4
  if(a(i)==9)then
    ans=ans+1
    exit
  end if
end do
do i=1,4
  if(a(i)==7)then
    ans=ans+1
    exit
  end if
end do
do i=1,4
  if(a(i)==4)then
    ans=ans+1
    exit
  end if
end do
print"(A)",merge("YES"," NO",ans==4)
end

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
    int main(){
      int n, x,i,j=0,k=0,l=0,f=0;
      scanf("%d", &n);
      char s[1000],m[100];
      for(i=0;i<n;i++){
          scanf("%s",s);
          if(s[0]=='A'){
              j++;
          }
          else if(s[0]=='W'){
              k++;
          }
          else if(s[0]=='T')
          {
              l++;
          }
          else if(s[0]=='R'){
              f++;
          }
      }
      printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",j,k,l,f);
        return 0;
    }

Measured memory_bytes: 1716
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
 
vector<int> dp;
 
 
int main() {
	// your code goes here
	
	int n;
	
	cin>>n;
	
	int arr[n];
	
	for(int i=0;i<n;i++)
	cin>>arr[i];
	
	dp.assign(n+1, -1);
	
	dp[0]=0;
	
	dp[1]=abs(arr[0]-arr[1]);
	
	for(int i=2;i<=n;i++)
	{
		dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
	}
	
	cout<<dp[n-1];
	
	return 0;
}

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

int main() {
    int k, s;
    cin >> k >> s;
    int x=0,y=0,z=0;
    int cnt=0;
    for (int x = 0; x <=k ; x++) {
        for(int y=0;y<=k; y++){
            z=s-x-y;
            if (z>=0 && z<=k){
                cnt++;
                // cout<<x<<y<<z<<endl;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;

}

Measured memory_bytes: 3600
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val s = sc.next
    val count = Array(s.count(_ == 'a'), s.count(_ == 'b'), s.count(_ == 'c'))
    println(if (count.max - count.min <= 1) ("YES") else ("NO"))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 31232
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  cin >> a >> b;
  vector<int> vec(a);
  bool flag = false;
  for (int i = 0; i < a; i++) {
    cin >> vec[i];
    if (vec[i] % 2 != 0) flag = true;
  }
  if (flag) cout << fixed << (long long)pow(2, a - 1) << endl;
  else if (!flag && b == 1) cout << 0 << endl;
  else cout << fixed << (long long)pow(2, a) << endl;
}

Measured memory_bytes: 512
/*
                                Bismillahi-r-Rahmani-r-Rahim
                                        RhIeyAaD
                                    IIT-7th Batch,JU
*/
#include<bits/stdc++.h>
using namespace std;

#define pf(a)           printf("%lld\n", a)
#define sf(a)           scanf("%lld", &a)
#define line(a)         getline(cin,(a))
#define ll              long long int
#define MAX             2134567891
#define MID(l,r)        (l+r)>>1
#define fr(i,n)         for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define per(i,a,n)      for(i=n;i>=a;i--)
#define FOR(i,a,n)      for(i=a;i<=n;i++)
#define ALL(n)          n.begin(),n.end()
#define mem(x,n)        memset(x,n,sizeof(x))
#define T_C(t)          printf("Case %lld: ",t)
#define TC(t)           printf("Case %lld:\n",t)
#define ans(t,c)        printf("Case %lld: %lld\n",t,c)
#define SETP(n)         cout<<setprecision(n)<<fixed
#define READ            freopen("F:\\Project\\Test_Case.txt","r",stdin)
#define WRITE           freopen("F:\\Project\\Output_Test.txt","w",stdout)
#define IO              ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define PAIR            pair<ll,ll>
#define MP              make_pair
#define pb(a)           push_back(a)
#define ff              first
#define ss              second
#define MOD             1000000007///10^9
#define p6              1000007 ///10^6->6 zero after 1 **
#define hlw             printf("hlw\n");
#define SN              4*p6
#define NN              111
#define N               p6

ll x[N],y[N],z[N],n;
string s,S;
vector<ll>v;
//map <ll,ll> mp;

int main()
{
    //IO;
    //while(1)
    //READ;WRITE;
{
    ll a=0,b=0,c=0,d,e,f,g,i,j,k,l,m,p,q,r,u,w,t,tc,in,mod,loc,diff,val,sz,lo,hi,mid,mn=MAX,mx=0,sum=0,ans=0;
    cin>>k>>n;
    rep(i,n)
    {
        cin>>x[i];
        if(i==1)b=0;
        else
        b=(x[i]-x[i-1]);
        a+=b;
        mx=max(mx,b);
    }
    x[n+1]=min(x[n]-x[1],k-a);
    mx=max(mx,x[n+1]);
    a+=x[n+1];

    //cout<<a<<" "<<mx<<endl;
    a-=mx;
    cout<<a<<endl;
}
    return 0;
}

/*

*/
/// Check for constraint 0 or 1?
/// long long or double? sqrt or division will work fine??


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'

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


int main()
{
    ll n,cnt=0,t;
    cin>>n;
    t=n;
    while(n>0)
    {
        cnt+=(n%10);
        n/=10;
    }
    if(t%cnt==0)
    {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3552
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

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

  int ans = 0;
  int cnt = 1;
  for(int i = 1; i < n; i++){
    if(a[i] == a[i-1]) cnt++;
    else{
      if(cnt % 2 == 0) ans += cnt / 2;
      else ans += (cnt-1) / 2;
       cnt = 1;
    }

    if(i == n-1){
      if(cnt % 2 == 0) ans += cnt / 2;
      else ans += (cnt-1) / 2;
    }
  }

  cout << ans << endl;

  return 0;
}

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

queue<string> q;


int main(){
    int n;
    cin >> n;
    q.push("a");
    for(int i=1;i<n;i++){
        ll count=q.size();
        for(ll j=0;j<count;j++){
            string s;
            s=q.front();
            q.pop();
            ll mins=0;
            for(ll k=0;k<s.size();k++){
                ll now=s[k]-'a';
                mins=max(mins,now);
            }
            mins+=2;
            for(ll l=0;l<mins;l++){
                char ss='a'+l;
                q.push(s+ss);
            }
        }
    }
    
    while(!q.empty()){
        string sss=q.front();
        q.pop();
        cout << sss << endl;
    }
    
    
    
    return 0;
}







Measured memory_bytes: 9728
//
//  main.cpp
//  Pana2020B
//
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    long long H,W,ans;
    cin>>H>>W;
    if (H==1 || W==1) {
        ans=1;
    }else{
        ans=(H*W+1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
double a,b,x;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>a>>b>>x;
	double a1=x/a*2/b;
	double pi=acos(-1);
	if(a1<=a){
		double o=atan2(b,a1);
		printf("%.7f\n",o/pi*180);
	}else{
		double b1=x/a*2/a-b;
		double b2=b-b1;
		double o=atan2(b2,a);
		printf("%.7f\n",o/pi*180);
	}
	return 0;
}
//(b1+b)=x/a*2/a

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

using namespace std;

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

void intarrayinput(int sz,int a[]){for(int ___=0;___<sz;++___)scanf("%d",a+___);}
void intarrayoutput(int sz,int a[]){for(int ___=0;___<sz;++___)printf("%d ",a[___]);printf("\n");}
template<class T>T emin(T& t1,T t2){if(t1>t2)return t1=t2;else return t1;}
template<class T>T emax(T& t1,T t2){if(t1<t2)return t1=t2;else return t1;}
template<class T1,class T2>ostream& operator<<(ostream& out,pair<T1,T2> _p){out<<_p.first<<" "<<_p.second;return out;}
template<class T>ostream& operator<<(ostream& out,vector<T> _v){for(int i=0;i<_v.size();++i)out<<_v[i]<<(i+1==_v.size()?"":" ");return out;}
template<class T>void byebye(T t){cout<<t<<endl;exit(0);}

int a,b;

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




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

using namespace std;

struct ioi{
	int l,r;	
} seg[510];

int n, m;

bool intersect(ioi a,ioi b){
	if (a.l>b.l) swap(a,b);
	if (b.l<=a.r) return true;
	else return false;
}

ioi combine(ioi a,ioi b){
	a.l = min(a.l, b.l);
	a.r = max(a.r, b.r);
	return a;
}

int main(){
	cin >> n >> m;
	for (int i=1;i<=m;i++)
		cin >> seg[i].l >> seg[i].r;
	long long res = n+1;
	sort(seg+1, seg+m+1,[](ioi a,ioi b){
		return (a.l<b.l or (a.l==b.l and a.r>b.r));
	});
	ioi current_segment = seg[1];
	for (int i=1;i<=m;i++){
		if (intersect(seg[i], current_segment)){
			current_segment = combine(current_segment, seg[i]);
		}
		else{
			res += 2*(current_segment.r - current_segment.l);
			current_segment = seg[i];
		}
	}

	res += 2*(current_segment.r - current_segment.l);
	cout << res << "\n";
}

Measured memory_bytes: 3172