akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>

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

  int k;
  int r;
  r = (a+b) % 2;

  if(r!=0){
    printf("IMPOSSIBLE\n");
  }else{
    k = (a+b)/2;
    printf("%d\n",k);
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int N, A, B, C, D, amount_X, amount_Y;
    scanf("%d %d %d %d %d", &N, &A, &B, &C, &D);
    
    if(N%A!=0) amount_X=(N/A+1)*B;
    else amount_X=(N/A)*B;
    
    if(N%C!=0) amount_Y=(N/C+1)*D;
    else amount_Y=(N/C)*D;
    
    if(amount_X>amount_Y){
        printf("%d\n", amount_Y);
    }
    else printf("%d\n", amount_X);
    
    return 0;
    
}


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

#define all(x) x.begin(),x.end()
#define pb push_back
#define ss second
#define ff first
#define int long long

int32_t main(){
	int l,r;	cin>>l>>r;
	if((r-l) >= 2019)	cout<<0<<endl;
	else{
		int rem = INT_MAX;
		for(int i=l;i<r;i++){
			for(int j=i+1;j<=r;j++){
				int temp = (i*j)%2019;
				rem = min(rem,temp);
			}
		}
//		if(rem == 0)	cout<<0<<endl;
//		else{
//				cout<<((l%2019)*((l+1)%2019))%2019<<endl;
//			}
		cout<<rem<<endl;
	}
}

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

using namespace std;
typedef long long ll;
const int MAXN = 1100;

int N, M;
ll X[MAXN], Y[MAXN];
ll v[MAXN];

int xc[4] = {-1, 1, 0, 0};
int yc[4] = {0, 0, -1, 1};
string sc = "RLUD";

void gogo (ll xcur, ll ycur)
{
    for (int i = 0; i + 1 < M; i += 2)
    {
        ll cv = v[i];
        ll nv = cv * 3;
        for (int j = 0; j < 16; j++)
        {
            int cj = j;
            string act = "";
            for (int k = 0; k < 2; k++)
            {
                int cc = cj % 4;
                xcur += xc[cc] * cv;
                ycur += yc[cc] * cv;
                act += sc[cc];
                cj /= 4;
            }
            if (xcur % nv == 0 && ycur % nv == 0)
            {
                cout << act;
                break;
            }

            cj = j;
            for (int k = 0; k < 2; k++)
            {
                int cc = cj % 4;
                xcur -= xc[cc] * cv;
                ycur -= yc[cc] * cv;
                cj /= 4;
            }
            //if (j == 15)
            //    cout << "BAD\n";
        }
    }
    if (M % 2 == 1)
    {
        if (xcur < 0) cout << "L";
        else if (xcur > 0) cout << "R";
        else if (ycur < 0) cout << "D";
        else cout << "U";
    }
    cout << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N;
    int m2 = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> X[i] >> Y[i];
        m2 = (X[i] + Y[i]) % 2;
    }
    m2 = abs (m2);

    for (int i = 0; i < N; i++)
        if ((X[i] + Y[i] + m2) % 2 != 0)
        {
            cout << "-1\n";
            return 0;
        }

    v[0] = v[1] = 1;
    for (int i = 2; i < 40; i++)
        v[i] = v[i-2] * 3;

    M = 40 - m2;
    cout << M << "\n";
    for (int i = 0; i < M; i++)
    {
        if (i) cout << " ";
        cout << v[i];
    }
    cout << "\n";

    for (int i = 0; i < N; i++)
        gogo (X[i], Y[i]);
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>

template<typename T>
void dump(std::vector<T> v){
  for(int i=0; i<v.size(); i++){
    std::cout << v[i] << " ";
  }
  std::cout << std::endl;
  return;
}

int main(void){

  std::string s;
  std::cin >> s;

  std::vector<long long int> renzoku_signs;
  char last = '>';
  int count = 0;
  for(int i=0; i<s.size(); i++){
    if(last != s[i]){
      renzoku_signs.push_back(count);
      count=1;
    }else{
      count++;
    }
    last = s[i];
  }
  if(last == '<'){
    renzoku_signs.push_back(count);
  }else{
    renzoku_signs.push_back(count);
    renzoku_signs.push_back(0);
  }
  //dump(renzoku_signs);

  std::vector<int> v(s.size()+1, 0);
  int now = 0;
  for(int i=0; i<renzoku_signs.size()/2; i++){
    
    //std::cout << now << std::endl;
    for(int j=0; j<renzoku_signs[i*2]; j++){
      if(j != 0 || v[now] < renzoku_signs[i*2])
	v[now] = renzoku_signs[i*2] - j;
      now++;
    }
    
    for(int j=0; j<=renzoku_signs[i*2+1]; j++){
      //std::cout << now << " " << renzoku_signs[i*2+1]-j << std::endl;
      v[now] = j;
      now++;
    }
    now--;
  }
  
  //dump(v);

  long long int total = 0;
  for(const auto& elem: v){
    total += elem;
  }
  std::cout << total << std::endl;
  
  
  return 0;
}


Measured memory_bytes: 4856
rh = 0
rect = 0
while True:
    try:
        a,b,c = map(int,input().split(','))
        if a == b:
            rh += 1
        elif a**2 + b**2 == c**2:
            rect += 1
    except EOFError:
        break
print(rect)
print(rh)

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

