akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    int a[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d",&a[i][j]);
        }
    }
    int b[m];
    for(int i = 0; i < m; i++){
        scanf("%d",&b[i]);
    }
    int s;
    for(int i = 0; i < n; i++){
        s = 0;
        for(int j = 0; j < m; j++){
            s += a[i][j] * b[j];
        }
        printf("%d\n",s);
    }
    return 0;
}


Measured memory_bytes: 2732
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;

  cin >> a >> b;
  if(a >= 13){
    cout << b << endl;
  }else if(a >= 6){
    cout << b / 2 << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}



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

int main() {
	int n, tmp;
	vector<int> a;
	cin >> n;
	rep(i, n) {
		cin >> tmp;
		a.push_back(tmp);
	}
	// cout << "start func" << endl;
	void insertion_sort(vector<int> a, int n);
	insertion_sort(a, n);
}

void insertion_sort(vector<int> a, int n) {
	void out_result(vector<int> a, int n);
	rep_1(i,n) {
		int tmp = a[i];
		int j = i-1;
		out_result(a, n);
		while(j>=0 && a[j]>tmp) {
			a[j+1] = a[j];
			a[j] = tmp;
			j--;
		}
	}
	out_result(a, n);
}

void out_result(vector<int> a, int n) {
	rep(i, n-1) cout << a[i] << " ";
	cout << a[n-1] << endl;	
}


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

#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  int a, b; cin >> a >> b;
  cout << a * b << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//ユークリッドの互除法
	static int GCD(int a, int b){
			int m = Math.Max(a, b);
			int n = Math.Min(a, b);

			while(n != 0){
					int x = m % n;
					m = n;
					n = x;
			}

			return m;
	}

	//Main
	static void Main(string[] args)
	{
		//読み込む
		int K = int.Parse(Console.ReadLine());

		//カウンター
		int cnt = 0;

		//ループ処理
		for(int i=1; i<=K; i++){
				for(int j=1; j<=K; j++){
						for(int k=1; k<=K; k++){
								int gcd = GCD(GCD(i,j), k);
								cnt += gcd;
						}
				}
		}

		Console.WriteLine(cnt);

	}
}


Measured memory_bytes: 17664
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
S = np.array(readline().split(), np.uint64)
T = np.array(readline().split(), np.uint64)
U = np.array(readline().split(), np.uint64)
V = np.array(readline().split(), np.uint64)


def solve(S, T, U, V):
    A = np.zeros((N, N), np.uint64)
    if N == 1:
        return np.array([[U[0]]], np.uint64)
    all_one_row = (S == 0) & (U == 1)
    all_zero_row = (S == 1) & (U == 0)
    r = np.any(all_zero_row), np.any(all_one_row)
    all_one_col = (T == 0) & (V == 1)
    all_zero_col = (T == 1) & (V == 0)
    c = np.any(all_zero_col), np.any(all_one_col)
    if (c[0] or c[1]) and not (r[0] or r[1]):
        return solve(T, S, V, U).T
    # 確定条件があるなら行にある
    if not (r[0] or r[1]):
        # 確定条件なし。十分均一ならok
        A[1::2, ::2] = 1
        A[::2, 1::2] = 1
        return A
    # 少なくとも行に確定条件がある場合
    if r[0] and r[1]:
        # 列の運命は確定なので、行本位で入れればよい
        A += U[:, None]
        return A
    if r[0]:
        if c[1]:
            return A
        if c[0]:
            # 行列とも強制的に 0 が入る。他は 1 を埋める。
            A += 1
            A[all_zero_row, :] = 0
            A[:, all_zero_col] = 0
            return A
        # 列に強制条件なし
        if np.any(U == 1):
            A += U[:, None]
            return A
        # 行は、all or exists で 0
        # 列は、exists 0 or 1
        if np.any(V == 0):
            A += V[None, :]
            A[all_zero_row] = 0
            return A
        if N - 1 <= np.count_nonzero(all_zero_row):
            return A
        ind = np.where(~all_zero_row)[0]
        A[ind[0], 0] = 1
        A[ind[-1], 1:] = 1
        return A
    if r[1]:
        if c[0]:
            return A
        if c[1]:
            # 行列とも強制的に 1 が入る。他は 0 を埋める。
            A[all_one_row, :] = 1
            A[:, all_one_col] = 1
            return A
        # 列に強制条件なし
        if np.any(U == 0):
            A += U[:, None]
            return A
        # 行は、all or exists で 1
        # 列は、exists 0 or 1
        if np.any(V == 1):
            A += V[None, :]
            A[all_one_row] = 1
            return A
        if N - 1 <= np.count_nonzero(all_one_row):
            return A
        A += 1
        ind = np.where(~all_one_row)[0]
        A[ind[0], 0] = 0
        A[ind[-1], 1:] = 0
        return A


