akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r  = scan.nextInt();
		int c  = scan.nextInt();
		int[][] table = new int[r+1][c+1];
		for(int i = 0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] = scan.nextInt();
			}
		}

		for(int i=0; i<r;i++){
			for(int j=0; j<c;j++){
				table[i][c] += table[i][j]; 
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];
			}
		}

		for(int i = 0; i<=r; i++){
			System.out.print(table[i][0]);
			for(int j=1;j<=c;j++){
				System.out.print(" "+table[i][j]);	
		}
		System.out.println();
	}
}
}

Measured memory_bytes: 40900
#include<iostream>
#include <vector>
#include <numeric>
int main(){
    std::vector<int> vec;
    int N;
    int sum1=0, sum2=0, avg1, avg2;
    std::cin >> N;
    for( int i = 0; i < N; i++){
        int tmp;
        std::cin >> tmp;
        vec.push_back(tmp);
    }
    avg1 =std::accumulate(vec.begin(), vec.end(), 0) / vec.size();
    for(int i=0; i<vec.size(); i++){
        sum1 += (vec[i] - avg1)*(vec[i] - avg1);
    }
    avg2 =std::accumulate(vec.begin(), vec.end(), 0) / vec.size()+1;
    for(int i=0; i<vec.size(); i++){
        sum2 += (vec[i] - avg2)*(vec[i] - avg2);
    }
    if(sum1<=sum2){
        printf("%d\n", sum1);
    }else{
        printf("%d\n", sum2);
    }
    return 0;
}

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


ll N;
ll bit[2010000];

//aの位置にwを追加
void add(ll a,ll w){
    a++;
    for(int x=a;x<=N+1;x+=(x&(-x)) ){
        bit[x] += w;
    }
}