ll len[51];
ll p[51];

ll dfs(ll N, ll X) {
    if (N == 0) return 1;
    if (X == 0) return 0;
    if (X == len[N] - 1) return 1 + 2 * p[N - 1];
    if (X == len[N] / 2) return 1 + p[N - 1];
    if (X < len[N] / 2) return dfs(N - 1, X - 1);
    return 1LL + p[N - 1] + dfs(N - 1, X - len[N - 1] - 2);
}

void solve() {
    ll N, X;
    cin >> N >> X;
    X--;
    len[0] = p[0] = 1;
    for (ll i = 1; i < 51; i++) {
        len[i] = len[i - 1] * 2 + 3;
        p[i] = p[i - 1] * 2 + 1;
    }
    cout << dfs(N, X) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

  int N ,K;cin >> N >> K;
  string S; cin >> S;
  if (S[K-1] == 'A'){
    S[K-1] = 'a';
  }else if(S[K-1] == 'B'){
    S[K-1] = 'b';
  }else{
    S[K-1] = 'c';
  }
  
  cout << S;
}







Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
N = int(input())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    to[a].append([b, c])
    to[b].append([a, c])

Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

dist = [0] * N

def dfs(v, pv, dis):
    for i in to[v]:
        if i[0] != pv:
            dfs(i[0], v, dis+i[1])
    dist[v] = dis

dfs(K-1, -1, 0)

for x, y in xy:
    print(dist[x-1] + dist[y-1])


Measured memory_bytes: 162264
# ['表面', '南面', '東面', '西面', '北面', '裏面']
N = int(input())
dices = [[int(d) for d in input().split()] for _ in range(N)]

R1 = [
    [0, 1, 2, 3, 4, 5], # 移動なし
    [3, 1, 0, 5, 4, 2], # 東へ1
    [2, 1, 5, 0, 4, 3], # 西へ1
    [4, 0, 2, 3, 5, 1], # 南へ1
    [1, 5, 2, 3, 0, 4], # 北へ1
    [5, 4, 2, 3, 1, 0]  # 北へ2
]

R2 = [0, 3, 1, 4, 2, 5] # 水平回り1

ans = 'Yes'

for i in range(N):
    for j in range(i + 1, N):
        for r1 in R1:
            dice = [dices[j][k] for k in r1]
            for _ in range(4):
                dice = [dice[l] for l in R2]
                if dices[i] == dice:
                    ans = 'No'

print(ans)


Measured memory_bytes: 5604
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        if((Math.abs(b - a) <= d && Math.abs(c - b) <= d) || Math.abs(c - a) <= d){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 64 * 1024
	maxBufSize     = 10000000
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	// writer  = bufio.NewWriter(os.Stdout)
)