def test(S, T, U, V, A):
    row_or = np.bitwise_or.reduce(A, axis=1)
    row_and = np.bitwise_and.reduce(A, axis=1)
    cond_row = np.all(U[S == 0] == row_and[S == 0]) and np.all(U[S == 1] == row_or[S == 1])
    col_or = np.bitwise_or.reduce(A, axis=0)
    col_and = np.bitwise_and.reduce(A, axis=0)
    cond_col = np.all(V[T == 0] == col_and[T == 0]) and np.all(V[T == 1] == col_or[T == 1])
    return cond_row and cond_col


A = np.zeros((N, N), np.uint64)
for k in range(64):
    A ^= solve(S, T, (U >> k) & 1, (V >> k) & 1) << k

if not test(S, T, U, V, A):
    print(-1)
else:
    print('\n'.join(' '.join(row) for row in A.astype(str)))


Measured memory_bytes: 54116
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a + b >= 24)
		cout << a + b - 24 << "\n";
	else
		cout << a + b << "\n";
}

Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
 
int main(void){
    int n,max=-1000000,min=1000000,r;
    long long sum=0;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> r;
        sum += r;
        if (r>max) max = r;
        if (r<min) min = r;
         
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007
int main() {
    fio;
    string s;
    cin >> s;
    ll l = s.size();
    ll ans = 0;
    for (ll i = 0; i < l; i++) {
        ans += s[i] - '0';
    }
    //cout << ans;
    if (ans % 9 == 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  reverse(s.begin(),s.end());
  s+='0';
  int n=s.size();
  vector<vector<int>> dp(n+1,vector<int>(2,100000001));
  dp.at(0).at(0)=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<2;j++){
      int x=s.at(i)-'0';
      x+=j;
      for(int a=0;a<10;a++){
        int b=a-x;
        int ni=i+1,nj=0;
        if(b<0){
          nj=1;
          b+=10;
        }
        dp.at(ni).at(nj)=min(dp.at(ni).at(nj),dp.at(i).at(j)+a+b);
      }
    }
  }
  cout << dp.at(n).at(0) << endl;
}

Measured memory_bytes: 55940
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
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; }
ll mod= 1e9 + 7;


int main(){
  int n;
  cin >> n;
  ll a[n];
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  reverse(a,a+n);
  map<ll ,ll> b;
  priority_queue<ll,vector<ll>> p={};
  ll ans=0;
  rep(i,n){
    if(i==0){
      b[a[i]]++;
      p.push(a[i]);
    }else{
      b[p.top()]--;
      ans+=p.top();
      while(p.size()!=0){if(b[p.top()]==0){p.pop();}else{break;}}
      b[a[i]]+=2;
      p.push(a[i]);
    }
  }
  cout  << ans << endl;
}

Measured memory_bytes: 18160
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String x = br.readLine();
		System.out.println(x.replace("2017", "2018"));
	}
}

Measured memory_bytes: 22996
N,K=map(int,input().split())
mod=10**9+7

import math
SQ=int(math.sqrt(N))

DP1=[1]*(SQ+1)
DP1[0]=0


DP2=[]

k=SQ

for i in range(SQ,0,-1):
    DP2.append(N//i-k)
    k=N//i


KOSUU2=[v for v in DP2]

#print(DP1)
#print(DP2)
#print()

for j in range(K-1):
    NDP1=[0]*(SQ+2)
    NDP2=[0]*(SQ+1)

    for j in range(1,SQ+1):
        NDP2[-j]-=DP1[j]
        NDP1[1]+=DP1[j]

    #print(NDP1)
    #print(NDP2)
    #print()

    for j in range(-1,-SQ-1,-1):
        NDP1[-j+1]-=DP2[j]
        NDP1[1]+=DP2[j]

    #print(NDP1)
    #print(NDP2)
    #print()

    for j in range(1,SQ+2):
        NDP1[j]+=NDP1[j-1]

    NDP2[0]+=NDP1[-1]

    for j in range(1,SQ+1):
        NDP2[j]+=NDP2[j-1]

    #print(NDP1)
    #print(NDP2)
    #print()

    for j in range(SQ):
        NDP2[j]=NDP2[j]*KOSUU2[j]

    #print(NDP1)
    #print(NDP2)
    #print()

    DP1=[n%mod for n in NDP1[:SQ+1]]
    DP2=[n%mod for n in NDP2[:SQ]]

    
print((sum(DP1)+sum(DP2))%mod)

Measured memory_bytes: 102236
# https://atcoder.jp/contests/abc137/tasks/abc137_c



N = gets.to_i
ss = Array.new(N) { gets.chomp }

tbl = Hash.new(0)
ss.each { |s| tbl[s.chars.sort.join] += 1 }
ans = tbl.values.reduce(0) { |m, k| m + k * (k - 1) / 2}

puts ans


Measured memory_bytes: 25468
import sys
N = int(input())
if N == 1:
    print(0)
    sys.exit()
alla = 1
for i in range(N):
    alla = (alla * 10) % (10**9+7)
exi1or9 = 1
for i in range(N):
    exi1or9 = (exi1or9 * 9) % (10**9+7)
exi1and9 = 1
for i in range(N):
    exi1and9 = (exi1and9 * 8) % (10**9+7)
ans = (alla-2*exi1or9+exi1and9) % (10**9+7)
print(ans)

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

using namespace std;

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

    for(int i=0;i<s.length();i++){
        if(s[i]+n>'Z'){
            s[i]='A'-1+n-('Z'-s[i]);
        }
        else{
            s[i]+=n;
        }
    }
    cout << s << endl;
}

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