//v[0] + ... + v[a-1]
ll sum(ll a){
    ll ret=0;
    for(int x=a;x>0;x-=(x&(-x)) ){
        ret+=bit[x];
    }
    return ret;
}



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int n,m;
    cin>>n>>m;
    N = m+2;
    array<int,3> a[n];
    for(int i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        a[i] = {r-l+1,l,r};
    }
    sort(a,a+n);
    int ans[m+1]={};
    int now = 0;
    for(int i=1;i<=m;i++){
        while(now<n && a[now][0] < i){
            add(a[now][1],1);
            add(a[now][2]+1,-1);
            now++;
        }
        for(int j=i;j<=m;j+=i){
            ans[i] += sum(j+1);
        }
        ans[i] += n-now;
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 5632
S = input()
for i in range(len(S)):
    S = S[:-1]
    if len(S) % 2 == 1:
        continue
    else:
        if S[:len(S)//2] == S[len(S)//2:len(S)]:
            print(len(S))
            exit()
        else:
            continue

Measured memory_bytes: 3060
N, M = map(int, input().split())
adj = [[] for _ in range(N)]
visited = [0] * N

for i in range(M):
  a, b = map(int, input().split())
  adj[a-1].append(b)
  adj[b-1].append(a)

ans = []

def dfs(x):
  visited[x-1] = 1
  if visited == [1] * N:
    ans.append(1)
  for i in range(len(adj[x-1])):
    if visited[adj[x-1][i] - 1] == 0:
      dfs(adj[x-1][i])
  visited[x-1] = 0
      
dfs(1)
print(sum(ans))

Measured memory_bytes: 3064
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from fractions import gcd

sys.setrecursionlimit(10**7)
N, X = map(int, input().split())
xs = list(map(int, input().split()))

xs.append(X)
xs.sort()

set_num = set()
for i in range(N):
    set_num.add(xs[i+1] - xs[i])

list_num = list(set_num)
val = list_num[0]
for new_val in list_num[1:]:
    val = gcd(val, new_val)

print(val)


Measured memory_bytes: 16280
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<x86intrin.h>
#include<math.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputIntAry(int *a,int nBuf,int N){
    char *buf,*ptr;

    buf=(char*)malloc(nBuf*sizeof(char));
    my_gets(buf,nBuf,stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoi(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}

int CheckOrdinary(int *a){
    if((a[0]<a[1] && a[1]<a[2]) || (a[0]>a[1] && a[1]>a[2]))
        return 1;
    return 0;
}

int main(){
    int n,cnt=0;
    int p[20];

    scanf("%d%*c",&n);
    InputIntAry(p,100,n);

    for(int i=0;i<n-2;i++)
        cnt += CheckOrdinary(p+i);

    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define FOR(i, r, n) for (int i=(int)(r); i<=(int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 2147483647
#define INF64 9223372036854775807
#define MOD 1000000007

int main(){

    int64_t n, m, k;cin>>n>>m>>k;
    vector<int64_t> a(n+1, 0), b(m+1, 0);
    FOR(i, 1, n){
        int64_t x;cin>>x;
        a[i]=a[i-1]+x;
    }
    FOR(i, 1, m){
        int64_t x;cin>>x;
        b[i]=b[i-1]+x;
    }

    int64_t ans=0;

    FOR(i, 0, n){
        if(a[i]>k) break;
        int64_t x=m/2;
        int64_t best=x;
        while(x>1){
            x/=2;
            if(a[i]+b[best]>k) best-=x;
            if(a[i]+b[best]==k) break;
            if(a[i]+b[best]<k) best+=x;
        }
        if(a[i]+b[best]>k){
            while(a[i]+b[best]>k) best--;
        }
        if(a[i]+b[best]<k){
            while(a[i]+b[best]<=k){
                best++;
                if(best>m) break;
            }
            best--;
        }
        if(i+best>ans) ans=i+best;
    }

    cout<<ans<<endl;

}

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

int main(){
    int N, A[200001];
    ll K;
    cin >> N >> K;
    for (int i = 1; i <= N; ++i){
        cin >> A[i];
    }
   
    int town = 1;

    int tor = A[1], hare = A[A[1]];
   
    while (tor != hare){
        tor = A[tor];
        hare = A[A[hare]];
    }

    ll mu = 0;
    tor = 1;
    while (tor != hare){
        tor = A[tor];
        hare = A[hare];
        mu += 1;
    }

    ll lam = 1;
    hare = A[tor];
    while (tor != hare){
        hare = A[hare];
        lam+=1;
    }
    ll a;
    if (K <= mu + lam)
        a = K;
    else  
        a= ((K-mu) % lam) + mu;
    
    while(a--){
        town = A[town];
    }
    cout << town;
}




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


int main()
{
	int n,k;  cin>>n>>k;
	int p[1001];	
	int i;
	for( i=0;i<n;i++)  cin>>p[i];
	sort(p,p+n);
	
	int ans=0;
	
	for(i=0;i<k;i++) ans+=p[i];
	
	
	cout<<ans<<endl;
}



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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n, a, b; std::cin >> n >> a >> b;
    string s; std::cin >> s;
    int cnt = 0, bcnt = 0;
    rep(i, n) {
        char c = s[i];
        bool ok = false;
        if (c == 'a' && cnt < a+b) cnt++, ok = true;
        else if (c == 'b' && cnt < a+b && bcnt < b) cnt++, bcnt++, ok = true;
        std::cout << (ok ? "Yes" : "No") << "\n";
    }
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

int main (){
	int n ;
	cin >> n ;
	vector<int> a (n) ;
	rep(i, n) cin >> a[i] ;
	int ans = 0 ;
	int t = 1 ;
	rep(i, n){
		if(a[i] == t) {
			t++ ;
			ans++ ;
		}
	}
	if(ans == 0){
		cout << -1 << endl ;
		return 0; 
	}
	cout << n - ans << endl ;
}

Measured memory_bytes: 3996
// https://atcoder.jp/contests/dp/tasks/dp_d

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

vector<int> w(101);
vector<int> v(101);

void solve(){
    int n,kw;
    cin>>n>>kw;
    for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
    vector<vector<ll> > dp(n+1,vector<ll>(kw+1,0LL));
    // dp[i][j] -> max value I can make using first i elements when I have knapsack weight j
    for(int i=1;i<=n;i++){
        for(int j=1;j<=kw;j++){
            dp[i][j] = max(dp[i-1][j], j-w[i] >= 0 ? (ll)v[i] + dp[i-1][j-w[i]] : 0);
        }
    }
    cout<<dp[n][kw]<<"\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 81140
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int N,Ma,Mb;
int a[45],b[45],c[45];
int dp[42][402][402];

int main()
{
	cin >> N >> Ma >> Mb;
	rep(i,1,N+1)cin >> a[i] >> b[i] >> c[i];
	rep(i,0,N+1) rep(j,0,401) rep(k,0,401) dp[i][j][k] = INF;
	dp[0][0][0] = 0;
	rep(i,1,N+1){
		rep(j,0,401) rep(k,0,401) dp[i][j][k] = dp[i-1][j][k];
		rep(j,0,401) rep(k,0,401){
			if(j-a[i]>=0 && k-b[i]>=0){
				dp[i][j][k] = min(dp[i][j][k],dp[i-1][j-a[i]][k-b[i]]+c[i]);
			}
		}
	}

	int C = INF;
	for(int j=1;;j++){
		if(j*Ma>400 || j*Mb>400)break;
		C = min(C,dp[N][j*Ma][j*Mb]);
	}
	if(C == INF)cout << -1 << endl;
	else cout << C << endl;

	return 0;
}


Measured memory_bytes: 26112
import java.util.Scanner;
import java.util.Stack;

public class Main
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		String X = in.next();
		in.close();
		Stack<Character> st = new Stack<>();
		for (int i = 0; i < X.length(); i++)
		{
			char c = X.charAt(i);
			if (c == 'S' || st.isEmpty())
			{
				st.push(c);
			} else//Tが来て かつ 空でない
			{
				if (st.peek() == 'S')
				{
					st.pop();//Sをポップ(Tと相殺)
				} else
				{
					st.push(c);//Tをプッシュ
				}
			}
		}
		System.out.println(st.size());
	}
}


Measured memory_bytes: 26636
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int A = s.nextInt(), B = s.nextInt(), C = s.nextInt();
		int x = 0, y = 0, z = 0;
		if(A == B) x++;
		if(B == C) y++;
		if(C == A) z++;
		int r = x + y + z;
		System.out.println(r == 1 ? "Yes" : "No");
	}
}

Measured memory_bytes: 35708
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

void func(vector<vector<int>>&win, vector<int>&sum, int a, int b) {
	//cout << "a b " << a << " " << b << endl;
	//cout << sum[a] << endl;
	if (a == N - 1) {
		//for (auto i : sum)cout << i << endl;
		//cout << endl;
		if (!sum[a])K++;
		return;
	}
	if (win[a][b] >= 0) {
		int bef = win[a][b];
		win[a][b] = 1, win[b][a] = -1;
		sum[a]++;
		sum[b]--;
		if (b == N - 1) {
			if (!sum[a]) {
				func(win, sum, a + 1, a + 2);
			}
			win[a][b] = bef, win[b][a] = -bef;
			sum[a]--;
			sum[b]++;
		}
		else {
			func(win, sum, a, b + 1);
			win[a][b] = bef, win[b][a] = -bef;
			sum[a]--;
			sum[b]++;
		}
	}
	if (win[a][b] <= 0) {
		int bef = win[a][b];
		win[a][b] = -1, win[b][a] = 1;
		sum[a]--;
		sum[b]++;
		if (b == N - 1) {
			if (!sum[a]) {
				func(win, sum, a + 1, a + 2);
			}
			win[a][b] = bef, win[b][a] = -bef;
			sum[a]++;
			sum[b]--;
		}
		else {
			func(win, sum, a, b + 1);
			win[a][b] = bef, win[b][a] = -bef;
			sum[a]++;
			sum[b]--;
		}
	}
	return;
}

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

	while (cin >> N, N) {
		K = 0;
		cin >> M;
		vector<vector<int>>win(N, vector<int>(N));
		vector<int>sum(N);
		for (int i = 0; i < M; i++) {
			cin >> L >> R;
			L--, R--;
			win[L][R] = 1;
			win[R][L] = -1;
		}
		func(win, sum, 0, 1);
		cout << K << endl;
	}
}


Measured memory_bytes: 3156
#include <iostream>
#include <queue>

using namespace std;
struct node
{
	char c;
	int x,y;
	int length;
};
int moved[5][3];
bool vis[1005][1005];
node a[1005][1005];
queue<node> q;
int main()
{
	moved[1][1]=-1;moved[1][2]=0;
	moved[2][1]=0;moved[2][2]=1;
	moved[3][1]=1;moved[3][2]=0;
	moved[4][1]=0;moved[4][2]=-1;
	int h,w;
	cin>>h>>w;
	int sum=0;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++) 
		{
			cin>>a[i][j].c;	
			if(a[i][j].c=='.') sum++;
			a[i][j].x=i;
			a[i][j].y=j;
			a[i][j].length=1;
		}
	}
	q.push(a[1][1]);
	a[1][1].length=1;
	vis[1][1]=true;
	int step=0;
	while(!q.empty())
	{
		for(int i=1;i<=4;i++)
		{
			int x=q.front().x+moved[i][1];
			int y=q.front().y+moved[i][2];
			if(a[x][y].c=='.'&&!vis[x][y])
			{
				a[x][y].length=q.front().length+1;
				if(x==h&&y==w) 
				{
					cout<<sum-a[x][y].length<<endl;
					return 0;
				}
				q.push(a[x][y]);
				vis[x][y]=true;
			}
		}
		q.pop();
	}	
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int w, h;
	ll ans = 0LL;
	cin >> w >> h;
	V p(w), q(h);
	pair<int, int> data = mp(w, h);
	vector<pair<ll, int>> id;
	rep(i, w) {
		cin >> p[i];
		id.emplace_back(p[i], i);
	}
	rep(i, h) {
		cin >> q[i];
		id.emplace_back(q[i], i + w);
	}
	sort(all(id));
	auto itr = id.begin();
	while
		(not((data.F == 0 and data.S == 0) )) {
		//	clog << (itr->F) << " " << (itr->S) <<" == "<< (data.F) << " " << (data.S) << endl;
			if (itr->S < w) {
				ans += (data.S+1) * (itr->F);
				data.F--;
			} else {
				ans += (data.F+1) * (itr->F);
				data.S--;
			}
		  //  clog << ans << endl;
		    itr++;
		}

	cout << ans << endl;
}
/*
o-o o-o o-o
o-o o-o o-o
o-o o-o o-o
o-o o-o o-o
o-o o-o o-o
o-o o-o o-o

6*6 -> 3* 6

o o o-o o o (p[i])
o o o-o o o
o o o-o o o
o o o-o o o
o o o-o o o
o o o-o o o

==
o o O o o
o o O o o
o o O o o
| | | | |
o o O o o
o o O o o
o o O o o

==
o o O o o
o o O o o
O O O O O
o o O o o
o o O o o
=

o o o-o o o
o o o-o o o
o o o-o o o
| |   | | |
o o o-o o o
o o o-o o o
o o o-o o o


o-o-o
| | |
o-o-o
| | |
o-o-o

o o o
| | |
o-o o

o-o o

o o o
o o o

o o
o o
*/

