akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

using lli = long long int;

lli gcd(lli s,lli t)
{
	if(t==0)return s;
	return gcd(t,s%t);
}

lli lcm(lli p,lli q)
{
	return 	p/gcd(p,q)*q;
}


int main(){
	int N;
	cin >> N;
	lli input = 0;
	lli answer = 1;
	for(int i=0;i<N;i++){
		cin >> input;
		answer = lcm(answer,input);
	}
	
//	
//	for(int i=0;i<N-1;i++){
//		answer = lcm(array[i],array[i+1]);
//	}
	
	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 256
s = list(map(int,list(input())))
op_num = len(s)-1
for i in range(2**op_num):
  ans = ['-']*op_num
  total = s[0]
  for j in range(op_num):
    if (i>>j) & 1:
      total += s[j+1]
      ans[j]='+'
    else:
      total -= s[j+1]
  if total == 7:
    print(str(s[0])+ans[0]+str(s[1])+ans[1]+str(s[2])+ans[2]+str(s[3])+'=7')
    exit()
    
  

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

int main()
{
    int l,r,d,cnt=0;
    cin>>l>>r>>d;
    for(int i=l ; i<=r ; i++)
    {
      if(i%d==0) cnt++;
    }
    cout<<cnt;


    return 0;

}

Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int getDigitSum(int a) {
  int sum = 0;
  while (a > 0) {
    sum += a % 10;
    a /= 10;
  }
  return sum;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;  cin >> n >> a >> b;
    int sum = 0;
    FOR(i, 1, n + 1) {
      if (getDigitSum(i) >= a && getDigitSum(i) <= b) {
        sum += i;
      }
    }
    cout << sum << '\n';

    return 0;
}


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

const int INF = 1e9 + 5;

const int MAX = 1000005;
int main(){
	
	int n;
	
	int data[MAX][4];
	int dp[MAX][3];
	scanf("%d",&n);
	
	
	for (int i = 0; i < n; i++){
		for(int j=0;j<3;j++){
			scanf("%d",&data[i][j]);
			dp[i][j] = -1000000000;
		}
	}
	
	dp[0][0] = data[0][0];
	dp[0][1] = data[0][1];
	dp[0][2] = data[0][2];
	
	for (int i=1;i<n;i++){
		dp[i][0] = max(data[i][0]+dp[i-1][1],data[i][0]+dp[i-1][2]);
		dp[i][1] = max(data[i][1]+dp[i-1][0],data[i][1]+dp[i-1][2]);
		dp[i][2] = max(data[i][2]+dp[i-1][1],data[i][2]+dp[i-1][0]);
		
	}
	
	
	int ans = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	
	printf("%d\n",ans);
	
	
	return 0;
}


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

int main(void){
	int a=0,b=0,tmp;
	for(int i=0;i<4;i++)
		cin >> tmp,a+=tmp;
	for(int i=0;i<4;i++)
		cin >> tmp,b+=tmp;
	cout << max(a,b) << endl;
	return 0;
}

Measured memory_bytes: 1160
import sys
input = sys.stdin.buffer.readline
N,M = list(map(int,input().split()))
p = [i-1 for i in map(int,input().split())]
alr = [False for i in range(N)]
xy = [[] for i in range(N)]
for i in range(M):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    xy[x].append(y)
    xy[y].append(x)
count = 0

for i in range(N):
    if (not alr[i]) and (xy[i]):
        alr[i] = True
        stack = [i]
        numlist = set()
        numlist.add(i)
        while stack:
            j = stack.pop()
            for k in xy[j]:
                if not alr[k]:
                    alr[k] = True
                    stack.append(k)
                    numlist.add(k)
        indlist = set([p[i] for i in numlist])
        count += len(numlist & indlist)
    else:
        if (not alr[i]) and p[i] == i:
            count += 1
print(count)
                
    

Measured memory_bytes: 82252
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
	
	static int INF = 1000000000;
	static int MAXN = 31;
	
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[][] point = new int[n][2];
		for (int i = 0; i < n; ++i) {
			point[i][0] = input.nextInt();
			point[i][1] = input.nextInt();
		}
		double res = 0;
		for (int i = 0; i < n - 1; ++i) {
			res += (point[i][0] - point[i + 1][0]) * (point[i][1] + point[i + 1][1]);
		}
		res += (point[n - 1][0] - point[0][0]) * (point[n - 1][1] + point[0][1]);
		res = Math.abs(res) / 2;
		System.out.printf("%.1f\n", res);
	}
}

Measured memory_bytes: 20144
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};