using namespace std;

const int N = 3e5+7;
const int MOD = 1e9+7;

int n;
long long a[N];
int cnt[70];

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        for (int j = 0; j < 60; ++j) {
            if ((a[i]>>j)&1) ++cnt[j];
        }
    }
    long long sum = 0;
    for (int i = 0; i < 60; ++i) {
        (sum += (1ll<<i)%MOD*cnt[i]%MOD*(n-cnt[i])%MOD) %= MOD;
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 2688
from math import ceil

n, k = map(int, input().split())

bef = n + 1
ans = 0
div = 1
while k > 0.5:
    a = ceil(k)
    cnt = max(0, bef - a)
    ans += cnt * div
    div /= 2
    k /= 2
    bef = min(n + 1, a)
print(ans / n)

Measured memory_bytes: 9096
#include <iostream>
using namespace std;
using ll = long long;
int main(void){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int ab = c * 2;

  ll ans = 1<<30;
  int z = max(x,y);
  for(int abi=0;abi<=z;abi++){
    int ac = x>abi ? x-abi:0;
    int bc = y>abi ? y-abi:0;
    ans = min(ans,(ll)(a*ac+b*bc+ab*abi));
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    println(lcm(2,n))
end
main()

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

// Common file
#include <ext/pb_ds/assoc_container.hpp>
// Including tree_order_statistics_node_update
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



#define pb push_back
#define F first
#define S second
#define rep(i,n) for(int i = 0; i < (n); i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ReadFile            freopen("input.in","r",stdin)
#define WriteFile           freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi=acos(-1);
const ld rad=Pi/180.0;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
            y = y>>1;
            x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
    return(m == 0)?1:n*nCr(n-1,m-1)/m;
}

/*****************************************************/

const int N = 1e4 + 5;
int a[N] , n;

int main()
{
    cin >> n;

    memset(a , 0 , sizeof a);

    for(int x = 1; x <= 100; ++x)
        for(int y = 1; y <= 100; ++y)
            for(int z = 1; z <= 100; ++z) {
                ll f = x*x + y*y + z*z + x*y + x*z + y*z;
                if(f <= 10000)
                    a[f]++;
            }

    for(int i = 1; i <= n; ++i)
        cout << a[i] << "\n";

    return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String x = sc.next();
		
		int N = Integer.parseInt(x);
		int S = 0;
		int a = 0;
		
		for(int i = 0; i < x.length(); i++) {
			a = (int)(N / Math.pow(10, i));
			S += a % 10;
		}
		
		if(N % S == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A) {
		cin >> x;
	}

	long long ans = 0;
	int h = 0;
	for (auto x : A) {
		if (x < h) {
			ans += h - x;
		}
		h = max(h, x);
	}
	cout << ans << endl;
}



Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
int h,w;
char c[1111][1111];
queue<P>q;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int d[1111][1111];
signed main(){
	cin>>h>>w;
	rep(i,h)rep(j,w)d[i][j]=1145141919;
	rep(i,h){
		rep(j,w){
			cin>>c[i][j];
			if(c[i][j]=='#'){
				q.push({i,j});
				d[i][j]=0;
			}
		}
	}
	
	while(!q.empty()){
		P p=q.front();
		q.pop();
		rep(i,4){
			int X=p.first+dx[i];
			int Y=p.second+dy[i];
			if(0<=X&&X<h&&0<=Y&&Y<w){
				if(d[X][Y]>d[p.first][p.second]+1){
					d[X][Y]=d[p.first][p.second]+1;
					q.push({X,Y});
				}
			}
		}
	}
	
	int ans=0;
	rep(i,h)rep(j,w)ans=max(ans,d[i][j]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 27316
#include<stdio.h>
#include<stdlib.h>
void countingSort(int[],int[],int,int);
void printArray(int[],int);
int main(void)
{
  int i;//counter
  int n;//length of array
  int max=0;//maximum value of array
  int *arr;
  int *sortedArr;
  scanf("%d",&n);
  arr=(int*)malloc(sizeof(int)*n);
  sortedArr=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&arr[i]);
      if(max<arr[i]) max=arr[i];
    }
  countingSort(arr,sortedArr,n,max);
  printArray(sortedArr,n);
  return 0;
}
void countingSort(int arr[],int sortedArr[],int n,int max)
{
  int i;//counter
  int size=max+1>n?max+1:n;
  int *countArr=(int*)malloc(sizeof(int)*(size));
  for(i=0;i<=size;i++) countArr[i]=0;
  for(i=0;i<n;i++) countArr[arr[i]]++;
  for(i=1;i<=max;i++) countArr[i]+=countArr[i-1];
  for(i=n-1;i>=0;i--)
    {
      sortedArr[countArr[arr[i]]-1]=arr[i];
      countArr[arr[i]]--;
    }
}
void printArray(int arr[],int n)
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      if(i>0) printf(" ");
      printf("%d",arr[i]);
    }
  printf("\n");
}



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