func main() {
	scanner.Buffer(make([]byte, maxBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	s := scanText()
	q := scanInt()

	isReverse := false
	head, tail := make([]byte, 0, q), make([]byte, 0, q)
	for i := 0; i < q; i++ {

		if scanInt() == 1 {
			isReverse = !isReverse
			continue
		}

		if f := scanInt(); (f == 1 && !isReverse) || (f == 2 && isReverse) {
			head = append(head, scanText()[0])
		} else {
			tail = append(tail, scanText()[0])
		}
	}

	if isReverse {
		fmt.Print(reverse(string(reverseByte(head)) + s + string(tail)))
	} else {
		fmt.Print(string(reverseByte(head)) + s + string(tail))
	}

}

func reverse(s string) string {
	return string(reverseByte([]byte(s)))
}

func reverseByte(b []byte) []byte {
	for i, j := 0, (len(b) - 1); i < j; i, j = i+1, j-1 {
		b[i], b[j] = b[j], b[i]
	}
	return b
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}


Measured memory_bytes: 6528
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
answer = 0
for i in range(N):
    summary = 0
    for j in range(M):
        summary += A[i][j] * B[j]
    if summary + C > 0:
        answer += 1
print(answer)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

ll h[305], n, k;
ll dp[305][305][305];

ll solve(int pos, int last, int left){
    if(left < 0) return 1e18;
    if(pos > n) return 0;
    if(dp[pos][last][left] != -1) return dp[pos][last][left];
    ll r1 = solve(pos+1, last, left-1);
    ll r2 = solve(pos+1, pos, left) + max(0LL, h[pos]-h[last]);
    return dp[pos][last][left] = min(r1,r2);
}

int main(){
    memset(dp, -1, sizeof dp);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> h[i];
    cout << solve(1, 0, k) << endl;

	return 0;
}

Measured memory_bytes: 222080
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
#define endl "\n"
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vi a(n);
    REP(i,0,n){
        cin>>a[i];
    }
    int maxi = 0;
    int ans =0;
    for(int i=0; i<n; i++){
        if(a[i]<maxi){
            ans+=(maxi-a[i]);
        }
        maxi = max(maxi, a[i]);
    }
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 4840
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define ALF "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LLBIG 1999999999999999999
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

int main() {
	int a, b, c; cin >> a >> b >> c;
	if ((a < c&&c < b) || (a > c&&c > b))cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
    int main(){
      int n,i,count;
      int a[10000];
      scanf("%d",&n);
      count = 0;
      for(i = 0;i < n;i++){
        scanf("%d",&a[i]);
        while(a[i] % 2 == 0) {
          a[i] /= 2; count++;
      }
      }
      printf("%d\n",count);
     
      return 0;
    }

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

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll solve(int N) {
    return -1LL;
}

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


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int mou[10];
	int i,j;
	int work;
	
	for(i=0;i<10;i++)
		scanf("%d",&mou[i]);
	
	for(i=0;i<3;i++){
		for(j=i+1;j<10;j++){
			if(mou[i]<mou[j]){
				work=mou[i];
				mou[i]=mou[j];
				mou[j]=work;
			}
		}
	}
	printf("%d\n%d\n%d\n",mou[0],mou[1],mou[2]);
	
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    int k[9];
    int a = 100000000;
    int f = 0;
    int n = N;
    for(int i=8; i>=0; --i) {
        k[i] = N/a;
        N = N - a*k[i];
        a /= 10;
        f += k[i];
    }
    if(n%f){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

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

class Cube{
public:
    int f[6];
    Cube(){}
    void roll_z(){}
    void roll_y(){roll(0,2,5,3);} //to W
    void roll_x(){roll(0,1,5,4);} //to N
    void roll(int i,int j,int k,int l){
        int tmp=f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=tmp;
    }
    void move(char ch){
        if(ch=='E') for(int i=0;i<3;i++)roll_y();
        if(ch=='W') roll_y();
        if(ch=='N') roll_x();
        if(ch=='S') for(int i=0;i<3;i++) roll_x();
    }
};

int main(void){
    Cube c;
    string com;
    
    for(int i=0;i<6;i++)cin>>c.f[i];
    cin>>com;
    
    for(int i=0;i<com.size();i++)c.move(com[i]);
    
    cout<<c.f[0]<<endl;
    return 0;
}

Measured memory_bytes: 3220
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int buf[1000];

signed main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> buf[i];
	}
	int ma = -1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (ma < abs(buf[i] - buf[j])) {
				ma = abs(buf[i] - buf[j]);
			}
		}
	}
	cout << ma << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define LIM 500000
#define INF 1000000001

int cnt = 0;
int A[LIM];
int L[LIM], R[LIM];

void merge(int A[], int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	int I, J;
	for (int i = 0; i < n1; i++) {
		L[i] = A[left + i];
	}
	for (int i = 0; i < n2; i++) {
		R[i] = A[mid + i];
	}
	L[n1] = INF; R[n2] = INF;
	I = 0; J = 0;
	for (int k = left; k < right; k++) {
		if (L[I] <= R[J]) {
			A[k] = L[I];
			I++;
			cnt++;
		}
		else {
			A[k] = R[J];
			J++;
			cnt++;
		}
	}
}

void mergeSort(int A[], int left, int right) {
	if (left + 1 == right)return;
	int mid = (left + right) / 2;
	mergeSort(A, left, mid);
	mergeSort(A, mid, right);
	merge(A, left, mid, right);
}

int main() {
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	mergeSort(A, 0, N);

	for (int i = 0; i < N; i++) {
		printf("%d", A[i]);
		if (i != N - 1)printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;

int main(){
    // あとで消す
    //std::ifstream in("din2.txt");
    //std::cin.rdbuf(in.rdbuf());

    int H,W;

    cin >> H ;
    cin >> W ;

    vector<vector<int> > gright(H, vector<int>(W, 0));
    vector<vector<int> > gdown(H, vector<int>(W, 0));
    vector<vector<int> > gleft(H, vector<int>(W, 0));
    vector<vector<int> > gup(H, vector<int>(W, 0));


    char s;
    for(int h=0;h<1;h++){
        for(int w=0;w<1;w++){
            cin >> s;
            if(s=='.'){
                gright[h][w] = 1;
                gdown[h][w] = 1;
            }else{
                gright[h][w] = 0;
                gdown[h][w] = 0;
            }
        }
        for(int w=1;w<W;w++){
            cin >> s;
            if(s=='.'){
                gright[h][w] = gright[h][w-1]+1;
                gdown[h][w] = 1;
            }else{
                gright[h][w] = 0;
                gdown[h][w] = 0;
            }
        }
    }
    for(int h=1;h<H;h++){
        for(int w=0;w<1;w++){
            cin >> s;
            if(s=='.'){
                gright[h][w] = 1;
                gdown[h][w] = gdown[h-1][w]+1;
            }else{
                gright[h][w] = 0;
                gdown[h][w] = 0;
            }
        }
        for(int w=1;w<W;w++){
            cin >> s;
            if(s=='.'){
                gright[h][w] = gright[h][w-1]+1;
                gdown[h][w] = gdown[h-1][w]+1;
            }else{
                gright[h][w] = 0;
                gdown[h][w] = 0;
            }
        }
    }


    ////////////////////////////////////////////////
    for(int h=H-1;h==H-1;h--){
        for(int w=W-1;w==W-1;w--){
            if(gdown[h][w]==0){
                gleft[h][w] = 0;
                gup[h][w] = 0;
            }else{
                gleft[h][w] = 1;
                gup[h][w] = 1;
            }
        }
        for(int w=W-2;w>=0;w--){
            if(gdown[h][w]==0){
                gleft[h][w] = 0;
                gup[h][w] = 0;
            }else{
                gleft[h][w] = gleft[h][w+1]+1;
                gup[h][w] = 1;
            }
        }
    }
    for(int h=H-2;h>=0;h--){
        for(int w=W-1;w==W-1;w--){
            if(gdown[h][w]==0){
                gleft[h][w] = 0;
                gup[h][w] = 0;
            }else{
                gleft[h][w] = 1;
                gup[h][w] = gup[h+1][w]+1;
            }
        }
        for(int w=W-2;w>=0;w--){
            if(gdown[h][w]==0){
                gleft[h][w] = 0;
                gup[h][w] = 0;
            }else{
                gleft[h][w] = gleft[h][w+1]+1;
                gup[h][w] = gup[h+1][w]+1;
            }
        }
    }

    int maxv = 0;
    int tmpvW,tmpvH,v;
    for(int h=0;h<H;h++)for(int w=0;w<W;w++){
        tmpvW = gleft[h][w]+gright[h][w]-1;
        tmpvH = gdown[h][w]+gup[h][w]-1;
        if(tmpvW<0)tmpvW=0;
        if(tmpvH<0)tmpvH=0;
        v = tmpvH+tmpvW-1;
        if(v<0)v=0;
        if(maxv<v)maxv=v;
    }



    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 63104
#include<iostream>
using namespace std;
int main(){
	int N,Y;
	cin>>N>>Y;
	for(int x=0;x<=N;x++)
		for(int y=0;y<=N-x;y++){
			int z=N-x-y;
			if(x*10000+y*5000+z*1000==Y){
				cout<<x<<' '<<y<<' '<<z;
				return 0;
			}
		}
	cout<<"-1 -1 -1";
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    string s;
    cin>>s;
    int sum=0;
    rep(i,s.size()) {
        if(s.at(i)=='+') sum++;
        else sum--;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
using namespace std;
const int MX = 1007;
const int LIM = 2e5+3;
const int MLOG = 25;
int arr[LIM+3];
map<std::vector<int>, int> cnt;
int main(){
    int n;cin >> n;
    ll Ans = 0;
    for(int i = 0;i<n;i++)
    {
        int tem[30] = {0};
        string s;cin >>s;
        for(int j = 0;j<s.size();j++)
        {
            tem[s[j]-'a']++;
        }
        std::vector<int> v;
        for(int j = 0;j<30;j++)
        {
            v.push_back(tem[j]);
        }
        Ans+=cnt[v];
        cnt[v]++;
    }
    cout << Ans << endl;
}

Measured memory_bytes: 26752
N,M= map(int,input().split())

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

bc = [0]*M

for i in range(M):
    bc[i]=list(map(int, input().split()))


a.sort()
bc.sort(key=lambda x:-x[1])

# print(a)
# print(bc)
ans = sum(a)
pre_ind = 0
now_ind = 0
for i in range(M):
    key = bc[i][0]
    value = bc[i][1]
    now_ind += key
    if now_ind > N:
        now_ind = N

    if value > a[now_ind-1]:
        ans += value*(now_ind-pre_ind)-sum(a[pre_ind:now_ind])
        # a=a[:pre_ind]+[value]*(now_ind-pre_ind)+ a[now_ind:]
        pre_ind = now_ind
        if now_ind == N:
            # print("ok")
            break
    else:
        max_count = key
        # print(key)
        key2 = key
        for j in range(key-1):
            now_ind -= 1
            key2 -= 1
            if value > a[now_ind-1]:
                # a=a[:pre_ind]+[value]*(now_ind-pre_ind) + a[now_ind:]
                ans += value*(now_ind-pre_ind)-sum(a[pre_ind:now_ind])
                # print(key2)
                break
        break

# print(a)

# print(sum(a))
print(ans)













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

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

typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> PII;

const int inf=1e9;
const int mod=1e9+7;



int main(){
	ll n;
	cin>>n;
	ll m=1e15+1;
	for (int i = 0; i < 5; ++i){
		ll a;
		cin>>a;
		m=min(a,m);
	}
	
	
	
	cout<<(n+m-1)/m+4<<endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);
const int MAXN = 51;

//変数
int N;
vector<int> a, b;


//サブ関数
//入力
void input()
{
	cin >> N;
	int tmp;
	REP(i, N) {
		cin >> tmp;
		a.push_back(tmp);
	}
	REP(i, N) {
		cin >> tmp;
		b.push_back(tmp);
	}
}


//テーブル作成
void create_cost_table(vector<vector<LL>>& cost)
{
	//init
	cost.resize(MAXN, vector<LL>(MAXN, (LL)INF*INF));

	//table(greedy)
	REP(from, MAXN)FOR(to, from + 1, MAXN)FOR(div, 1, to + 1) {
		if (from == (to % div)) {
			cost[from][to] = pow(2, div);
			break;
		}
	}

	//same will be ignored
	REP(i, MAXN)cost[i][i] = 0;
}

int largest_division_search(vector<vector<LL>> cost)
{
	//ダイクストラ
	REP(from, MAXN)REP(to, MAXN)REP(mid, MAXN) {
		cost[from][to] =
			min(
				cost[from][to],
				cost[from][mid] + cost[mid][to]
			);
	}

	LL tmp = 0;
	REP(i, N) {
		tmp |= cost[b[i]][a[i]];
	}
	if (tmp == (LL)INF*INF)return -2;
	for (int i = MAXN; i >= 0; i--) {
		if (tmp&(LL)pow(2, i))return i;
	}
	return -1;
}

void delete_concerning_edge(int division, vector<vector<LL>>& cost)
{
	//table(greedy)
	REP(from, MAXN)FOR(to, from + 1, MAXN){
		if (from == (to % division)) {
			cost[from][to] = 0;
		}
	}
}


//計算
void calc()
{
	LL ans = 0;
	vector<vector<LL>> cost;
	create_cost_table(cost);

	REP(i, N) {
		int must = largest_division_search(cost);
		if (must == -2) {
			ans = (LL)INF*INF;
			break;
		}
		if (must == -1)break;

		ans += pow(2, must);
		delete_concerning_edge(must, cost);
	}
	

	cout << (ans == (LL)INF*INF ? -1 : ans) << endl;
}


//出力
void output()
{
	
}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,d[maxn],siz[maxn],f,dis;
map <ll,int> p;
vector <int> a1,a2;

inline bool cmp(ll a,ll b){return a>b;}

int main()
{
	n=read(); f=0;
	for(int i=1;i<=n;i++) d[i]=read(),p[d[i]]=i;
	sort(d+1,d+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		siz[p[d[i]]]++;
		ll dfa=d[i]-n+2*siz[p[d[i]]];
		if(dfa>d[i]) continue;
		siz[p[dfa]]+=siz[p[d[i]]]; dis+=siz[p[d[i]]];
		//cout<<d[i]<<" "<<p[d[i]]<<" "<<siz[p[d[i]]]<<" "<<dfa<<endl;
		if(p[dfa]==0) {f=1; break;}
		a1.push_back(p[d[i]]),a2.push_back(p[dfa]);
	}
	if(f==1||dis!=d[n]) {puts("-1"); return 0;}
	for(int i=0;i<a1.size();i++) printf("%d %d\n",a1[i],a2[i]);
	return 0;
}

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

void solve(long long R){
    if (R < 1200) cout << "ABC" << '\n';
    else if (R < 2800) cout << "ARC" << '\n';
    else cout << "AGC" << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long R;
    scanf("%lld",&R);
    solve(R);
    return 0;
}


Measured memory_bytes: 256
N, M, X = map(int, input().split())
Cs = []
A = []
for i in range(N):
  As = list(map(int, input().split()))
  C = As.pop(0)
  Cs.append(C)
  A.append(As)
rs = []
for n in range(2**N):
  Bs = [0]*M
  r = 0
  for i in range(N):
    if (1<<i)&n != 0:
      r += Cs[i]
      As = A[i]
      for j in range(M):
        Bs[j] += As[j]
  if min(Bs) >= X:
    rs.append(r)
if len(rs) > 0:
  r = min(rs)
  print(r)
else:
  print(-1)


Measured memory_bytes: 9204
#!/usr/bin/env python3
import sys


def f(n):
    '''
    >>> f(1)
    1
    >>> f(6)
    7
    '''
    return (0 if n % 2 else n) ^ (1 if (n+1) // 2 % 2 else 0)


def solve(A: int, B: int):
    return f(A-1) ^ f(B)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(solve(A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()


Measured memory_bytes: 8048
using System;
public class Hello{
    public static void Main(){
        // Your code here!
        
        int N = int.Parse(Console.ReadLine());
        int Zoro = 0;
        for(int i = 0; i<N;i++)
        {
            string[] D = Console.ReadLine().Split(' ');
            
            if(D[0] == D[1]) 
            {
                Zoro++;
            if(Zoro ==3) break;
                
            }
            
            
            else Zoro = 0;
            
        }
        
        if(Zoro == 3) Console.WriteLine ("Yes");
        
        else Console.WriteLine ("No");
        
    }
}


Measured memory_bytes: 27512
#include <stdio.h>
int main(void){
    int r, c, i, j;
    int h[101][101] = {0};
     
    scanf("%d %d", &r, &c );
    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            scanf("%d", &h[i][j]);
        }
    }
    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            h[i][c] += h[i][j];
        }
    }
     
    for(j = 0; j < c + 1; j++){
        for(i = 0; i < r; i++){
            h[r][j] += h[i][j];
        }
    }
    for(i = 0; i < r + 1; i++){
        for(j = 0; j < c + 1; j++){
            printf("%d", h[i][j]);
            if(j != c){
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2112
'use strict'

function main(input) {
  let ans = ''
  input = input.slice(0,-1)
  for (let i in input) {
    ans += input[i] === '1' ? '9' : '1'
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 11468
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e+9;
#define rep(i, n) for(int i = 0; i < n;i++)
#define REP(i, n) for(int i = 0; i <= n;i++)

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

    if(s=="Sunny"){
        cout << "Cloudy" << endl;
    }else if(s=="Cloudy"){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    int x; cin >> x;
    if (x == 0) x = 1;
    else x = 0;
    cout << x << endl;
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
xl2 = sorted([[x + l, x - l] for x, l in xl])

ans = 0
mr = xl2[0][1]
for r, l in xl2:
    if l >= mr:
        ans += 1
        mr = r
print(ans)


Measured memory_bytes: 42160
#include<bits/stdc++.h>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	string s;
	cin>>s;
	if(s=="ABC"){
      cout<<"ARC";
    }
    else
      cout<<"ABC";
  

}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
typedef pair<ll,ll> P;
const ll INF=10000000000000000;
const ll mod=1000000007;
#define F first
#define S second
#define all(a) (a.begin(),a.end())
int main(void){
    int n;cin>>n;
    vector<ll>v(n);rep(i,n)cin>>v[i];
    sort(v.begin(),v.end());
    ll m=(v[n-1]+1)/2;
    ll ans=-1;
    rep(i,n-1){
        if(abs(ans-m)>abs(v[i]-m))ans=v[i];
    }
    cout<<v[n-1]<<' '<<ans;
}

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

int main(){
//    freopen("./input.txt", "r", stdin);
    int i;
    scanf("%d", &i);
    if(i==3 || i ==5|| i ==7)printf("YES\n");
    else printf("NO\n");
    return 0;
}


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

int main()
{
	int a1,a2,b1,b2;
	cin>>a1>>a2>>b1>>b2;
	
	while(1)
	{
		b1-=a2;
		if(b1<=0)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
		a1-=b2;
		if(a1<=0)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}		
}

Measured memory_bytes: 3576
import copy
S = input()
a = "abcdefghijklmnopqrstuvwxyz"
A = list(a)
ans = []
for a in A:
    tmp = copy.copy(S)
    cnt = 0
    while len(list(set(tmp))) > 1:
        tmp1 = []
        cnt += 1
        for i in range(len(tmp) - 1):
            if tmp[i] == a:
                tmp1.append(a)
            elif tmp[i+1] == a:
                tmp1.append(a)
            else:
                tmp1.append(tmp[i])
        tmp = copy.copy(tmp1)
    ans.append(cnt)
print(min(ans))


Measured memory_bytes: 41840
#define _[301][301]
N,M,i,j,t,v,r,C _,D _;char S _;
main(){
	for(scanf("%d%d ",&N,&M);gets(S+i++););
	for(;++t<M;r+=v){
		for(i=0;i++<N;)
			for(j=0;j++<N;)
				v=D[i][j]=fmin(D[i-1][j],D[i][j-1])+(C[i][j]=C[i-1][j-1]+(S[i-1][t-1]==S[j-1][t]));
	}
	printf("%d\n",r);
}


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

#define lpsbd(i, s, b, d) for(size_t i = s; i < b; i+=d)
#define lpsb(i, s, b) for(size_t i = s; i < b; i++)
#define lpn(i, n) for(size_t i = 0; i < n; i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)

using namespace std;
using ull = unsigned long long;

#define MOD 1000000007

#define MAX 2010

ull powm(ull a, int n)
{
    ull ans = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            ans = (ans * a) % MOD;
            n ^= 1;
        }
        else
        {
            a = (a * a) % MOD;
            n >>= 1;
        }
    }
    return ans;
}

int main(void)
{
    int N, K;
    cin >> N >> K;
    auto m = vc(ull, MAX);
    m[0] = 1;
    lpsb(i, 1, MAX) m[i] = (m[i-1] * i) % MOD;
    int R = N - K + 1, B = K - 1;
    for (size_t i = 1; i <= R && i <= K; i++)
    {
        auto a = (m[B] * m[R]) % MOD;
        auto b = (((m[i-1] * m[K-i]) % MOD) * ((m[i] * m[R-i]) % MOD)) % MOD;
        cout << (a * powm(b, MOD-2)) % MOD  << endl;
    }
    for (size_t i = R + 1; i <= K; i++) cout << 0 << endl;
    return 0;
}

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


int dp[2005][20005];
int res[2005];
int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
   
    int t=1;
    while(t--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        int mini=INT_MAX;
        for(int i=1;i<=a;i++)
        {
            for(int j=i+1;j<=a;j++)
            {
                dp[i][j]=dp[i][j]==0?INT_MAX:dp[i][j];
                if(abs(c-j)+abs(b-i)+1<j-i)
                    dp[i][j]=min(dp[i][j],abs(c-j)+abs(b-i)+1);
                else
                    dp[i][j]=min(dp[i][j],j-i);

            }
        }
        for(int i=1;i<=a;i++)
        {
            for(int j=i+1;j<=a;j++)
            {
                res[(dp[i][j]==INT_MAX?0:dp[i][j])]++;
            }
        }

        for(int i=1;i<a;i++)
            cout<<res[i]<<endl;

    }

return 0;

}

Measured memory_bytes: 154240
#include <bits/stdc++.h>
using namespace std;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(int x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,val[200004],cnt[16],ans,mask,dp[65540];
bool good[65548];
int main(){
	read(n);
	for (int i=1;i<n;i++){
	    int x,y,z;
	    read(x),read(y),read(z);
	    val[x]^=z,val[y]^=z;
	}
	for (int i=0;i<n;i++){
    	cnt[val[i]]++;
	}
	for (int i=1;i<16;i++)ans+=cnt[i]/2,cnt[i]%=2;
	for (int i=1;i<16;i++)if(cnt[i]==1)ans++,mask|=(1<<i); 
	for (int i=0;i<(1<<16);i++){
		int x=0;
    	for (int j=0;j<16;j++){
    		if (i&(1<<j)){
        		x^=j;
    		}
    	}
    	good[i]=(x==0);
	}
	for (int i=0;i<(1<<16);i++){
		if (i&1)continue;
    	for (int j=i;j;j=(j-1)&i)if(good[j])dp[i]=max(dp[i],dp[i^j]+1);
    }
	write(ans-dp[mask]);
	return 0;
}

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

int calc_point(int D, vector<int> c, vector<vector<int>> s, vector<int> t)
{
    int point = 0;
    vector<int> last(26);
    for (int i = 0; i < D; i++)
    {
        last.at(t.at(i) - 1) = i + 1;
        for (int j = 0; j < 26; j++)
        {
            point -= c.at(j) * (i + 1 - last.at(j));
        }

        point += s.at(i).at(t.at(i) - 1);
    }

    return point;
}

int main()
{
    clock_t start = clock();

    int D;
    cin >> D;

    vector<int> c(26);
    vector<vector<int>> s(D, vector<int>(26));

    for (int i = 0; i < 26; i++)
    {
        cin >> c.at(i);
    }

    for (int i = 0; i < D; i++)
    {
        for (int j = 0; j < 26; j++)
        {
            cin >> s.at(i).at(j);
        }
    }

    vector<int> t(D);
    for (int i = 0; i < D; i++)
    {
        t.at(i) = rand() % 26 + 1;
    }

    int point = calc_point(D, c, s, t);

    int old = 0;
    int new_point = 0;

    clock_t end;

    double time;

    int d;
    int q;
    while (true)
    {
        d = rand() % D + 1;
        q = rand() % 26 + 1;
        old = t.at(d - 1);
        t.at(d - 1) = q;

        new_point = calc_point(D, c, s, t);
        if (point < new_point)
        {
            point = new_point;
        }
        else
        {
            t.at(d - 1) = old;
        }

        end = clock();
        time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;

        if (time > 1970)
        {
            break;
        }
    }

    for (int i = 0; i < D; i++)
    {
        cout << t.at(i) << endl;
    }

    return 0;
}

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

int main(){

ll mh,n;
cin>>mh>>n;

ll sum=0;

for(int i = 0;i<n;i++){
     int x;
     cin>>x;
     sum+=x;
}
if(sum>=mh){
     cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool search(int *array, int n, int key)
{
    int low = 0, high = n - 1;
    while (low <= high)
    {
        int middle = (low + high) / 2;
        if (key > array[middle])
            low = middle + 1;
        else if (key < array[middle])
            high = middle - 1;
        else if (key == array[middle])
            return true;
    }
    return false;
}
int main()
{
    int n;
    cin >> n;
    int s[n];
    for (int i = 0; i < n; ++i)
        cin >> s[i];
    int q;
    cin >> q;
    int t[q];
    for (int i = 0; i < q; ++i)
        cin >> t[i];
    int ans(0);
    for (int i = 0; i < q; ++i)
    {
        if (search(s, n, t[i]))
            ans++;
    }
    cout << ans << endl;
}


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

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

    vector<vector<char>> img(H+2, vector<char>(W+2));

    // img initialize
    for(int y=0; y<img.size(); y++) {
        for(int x=0; x<img[0].size(); x++) {
            img[y][x] = '#';
        }
    }

    for(int i=0; i<H; i++) {
        int y = (i + 1);
        string s;
        cin >> s;

        for(int j=0; j<s.size(); j++) {
            int x = (j + 1);
            img[y][x] = s.at(j);
        }
    }

    for(int y=0; y<img.size(); y++) {
        for(int x=0; x<img[0].size(); x++) {
            cout << img[y][x];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
  int res = 1;
  x = x % p;
  while (y > 0)
  {

    if (y & 1)
      res = (res * x) % p;

    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  tc = 1;
  //cin>>tc;
  while(tc--){
    int n, m;
    cin >> n >> m;
    int a = n % m;
    int mn = min(a, abs(a - m));
    cout << mn;
  }

  return 0;
}


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

int main(){
    ll s;
    cin >> s;
    ll x1 = ceil(sqrt(s)), y1 = 1;
    ll x2, y2 = ceil(sqrt(s));
    x2 = x1 * y2 - s;
    cout << 0 << " " << 0 << " ";
    cout << x1 << " " << y1 << " ";
    cout << x2 << " " << y2 << " " << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rt register int
#define all(it) it.begin(), it.end()
#define rep(it, f, e) for (rt it = f; it <= e; ++it)
#define per(it, f, e) for (rt it = f; it >= e; --it)
const int MAXN = 2e5 + 10;
int A[MAXN];
ll dpl[MAXN], dpr[MAXN];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, d;
	cin >> n >> d;
	ll ans = (n - 1ll) * d;
	rep (i, 1, n) {
		cin >> A[i];
		ans += A[i];
	}
	if (n == 1) {
		cout << 0 << endl;
		return 0;
	}
	dpl[1] = A[1];
	rep (i, 2, n) {
		dpl[i] = min((ll)A[i], dpl[i - 1] + d);
	}
	dpr[n] = A[n];
	per (i, n - 1, 1) {
		dpr[i] = min((ll)A[i], dpr[i + 1] + d);
	}
	rep (i, 2, n - 1) {
		ans += min(dpl[i], dpr[i]);
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;



int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n;
	
	cin>>n; cout<<1-n;
	
	
	return 0;
}


Measured memory_bytes: 3648
console.log((args=>{
  const [[N,M],...tmp] = args.trim().split('\n').map(r=>r.split(' ').map(v=>parseInt(v)));
  const dp = Array.from({length:N+1},_=>Array.from({length:M+1},_=>Array(8).fill(-Infinity)));
  dp[0][0] = [0,0,0,0,0,0,0,0];
  for ( let i = 0; i < N; i++ ) {
    const [x,y,z] = tmp[i];
    dp[i+1][0] = [0,0,0,0,0,0,0,0];
    for ( let j = 0; j < M; j++ ) {
      for ( let b = 0; b < 8; b++ ) {
        let s = 0;
        s += (b&1)?x:-x;
        s += (b&2)?y:-y;
        s += (b&4)?z:-z;
        dp[i+1][j+1][b] = Math.max( dp[i][j+1][b], dp[i][j][b] + s );
      }
    }
  }
  return `${Math.max(...dp[N][M])}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 187572
N = int(input())
H = list(map(int, input().split()))

cnt = 0
for i in range(N):
  if i == 0:
    cnt += 1
  else:
    high = True
    for j in range(i):
      if H[i] < H[j]:
        high = False
    if high:
      cnt += 1
print(cnt)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main (String[] args) throws IOException
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));

		int kaisuu = Integer.parseInt(input.readLine());

		int pointT = 0;

		int pointH = 0;

		//勝負をkaisuu回行う
		for(int kai = 0; kai < kaisuu; kai++)
		{
			String[] cards = input.readLine().split(" ");;

			for(int next = 0; next <= cards[0].length(); next++)
			{

				char head = 'a';

				int tarou = 0;

				int hanako = 0;

				int alphabet = 26;

				//太郎のカードの強さを調べる
				for(int num = 0; num < alphabet; num++,head++)
				{
					if(next == cards[0].length())
					{
						tarou = -1;

						break;
					}

					if(cards[0].charAt(next) == head)
					{
						tarou = num;

						break;
					}
				}

				head = 'a';

				//花子のカードの強さを調べる
				for(int num = 0; num < alphabet; num++,head++)
				{
					if(next == cards[1].length())
					{
						hanako = -1;

						break;
					}

					if(cards[1].charAt(next) == head)
					{
						hanako = num;

						break;
					}
				}

				//得点を振り分ける
				if(tarou > hanako)
				{
					pointT = pointT + 3;

					break;
				}

				else if(tarou < hanako)
				{
					pointH = pointH + 3;

					break;
				}

				else if(tarou == -1 && hanako == -1)
				{
					pointT++;

					pointH++;
				}
			}
		}

		System.out.println(pointT + " " + pointH);
	}
}



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

  int main() {
LL L,R,D,A;
cin>>L>>R>>D;
A=R/D-L/D;
if(L%D==0){
  A=R/D-L/D+1;
}
if(A<0){
  A=0;
}
cout<<A<<endl;
}


Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		try (Stream<String> lines = new BufferedReader(new InputStreamReader(System.in)).lines()) {
			new Main().exec(lines.toArray(String[]::new));
		}
	}

	void exec(String[] args) {
		String[] a = args[0].split(" ");
		int A = Integer.parseInt(a[0]);
		int B = Integer.parseInt(a[1]);
		int AL = (int)(12.5 * A + 0.5);
		int AH = (int)(12.5 * A + 12);
		int BL = 10 * B;
		int BH = 10 * B + 9;
		System.out.println(BL <= AL && AL <= BH ? AL : AL <= BL && BL <= AH ? BL : -1);
	}

}

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

using namespace std;

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

int main() {
	int n, x, t;
	cin>>n>>x>>t;
	int sth = n/x;
	if(n%x != 0) ++sth;
	cout<<sth*t;
	cout<<endl;
	return 0;
}

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


int main(){
	int n,m,a;
	vector<int> v;
	map<int,int> mp,mp2;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a;
		mp[a]++;
	}
	
	cin >> m;
	for(int i=0;i<m;i++){
		cin >> a;
		mp2[a]++;
		v.push_back(a);
	}
	
	for(int i=0;i<m;i++){
		if(mp[v[i]]<mp2[v[i]]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 19828
import sys
from collections import deque,defaultdict

I=sys.stdin.readline

def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))

def mi():
	return map(int,I().strip().split())


def main():
	n=ii()
	arr=li()
	p=1000
	for i in range(n-1):
		if arr[i]<arr[i+1]:
			buy=p//arr[i]
			p+=(arr[i+1]-arr[i])*buy

	
	print(p)








		


		










		






if __name__ == '__main__':
	main()

Measured memory_bytes: 9416
#include <bits/stdc++.h>
using namespace std;
int f[1000001];
int v[1000001];
int find(int x){
  if(f[x]==x){
    return x;
  }else{
    int fx=f[x];
    f[x]=find(f[x]);
    v[x]+=v[fx];
    return f[x];
  }
}
void join(int x,int y,int z){
  int fx=find(x);
  int fy=find(y);
  if(fx!=fy){
    v[fx]=z+v[y]-v[x];
    f[fx]=fy;
  }
}
int main(){
  int n,q,t,l,r;
  cin >> n >> q;
  for(int i=0;i<=n;i++)f[i]=i;
  while(q--){
    cin >> t >> l >> r;
    if(t){
      int fx=find(l);
      int fy=find(r);
      if(fx==fy){
	cout<<v[l]-v[r]<<endl;
      }else cout<<"?"<<endl;
    }else{
      int z;cin>>z;
      join(l,r,z);
    }
  }
  return 0;
}



Measured memory_bytes: 5104
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int r,g,b;cin>>r>>g>>b;
    if((g*10+b)%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256