Measured memory_bytes: 9036
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if (s[0] != s[1] || s[1] != s[2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int x, y, z, k; cin>>x>>y>>z>>k;
    vector<ll> a(x), b(y), c(z);
    for(int i=0; i<x; i++) cin>>a[i];
    for(int i=0; i<y; i++) cin>>b[i];
    for(int i=0; i<z; i++) cin>>c[i];

    sort(a.rbegin(), a.rend());
    
    vector<ll> bc;
    for(int i=0; i<y; i++){
        for(int j=0; j<z; j++){
            bc.eb(b[i] + c[j]);
        }
    }

    sort(bc.rbegin(), bc.rend());
    if(k < bc.size()) bc.resize(k);

    vector<ll> ans;
    for(int i=0; i<x; i++){
        for(int j=0; j<bc.size(); j++){
            ans.eb(a[i] + bc[j]);
        }
    }

    sort(ans.rbegin(), ans.rend());

    for(int i=0; i<k; i++){
        cout << ans[i] << endl;
    }
}

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

using pii = pair<int, int>;
using ll  = long long;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for (int i = (j); i < (int)(k); i++)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " : " << x << endl

template <class T>
bool set_min(T &a, const T &b) {
    return a > b ? a = b, true : false;
}
template <class T>
bool set_max(T &a, const T &b) {
    return a < b ? a = b, true : false;
}
// vector
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &a : v) is >> a;
    return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &t : v) os << "\t" << t;
    return os << endl;
}
// pair
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &v) {
    return os << "<" << v.first << ", " << v.second << ">";
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;



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

    ll X; cin >> X;
    ll ans = (X / 500) * 1000 + ((X % 500) / 5) * 5;
    cout << ans << endl;
    return 0;
}


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