use itertools::Itertools;

use maplit::*;

use proconio::{input, fastout};
use proconio::marker::*;

const INF: usize = 1_000_000_007;

#[fastout]
fn solve() {
  input! {
    a: usize, b: usize, n: usize,
  };

  let x = min(b - 1, n);
  println!("{}", (a * x) / b - a * (x / b));
}

fn main() {
  std::thread::Builder::new()
    .name("big stack size".into())
    .stack_size(32 * 1024 * 1024)
    .spawn(|| {
      solve();
    })
    .unwrap()
    .join()
    .unwrap();
}


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

int main() {
    int h, w; cin >> h >> w;
    char c[100][100];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) cin >> c[i][j];
    }

    for (int i = 0; i < h; i++) {
        for (int k = 0; k < 2; k++) { 
            for (int j = 0; j < w; j++) {
                cout << c[i][j];
            }
            cout << endl;
        }
    }
}

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

#define rep(i,n) for(int i=0; i<n; i++)
int dp[1001][1001];

int main(){
	int W, cnt=1;
	while( cin >> W, W ){
		int n, v[1000], w[1000];
		memset( dp, -1, sizeof(dp) );
		cin >> n;
		rep(i,n){
			scanf("%d,%d", &v[i], &w[i]);
		}
		dp[0][0] = 0;
		rep(i,n){
			rep(j,W+1){
				if( j<w[i] )
					dp[i+1][j] = dp[i][j];
				else
					dp[i+1][j] = max( dp[i][j], dp[i][j-w[i]]+v[i] );
			}
		}
		int mw = 0;
		rep(i,W+1){
			if( dp[n][i]>dp[n][mw] )	mw = i;
		}
		cout << "Case " << cnt << ":" << endl;
		cnt++;
		cout << dp[n][mw] << endl;
		cout << mw << endl;
	}
}

Measured memory_bytes: 5168
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int n, m;
vector<int> l, r;

void solve() {
  int ll = l.front(), rr = r.front();
  FOR(i, 1, m) {
    ll = max(ll, l[i]);
    rr = min(rr, r[i]);
  }
  // cout << ll << " " << rr << endl;
  int ans{};
  FOR(i, 1, n + 1) {
    if (i >= ll && i <= rr)
      ++ans;
  }
  cout << ans << endl;
}

int main() {
  cin >> n >> m;
  REP(i, m) {
    int in;
    cin >> in;
    // --in;
    l.push_back(in);
    cin >> in;
    // --in;
    r.push_back(in);
  }
  solve();
}


Measured memory_bytes: 1276
// C++ program to find the longest repeated 
// non-overlapping substring 
#include<bits/stdc++.h> 
using namespace std; 
  
// Returns the longest repeating non-overlapping 
// substring in str 
int longestRepeatedSubstring(string str) 
{ 
    int n = str.length(); 
    int LCSRe[n+1][n+1]; 
  
    // Setting all to 0 
    memset(LCSRe, 0, sizeof(LCSRe)); 
  
    string res; // To store result 
    int res_length  = 0; // To store length of result 
  
    // building table in bottom-up manner 
    int i, index = 0; 
    for (i=1; i<=n; i++) 
    { 
        for (int j=i+1; j<=n; j++) 
        { 
            // (j-i) > LCSRe[i-1][j-1] to remove 
            // overlapping 
            if (str[i-1] == str[j-1] && 
                LCSRe[i-1][j-1] < (j - i)) 
            { 
                LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 
  
                // updating maximum length of the 
                // substring and updating the finishing 
                // index of the suffix 
                if (LCSRe[i][j] > res_length) 
                { 
                    res_length = LCSRe[i][j]; 
                    index = max(i, index); 
                } 
            } 
            else
                LCSRe[i][j] = 0; 
        } 
    } 
  
    // If we have non-empty result, then insert all 
    // characters from first character to last 
    // character of string 
    
    return res_length; 
} 
  
// Driver program to test the above function 
int main() 
{ 
  int n;
  cin>>n;
  string str;
  cin>>str;
    //string str = "geeksforgeeks"; 
    cout << longestRepeatedSubstring(str); 
    return 0; 
} 