using namespace std;
typedef long long ll ;
#define forl(i,n) for(int i=0 ; i<n ; i++)

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

	while(T--)
	{
		ll n,l ;
		cin>>n>>l ;
		ll w[n+1],v[n+1] ;
		w[0]=0 ;
		v[0]=0 ;
		for(int i=1 ; i<=n ; i++)
			cin>>w[i]>>v[i] ;

		ll dp[n+1][l+1] ;
		for(int i=0 ; i<=l ; i++) 
			dp[0][i]=0 ;
		for(int i=0 ; i<=n ; i++)
			dp[i][0]=0 ;

		for(int i=1 ; i<=n ; i++)
		{
			for(int j=1 ; j<=l ; j++)
			{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]) ; 
				if(j>=w[i])
					dp[i][j] = max(dp[i][j],v[i]+dp[i-1][j-w[i]]) ;
			}
		}
		ll ans=0 ;
		for(int i=1 ;i<=n ; i++)
			ans=max(ans,dp[i][l]) ;
		cout<<ans<<endl ;
		// for(int i=0 ; i<=n ; i++ ,cout<<endl)
			// for(int j=0 ; j<=l; j++) cout<<dp[i][j]<<" " ;
	}
	return 0;
}

Measured memory_bytes: 82328
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll amari = N % (A + B);
  ll ans = N / (A + B) * A;
  debug(ans);
  if (amari > A) {
    ans += A;
  } else {
    ans += amari;
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 256
(defun search-value (target &optional (left 1) (right 1))
  (if (= left 10)
      nil
      (let ((value (* left right)))
        (if (= value target)
            t
            (cond ((= right 9)
                   (search-value target (1+ left) 1))
                  (t
                   (search-value target left (1+ right))))))))

(if (search-value (read))
    (princ "Yes")
    (princ "No"))




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

using namespace std;

#define f first
#define s second
#define ll long long
#define pb push_back

const int INF = 1e7;

int n, m, nx, ny, ma, k;

int a[10][10];

string in, out;

int main(){
    cin >> n >> m >> k;
    cin >> nx >> ny;
    cin >> out >> in;

    for (int i = 0; i < k; i++){
        if (out[i] == 'R'){
            if (a[2][2] == 0)
                a[1][1]++;
            else
                a[2][2]--;
        }
        if (out[i] == 'L'){
            if (a[2][1] == 0)
                a[1][2]++;
            else
                a[2][1]--;
        }
        if (out[i] == 'U'){
            if (a[2][4] == 0)
                a[1][3]++;
            else
                a[2][4]--;
        }
        if (out[i] == 'D'){
            if (a[2][3] == 0)
                a[1][4]++;
            else
                a[2][3]--;
        }


        if (a[1][1] > m - ny){
            cout << "NO";
            return 0;
        }
        if (a[1][2] >= ny){
            cout << "NO";
            return 0;
        }
        if (a[1][3] >= nx){
            cout << "NO";
            return 0;
        }
        if (a[1][4] > n - nx){
            cout << "NO";
            return 0;
        }

        if (in[i] == 'R'){
            if (a[1][2] == 0)
                a[2][1]++;
            else
                a[1][2]--;
        }
        if (in[i] == 'L'){
            if (a[1][1] == 0)
                a[2][2]++;
            else
                a[1][1]--;
        }
        if (in[i] == 'U'){
            if (a[1][4] == 0)
                a[2][3]++;
            else
                a[1][4]--;
        }
        if (in[i] == 'D'){
            if (a[1][3] == 0)
                a[2][4]++;
            else
                a[1][3]--;
        }

        if (a[2][1] > m - ny){
            a[2][1]--;
        }
        if (a[2][2] >= ny){
            a[2][2]--;
        }
        if (a[2][3] >= nx){
            a[2][3]--;
        }
        if (a[2][4] > n - nx){
            a[2][4]--;
        }
    }

    cout << "YES";
}



Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    int n;
    cin >> n;
    int count[4] = {0, 0, 0, 0};
    /*
    0 = AC
    1 = WA
    2 = TLE
    3 = RE*/

    for(int i = 0; i<n; i++){
        string s;
        cin >> s;
        if(s == "AC"){
            count[0]+=1;
        } else if(s == "WA"){
            count[1] += 1;
        } else if(s == "TLE"){
            count[2] += 1;
        } else{
            count[3] += 1;
        }
    }

    string res[4] = {"AC", "WA", "TLE", "RE"};
    for(int i = 0; i<4; i++){
        cout << res[i] << " x " << count[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3632
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
INF=float("inf")
ans=INF
for i in range(2**n):
    tl=[0]*m
    c=0
    for j in range(n):
        if (i>>j)&1:
            c+=l[j][0]
            for k,a in enumerate(l[j][1:]):
                tl[k]+=a
    for j in tl:
        if j<x:
            break
    else:
        ans=min(ans,c)
if ans==INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68612
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i = 0; i < n; i++)
    {
        cin>>arr[i];
    }
    vector<ll>ans(n);
    ans[1] = abs(arr[0] - arr[1]);
    for(ll i = 2; i < n; i++)
    {
        ans[i] = min(ans[i-1] + abs(arr[i] - arr[i-1]) , ans[i-2] + abs(arr[i] - arr[i-2]));
    }
    cout<<ans[n-1];
}

Measured memory_bytes: 4744
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[12345];
int main(){
	scanf("%s",s);
	int len=strlen(s);
	long long ans=0;
	for(int t=0;t<(1<<(len-1));t++){
		long long num=s[0]-'0';
		for(int i=0;i<len-1;i++){
			if(t&(1<<i)){
				ans+=num;
				num=0;
			}
			num=num*10+s[i+1]-'0'; 
		}
		ans+=num;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, K = map(int, raw_input().split())
if K <= A:
    print A - K, B
elif K <= A + B:
    print 0, A + B - K
else:
    print 0, 0

Measured memory_bytes: 4268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    vector<ll> a(n+1);rep(i,n+1)cin>>a[i];
    vector<ll> sum(n+1);
    ll s = 0;
    for(int i=n; i>=0; i--){
        s+=a[i];
        sum[i]=s;
    }

    ll c=1, u=1, ans=0;
    bool flag = false;
    rep(i,n+1){
        if(flag){ans+=sum[i];continue;}
        if(c>=sum[i]){ans+=sum[i];flag=true;continue;}
        ans+=c;
        c-=a[i];
        if(c<0){ans=-1;break;}
        c*=2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4784
//Author : Sukarna Paul

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

//dp[i]=1   if player with current move can win
//with i remaining stones, otherwise dp[i]=0
//So if dp[k]=1 First player will win
//and if dp[k]=0 Second player will win

int dp[100005];

int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n,k;
    cin>>n>>k;

    vector<int>A; //given array

    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        A.push_back(a);
    }


    //iterating over all possible number of stones

    for(int remstone = 0 ; remstone<=k; remstone++){
        for(int i=0;i<A.size();i++){
            int x = A[i];


            if(x>remstone)continue; //x is greater than remaining number
                                    //of stones , so we can't take it

            if(dp[remstone-x]==0){  //if after removing x stones it is
                                    //not possible for other player to win
                dp[remstone]=1;
            }
        }
    }

    if(dp[k]==1)    cout<<"First\n";
    else            cout<<"Second\n";
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long ans = 0;
        for (int i=k;i<=n+1;i++){
            ans=((((n-i+1)*(long)i)+1)+ans)%1000000007;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35664
import java.util.Scanner;

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

		int cnt = 0;
		int k = sc.nextInt(), def = sc.nextInt();
		int x = 0, y = 0, z = def;

		// y -> x
		while (true)
		{
			z = def - x;
			y = 0;

			// z -> y
			while (true)
			{
				if (x <= k && y <= k && z <= k) { ++cnt; }

				if (z == 0) { break;}

				--z; ++y;
			}

			++x;

			if (x > def) { break; }
		}

		System.out.println(cnt);
	}
}


Measured memory_bytes: 23508
n=int(input())
a=list(map(int,input().split()))
a1=a[0:1]+a[1::2]
a2=a[2::2]

if n % 2 == 1 :
    a2=list(reversed(a2))
    a=a2+a1

elif n % 2 == 0 :
    a1=list(reversed(a1))
    a=a1+a2

for j in a:
    print(j,end=' ')

Measured memory_bytes: 26020
#include <stdio.h>

int main(void)
{
    int mt[10];
    int i, j;
    int tmp;
    
    for (i = 0; i < 10; i++){
        scanf("%d", &mt[i]);
    }
    
    for (i = 0; i < 10; i++){
        for (j = 9; j > i; j--){
            if (mt[j] > mt[j - 1]){
                tmp = mt[j - 1];
                mt[j - 1] = mt[j];
                mt[j] = tmp;
            }
        }
    }
    printf("%d\n", mt[0]);
    printf("%d\n", mt[1]);
    printf("%d\n", mt[2]);

    return (0);
}

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

int main(){

	int n;
	cin >> n;

	int count = 0;
	
	for(int i=1;i<=n;i++){

		int k;
		cin >> k;

		if(((i%2)!=0) && ((k%2)!=0)){
			count++;
		}

	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3616
import java.io.InputStream
import java.math.BigDecimal
import java.math.BigInteger

fun main(args: Array<String>) = input.run {
    val n = nextInt()
    val a = nextInts(n)
    var d = 0
    var prev = a[0]
    var ans = 1
    a.forEach {
        val nd = Integer.signum(it - prev)
        if (d != 0 && nd != 0 && nd != d) {
            ans++
            d = 0
        } else if (d == 0) {
            d = nd
        }
        prev = it
    }
    println(ans)
}

val input = FastScanner()

fun String.toBigInteger() = BigInteger(this)
fun String.toBigDecimal() = BigDecimal(this)

class FastScanner(private val input: InputStream = System.`in`) {
    private val sb = StringBuilder()
    private val buffer = ByteArray(4096)
    private var pos = 0
    private var size = 0

    fun nextString(): String? {
        var c = skipWhitespace()
        if (c < 0) return null

        return sb.run {
            setLength(0)

            do {
                append(c.toChar())
                c = read()
            } while (c > ' '.toInt())

            toString()
        }
    }

    fun nextLine(): String? {
        var c = read()
        if (c < 0) return null

        return sb.run {
            setLength(0)

            while (c >= 0 && c != '\n'.toInt()) {
                append(c.toChar())
                c = read()
            }

            toString()
        }
    }

    fun nextLong(): Long {
        var c = skipWhitespace()

        val sign = if (c == '-'.toInt()) {
            c = read()
            -1
        } else 1

        var ans = 0L

        while (c > ' '.toInt()) {
            ans = ans * 10 + c - '0'.toInt()
            c = read()
        }

        return sign * ans
    }

    fun nextInt() = nextLong().toInt()
    fun nextDouble() = nextString()?.toDouble() ?: 0.0
    fun nextBigInteger(): BigInteger = nextString()?.toBigInteger() ?: BigInteger.ZERO
    fun nextBigDecimal(): BigDecimal = nextString()?.toBigDecimal() ?: BigDecimal.ZERO

    fun nextStrings(n: Int) = Array<String>(n) { nextString() ?: "" }
    fun nextInts(n: Int) = IntArray(n) { nextInt() }
    fun nextLongs(n: Int) = LongArray(n) { nextLong() }
    fun nextDoubles(n: Int) = DoubleArray(n) { nextDouble() }
    fun nextBigIntegers(n: Int) = Array<BigInteger>(n) { nextBigInteger() }
    fun nextBigDecimals(n: Int) = Array<BigDecimal>(n) { nextBigDecimal() }

    fun nextStrings(n: Int, m: Int) = Array(n) { nextStrings(m) }
    fun nextInts(n: Int, m: Int) = Array(n) { nextInts(m) }
    fun nextLongs(n: Int, m: Int) = Array(n) { nextLongs(m) }
    fun nextDoubles(n: Int, m: Int) = Array(n) { nextDoubles(m) }
    fun nextBigIntegers(n: Int, m: Int) = Array(n) { nextBigIntegers(m) }
    fun nextBigDecimals(n: Int, m: Int) = Array(n) { nextBigDecimals(m) }

    private fun skipWhitespace(): Int {
        while (true) {
            val c = read()
            if (c > ' '.toInt() || c < 0) return c
        }
    }

    private fun read(): Int {
        while (pos >= size) {
            if (size < 0) return -1
            size = input.read(buffer, 0, buffer.size)
            pos = 0
        }
        return buffer[pos++].toInt()
    }
}


Measured memory_bytes: 23596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_168
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int k = ReadInt();
            string s = Read();
            if (s.Length <= k) {
                WriteLine(s);
            }
            else
            {
                WriteLine(s.Substring(0, k) + "...");
            }

        }

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


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

int main(void){
  ll a; double b;
  cin >> a >> b;
  ll B = b * 100 + 0.01;
  ll ans = a*B/100;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    string a,b,c;
    cin>>a>>b>>c;
    cout<<a[0]<<b[1]<<c[2]<<endl;
}

Measured memory_bytes: 256
import java.util.*;

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

        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            map.put(Integer.parseInt(sc.next()), i);
        }

        for (int i = 1; i <= N; i++) {
            System.out.printf("%d ", map.get(i));
        }
    }
}