long long gcd(long long a, long long b) {
    long long x,y;
    if(a > b){
        y = b;
        x = a;
    }else{
        y = a;
        x = b;
    }

    return ((y==0)? x : gcd(y,x%y));
}

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N){
        cin >> a[i];
    }
    int tmp=1,cnt=0;
    rep(i,N){
        if(a[i] == tmp){
            tmp++;
        }else{
            cnt++;
        }
    }

    cout << ((tmp==1)? -1:cnt) << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
/*ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
*/


/*最小公倍数*/
/*
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
*/

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll a,b,c,x,y,t=0;
    cin>>a>>b>>c>>x>>y;
    if(min(x,y)==x){
        t+=2*min(x,y)*c+abs(max(x,y)-min(x,y))*b;
    }
    else if(min(x,y)==y){
        t+=2*min(x,y)*c+abs(max(x,y)-min(x,y))*a;
        //cout<<2*min(x,y)*c<<endl;
        //cout<<abs(max(x,y)-min(x,y))*a<<endl;;
    }
    


    cout<<min({a*x+b*y,2*max(x,y)*c,t})<<endl;
    


}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/27  Problem: 060_arc_b / Link: https://arc060.contest.atcoder.jp/tasks/arc060_b?lang=en  ----- */
/* ------問題------

2 以上の整数 b および 1 以上の整数 n に対し、関数 f(b,n) を次のように定義します。

n<b のとき f(b,n)=n
n≥b のとき f(b,n)=f(b, floor(n⁄b))+(n mod b)
ここで、floor(n⁄b) は n⁄b を超えない最大の整数を、 n mod b は n を b で割った余りを表します。

直感的に言えば、f(b,n) は、n を b 進表記したときの各桁の和となります。 例えば、

f(10, 87654)=8+7+6+5+4=30
f(100, 87654)=8+76+54=138
などとなります。

整数 n と s が与えられます。 f(b,n)=s を満たすような 2 以上の整数 b が存在するか判定してください。 さらに、そのような b が存在するならば、その最小値を求めてください。

-----問題ここまで----- */
/* -----解説等-----

全探索だけど最後の方ははしょれる

----解説ここまで---- */