Measured memory_bytes: 98048
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	ll n;
	ll *x, *y;
	cin >> n;
	x = new ll[n];
	y = new ll[n];
	
	for (ll i = 0; i < n; i++) {
		cin >> x[i];
		y[i] = x[i];
	}
	sort(y, y + n);

	for (ll i = 0; i < n; i++) {
		ll pos = n / 2-1;
		if (x[i] <= y[pos]) {
			cout << y[pos+1] << endl;
		}
		else {
			cout << y[pos] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 5376
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;

const int mod = 1000000007;
struct mint{
    ll x;
    mint(ll x=0):x(x%mod){}
    mint& operator+=(const mint a){
        if ((x+= a.x) >= mod) x-= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if ((x+= mod - a.x) >= mod) x-= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=mod;
        return *this;
    }
    mint operator+(const mint a) const{
        mint ans(*this);
        return ans+= a;
    }
    mint operator-(const mint a) const{
        mint ans(*this);
        return ans-= a;
    }
    mint operator*(const mint a) const{
        mint ans(*this);
        return ans*= a;
    }
};

int main(){
    int N,L;
    cin >> N >> L;
    int diff = 1e8;
    int out = 0;
    rep(i,N){
        if (abs(L+i)<= diff){out = i; diff = abs(L+i);}
    }
    cout << ((N-1)*N)/2 + N*L - out - L;
}

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

int R,G,B,n;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	R=rd();G=rd();B=rd();n=rd();
	int ans=0;
	for (int i=0;i*R<=n;i++) for (int j=0;i*R+j*G<=n;j++) if ((n-i*R-j*G)%B==0) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main () {
    int n = 0;
    cin >> n;
    vector<vector<long long>> in(n, vector<long long>(2));
    for (int i=0; i<n; i++) {
        cin >> in.at(i).at(1) >> in.at(i).at(0);
    }
    sort(in.begin(), in.end());
    long long time = 0;
    for (int i=0; i<n; i++) {
        time += in.at(i).at(1);
        if (time > in.at(i).at(0)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;

int main()
{
    long long a[7], S=0;
    for (int i = 0; i < 7; i++)
    {
        cin >> a[i];
    }
    S = a[1];
    if (a[0] % 2 + a[3] % 2 + a[4] % 2 >= 2 && a[0] > 0 && a[3] > 0 && a[4] > 0)
    {
        S += 3;
        a[0]--;
        a[3]--;
        a[4]--;
    }
    S += (a[0]/2)*2;
    S += (a[3]/2)*2;
    S += (a[4]/2)*2;
    a[0] %= 2;
    a[3] %= 2;
    a[4] %= 2;
    cout << S;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
   ll q, h, s, d, n;
   cin >> q >> h >> s >> d >> n;
   q*=8, h*=4, s*=2;
   ll cheap = min(q, min(h, min(s, d)));
   ll ans = (n/2)*cheap;
   if(n&1){
       ans += (min(q, min(h, s)))/2;
   }

   cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define MAX_N 100000

using namespace std;

int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a % b);
}

int A[MAX_N+10];

int main() {
  int N,K;
  scanf("%d%d", &N, &K);

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

  int all_gcd = A[0];
  int max_a = -1;
  for(int i=0;i<N;++i) {
    all_gcd = gcd(all_gcd, A[i]);
    max_a = max(max_a, A[i]);
  }

  if(K>max_a) {
    printf("IMPOSSIBLE\n");
    return 0;
  }

  if((max_a-K) % all_gcd ==0) {
    printf("POSSIBLE\n");
  } else {
    printf("IMPOSSIBLE\n");
  }

  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <queue>

using namespace std;
static const int N=100;

int n,M[N][N];
int d[N];


void bfs(int s){
    queue<int> Q;
    Q.push(s);
    d[s]=0;
    int u,v;
    while(!Q.empty()){
        u=Q.front();Q.pop();
        for(v=0;v<n;v++){
            if(M[u][v]==0) continue;
            if(d[v]!=-1) continue;
            d[v]=d[u]+1;
            Q.push(v);
        }
    }
    for(int i=0;i<n;i++) printf("%d %d\n",i+1,d[i]);
}

int main()
{
    int u,k,v;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) M[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    for(int i=0;i<n;i++) d[i]=-1;
    bfs(0);
    return 0;
}



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

int q1,q2,b,c1,c2,ans1,ans2;

bool solve(){
	if(!q2)
		return false;
	ans1 = q2;
	ans2 = 0;
	while(ans1*c1 + ans2*c2 <= b)
		ans2++;
	if(ans2)
		ans2--;
	if(ans1 + ans2 >= q1 && ans1*c1 + ans2*c2 <= b)
		return true;
	while(true){
		ans1--;
//		if(!ans1)
//			return false;
		while(true){
			ans2++;
			if(ans1*c1 + ans2*c2 > b){
				ans2--;
				break;
			}
		}
		if((ans1*c1 + ans2*c2 <= b && ans1 + ans2 >= q1) || ans1 == 0)
			break;
	}
	if(!ans1)
		return false;
	else
		return true;
}

int main(){
	while(true){
		cin >> q1;
		if(!q1)
			return 0;
		cin >> b >> c1 >> c2 >> q2;
		if(solve())
			cout << ans1 << ' ' << ans2 << endl;
		else
			cout << "NA" << endl;
	}
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int N;
    cin >> N;
    
    if (N % 2 == 0) cout << N << endl;
    else cout << N * 2 << endl;
    
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N, A, B = ln()

max_val = min(A, B)
min_val = A + B - N if A + B - N > 0 else 0

print max_val, min_val


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

int main(){
    int N;
    cin >> N;
    string S;

    for(int i = 0; i < N; i++){
        cin >> S;

        if(S == "Y"){
            cout << "Four" << endl;
            break;
        }

    }

    if(S != "Y"){
        cout << "Three" << endl;
    }
}


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

int n;
pair<pair<string, int>, int> a[102];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i].first.first >> a[i].first.second;
        a[i].first.second *= -1;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; ++i) {
        cout << a[i].second << endl;
    }
}

Measured memory_bytes: 256
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))

if n == 0:
  print(x)
  sys.exit()

tmp = x
for i in range(100):
  if not((x-i) in p):
    print(x-i)
    sys.exit()
  elif not((x+i) in p):
    print(x+i)
    sys.exit()

Measured memory_bytes: 9196
s = str(input())
if str(s) == "SUN":
    print(7)
elif str(s) == "MON":
    print(6)
elif str(s) == "TUE":
    print(5)
elif str(s) == "WED":
    print(4)
elif str(s) == "THU":
    print(3)
elif str(s) == "FRI":
    print(2)
else:
    print(1)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    int X,Y,Z,count=0;
    cin>>X;
    while(1){
        Y=sqrt(X);
        for(int i=2;i<=Y;i++){
            if(X%i==0){
                count++;
                break;
            }
        }
        if(count==0){
            cout<<X<<endl;
            exit(0);
        }
        count=0;
        X++;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

//????????£?¨?--------------------------- 
int baisu(int n);   //3????????°
int three(int n);   //3??????
//------------------------------------
int main(void)
{
	int n;
	scanf("%d", &n);
	
	for(int i = 1; i <= n; i++){
		if((baisu(i) == 1) || (three(i) == 1)) {
			printf(" %d", i);
		}
	}
	printf("\n");

	return 0;
}

//--------------------------------------------//3????????°
int baisu(int n)
{
	if ( n % 3 == 0 ){
		return 1;
	}
	else return -1;
}
//--------------------------------------------//3??????
int three(int n)
{
	while(n > 0){
		if((n % 10) == 3){
			return 1;
		}
		n /= 10;
	}
	return -1;
}

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

// mod(2*K) の空間にして、2次元累積和する。
// K=3
// 	        x
// 	  0 1 2 3 4 5 6
// 	0 0 0 0|0 0 0|0
// 	1 0 # #|     |#
// 	  -----+-----+-
// y	2 0    |# # #| 
// 	3 0    |# # #| 
// 	4 0    |# # #| 
// 	  -----+-----+-
// 	5 0 # #|     |#
// 	6 0 # #|     |#


int bk[2020][2020];

int main() {
  int N, K;
  cin >> N >> K;
  REP(i,N) {
    int x,y; char c;
    cin >> x >> y >> c;
    // 白はKずらして黒にする
    if (c == 'W') y += K;
    bk[ (x%(2*K))+1 ][ (y%(2*K))+1 ]++;
  }
  // 二次元累積和
  for (int y=1; y<=2*K+1; y++)
    for (int x=1; x<=2*K+1; x++)
      bk[x][y] += bk[x][y-1];
  for (int x=1; x<=2*K+1; x++)
    for (int y=1; y<=2*K+1; y++)
      bk[x][y] += bk[x-1][y];

  int ans = 0;
  for (int y=1; y<=K+1; y++) {
    for (int x=1; x<=K+1; x++) {
      int num = bk[x-1][y-1];
      num += bk[2*K][2*K] - bk[2*K][y+K-1] - bk[x+K-1][2*K] + bk[x+K-1][y+K-1];
      num += bk[2*K][y-1] - bk[x+K-1][y-1];
      num += bk[x-1][2*K] - bk[x-1][y+K-1];
      num += bk[x+K-1][y+K-1] - bk[x+K-1][y-1] - bk[x-1][y+K-1] + bk[x-1][y-1];
      ans = max( num, ans );
      ans = max( N-num, ans );
    }
  }
  cout << ans << endl;
/*
  REP(y,2*K+1) {
    REP(x,2*K+1) {
      cout << bk[x][y] << " " ;
    }
    cout << endl;
  }
  */

}



Measured memory_bytes: 16000
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int
main(int argc, const char *argv[])
{
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    printf("%.5lf\n", sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)));

    return 0;
}

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n=sc.nextInt();
		boolean dir[]=new boolean[n];
		String s=sc.next();
		for(int i=0;i<n;i++){
			if(s.charAt(i)=='E') dir[i]=true;
		}
		
		int cost=0;
		for(int i=1;i<n;i++) if(dir[i])cost++;

		int min_cost=cost;
		for(int reader=1;reader<n;reader++){
			if(!dir[reader-1])cost++;
			if(dir[reader])cost--;
			min_cost=Math.min(cost, min_cost);
		}
		System.out.println(min_cost);
	}
	
	public static int[][] readhw(int height, int width){
		int[][] hw = new int[height][width];
		Scanner sc = new Scanner(System.in);
		for(int i=0;i<height;i++)
			for(int j=0;j<width;j++)
				hw[i][j]=sc.nextInt();
		return hw;
	}
}