Measured memory_bytes: 74076
# ABC 097: B – Exponential
x = int(input())
e = 0

if x == 1:
    e = 1
else:
    for b in range(1, x + 1):
        for p in range(2, x + 1):
            if b ** p > x:
                break
            else:
                e = max(e, b ** p)

print(e)

Measured memory_bytes: 2940
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!

const gcdArr = function(arr) {
  let gcdres = gcd(arr[0], arr[1])
  for (let i=2; i<arr.length; i++) {
    gcdres = gcd(gcdres, arr[i])
  }
  return gcdres
}

function gcd_impl(n,m) {
        for( let i = 0; i < 10; ++i ) {
                let t = n - m;
                let q = m > t;
                n = q ? m : t;
                m = q ? t : m;
                if( m == 0 ) { return n; }
        }
        return gcd_impl( m, n % m );
}

function gcd( n, m ) {
        return n > m ? gcd_impl( n, m ) : gcd_impl( m, n );
}

const Main = (p)=>{
	// 1行目がinput[0], 2行目がinput[1], …に入る
	
	let t = parseInt(p)//p.split(" ").map(Number);
	//文字列から10進数に変換するときはparseIntを使います
	//出力
	let s=0;
	for(let i=1;i<=t;i++){
	    for(let j=1;j<=t;j++){
    	    for(let k=1;k<=t;k++){
    	        s+=gcdArr([i,j,k]);
    	    }   
    	}
	}
	console.log(s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 36260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
int main()
{
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int y;
    y=a-1;
    long long int ans=b/c+b/d-b/lcm(c,d)-(y/c+y/d-y/lcm(c,d));
    ans=b-a+1-ans;
    cout<<ans;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A*N, B) << endl;
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = reader.nextInt();
		}
		Arrays.sort(a);
		int ans = Math.abs(a[N-1]-a[0]);

		reader.close();
		System.out.print(ans);
	}
}



Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  cin >> N;
  int ans = 0;
  rep(i, N + 1)
  {
    if ((long long)i * i > N)
    {
      break;
    }
    ans = (long long)i;
    ans *= ans;
  }

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

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