LL N;

LL ans = 0LL;


LL f(LL b, LL n) {
	if (n < b)return n;
	else return f(b, n / b) + n % b;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);


	cin >> N;
	LL s; cin >> s;

	ans = LINF;
	if (N == s)ans = N + 1;

	for (LL i = 2; i*i <= N; i++) {
		LL val = f(i, N);
		if (val == s)
			ans = min(ans, i);
	}

	for (LL i = 1; i*i < N; i++) {
		LL b = (N - s) / i + 1;
		if (b > 1) {
			if (f(b, N) == s) {
				ans = min(ans, b);
			}
		}
	}

	if (ans == LINF)ans = -1;
	cout << ans << "\n";

	return 0;
}


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

const double pi = 3.1415;

double R;

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

  cin >> R;

  cout << setprecision(6) << fixed << (R * 2.0) * pi << endl;

  return 0;
}

Measured memory_bytes: 3792
import static java.lang.System.*;
import java.util.*;

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

        int n = sc.nextInt();
		long a = sc.nextInt();
		long b = sc.nextInt();

		int ac=0, bc=0;
		for(long i=a; i>0; i>>=1) if((i&1) > 0) ac++;
	    for(long i=b; i>0; i>>=1) if((i&1) > 0) bc++;
		//out.println(ac + " " + bc);
		
			
		int[] num = new int[n+1];
		Arrays.fill(num, 0);
		num[0] = 1;
		for(int i=0; i<n; i++) 
			for(int j=i; j>=0; j--) num[j+1] += num[j];
        //for(int i=0; i<=n; i++) out.print(num[i] + " ");
		//out.println();
			
		for(int i=Math.min(ac,bc); i<=Math.max(bc,ac); i++) 
			num[i]--;
		
		for(int i=0; i<n; i++) num[i+1] -= num[i];
		
		
		if(num[n] != 0) out.println("NO");
		else {
			out.println("YES");
			search(n, a, b, 0);
		}
    }
	
	static void search(int n, long a, long b, long m) {
		//out.println(a + " " + b + " " + m);
		if((m|(m+1)) == (1<<n)-1) {
			out.println(a);
			out.println(b);
			return;
		}
		
	    for(long i=1; i<(1<<n); i<<=1) {
			if((m&i) ==0 && ((a&i) ^ (b&i)) != 0) {
				m |= i;
				search(n, a, a^((m|m+1)-m), m);
				search(n, (a^((m|m+1)-m))^i, b, m);
				break;
			}
		}
	}

}

Measured memory_bytes: 43564
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, H, W);
  VEC(string, a, H);
  int n = a[0].length() + 2;
  print(string(n, '#'));
  each(x, a) {
    cout << '#' << x << '#' << endl;
  }
  print(string(n, '#'));
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,T;
    cin>>N>>T;
    int c[100];
    int t[100];
    REP(i,N)cin>>c[i]>>t[i];
    int ans = 100000;
    REP(i,N){
        if(t[i] <= T){
            ans = min(ans, c[i]);
        }
    }
    if(ans == 100000){
        PUTS("TLE");
    }else{
        PUTS(ans);
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=b-a+1;
    int l=c/__gcd(c,d)*d;
    int cc=b/c-(a-1)/c;
    int dd=b/d-(a-1)/d;
    int ll=b/l-(a-1)/l;
    ans=ans-cc-dd+ll;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        long n = sc.nextLong();
        long sn = (long)Math.sqrt(n);
        long ans = Long.MAX_VALUE;
        for(long i = 1; i <= sn; i++){
            if(n % i == 0){
                ans = Math.min(ans, i+n/i-2);
            }
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();//a
		int b = sc.nextInt();//b
		int small = 0, lerge = 0;
		if(a >= b) {
			lerge = a;
			small = b;
		}else{
			lerge = b;
			small = a;
		}
		for(int i = 0; i < lerge; i++) {
			System.out.print(small);
		}
		System.out.println();
	
		
		sc.close();
	}

}