Measured memory_bytes: 28676
s = gets.chomp
p = gets.chomp

p_length = p.length
input_string = s + s[0..(p_length - 2)]

success = false

input_string.split('').each_cons(p_length) do |word|
  if word.join == p
    success = true
  end
end

if success
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 8756
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include <cstdlib> 
using namespace std;

int x[110], y[110], h[110];
int main(void){
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> x[i] >> y[i] >> h[i];
  }

  int cx=0,cy=0, ans=0;
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      set<int> tmp;
      for(int k=0;k<N;k++){
        if(h[k]>0){
          tmp.insert(std::abs(i-x[k]) + std::abs(j-y[k]) + h[k]);
        }
      }
      if(tmp.size()==1){
        int ans = *tmp.begin();

        bool check = true;
        for(int k=0;k<N;k++){
          if(h[k]==0 && ans - (std::abs(i-x[k]) + std::abs(j-y[k]))>0){
            check = false;
          }
        }
        if(check){
          cout << i << " " << j << " " << *tmp.begin() ;
          return 0;
        }
      }
    }
  }

  cout << "can't find" ;
  return 0;
}


Measured memory_bytes: 256
s = gets.chomp.split("")
len = s.length
p01 = 0
p10 = 0
len.times do |i|
  if i % 2 == 0
    p01 += 1 if s[i] == "1"
    p10 += 1 if s[i] == "0"
  else
    p01 += 1 if s[i] == "0"
    p10 += 1 if s[i] == "1"
  end