long gcd(long u, long v){
    long r;
    while (v != 0){
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

int main(){
    int n, tmp;
    long a[100010], l[100010], r[100010], ans, m;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    l[0] = r[n+1] = 0;
    for (int i = 0; i < n; ++i) l[i+1] = gcd(a[i], l[i]);
    for (int i = 0; i < n; ++i) r[n-i] = gcd(a[n-i-1], r[n+1-i]);
    ans = 0;
    for (int i = 1; i <= n; ++i){
        m = gcd(l[i-1], r[i+1]);
        if (ans < m) ans = m;
    }
    cout << ans;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define Inf 1000000
int dist[105][105];
int main()
{
    int n,a,b,s;
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        //memset(dist,0,sizeof(dist));
        for(int i=0; i<20; ++i)
        {
            for(int j=0; j<20; ++j)
            {
                dist[i][j]=Inf;
                dist[j][i]=Inf;
                if(i==j) dist[i][j]=0;
            }
        }
        int m=0;
        for(int i=0; i<n; ++i)
        {
            scanf("%d%d%d",&a,&b,&s);
            dist[a][b]=s;
            dist[b][a]=s;
            m=max(m,max(a,b)+1);
        }
        for(int k=0; k<m; ++k)
        {
            for(int i=0; i<m; ++i)
            {
                for(int j=0; j<m; ++j)
                {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        int x[100];
        memset(x,0,sizeof(x));
        for(int i=0; i<m; ++i)
        {
            for(int j=0; j<m; ++j)
            {
                x[i]+=dist[i][j];
            }
        }
        int ans=min_element(x,x+m)-x;
        printf("%d %d\n",ans,x[ans]);
    }
    return 0;
}

Measured memory_bytes: 1196
import sys
sys.setrecursionlimit(4100000)
import math
import bisect
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A.sort()
    B.sort()
    C.sort()

    ans = 0
    for b in B:
        a_num = bisect.bisect_left(A,b)
        c_num = bisect.bisect_right(C,b)
        ans += a_num*(len(C) - c_num)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 107760
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1000000007;

int main() {
  ll n, k;

  cin >> n >> k;

  ll mx = 4 * k;

  vvll mp(mx, vll(mx, 0));
  vP lst;
  rep(i, n) {
    ll x, y;
    string s;
    cin >> x >> y >> s;
    if (s == "W") x += k;
    x = x % (2 * k) + k;
    y = y % (2 * k) + k;
    mp[y][x]++;
    lst.push_back(P(y, x));
  }

  vvll acc(mx + 1, vll(mx + 1, 0));
  rep(i, mx) rep(j, mx) {
    acc[i + 1][j + 1] = mp[i][j] + acc[i + 1][j] + acc[i][j + 1] - acc[i][j];
  }

  // rep(i, mx) {
  //   rep(j, mx) { cout << mp[i][j]; }
  //   cout << endl;
  // }

  ll ans = 0;
  for (ll i = 0; i <= 2 * k; i++) {
    for (ll j = 0; j <= 2 * k; j++) {
      ll t = 0;
      for (ll ii = -4; ii <= 4; ii++) {
        for (ll jj = ii - 1; jj <= 4; jj += 2) {
          ll yu = i + k * ii + k;
          ll xu = j + k * jj + k;
          ll yl = i + k * ii;
          ll xl = j + k * jj;
          bool skip = yu < 0 || yu > mx || xu < 0 || xu > mx || yl < 0 ||
                      yl > mx || xl < 0 || xl > mx;
          if (skip) continue;
          ll addv = acc[yu][xu] - acc[yl][xu] - acc[yu][xl] + acc[yl][xl];
          // if(addv > 0) {
          //   printf("%lld %lld, %lld %lld: %lld\n", i, j, ii, jj, addv);
          // }
          if (!skip) t += addv;
        }  // jj
      }    // ii
      chmax(ans, t);
    }  // j
  }    // i

  cout << ans << endl;

  return 0;
}


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

#define ll long long int
#define endl "\n"
#define mod 1000000007


int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
	ll n, k, d, x;
	set<ll> s;
	cin >> n >> k;
	for (ll i = 0; i < k; i++) {
		cin >> d;
		for (ll i = 0; i < d; i++) {
			cin >> x;
			s.insert(x);
		}
	}
	cout << (n - s.size()) << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define invrep(i, n) for(int i = (n)-1; i >= 0; i--)        // n-1, n-2, ..., 0
#define invREP(i, x, n) for(int i = (n)-1; i >= (x; i--)    // n-1, n-2, ..., x
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define PB push_back

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

int H, W, N;
char maze[1000][1000];
int d[1000][1000];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
pint cheese[11];

int bfs(int x){
    queue<pint> que;
    rep(i, H) rep(j, W) d[i][j] = INF;
    int sy = cheese[x].first, sx = cheese[x].second;
    int gy = cheese[x + 1].first, gx = cheese[x + 1].second;
    que.push(pint(sy, sx));
    d[sy][sx] = 0;

    while(que.size()){
        pint p =  que.front(); que.pop();
        if(p.first == gy && p.second == gx) break;
        rep(i, 4){
            int ny = p.first + dx[i], nx =  p.second + dy[i];
            if(0 <= ny && ny < H && 0 <= nx && nx < W && maze[ny][nx] != 'X' && d[ny][nx] == INF){
                d[ny][nx] = d[p.first][p.second] + 1;
                que.push(pint(ny, nx));
            }
        }
    }
    return d[gy][gx];
}

int main(){
    cin >> H >> W >> N;
    rep(i, H) rep(j, W){
        cin >> maze[i][j];
        if(maze[i][j] == 'S'){
            cheese[0] = pint(i, j);
        }
        if(maze[i][j] != 'S' && maze[i][j] != 'X' && maze[i][j] != '.') cheese[maze[i][j] - '0'] = pint(i, j);  
    }
    int ans = 0;
    rep(i, N) ans += bfs(i);
    COUT(ans);
}


Measured memory_bytes: 7896
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		
		if (a == b + c || b == a + c || c == a + b) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35516
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define il inline
#define re register
#define fo(i,j,k) for(register int i=j;i<=k;i++)
#define do(i,j,k) for(register int i=j;i>=k;i--) 
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read()
{
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f*x;	
}
int n,m,cnt; 
int ans;
/*int h[200010],dis[200010],v[200010];
int dp[1005][1005];
struct edge
{
	int v,w,next;
}e[200010*2];
il void add(int u,int v)
{
	e[++cnt].v=v;
//	e[cnt].w=w;
	e[cnt].next=h[u];
	h[u]=cnt;
}*/ 
int main()
{
	double r;
	cin>>r;
	printf("%lf",3.1415926*2*r);
	return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long N, long long A, long long B){
    cout << min(N * A, B) << '\n';
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    vi a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    int ans = 0;
    vi c(n-1);
    rep(i,n){
        int x;
        cin >> x;
        ans += x;
    }
    rep(i,n-1) cin >> c[i];
    rng(i,1,n){
        if(a[i]-1 == a[i-1]) ans += c[a[i-1]];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n ;
  vector<int> w(n);
  vector<int> e(n);
  for(int i = 0 ; i < n; i++){
    char s ;
    cin >> s ;
    if( s == 'W'){
      w.at(i) = 1;
    }
    if( s == 'E'){
      e.at(i) = 1;
    }
    if( i != 0){
      w.at(i) = w.at(i) + w.at(i-1);
      e.at(i) = e.at(i) + e.at(i-1);
    }
  }
  int ans = 1<<30;
  for(int i= 0 ; i<n;i++){
    int sum ;
    if( i != 0){
      sum = e.at(n-1) -e.at(i) + w.at(i-1); 
    }
    else{
      sum = e.at(n-1) -e.at(i) ;
    }
    if( sum < ans){
      ans = sum;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560