Measured memory_bytes: 21844
/*
    Take me to church
    I'll worship like a dog at the shrine of your lies
    I'll tell you my sins and you can sharpen your knife
    Offer me that deathless death
    Good God, let me give you my life
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, cnt, A[N], V[N], U[N], W[N], S[N], M[N], MR[N];
long long P[N];
vector < pair < int , int > > Adj[N];
inline bool CMP(int i, int j)
{
    return (W[i] < W[j]);
}
long long Find(int v)
{
    return ((P[v] < 0) ? v : (P[v] = Find(P[v])));
}
void DFS(int v, int w)
{
    M[v] = 1;
    for (auto u : Adj[v])
    {
        if (u.second <= w)
            cnt ++;
        if (!M[u.first] && u.second <= w)
            DFS(u.first, w);
    }
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++)
        scanf("%d", &A[i]), P[i] = - A[i];
    for (int i = 1; i <= m; i ++)
    {
        scanf("%d%d%d", &V[i], &U[i], &W[i]), S[i] = i;
        Adj[V[i]].push_back({U[i], W[i]});
        Adj[U[i]].push_back({V[i], W[i]});
    }
    sort(S + 1, S + m + 1, CMP);
    for (int j = 1; j <= m; j ++)
    {
        int i = S[j];
        if (Find(V[i]) != Find(U[i]))
            P[Find(V[i])] += P[Find(U[i])], P[Find(U[i])] = Find(V[i]);
        if (- P[Find(V[i])] >= W[i])
            MR[i] = 1;
    }
    for (int j = m; j; j --)
    {
        int i = S[j];
        if (MR[i] && !M[V[i]])
            DFS(V[i], W[i]);
    }
    return !printf("%d\n", m - cnt / 2);
}

Measured memory_bytes: 12288
n,k = map(int,input().split())
p =list(map(int,input().split()))
mx = 0
s = 0
for i in range(k):
    s+=p[i]
mx = s
for i in range(k,n):
    s+=p[i]
    s-=p[i-k]
    if s>mx:
        mx = s
print((mx+k)/2)

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

ll power(ll X,ll Y,ll P){
  vector<ll> digit2(1000),XX(1000);
  ll I,N,mod;
  I=0;
  
  while(Y!=0){
    digit2.at(I)=Y%2;
    Y=Y/2;
    I++;
  }
  N=I;
  
  XX.at(0)=X%P;
  for(I=1;I<N;I++){
    XX.at(I)=(XX.at(I-1)*XX.at(I-1))%P;
  }
  
  mod=1;
  for(I=0;I<N;I++){
    if(digit2.at(I)==1){
      mod=(mod*XX.at(I))%P;
    }
  }
  
  if(mod<0){
    mod=mod+P;
  }
  
  return mod;
}

int main(){
  ll n,k,i;
  cin >> n >> k;
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  
  ll p=1000000007;
  ll c=1,s=0;
  for(i=k-1;i<n;i++){
    s=(s+c*(a.at(i)-a.at(n-i-1)))%p;
    c=(((c*(i+1))%p)*power(i-k+2,p-2,p))%p;
  }
  
  if(s<0){
    s += p;
  }
  
  cout << s << endl;
}

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

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

	ll int w[n], v[n];

	for(int i=0; i<n ;i++)
		cin >> w[i] >> v[i];

	ll int dp[n+1][W+1];

	for(int i=0; i<=n; i++)
		dp[i][0] = 0;
	for(int i=0; i<=W; i++)
		dp[0][i] = 0;

	for(int i=1; i<=n; i++)
	{
		for(int j = 1; j<=W; j++)
		{
			if(w[i-1] >	 j)
				dp[i][j] = dp[i-1][j];
			else
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1]);
		}
	}
	cout << dp[n][W];

	return 0;
}

Measured memory_bytes: 79104
fun main(args: Array<String>) {
    val l = readLine()!!.split(' ').map { it.toLong() }
    if (l[1] == 0L) {
        println(0)
        return
    }
    val r = l[0]%(l[1]+l[2])
    println(Math.min(r, l[1]) + (l[0]-r)/(l[1]+l[2])*l[1])
}


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

int main(){
  	int n;
  	cin >> n;
  	int p[n+5];
  	for(int i=1;i<=n;i++) cin >> p[i];
  	int ans=1;
  	int min=p[1];
  	for(int i=2;i<=n;i++){
    	if(min>=p[i]){
        	min = p[i];
          	ans++;
        }
    }
  	
  	cout << ans;
	return 0;
}




Measured memory_bytes: 1024
a,b,c,d=map(int, input().split())
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

ans_b=b-(b//c)-(b//d)+(b//(lcm(c,d)))
ans_a=a-(a//c)-(a//d)+(a//(lcm(c,d)))
ans=ans_b-ans_a

if a%c!=0 and a%d!=0:
    ans+=1
print(ans)

Measured memory_bytes: 62096
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		char[] c = {sc.next().charAt(0), sc.next().charAt(0), sc.next().charAt(0)};
		Arrays.sort(c);

		System.out.println((c[0] == c[1] && c[1] != c[2]) || (c[0] != c[1] && c[1] == c[2]) ? "Yes" : "No");
	}
}

Measured memory_bytes: 35732
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      int n = int.Parse(ReadLine());
      List<int> x = ReadLine().Split().ToList().ConvertAll(x=>int.Parse(x));
      
      int Mx= x.Max();
      int mx= x.Min();
      int ans =(int)Math.Pow(10,9)+1;
      int hantei=0;
      
      
      for (int j=mx;j<=Mx;j++)
      {
        hantei =0;
        for (int i=0;i<n;i++)
        {
          hantei+=(int)Math.Pow(Math.Abs(x[i]-j),2);
        }
        if (ans>=hantei)
        {
          ans=hantei;
        }
      }
      WriteLine(ans);
      
    }
}

Measured memory_bytes: 28656
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {int operator()(int x) const { return x ^ RANDOM; }};
string toString(long long x){stringstream ss;ss << x;string str = ss.str();return str;}
long long fastpow(long long x,long long k){if(!k)return 1;if(k & 1)return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
long long ans = fastpow(x,k/2);ans %= MOD;ans *= ans;ans %= MOD;return ans;}
long long sumF(long long x){int s = 0;while(x)s += x%10,x /= 10;return s;}
bool isS(char c){return (c >= 'a' && c <= 'z');}
bool isB(char c){return (c >= 'A' && c <= 'Z');}
bool isD(char c){return (c >= '0' && c <= '9');}
bool isSqrt(long long x){ long long f = sqrt((long double)x + 0.5); return f*f == x;}
long long lcm(long long a,long long b){return a * (b / __gcd(a,b));}
const string moves = "LURD";
const string altmoves = "RDLU";
int h,w,n,xb,yb;
bool offBoard(int x,int y)
{
    return (x <= 0 || x > h || y <= 0 || y > w);
}
int main()
{
    IO;
    string s,t;
    cin >> h >> w >> n >> xb >> yb >> s >> t;
    for(int j = 0;j < moves.size();j++)
    {
        char c = moves[j];
        char c2 = altmoves[j];
        int tx = xb;
        int ty = yb;
        for(int i = 0;i < n;i++)
        {
            if(c == s[i])
            {
                if(c == 'L')
                    ty--;
                else if(c == 'R')
                    ty++;
                else if(c == 'U')
                    tx--;
                else
                    tx++;
                if(offBoard(tx,ty))
                {
                    cout << "NO";
                    return 0;
                }
            }
            if(c2 == t[i])
            {
                if(c2 == 'L' && ty > 1)
                    ty--;
                else if(c2 == 'R' && ty < w)
                    ty++;
                else if(c2 == 'U' && tx > 1)
                    tx--;
                else if(tx < h)
                    tx++;
            }
        }
    }
    cout << "YES";
    return 0;
}


Measured memory_bytes: 920
n = int(input())
hL = list(map(int, input().split()))

dp = [10**10]*n
dp[0] = 0
dp[1] = abs(hL[1] - hL[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(hL[i]-hL[i-1]), dp[i-2]+abs(hL[i]-hL[i-2]))
print(dp[n-1])

Measured memory_bytes: 13924
#include <iostream>
#include <cstdlib>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
    vector<int> n;
    n.resize(3);
    cin >> n[0] >> n[1] >> n[2];
    sort(n.begin(), n.end());
    int answer;
    answer = (10 * n[2]) + n[1] + n[0];
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<ll> a(n), s(n+1);
  rep(i, n) {
    cin >> a[i];
    --a[i];
  }
  rep(i, n) s[i+1] = (a[i]+s[i])%k;
  map<ll, int> mp;
  ll ans = 0;
  rep(i, n+1) {
    ans += mp[s[i]];
    mp[s[i]]++;
    if (i >= k-1) 
      mp[s[i-k+1]]--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 15872
import java.util.*;

// C - Poll
// https://atcoder.jp/contests/abc155/tasks/abc155_c
public class Main {

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

        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            String word = scanner.next();
            if (map.containsKey(word)) {
                map.put(word, map.get(word) + 1);
            } else {
                map.put(word, 1);
            }
        }
        scanner.close();

        List<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet());

        // count: desc, word: asc
        list.sort((o1, o2) -> {
            int compare = o2.getValue() - o1.getValue();
            if (compare == 0) {
                return o1.getKey().compareTo(o2.getKey());
            }
            return compare;
        });

        int maxCount = list.get(0).getValue();
        for (Map.Entry<String, Integer> entry : list) {
            if (maxCount == entry.getValue()) {
                System.out.println(entry.getKey());
            }
        }
    }
}


Measured memory_bytes: 90576
#include "bits/stdc++.h"

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

using namespace std;

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

	int ans = 0;
	rep(i, S.size()) {
		if (S[i] != S[S.size() - 1 - i])ans++;
	}
	cout << ans / 2;
}

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

int main() {
  int L, R;
  cin >> L >> R;
  if (R - L + 1 >= 2019 || L == 0) {
    cout << 0 << endl;
  } else {
    vector<int> m(R - L + 1);
    for (int i = L; i <= R; ++i)
      m[i - L] = i % 2019;
    int ans = 1000000000;
    for (int i = 0; i < R - L + 1; ++i)
      for (int j = i + 1; j < R - L + 1; ++j)
        ans = min(ans, (m[i] * m[j]) % 2019);
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	LL A,B;
	cin >> A >> B;
	if( A<=0 && 0<=B){
		cout << "Zero" << endl;
		return;
	}
	if( 0 < A ){
		cout << "Positive" << endl;
		return;
	}
	//A<=B<0
	LL res = B-A+1;
	if( res & 1 ){
		cout << "Negative" << endl;
	}else{
		cout << "Positive" << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


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

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s;
    int k;
    cin >> s >> k;
    for (int i = 0; i < s.length()-1; ++i) {
        if('z' - s[i] < k && s[i] != 'a'){
            k -= ('z' - s[i] + 1);
            s[i] = 'a';
        }
    }
    s[s.length()-1] = char('a' + ((s[s.length()-1] - 'a') + k) % 26);
    cout << s << "\n";
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    
    if(A==B){
        cout << C << endl;
    }else if(B==C){
        cout << A << endl;
    }else{
        cout << B << endl;
        
    }
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vll a(n),b(n);
    priority_queue<pair<ll,ll> > pq;
    REP(i,n){
        cin >> a[i] >> b[i];
        pair<ll,ll> p = make_pair(b[i],m-a[i]);
        pq.push(p);
    }
    
    ll ans = 0;
    vll day(m);
    REP(i,m){
        day[i]=i;
    }
    while(!pq.empty()&&(int)day.size()>0){
        pair<ll,ll> p=pq.top();
        pq.pop();
        auto itr = upper_bound(ALL(day), p.se);
        if(itr==day.begin()){
            continue;
        }else{
            itr--;
            ans+=p.fi;
            day.erase(itr);
        }
        
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4208
#include <iostream>
#include <vector>
#include <algorithm>

long get_last_edge(int i, int j, std::vector<int> &L);

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> L(N);
  for (int i = 0; i < N; i++) std::cin >> L.at(i);
  sort(L.begin(), L.end());
  long ans = 0;
  for (int i = 0; i < N-2; i++)
  {
    for (int j = i+1; j < N-1; j++)
    {
      ans += get_last_edge(i, j, L);
      // std::cout << "i = " << i << ", j = " << j << ", ans = " << ans << std::endl;
    }
  }
  std::cout << ans << std::endl;
}

/* ++++++++++ function ++++++++++ */
long get_last_edge(int i, int j, std::vector<int> &L)
{
  long lower = j+1, upper = L.size();
  if (L.at(i) + L.at(j) <= L.at(lower)) return 0;
  while (upper - lower != 1)
  {
    long mid = (upper + lower)/2;
    if (L.at(i) + L.at(j) > L.at(mid)) lower = mid;
    else upper = mid;
  }
  return lower - j;
}


Measured memory_bytes: 256