end
puts [p01,p10].min


Measured memory_bytes: 22696
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);

#ifdef BUGGY
	bool DEBUG = 1;
#endif
#ifndef BUGGY
	bool DEBUG = 0;
#endif

string S;

int main()
{
	cin >> S;

	if(S[1] != S[2]) {
		cout << "No";
		return 0;
	}

	if(S[0] == S[1] || S[2] == S[3]) {
		cout << "Yes";
	} else {
		cout << "No";
	}

	return 0;
}
/*
	Powered by Buggy Plugin
*/

Measured memory_bytes: 256
i=0

while True:
  a, op, b = map(str, input().split())
  a=int(a)
  b=int(b)
  if op=='?':
    break
    
  elif op=='+':
    print(a+b)
  
  elif op=='-':
    print(a-b)
    
  elif op=='*':
    print(a*b)
    
  elif op=='/':
    print(a//b)
    
    


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define x first
#define y second
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'


int main()
{
	int s,w;
	cin>>s>>w;
	if(s<=w)printf("unsafe\n");
	else printf("safe\n");
	return 0;
}

Measured memory_bytes: 3616
import math
N = int(input())
ans_min = math.floor(N / 1.08)
ans_max = math.ceil(N / 1.08)
if math.floor(ans_min * 1.08) == N:
    ans = ans_min
elif math.floor(ans_max * 1.08) == N:
    ans = ans_max
else:
    ans = ':('
print(ans)

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

int n;
int d[100];
int ans = 0;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    int num[101] = {0}; //パケット
    for (int i = 0; i < n; i++) {
        num[d[i]]++;
    }
    for (int i = 0; i <= 100; i++) {
        if (num[i] > 0) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}


int g[2][105];
int dp[2][105];
int n;
int ans = 0;

int go(int x, int y) {
  if(x == 1 and y == n - 1) {
    return g[x][y];
  }
  if(dp[x][y] != -1) return dp[x][y];
  int cur = 0;
  if(x + 1 < 2) {
    cur = g[x][y] + go(x + 1, y);
  }
  if(y + 1 < n) {
    cur = max(cur, g[x][y] + go(x, y + 1));
  }
  return dp[x][y] = cur;
}

int main() {
  ll n, m; cin >> n >> m;
  if(n == 1 and m == 1) {
    print(1);
  }
  else if(n == 1 or m == 1) {
    if(n == 1) {
      print(m - 2);
    }
    else {
      print(n - 2);
    }
  }
  else {
    print((n - 2) * (m - 2));
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s;
map<string, ll> mp;
int main() {
    cin>>s;

    mp["SUN"]=7;
    mp["MON"]=6;
    mp["TUE"]=5;
    mp["WED"]=4;
    mp["THU"]=3;
    mp["FRI"]=2;
    mp["SAT"]=1;
    cout<<mp[s]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	ll n, k;
	cin >> n >> k;
	ll x = n % k;
	cout << min(x, k - x);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int R;

  cin >> R;

  if (R < 1200) cout << "ABC" << endl;
  else if (1200 <= R && R < 2800) cout << "ARC" << endl;
  else if (2800 <= R) cout << "AGC" << endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;

    int x = 0;
    int ans = 0;
    for(int i=0; i<n; ++i){
        int h;
        cin >> h;
        if(x <= h)
            ++ ans;
        x = max(x, h);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

ll d[MAXn];

int main()
{
    IOS();
    // D
    ll n;
    cin>>n;
    REP(i,n)cin>>d[i];
    ll id=0;
    REP1(i,n-1)if(abs(d[i])>abs(d[id]))id=i;
    if(d[id]==0)
    {
      cout<<0<<endl;
      return 0;
    }
    else if(d[id]>0)
    {
      cout<<2*n-1<<endl;
      REP1(i,n)cout<<id+1<<" "<<i<<endl;
      REP1(i,n-1)cout<<i<<" "<<i+1<<endl;
    }
    else
    {
      cout<<2*n-1<<endl;
      REP1(i,n)cout<<id+1<<" "<<i<<endl;
      for(int i=n;i>1;i--)cout<<i<<" "<<i-1<<endl;
    }
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int M1 = in.nextInt();
            int D1 = in.nextInt();
            int M2 = in.nextInt();
            int D2 = in.nextInt();
            if (D2 == 1) {
                out.println(1);
            } else {
                out.println(0);
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}



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

#define mx 1000008

#define pii pair<int,int>
#define pi acos(-1.0)
#define pb push_back
#define ss second
#define ff first
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
ll dp[3003][3003][2];
ll a[mx];
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll cal(ll i,ll j,ll ok)
{
    if(i==j){
        if(ok==0){
            return dp[i][j][0]=a[i];
        }
        else return dp[i][j][1]=-1*a[i];
    }
    if(dp[i][j][ok]!=-1) return dp[i][j][ok];
    if(ok==0){
        dp[i][j][ok]=max(cal(i+1,j,1)+a[i],cal(i,j-1,1)+a[j]);
    }
    else {
        dp[i][j][ok]=min(cal(i+1,j,0)-a[i],cal(i,j-1,0)-a[j]);
    }
    return dp[i][j][ok];
}
int main()
{
    ll n;
    memset(dp,-1,sizeof(dp));
    cin>>n;

    ll maxx=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];

    }
    cout<<cal(1,n,0)<<endl;
}


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

const int Maxn = 10005;

int n, k;
string s;
int rnk[Maxn];
int cur[Maxn];
int cnt[Maxn], nxt[Maxn];
bool dif1[Maxn], dif2[Maxn];

bool Less(const int &a, const int &b) { return s[a] < s[b]; }

void buildSA()
{
	for (int i = 0; i < s.length(); i++)
		cur[i] = i;
	sort(cur, cur + s.length(), Less);
	for (int i = 0; i < s.length(); i++) {
		dif1[i] = i == 0 || s[cur[i - 1]] != s[cur[i]];
		dif2[i] = false;
	}
	for (int h = 1; h < s.length(); h <<= 1) {
		int buck = 0;
		for (int i = 0, j; i < s.length(); i = j) {
			j = i + 1;
			while (j < s.length() && !dif1[j]) j++;
			nxt[i] = j;
			buck++;
		}
		if (buck == s.length()) break;
		for (int i = 0; i < s.length(); i = nxt[i]) {
			cnt[i] = 0;
			for (int j = i; j < nxt[i]; j++)
				rnk[cur[j]] = i;
		}
		cnt[rnk[s.length() - h]]++; dif2[rnk[s.length() - h]] = true;
		for (int i = 0; i < s.length(); i = nxt[i]) {
			for (int j = i; j < nxt[i]; j++) {
				int s = cur[j] - h;
				if (s >= 0) {
					int head = rnk[s];
					rnk[s] = head + cnt[head]++;
					dif2[rnk[s]] = true;
				}
			}
			for (int j = i; j < nxt[i]; j++) {
				int s = cur[j] - h;
				if (s >= 0 && dif2[rnk[s]])
					for (int k = rnk[s] + 1; !dif1[k] && dif2[k]; k++) dif2[k] = false;
			}
		}
		for (int i = 0; i < s.length(); i++) {
			cur[rnk[i]] = i;
			dif1[i] |= dif2[i];
		}
	}
}

bool Same()
{
    for (int i = 1; i < s.length(); i++)
        if (s[i] != s[0]) return false;
    return true;
}

int main()
{
    cin >> n >> k;
    cin >> s;
    reverse(s.begin(), s.end());
    while (k > 0 && !Same()) {
        k--;
        string cp = s;
        reverse(cp.begin(), cp.end());
        s = cp + s;
        buildSA();
        for (int i = 0; i < s.length(); i++)
            if (cur[i] + n <= s.length()) {
                s = s.substr(cur[i], n);
                break;
            }
    }
    cout << s << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

string str[2];
signed main(){
	int n;
	scanf("%lld", &n);
	cin >> str[0] >> str[1];
	rep(i,n+1){
		if(str[0].substr(i, n-i) == str[1].substr(0, n-i)){
			printf("%lld\n", 2*n-(n-i));
			break;
		}
	}
	return 0;
}






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

int main() {
    int n; cin >> n;
    vector<int> p(n);
    vector<int> q(n);

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

    copy(p.begin(), p.end(), q.begin());
    sort(q.begin(), q.end());

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] != q[i]) cnt++;
    }

    if (cnt == 0 or cnt == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main()
{
	cout << fixed << setprecision(10);
	int n, k, c;
	string s;
	cin >> n >> k >> c >> s;

	vector<int> l(n);
	vector<int> r(n);

	//left
	{
		int cnt = 1;
		int pre = 0;
		REP(i, n)
		{
			if (s[i] == 'x')continue;
			if (pre + c < i)
			{
				cnt++;
				pre = i;
			}
			if (pre == i)l[i] = cnt;
			else l[i] = -cnt;
		}
	}
	//right
	{
		int cnt = 1;
		int pre = n - 1;
		REP(i, n)
		{
			if (s[n - i - 1] == 'x')continue;

			if (n - i - 1 < pre - c)
			{
				cnt++;
				pre = n - i - 1;
			}
			if (pre == n - i - 1)r[n - i - 1] = cnt;
			else r[n - i - 1] = -cnt;
		}
	}
	REP(i, n)
	{
		if (k < l[i] + r[i] - 1)continue;
		if (0 < l[i] && 0 < r[i])
			cout << i + 1 << " ";
	}

	return 0;
}

Measured memory_bytes: 3332
#map(int,input().split())
n=input()
n='0'+n
l=len(n)
count=0
carry=0
for i in range(l-1,-1,-1):
    x=int(n[i])
    x+=carry
    if x<10-x:
        count+=x
        carry=0
    elif x>10-x:
        count+=10-x
        carry=1
    else:
        count+=5
        if int(n[i-1])<=4:
            carry=0
        else:
            carry=1
print(count)

Measured memory_bytes: 54384
#include <iostream>
#include <map>
using namespace std;
int a[100000];
int main(void){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    map<int,int> mp;
    for(int i = 0;i < n;i++){
        mp[a[i]]++;
    }
    int ans = 0;
    for(auto p: mp){
        int f = p.first,s = p.second;
        if(f < s){
            ans += s-f;
        }else if(f > s){
            ans += s;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5120
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main(int argc, const char * argv[]) {

    int x;
    cin >> x;
    
    cout << x*x*x << endl;

    return 0;
    
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n,k;
    cin>>n>>k;
    int up=(n-1)*(n-2)/2;
    if(k>up)
         cout<<"-1";
    else{
        int m=n-1+(n-1)*(n-2)/2-k;
        cout<<m<<"\n";
        for(int i=2; i<=n; i++)
             cout<<"1 "<<i<<"\n";
        int cnt=(n-1)*(n-2)/2-k;
        for(int i=2; i<=n; i++){
            for(int j=i+1; j<=n; j++){
                if(cnt==0)
                    break;
                else{
                    cnt--;
                    cout<<i<<" "<<j<<"\n";
                }
            }
        }
    }
    return 0;
    
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstdlib>//for including malloc.
#include<cstring>
#include<iostream>

struct Node{
    int key;
    Node *prev,*next;
};

Node *NIL;

void init(){//reset.
    NIL=(Node *)malloc(sizeof(Node));
    NIL->prev = NIL;
    NIL->next = NIL;
}
void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    //insert just after NIL.
    x->next = NIL->next;
    NIL->next->prev = x;
    //if x is the first Node, NIL's prev pointer will join to x.
    NIL->next = x;
    x->prev = NIL;
}
Node* listSearch(int key){
    Node *cur = NIL->next;//seaching begin with the next of NIL.
    while(cur != NIL && cur->key != key){
        cur = cur->next;
    }
    return cur;
}
void deleteNode(Node *t){
    if(t == NIL)return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}
void deleteFirst(){
    deleteNode(NIL->next);
}
void deleteLast(){
    deleteNode(NIL->prev);
}
void deleteKey(int key){
    deleteNode(listSearch(key));
}
void print(){
    Node *cur = NIL->next;
    int cnt = 0;
    while(cur != NIL){
        if(cnt++>0)printf(" ");
        printf("%d",cur->key);
        cur = cur->next; 
    }
    printf("\n");
}

int main(){
    init();
    int n;
    std::cin>>n;
    for(int i=0;i<n;i++){
        char order[20];
        scanf("%s",order);
        if(order[0] == 'i'){
            int key;scanf("%d",&key);
            insert(key);
        }else if(order[0] == 'd' && strlen(order)<7){
            int key;scanf("%d",&key);
            deleteKey(key);
        }else if(order[6] == 'F'){
            deleteFirst();
        }else{
            deleteLast();
        }
    }
    print();
    return 0;
}


Measured memory_bytes: 34372
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int tmp;
int main(){
    int A, B;
    cin >> N >> A >> B;
    cnt = B - A;
    if(cnt % 2 == 0)
        cout << "Alice" << endl;
    else
        cout << "Borys" << endl;
    return 0;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

string vow = "aeiou";
const ld pie = 3.14159265358979 ;

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n ; cin >> n ; 
    string s ; cin >> s ; 
    
    if ( n < 3200 ) cout << "red" ; 
    else cout << s ; 
}

int main()
{
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool isPrime(int n){
    if(n==2)return true;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return true;
}

bool data[1000000]={true,true};

vi makeEra(){

    for(int i=2;i<1000000;i++){
        if(data[i]==false){
            if( isPrime(i) ){
                for(int j=2;;j++){
                    if(i*j<1000000)
                        data[i*j]=true;
                    else break;
                }
            }
        }
    }
    vi ret;
    rep(i,1000000){
        if(data[i]==false){
            ret.pb(i);
        }
    }
    return ret;
}


int main() {
    vi era=makeEra();
    
    int len=era.size();
    
    int n;
    while(cin>>n){
        if(n==0)break;
        int sum=0;
        rep(i,len){
            if(n-era[i]>=0 && n-era[i]<1000000 && data[n-era[i]]==false && era[i]<=n-era[i]){
                sum++;
            }
        }
        cout<<sum<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 2568
n,a,b = gets.split.map(&:to_i)
dis=b-a
if dis.even?
  puts (dis+1)/2
  exit
end

ans = 0
dis_l=a-1
dis_r=n-b
if dis_l < dis_r
  ans = dis_l + (dis+1)/2
else
  ans = dis_r + (dis+1)/2
end
puts ans

Measured memory_bytes: 14312
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  cout << (A * B) << endl;

  return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    string S;
    cin>>S;
    int ans[100000]={0};
    int cou=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='R')cou++;
        else{
            ans[i-1]+=(cou+1)/2;
            ans[i]+=cou/2;
            cou=0;
        }
    }
    cou=0;
    for(int i=S.size();0<=i;i--){
        if(S[i]=='L')cou++;
        else{
            ans[i+1]+=(cou+1)/2;
            ans[i]+=cou/2;
            cou=0;
        }
    }
    for(int i=0;i<S.size();i++){
        cout<<ans[i];
        if(i!=S.size()-1){
            cout<<' ';
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1024