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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
#define chmin(x, v)                                                            \
  do {                                                                         \
    x = min(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// {{{ (k)MP: Search pattern from text
// MP<std::string> mp("a");
// auto res = mp.findAll("aabb"); // res = {0, 1}
template<typename T>
class MP {
  private:
    ll n;
    T t;
    std::vector<ll> a;
  public:
    explicit constexpr MP(const T &pattern) : t(pattern) {
      n = pattern.size();
      a = std::vector<ll>(n+1);
      a[0] = -1;
      int j = -1;
      for (int i = 0; i < n; ++i) {
        while (j != -1 && pattern[j] != pattern[i])
          j = a[j];
        j++;
        a[i+1] = j;
      }
    }
    ll operator[](ll i) {
      return a[i];
    }
    std::vector<ll> findAll(const T &text) {
      std::vector<ll> res;
      int j = 0;
      for (int i = 0; i < text.size(); ++i) {
        while (j != -1 && t[j] != text[i])
          j = a[j];
        j++;
        if (j == n) {
          res.push_back(i-j+1);
          j = a[j];
        }
      }
      return res;
    }
};
// }}}

ll N;
vector<ull> a, b;

vector<ull> diff(vector<ull> &v) {
  vector<ull> res(v.size());
  rep(i, N) {
    res[i] = v[i] ^ v[(i+1)%N];
  }
  return res; 
}

signed main() {
  cin >> N;
  a.resize(N);
  b.resize(N);
  rep(i, N) { cin >> a[i]; }
  rep(i, N) { cin >> b[i]; }
  auto ad = diff(a);
  auto bd = diff(b);

  bd.insert(bd.end(), bd.begin(), bd.end()); // bd += bd;

  // cout << "diff: " << endl;
  // for (auto x : ad) { cout << x << " "; } cout << endl;
  // for (auto x : bd) { cout << x << " "; } cout << endl;

  MP<vector<ull>> mp(ad);
  auto matches = mp.findAll(bd);
  reverse(begin(matches), end(matches));
  for (auto i : matches) {
    ll k = N-i;
    if (k >= N)
      continue;
    ull x = a[k] ^ b[0];
    cout << k << " " << x << endl;
  }
  return 0;
}


Measured memory_bytes: 18020
import math
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

s_a = [x for x in str(a)]
s_b = [x for x in str(b)]
s_c = [x for x in str(c)]
s_d = [x for x in str(d)]
s_e = [x for x in str(e)]

l = [a,b,c,d,e]
m = [s_a,s_b,s_c,s_d,s_e]
s = []
ans = 0

for i in range(len(m)):
  if int(m[i][-1]) != 0:
    s.append(int(m[i][-1]))
  else:
    s.append(9) 
min_index = s.index(min(s))
max_num = l.pop(min_index)

for i in range(len(l)):
  ans += math.ceil(l[i] / 10) * 10

print(ans + max_num)


Measured memory_bytes: 3064
# coding: utf-8
import re
import math
import fractions
import random
from heapq import heappop,heappush
import time
import sys
input = sys.stdin.readline
#import numpy as np

 

 
#main
N,Q=map(int,input().split())
E=[]
for a in range(N):
    s,t,x=map(int,input().split())
    E.append((s-x,1,x))
    E.append((t-x,0,x))

for a in range(Q):
    E.append((int(input()),2,0))
E.sort()
 
S=set()
H=[]
for time_,type_,x in E:
    if type_&1:
        S.add(x)
        heappush(H,x)
    elif not type_:
        S.remove(x)
    else:
        while H and H[0] not in S:
            heappop(H)
        print(H[0] if H else -1)

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

char f[124][124];
int H, W;

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
inline bool inside(int y, int x){return 0 <= y && y < H && 0 <= x && x < W;}

void area(int y, int x)
{
	char if2 = f[y][x];
	f[y][x] = '0';
	
	for (int i = 0; i < 4; i++){
		int ny = y + dy[i], nx = x + dx[i];
		if (inside(y, x) && f[ny][nx] != '0' && f[ny][nx] == if2){
			area(ny, nx);
		}
	}
}

int main()
{
	while (cin >> H >> W, H || W){
		int c = 0;
		for (int i = 0; i < H; i++){
			cin >> f[i];
		}
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				if (f[i][j] != '0'){
					area(i, j);
					c++;
				}
			}
		}
		cout << c << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1644
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;
typedef long long LL;

const int maxn = 4e5 + 5;
int pre[maxn],other[maxn],last[maxn];
LL cost[maxn];
LL dis[maxn];
int vis[maxn];
int all = -1;

void build(int x,int y,LL w){
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
	cost[all] = w;
}

bool dfs(int x){
	int dt = last[x];
	while(dt != -1){
		int dr = other[dt];
		if(vis[dr] == 0 && vis[x] == 1){
			vis[dr] = 1;
			dis[dr] = dis[x] + cost[dt];
			if(!dfs(dr)) return false;
		}
		else if(vis[dr] == 1 && vis[x] == 1){
			if(dis[dr] != dis[x] + cost[dt]) return false;
		}
		dt = pre[dt];
	}
	return true;
}

int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	memset(last,-1,sizeof(last));
	for(int i = 1;i <= m;i++){
		int x,y;
		LL w;
		scanf("%d %d %lld",&x,&y,&w);
		build(x,y,w);
		build(y,x,-w);
	}
	for(int i = 1;i <= n;i++){
		if(vis[i] == 0){
			vis[i] = 1;
			if(!dfs(i)){
				dis[i] = 0;
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
}

Measured memory_bytes: 14336
K=int(input())
A, B=map(int, input().split())

if K==1 or A%K==0 or B%K==0:
    print('OK')
elif (A==B) and (A%K == 0):
    print('OK')
elif (B-A) > K:
    print('OK')
elif (B-A) + (A%K) >=K:
    print('OK')
else:
    print('NG')


Measured memory_bytes: 9020
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int H,W,h,w,x,y;
  double u,d,l,r;
  scanf("%d %d %d %d %d %d",&W,&H,&w,&h,&x,&y);
  u=MIN(H/2,y+h/2);
  d=y-h/2;
  l=x-w/2;
  r=MIN(W/2,x+w/2);
  printf("%.10lf\n",(u+d)/(l+r));
  return 0;
}



Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int n,q;
str s;
int sum[200000];
bool neg[200000];
int main(){
    cin>>n>>q;
    cin>>s;
    s = " "+s;
    sum[0]=0;
    for(int i=1;i<s.size();i++){
        sum[i]=sum[i-1];
        if(s[i]=='C' && s[i-1]=='A'){sum[i]++;neg[i]=true;}
    }

    for(int i=1;i<=q;i++){
        int l,r;
        cin>>l>>r;
        int ans;
        ans = sum[r]-sum[l-1];
        if(neg[l])ans--;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 1532
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	s := sc.Text()

	t := ""
	for _, c := range s {
		t += string(increase(c, n))
	}
	fmt.Println(t)
}

func increase(c rune, n int) int {
	ret := int(c) - 'A' + n
	return (ret % 26) + 'A'
}


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

int main(void)
{
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for(int i{0}; i<N; ++i){
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    for(int i{0}; i<N; ++i){
        cout << S[i];
    }
    cout << endl;
}


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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int> frsum(n),basum(n);
    frsum[0] = a[0]; //i番目以前の要素sの最大値
    basum[n-1] = a[n-1]; //i番目以降の要素の最大値
    for(int i = 0; i < n-1; i++){
        frsum[i+1] = max(a[i+1],frsum[i]);
        basum[n-2-i] = max(a[n-2-i],basum[n-1-i]);
    }
    cout << basum[1] << endl;
    for(int i = 1; i < n-1; i++){
        cout << max(frsum[i-1],basum[i+1]) << endl;
    }
    cout << frsum[n-2] << endl;
}

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

int main()
{
    vector<P> a;
    int f, s;
    f = s = -1;
    while (!(f == 0 && s ==0))
    {
        cin >> f >> s;
        if (f > s)
        {
            int t;
            t = f;
            f = s;
            s = t;
        }

        a.push_back(make_pair(f, s));
    }


    for (int i = 0; i < a.size()-1; i++)
        cout << a.at(i).first << " " << a.at(i).second << endl;

    return 0;
}



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

typedef long long ll;

int T1, T2;
ll A1, A2;
ll B1, B2;

int main()
{
    cin >> T1 >> T2;
    cin >> A1 >> A2; A1 *= T1; A2 *= T2;
    cin >> B1 >> B2; B1 *= T1; B2 *= T2;
    if (A1 + A2 == B1 + B2) { printf("infinity\n"); return 0; }
    if (A1 + A2 > B1 + B2) { swap(A1, B1); swap(A2, B2); }
    if (A1 > B1) {
        ll r = (A1 - B1) / (B1 + B2 - A1 - A2);
        ll res = 2ll * r;
        if ((A1 - B1) % (B1 + B2 - A1 - A2)) res++;
        cout << res << endl;
    } else printf("0\n");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
long int x;
int n,m[100],i,min,count=0,sum=0,temp;
scanf("%d%ld",&n,&x);

for(i=0;i<n;i++)
scanf("%d",&m[i]);

min=m[0];

for(i=0;i<n;i++)
{
sum+=m[i];
if(m[i]<=min)
min=m[i];
}

count=n;

temp=x-sum;
count+=temp/min;
printf("%d",count);


}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

string s[8];
signed main(void)
{
  int cnt = 0;
  while(getline(cin, s[cnt])) {
    if(s[cnt] == "") continue;
    if(cnt == 7) {
      REP(i, 8) REP(j, 8) {
        if(i <= 6 && j <= 6 && s[i][j] == '1' && s[i][j+1] == '1' && s[i+1][j] == '1' && s[i+1][j+1] == '1')
          cout << "A" << endl;
        else if(i <= 4 && s[i][j] == '1' && s[i+1][j] == '1' && s[i+2][j] == '1' && s[i+3][j] == '1')
          cout << "B" << endl;
        else if(j <= 4 && s[i][j] == '1' && s[i][j+1] == '1' && s[i][j+2] == '1' && s[i][j+3] == '1')
          cout << "C" << endl;
        else if(i <= 5 && j >= 1 && s[i][j] == '1' && s[i+1][j] == '1' && s[i+1][j-1] == '1' && s[i+2][j-1] == '1')
          cout << "D" << endl;
        else if(i <= 6 && j <= 5 && s[i][j] == '1' && s[i][j+1] == '1' && s[i+1][j+1] == '1' && s[i+1][j+2] == '1')
          cout << "E" << endl;
        else if(i <= 5 && j <= 6 && s[i][j] == '1' && s[i+1][j] == '1' && s[i+1][j+1] == '1' && s[i+2][j+1] == '1')
          cout << "F" << endl;
        else if(i >= 1 && j <= 5 && s[i][j] == '1' && s[i][j+1] == '1' && s[i-1][j+1] == '1' && s[i-1][j+2] == '1')
          cout << "G" << endl;
      }
    }
    cnt++;
    if(cnt == 8) cnt = 0;
  }

  return 0;
}

Measured memory_bytes: 2968
function main(){
 
var seats = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var groupMembers = [2,5,2,2,2];
var eatTimes = [19,39,25,36,22,42];
 
var headGroup = -1;
var pastMinutes = 0;
var waitTime = [];
 
while(waitTime.length < 100){
  // たべおわる
  var slen = seats.length;
  for(; slen--;){
    seats[slen] = mx(seats[slen] - 1, 0);
  }
 
  // 来店
  if(headGroup == -1 && pastMinutes % 5 == 0){
    headGroup = pastMinutes / 5;
  }
 
  // ちゃくせき
  while(headGroup != -1){
    var needsSequencialSeats = groupMembers[headGroup % 5];
    var sequencialSeats = 0;
    var startIndex = -1;
    for(var i = 0; i < seats.length; i++){
      sequencialSeats = seats[i] == 0 ? sequencialSeats + 1 : 0;
 
      if(sequencialSeats == needsSequencialSeats){
        startIndex = i - (needsSequencialSeats - 1);
        break;
      }
    }
 
    if(startIndex != -1){
      // すわれたみたい
      waitTime[headGroup] = pastMinutes - (headGroup * 5);
      for(var i = startIndex; i < (needsSequencialSeats + startIndex); i++){
        seats[i] = eatTimes[headGroup % 6];
      }
       
      headGroup = (((headGroup + 1) * 5) <= pastMinutes) ? headGroup + 1 : -1;
    }else{
      // すわれなかったみたい
      break;
    }
 
  }
 
  pastMinutes++;
 
}
 
for(var i = 0; i < (input.length - 1); i++){
  console.log(waitTime[parseInt(input[i], 10)]);
}
 
}

function mx(a, b){
 var t = (a-b);
 return a - (t & (t >> 31));
}
 
var
input = '';
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

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

int N,M;
int pass;

void dfs( int x , vector<bool> seen ,vector< vector<int> > &G){

  //すでに頂点xを訪れている
  if( seen[x] ) return;

  seen[x] = true;

  //全ての頂点に訪問したか
  bool flag = true;
  for( int i = 0; i < N; i++){
    if( !(seen[i]) ){
      flag = false;
    }
  }
  //した（→パスになっている）
  if( flag ){
    pass++;
    return;
  }

  for( auto next_x : G[x] ){
    dfs( next_x , seen , G );
  }

}

int main(){

  cin >> N >> M;
  vector< vector<int> > G( N , vector<int> (M) );
  for( int i = 0; i < M; i++){

    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);

  }

  pass = 0;
  vector<bool> seen(N);
  dfs( 0 , seen , G );

  cout << pass << endl;

  return 0;

}


Measured memory_bytes: 256
// AOJ Vol3-0383 Heat Strokes
// 2018.12.25
 
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int A, B, ans;

	scanf("%d%d", &A, &B);
	ans = B / A;
	if (B % A) ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>
#define NIL -1

typedef struct node{
  int p;
  int r;
  int l;
}Node;

Node T[25];

void Preorder(int u){
  if(u == NIL)return;
  printf(" %d",u);
  Preorder(T[u].l);
  Preorder(T[u].r);
}

void Inorder(int u){
  if(u == NIL)return;
  Inorder(T[u].l);
  printf(" %d",u);
  Inorder(T[u].r);
}

void Postorder(int u){
  if(u == NIL)return;
  Postorder(T[u].l);
  Postorder(T[u].r);
  printf(" %d",u);
}



int main(){
  int n,i,j;
  int v,l,r;
  int root;

  scanf("%d",&n);


  for(i=0;i<n;i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL)T[l].p = v;
    if(r != NIL)T[r].p = v;
  }

  for (i=0;i<n;i++) {
    if (T[i].p == NIL) root = i;
  }

  printf("Preorder\n");
  Preorder(root);
  printf("\nInorder\n");
  Inorder(root);
  printf("\nPostorder\n");
  Postorder(root);
  puts("");
  return 0;
}


Measured memory_bytes: 2108
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String work[] = new String[4];
        int table[][][] = new int[4][3][10];
 
        for(int a = 0; a < 4; a++){
            for(int b = 0; b < 3; b++){
                for(int c = 0; c < 10; c++)table[a][b][c] = 0;
            }
        }
 
        try {
            int N = Integer.parseInt(br.readLine());
 
            for(int loop = 0; loop < N; loop++){
                work = br.readLine().split("\\s+");
                table[Integer.parseInt(work[0])-1][Integer.parseInt(work[1])-1][Integer.parseInt(work[2])-1] += Integer.parseInt(work[3]);
            }
 
 
            print(table[0]);
            for(int i = 1; i <= 3; i++){
                System.out.printf("####################\n");
                print(table[i]);
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private static void print(int house[][]){
 
        for(int row = 0; row < 3; row++){
            for(int col = 0; col < 10; col++){
                System.out.printf(" %d", house[row][col]);
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 25628
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int f(vector<vector<int>> &v, int k){
	int l = 0;
	int h = v.size();
	int w = v[0].size();
	for(int i=1; i<w; ++i){
		for(int j=0; j<h; ++j){
			v[j][i] += v[j][i-1];
		}
	}
	int cnt = 0;
	for(int i=0; i<w; ++i){
		bool f = false;
		for(int j=0; j<h; ++j){
			int t = (l == 0 ? v[j][i] : v[j][i] - v[j][l]);
			if(t > k) f = true;
		}
		if(f){
			if(l == i){
				return 1e9;
			}
			l = i-1;
			++cnt;
		}
	}
	return cnt;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	int h, w, K; cin >> h >> w >> K;
	vector<string> s(h);
	for(auto &i:s) cin >> i;
	int ans = 1e9;
	for(int i=0; i<(1<<(h-1)); ++i){
		int cnt = 0;
		for(int j=0; (i>>j)>0; ++j)
			if(((i>>j)&1) == 1)
				++cnt;
//		cout << cnt << "\n";
		vector<vector<int>> v(cnt+1, vector<int>(w, 0));
		for(int j=0; j<w; ++j){
			int t = 0;
			for(int k=0; k<h; ++k){
				v[t][j] += s[k][j]-'0';
				if(((i>>k)&1) == 1) ++t;
			}
		}
//		cout << bitset<4>(i) << "\n";
//		for(int j=0; j<cnt+1; ++j)
//			for(int k=0; k<w; ++k)
//				cout << v[j][k] << " \n"[k+1==w];
		ans = min(ans, cnt+f(v, K));
//		cout << ans << "\n";
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
using System;

namespace abc092_a
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Math.Min(int.Parse(Console.ReadLine()),int.Parse(Console.ReadLine())) + Math.Min(int.Parse(Console.ReadLine()),int.Parse(Console.ReadLine())));
        }
    }
}

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

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
	char a, b;
	cin >> a >> b;
	
	if (a != 'H') {
		if (b == 'H') {
			b = 'D';
		} else {
			b = 'H';
		}
	}
	
	cout << b << endl;
  return 0;
}

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

signed main(){
	lint N; cin >> N;
  set<string> map;
  for(lint i = 0; i < N; i++){
    string s; cin >> s;
    map.insert(s);
  }
  cout << map.size() << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;

const int M = (int)2e5;
const int N = (int)5e5;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)1e9 + 7;
const double eps = 1e-6;

int n, m;

int fa[M + 5];
int sz[M + 5];

int tofind(int x)
{
    if(x == fa[x]) return x;
    return fa[x] = tofind(fa[x]);
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; ++i) fa[i] = i, sz[i] = 1;
    for(int i = 1, a, b; i <= m; ++i)
    {
        scanf("%d %d", &a, &b);
        a = tofind(a), b = tofind(b);
        if(a == b) continue;
        fa[a] = b, sz[b] += sz[a];
    }
    int ans = 0;
    for(int i = 1; i <= n; ++i) if(fa[i] == i) ans = max(ans, sz[i]);
    printf("%d\n", ans);
    return 0;
}


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

int main(void){
    int num=0;
    int i=0;
    int n=0;
    int v[30];
    int c[30];
    int kotae=0;
    char str[1000];
    char*tp;
    scanf("%d\n",&n);
    fgets(str,100,stdin);
    tp=strtok(str," ");
    num=atoi(tp);
    v[0]=num;
    while(1){
        i++;
        tp=strtok(NULL," ");
        if (tp==NULL)break;
        num=atoi(tp);
        v[i]=num;
    }
    
    i=0;
fgets(str,100,stdin);
    tp=strtok(str," ");
    num=atoi(tp);
    c[0]=num;
    while(1){
        i++;
        tp=strtok(NULL," ");
        if (tp==NULL)break;
        num=atoi(tp);
        c[i]=num;
    }
    i=0;
    for(;i<n;i++){
        
        if(v[i]-c[i]>0){
            kotae=kotae+(v[i]-c[i]);
            
            }
    }
    printf("%d\n",kotae);
    return 0;
}

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

const long Day_num = 365;
const long type_num = 26;

class Scoring {
public:
    Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives);
    std::vector<long> score(const std::vector<long>& arg_types);
private:
    long days;
    std::vector<long> costs;
    std::vector<std::vector<long>> incentives;
};

std::vector<long> Scoring::score(const std::vector<long>& arg_types) {
    std::vector<long> result(days);
    long satisfy = 0;
    std::vector<long> last_days(type_num, 0);


    for (long day = 1; day <= days; ++day) {
        const auto exe_type = arg_types[day-1];
        satisfy += incentives[day-1][exe_type-1];
        last_days[exe_type-1] = day;
        for (long type = 1; type <= type_num; ++type) {
            satisfy -= costs[type-1] * (day - last_days[type-1]);
        }
        result[day-1] = satisfy;
    }
    return result;
}

Scoring::Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives) {
    days = arg_days;
    costs = arg_costs;
    incentives = arg_incentives;
}

int main() {
    long D;
    std::cin >> D;
    std::vector<long> costs(type_num);
    for (long type = 1; type <= type_num; ++type) {
        std::cin >> costs[type-1];
    }
    std::vector<std::vector<long>> incentives(D, std::vector<long>(type_num));
    for (long day = 1; day <= D; ++day) {
        for (long type = 1; type <= type_num; ++type) {
            std::cin >> incentives[day-1][type-1];
        }
    }
    std::vector<long> types(D);
    for (long day = 1; day <= D; ++day) {
        std::cin >> types[day-1];
    }
    Scoring scoring(D, costs, incentives);
    const auto scores = scoring.score(types);
    for (const auto score : scores) {
        std::cout << score << std::endl;
    }
}

Measured memory_bytes: 3784
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll n, m;
	cin >> n >> m;
	vector<vll> st(n, vll(2)), chk(m, vll(2));
	for (ll i = 0; i < n; i++) cin >> st[i][0] >> st[i][1];
	for (ll i = 0; i < m; i++) cin >> chk[i][0] >> chk[i][1];

	for (ll i = 0; i < n; i++) {
		ll x = st[i][0], y = st[i][1];
		priority_queue<vll, vector<vll>, greater<vll>> pq;
		for (ll j = 0; j < m; j++) {
			ll z = chk[j][0], w = chk[j][1];
			pq.push({abs(x - z) + abs(y - w), j});
		}
		cout << pq.top()[1] + 1 << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using Int = long long;
int main() {
    Int N;
    cin >> N;
    for (Int h = 1; h <= 3500; h++) {
        for (Int n = 1; n <= 3500; n++) {
            Int t1 = N * h * n;
            Int t2 = 4 * h * n - N * n - N * h;
            if (t2 != 0 && t1 % t2 == 0 && t1 / t2 >= 1) {
                cout << h << " " << n << " " << t1 / t2 << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXH 300001
#define MAXW 300001
int ch[MAXH];
int cw[MAXW];
vector<pair<int, int> > vec;
bool mh[MAXH];
bool mw[MAXW];
int main() {
    int h, w, m;
    cin >> h >> w >> m;
    for (int i = 1; i <= h; i++) {
        ch[i] = 0;
    }
    for (int i = 1; i <= w; i++) {
        cw[i] = 0;
    }
    for (int i = 1; i <= m; i++) {
        int bh, bw;
        cin >> bh >> bw;
        vec.push_back(make_pair(bh, bw));
        ch[bh]++;
        cw[bw]++;
    }
    int maxh = 0;
    int maxw = 0;
    for (int i = 1; i <= h; i++) {
        if (maxh < ch[i]) {
            maxh = ch[i];
        }
    }
    for (int i = 1; i <= w; i++) {
        if (maxw < cw[i]) {
            maxw = cw[i];
        }
    }
    //cout << maxh << endl << maxw << endl;
    memset(mh, false, sizeof(mh));
    memset(mw, false, sizeof(mw));
    int num_of_maxh = 0;
    int num_of_maxw = 0;
    for (int i = 1; i <= h; i++) {
        if (maxh == ch[i]) {
            mh[i] = true;
            num_of_maxh++;
        }
    }
    for (int i = 1; i <= w; i++) {
        if (maxw == cw[i]) {
           mw[i] = true; 
           num_of_maxw++;
        }
    }
    ll num = (ll)num_of_maxh * num_of_maxw;
    for (int i = 0; i < vec.size(); i++) {
        if ((mh[vec[i].first]) && (mw[vec[i].second])) {
            num--;
        }
    }
    int ret = maxh + maxw;
    if (num == 0) {
        ret--;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 9704
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	
	ll r,d,x,i;
	cin>>r>>d>>x;
	for(i=1;i<=10;i++){
		cout<<r*x-d<<endl;
		x=r*x-d;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
return 0;}











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

int nums[4];
char o[27][3] = {
  { '+', '+', '+' }, { '+', '+', '-' }, { '+', '+', '*' },
  { '+', '-', '+' }, { '+', '-', '-' }, { '+', '-', '*' },
  { '+', '*', '+' }, { '+', '*', '-' }, { '+', '*', '*' },
  { '-', '+', '+' }, { '-', '+', '-' }, { '-', '+', '*' },
  { '-', '-', '+' }, { '-', '-', '-' }, { '-', '-', '*' },
  { '-', '*', '+' }, { '-', '*', '-' }, { '-', '*', '*' },
  { '*', '+', '+' }, { '*', '+', '-' }, { '*', '+', '*' },
  { '*', '-', '+' }, { '*', '-', '-' }, { '*', '-', '*' },
  { '*', '*', '+' }, { '*', '*', '-' }, { '*', '*', '*' }
};

int p[24][4] = {
  { 0, 1, 2, 3 }, { 0, 1, 3, 2 }, { 0, 2, 1, 3 }, { 0, 2, 3, 1 },
  { 0, 3, 1, 2 }, { 0, 3, 2, 1 }, { 1, 0, 2, 3 }, { 1, 0, 3, 2 },
  { 1, 2, 0, 3 }, { 1, 2, 3, 0 }, { 1, 3, 0, 2 }, { 1, 3, 2, 0 },
  { 2, 0, 1, 3 }, { 2, 0, 3, 1 }, { 2, 1, 0, 3 }, { 2, 1, 3, 0 },
  { 2, 3, 0, 1 }, { 2, 3, 1, 0 }, { 3, 0, 1, 2 }, { 3, 0, 2, 1 },
  { 3, 1, 0, 2 }, { 3, 1, 2, 0 }, { 3, 2, 0, 1 }, { 3, 2, 1, 0 }
};

int scan() {
  int i;
  for (i = 0; i < 4; i++) scanf("%d", nums + i);
  return nums[0] || nums[1] || nums[2] || nums[3];
}

int calc(int a, int b, char op) {
  int ans = -1;
  switch (op) {
    case '+':
      ans = a + b;
      break;
    case '-':
      ans = a - b;
      break;
    case '*':
      ans = a * b;
      break;
  }
  return ans;
}

void printExp(char *str, int pi, int oi) {
  printf(str,
	 nums[p[pi][0]], o[oi][0], nums[p[pi][1]], o[oi][1],
	 nums[p[pi][2]], o[oi][2], nums[p[pi][3]]);
}

int fna(int pi, int oi) {
  int ret = 10 == calc(calc(nums[p[pi][0]], nums[p[pi][1]], o[oi][0]),
		       calc(nums[p[pi][2]], nums[p[pi][3]], o[oi][2]),
		       o[oi][1]);
  if (ret) { printExp("((%d %c %d) %c (%d %c %d))\n", pi, oi); }
  return ret;
}

int fnb(int pi, int oi) {
  int ret = 10 == calc(calc(nums[p[pi][0]],
			    calc(nums[p[pi][1]], nums[p[pi][2]], o[oi][1]),
			    o[oi][0]),
		       nums[p[pi][3]], o[oi][2]);
  if (ret) { printExp("((%d %c (%d %c %d)) %c %d)\n", pi, oi); }
  return ret;
}

int fnc(int pi, int oi) {
  int ret = 10 == calc(calc(calc(nums[p[pi][0]], nums[p[pi][1]], o[oi][0]),
			    nums[p[pi][2]], o[oi][1]),
		       nums[p[pi][3]], o[oi][2]);
  if (ret) { printExp("(((%d %c %d) %c %d) %c %d)\n", pi, oi); }
  return ret;
}

int fnd(int pi, int oi) {
  int ret = 10 == calc(nums[p[pi][0]],
		       calc(nums[p[pi][1]],
			    calc(nums[p[pi][2]],
				 nums[p[pi][3]], o[oi][2]),
			    o[oi][1]), o[oi][0]);
  if (ret) { printExp("(%d %c (%d %c (%d %c %d)))\n", pi, oi); }
  return ret;
}

int fne(int pi, int oi) {
  int ret = 10 == calc(nums[p[pi][0]],
		       calc(calc(nums[p[pi][1]], nums[p[pi][2]], o[oi][1]),
			    nums[p[pi][3]], o[oi][2]), o[oi][0]);
  if (ret) { printExp("(%d %c ((%d %c %d) %c %d))\n", pi, oi); }
  return ret;
}

int solve() { 
  int i, j;
  int flag = 1;
  for (i = 0; i < 24 && flag; i++) {
    for (j = 0; j < 27 && flag; j++) {
      if (fna(i, j) || fnb(i, j) || fnc(i, j) || fnd(i, j) || fne(i, j)) {
	flag = 0;
      }
    }
  }
  if (flag) puts("0");
}

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

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define mm 1000000007
#define pb push_back
									//nestedcode



 int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0); cout.tie(0);
  	ll a;
  	string s;
   cin>>a>>s;
   if(a>=3200){
   	cout<<s;
   }else{
   	cout<<"red";
   }
}

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

using namespace std;

int main()
{
    string s;
    string t;
    bool resu = true;
    cin>>s;
    for(int i=0;i<s.length();i++){
        t=s.substr(i,1);
        if(i%2==0){ //奇数
            if(t=="R"||t=="U"||t=="D"){

            }
            else{
                resu=false;
            }
        }
        else{
            if(t=="L"||t=="U"||t=="D"){

            }
            else {
                resu=false;
            }
        }
    }
    if(resu){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    long long con=0ll;
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        if(u>v){
            swap(u,v);
        }
        con+=1ll*u*(n-v+1ll);
    }
    long long ans=0ll;
    for(int i=n;i>0;i--){
        ans+=1ll*((i)*(i+1ll))/2ll;
    }
    //cout<<ans<<" "<<con<<endl;
    ans-=con;
    cout<<ans<<endl;
    return 0;
}

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

bool find(int i, int j, int k, string s) {
  int now = 0;
  for (int idx = 0; idx < s.size(); idx++) {
    if (now == 0 && s[idx] == '0' + i) {
      now++;
      continue;
    }
    if (now == 1 && s[idx] == '0' + j) {
      now++;
      continue;
    }
    if (now == 2 && s[idx] == '0' + k) {
      now++;
      break;
    }
  }
  if (now == 3) {
    return true;
  } else {
    return false;
  }
}

int solve(int n, string s) {
  int ans = 0;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        if (find(i, j, k, s)) {
          ans++;
        }
      }
    }
  }
  return ans;
}
int main() {
  int n;
  string s;
  cin >> n >> s;
  cout << solve(n, s) << endl;
}


Measured memory_bytes: 3740
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;

struct point2D
{
	double x, y;
	point2D(){
		x = (double)0.0;
		y = (double)0.0;
	}
	point2D(double x, double y){
		this->x = x;
		this->y = y;
	}
	point2D(point2D *p){
		x = p->x;
		y = p->y;
	}
};
void koch(point2D *start, point2D *end, int d);
void print_point2D(point2D *p);
int main(){
	int n;

	cin >> n;

	point2D *start = new point2D((double)0.0, (double)0.0);
	point2D *end = new point2D((double)100.0, (double)0.0);
	print_point2D(start);
	koch(start, end, n);
	return 0;
}

void koch(point2D *start, point2D *end, int d){
	point2D *p1 = new point2D( (2*start->x +   end->x)/3, (2*start->y +   end->y)/3);
	point2D *p3 = new point2D( (  start->x + 2*end->x)/3, (  start->y + 2*end->y)/3);

	point2D *vec_p1_to_p3 = new point2D(p3->x - p1->x, p3->y - p1->y);
	point2D *vec_p1_to_p2 = new point2D( 0.5 * vec_p1_to_p3->x - 0.86602540378 * vec_p1_to_p3->y,
										0.86602540378 * vec_p1_to_p3->x + 0.5 * vec_p1_to_p3->y);
	point2D *p2 = new point2D(p1->x + vec_p1_to_p2->x, p1->y + vec_p1_to_p2->y);
	if(d <= 0){
		print_point2D(end);
		return;
	}
	koch(start, p1, d-1);
	koch(p1, p2, d-1);
	koch(p2, p3, d-1);
	koch(p3, end, d-1);
}
void print_point2D(point2D *p){
	printf("%.8lf %.8lf\n", p->x, p->y);
}

Measured memory_bytes: 2072
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  s=S()

  a=[0]*n
  for i in range(n):
    if s[i]=='W':
      a[i]+=1
    if i<n-1:
      a[i+1]=a[i]

  b=[0]*n
  for i in range(n-1,-1,-1):
    if s[i]=='E':
      b[i]+=1
    if i-1>=0:
      b[i-1]=b[i]

  # print(a)
  # print(b)

  mn=inf
  for i in range(n):
    mn=min(mn,a[i]+b[i]-1)

  return mn

print(main())


Measured memory_bytes: 19920
#include <iostream>

using namespace std;

int main(){

    int W, H, N;
    cin >> W >> H >> N;

    int S[W][H];
    for (int i = 0; i < W; i++){
        for (int j = 0; j < H; j++){
            S[i][j] = 1;
        }
    }
    
    for (int i = 0; i < N; i++){
        int x, y, a;
        cin >> x >> y >> a;

        if(a == 1){
            for (int j = 0; j < x; j++){
                for (int k = 0; k < H; k++){
                    S[j][k] = 0;
                }
            }
        }else if(a == 2){
            for (int j = x; j < W; j++){
                for (int k = 0; k < H; k++){
                    S[j][k] = 0;
                }
            }
        }else if(a == 3){
            for (int j = 0; j < W; j++){
                for (int k = 0; k < y; k++){
                    S[j][k] = 0;
                }
            }
        }else{
            for (int j = 0; j < W; j++){
                for (int k = y; k < H; k++){
                    S[j][k] = 0;
                }
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < W; i++){
        for (int j = 0; j < H; j++){
            ans += S[i][j];
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
// 普通の実装
#include <iostream>
#include <stdio.h>
using namespace std;

long int bekizyou(int x, int n)
{   
    long int ret = 1;
    for (int i=0; i<n; i++)
        ret *= x;

    return ret;
}

 
int main(){

    long int h;

	cin >> h;
    int sepCT = 0;

    if(h == 1){
        cout << 1 << endl;
        return 0;
    }

    while(true){
        if(h == 1)
            break;
        h /= 2;
        sepCT += 1;
    }
    
    cout << bekizyou(2, sepCT)*2-1 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const string D_blue    = "\x1b[36m";
const string D_green   = "\x1b[32m";
const string D_red     = "\x1b[31m";
const string D_yellow  = "\x1b[33m";
const string Db_red    = "\x1b[41m";
const string Db_yellow = "\x1b[43m";
const string D_end     = "\x1b[39m";
const string Db_end    = "\x1b[49m";

int main (){
  int X,A,B;
  while (cin >> X >> A >> B){
    int ans = (X-A)%B;
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef vector <ii> vii;
typedef vector <vii> graph;

bool comp(ii a, ii b) {
	if (a.first > b.first) {
		return true;
	}
	return false;
}

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

	int n, m;
	cin >> n >> m;
	ii arr[m];
	int in1, in2;
	for (int i = 0; i < m; ++i)
	{
		cin >> in1 >> in2;
		arr[i] = {in1, in2};
	}
	for (int i = 0; i < m; ++i)
	{
		if (arr[i].first > arr[i].second) {
			int temp = arr[i].first;
			arr[i].first = arr[i].second;
			arr[i].second = temp;
		}
	}
	sort(arr, arr + m, comp);
	int menor = n, cont = 0;
	for (int i = 0; i < m; ++i)
	{
		if (arr[i].second <= menor) {
			cont++;
			menor = arr[i].first;
		}
	}
	cout << cont << "\n";
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	char board[H+2][W+2];
	for (int i = 1; i < H + 1; i++) {
		for (int j = 1; j < W + 1; j++)
			cin >> board[i][j];
		board[i][0] = '#';
		board[i][W + 1] = '#';
	}
	for (int j = 0; j < W + 2; j++) {
		board[0][j] = '#';
		board[H + 1][j] = '#';
	}
	for (int i = 0; i < H + 2; i++){
		for (int j = 0; j < W + 2; j++)
			cout << board[i][j];
        cout<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
/*typedef struct{
  int id;
  int d;
  int frag;
  }node;*/
void DA(int **,int *,int,int);
int main(){
  int i,j,n,u,k;
  int **G;
  int *A;

  scanf("%d",&n);
  A=malloc(n*sizeof(int));
  G=malloc(n*sizeof(int *));
  for(i=0;i<n;i++)
    {
      G[i]=malloc(n*sizeof(int)*2);
      A[i]=INT_MAX;
    }
  A[0]=0;
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&u,&k);
      for(j=0;j<2*k;j++)
	{
	  scanf("%d",&G[u][j]);
	}
    }

  DA(G,A,n,0);
  for(i=0;i<n;i++)
    {
      printf("%d %d\n",i,A[i]);
    }
  return 0;
}
void DA(int **G,int *A,int n,int num){
  int i,j;
 
  

  for(j=1;j<2*n;j+=2)
    {
      if(A[num]+G[num][j]<A[G[num][j-1]])
	{
	  A[G[num][j-1]] = A[num]+G[num][j];
	  DA(G,A,n,G[num][j-1]);
	}
    }
    
 
}



Measured memory_bytes: 2056
def counting_sort(A):
    n = len(A)
    C = [0] * 10000
    B = [0] * n
    for i in range(n):
        C[A[i]] += 1

    for i in range(1, 10000):
        C[i] = C[i] + C[i-1]

    for i in reversed(range(n)):
        # print('len B {}, i, {} A[i] {}'.format(len(B), i, A[i]))
        B[C[A[i]] - 1] = A[i]
        C[A[i]] -= 1

    return B


if __name__ == "__main__":
    input()
    A = list(map(int, input().split()))

    A = counting_sort(A)

    print(' '.join(map(str, A)))



Measured memory_bytes: 224696
A, B, K = map(int, input().split())
ans = set()
for i in range(A, A + K):
  if i > B:
    break
  ans.add(i)
for i in range(B, B - K, -1):
  if i < A:
    break
  ans.add(i)
for i in sorted(ans):
  print(i)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
int main(){
  long long int a,b,c,d,ans;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
  if(a>0 && c>0) ans=b*d;
  else if(b<0 && d<0) ans=a*c;
  else if(a>0 && d<0) ans=a*d;
  else if(c>0 && b<0) ans=b*c;
  else if(b>0 && d>0 && a>0 || c>0) ans=b*d;
  else if(a<0 && c<0 && b<0 || d<0) ans=a*c;
  else{
    if(a*c>b*d) ans=a*c;
    else ans=b*d;
  }
  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 1736
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


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

    ll l,r;
    cin >> l >> r;
    if(r - l >= 2018) {cout << 0; return 0;}

    int range = r - l;

    l %= 2019;
    r = l + range;
    int ans = 2018;
    FOR(i,l,r+1)
      FOR(j,i+1,r+1)
        if(ans > (i*j)%2019)
            ans = (i*j)%2019;
    cout << ans << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	fmt.Print(getSumCurtain(a, b))
}

func getSumCurtain(a, b int) int {
	unhiddenLength := a - b*2
	if unhiddenLength <= 0 {
		return 0
	}
	return unhiddenLength
}


Measured memory_bytes: 512
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n:usize,
        d:i64,
        com:[(i64, i64); n]
    };

    let mut cnt=0;

    for i in com.iter() {
        if i.0.pow(2) + i.1.pow(2) <= d.pow(2){
            cnt+=1;
        }

    }
    println!("{}", cnt);

}


Measured memory_bytes: 7848
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 200000
typedef long long LL;
using namespace std;
int N;
int a[MAXN+5],que[MAXN+5];
int l[MAXN+5],r[MAXN+5];
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&a[i]);
	int t=0;
	que[t++]=0;
	for(int i=1;i<=N;i++)
	{
		while(t>0&&a[que[t-1]]>=a[i])
			t--;
		l[i]=que[t-1]+1;
		que[t++]=i;
	}
	t=0;
	que[t++]=N+1;
	for(int i=N;i>=1;i--)
	{
		while(t>0&&a[que[t-1]]>=a[i])
			t--;
		r[i]=que[t-1]-1;
		que[t++]=i;
	}
	LL ans=0;
	for(int i=1;i<=N;i++)
		ans+=1LL*a[i]*(i-l[i]+1LL)*(r[i]-i+1LL);
	printf("%lld\n",ans);
	return 0;
}

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

N = int(input())
S = [list(input().rstrip()) for _ in range(N)]
row = [[0] * 26 for _ in range(N)]
col = [[0] * 26 for _ in range(N)]
for i in range(N):
    for j in range(N):
        c = ord(S[i][j]) - ord('a')
        row[i][c] += 1
        col[j][c] += 1
ans = 0
same = [[row[i] == col[j] for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(N):
        if all(same[(i+k) % N][(j+k) % N] for k in range(N)):
            ans += 1
print(ans)

Measured memory_bytes: 48092
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, K: int):
    print(K * (K-1)**(N-1))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using Double = long double;
signed main(){
  Int h,w;
  cin>>w>>h;
  vector<string> s(h);
  for(Int i=0;i<h;i++) cin>>s[i];
  vector<vector<Int> > dg(h,vector<Int>(w,-1)),ds=dg;
  using T = pair<Int,int>;
  queue<T> qg,qs;
  
  for(Int i=0;i<h;i++){
    for(Int j=0;j<w;j++){
      if(s[i][j]=='g'){
	qg.push(T(i,j));
	dg[i][j]=0;
      }
      if(s[i][j]=='*'){
	qs.push(T(i,j));
	ds[i][j]=0;
      }
    }
  }

  Int dy[]={0,0,1,-1};
  Int dx[]={1,-1,0,0};
  auto bfs=[&](queue<T> &q,vector<vector<Int> > &d){
    while(!q.empty()){
      T t=q.front();q.pop();
      Int y=t.first,x=t.second;
      for(Int k=0;k<4;k++){
	Int ny=y+dy[k],nx=x+dx[k];
	if(s[ny][nx]=='#'||s[ny][nx]=='*') continue;
	if(~d[ny][nx]&&d[ny][nx]<=d[y][x]+1) continue;
	d[ny][nx]=d[y][x]+1;
	q.push(T(ny,nx));
      }
    }
    if(0){
      cout<<endl;
      for(Int i=0;i<h;i++){
	for(Int j=0;j<w;j++){
	  if(d[i][j]<0) cout<<"x";
	  else cout<<hex<<d[i][j];
	}
	cout<<endl;
      }
    }
  };

  bfs(qg,dg);
  bfs(qs,ds);

  auto get=[&](Int i,Int j,Double p){
    if(~dg[i][j]&&~ds[i][j])
      return min((Double)dg[i][j],ds[i][j]+p);
    if(~ds[i][j]) return ds[i][j]+p;
    if(~dg[i][j]) return (Double)dg[i][j];
    return Double(0);
  };
  
  auto calc=[&](Double p){
    Double q=0,c=0;
    for(Int i=0;i<h;i++){
      for(Int j=0;j<w;j++){
	if(s[i][j]=='#'||s[i][j]=='g'||s[i][j]=='*') continue;
	c+=1.0;
	q+=get(i,j,p);
      }
    }
    q/=c;
    //printf("%.12Lf %.12Lf\n",p, p-q);
    return p-q;
  };

  Double l=0,r=1e15;

  for(int k=0;k<300;k++){
  //while(abs(calc(l))>1e-10){
    Double m=(l+r)/2;
    if(calc(m)<=Double(0)) l=m;
    else r=m;
  }
  
  //printf("%.12f\n",calc(l));
  for(Int i=0;i<h;i++)
    for(Int j=0;j<w;j++)
      if(s[i][j]=='s')
	printf("%.12Lf\n",get(i,j,l));
  
  return 0;
}

Measured memory_bytes: 7444
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    long long int n,k,x,y;
    cin  >> n >> k>> x>> y;
    if (n <= k)
        cout << n*x <<endl;
    else
    cout << k*(x)+(n-k)*y <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
typedef unsigned int UINT;
using namespace std;
int main(void) {
    int r, g, b;
    cin >> r >> g >> b;
    int sum = g * 10 + b;
    if (sum % 4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;

  int y = 700;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'o') {
      y = y + 100;
    }
  }

  cout << y << endl;

  return 0;
}


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

int main() {
    stack<int> st;
    for ( ; ; ) {
        string str;
        cin >> str;
        if (std::cin.eof()) {
            break;
        }
        if (str == "+") {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a+b);
        }
        else if (str == "-") {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(b-a);
        }
        else if (str == "*") {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a*b);
        }
        else {
            int a = stoi(str);
            st.push(a);
        }
    }
    cout << st.top() << endl;
    return 0;
}


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

fun solve(N: Long, a: LongArray){
    a.sort()
    val n = N.toInt()
    val p = (0 until n step 2).map{ a[it] }.sum()
    val q = (1 until n step 2).map{ a[it] }.sum()
    println(Math.abs(p-q))
    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().toLong()
    val a = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        a[i] = sc.next().toLong()
    }
    solve(N, a)
}



Measured memory_bytes: 32176