akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;

int main(){
    int h, w; cin >> h >> w;
    vector<string> field(h);
    for(auto& v:field){
        cin >> v;
    }
    vector<vector<int>> lr(h+1, vector<int>(w+1, 0));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(field[i][j] == '.'){
                lr[i+1][j+1] = lr[i+1][j] + 1;
            }
            if(field[i][j] == '#'){
                lr[i+1][j+1] = 0;
            }
        }
    }
    for(int i=0; i<h; i++){
        for(int j=w; j>0; j--){
            if(lr[i][j-1] != 0){
                lr[i][j-1] = max(lr[i][j-1], lr[i][j]);
            }
        }
    }
    vector<vector<int>> ud(h+1, vector<int>(w+1, 0));
    for(int i=0; i<w; i++){
        for(int j=0; j<h; j++){
            if(field[j][i] == '.'){
                ud[j+1][i+1] = ud[j][i+1] + 1;
            }
            if(field[j][i] == '#'){
                ud[j+1][i+1] = 0;
            }
        }
    }
    for(int i=0; i<w; i++){
        for(int j=h; j>0; j--){
            if(ud[j-1][i] != 0){
                ud[j-1][i] = max(ud[j-1][i], ud[j][i]);
            }
        }
    }
    // Debug
    // for(auto& line:ud){
    //     for(auto& v:line){
    //         cout << v << " ";
    //     }
    //     cout << endl;
    // }
    int ans = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            ans = max(ans, lr[i+1][j+1] + ud[i+1][j+1] - 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35840
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] rabbits = new int[N];
		for(int i=0; i<N; ++i) {
			rabbits[i] = sc.nextInt();
		}
		
		int sum = 0;
		for(int i=0; i<N; ++i) {
			if(i == rabbits[rabbits[i]-1]-1)
				++sum;
		}
		sum = sum/2;
	
		System.out.println(sum);
		sc.close();
	}
}

Measured memory_bytes: 33152
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)

int main(){
	ll h, w;
	cin >> h >> w;
	ll ans=(ll)(1e10);
	if(h%3==0 || w%3==0) ans=0;
	else if(h==2 || w==2) ans=1;
	else if(h%2==0 && w%2==0) ans=min(h/2, w/2);
	else{
		for(ll i=1; i<w-1; i++){
			ll h1=h/2, h2=(h+1)/2;
			ll s1=h*i, s2=h1*(w-i), s3=h2*(w-i);
			ll s_max=max(s1, s3);
			ll s_min=min(s1, s2);
			if(ans>s_max-s_min) ans=s_max-s_min;
		}
		for(ll i=1; i<h-1; i++){
			ll w1=w/2, w2=(w+1)/2;
			ll s1=w*i, s2=w1*(h-i), s3=w2*(h-i);
			ll s_max=max(s1, s3);
			ll s_min=min(s1, s2);
			if(ans>s_max-s_min) ans=s_max-s_min;
		}
		ll min_l=min(h, w);
		ans=min(ans, min_l);
	}
	cout << ans << endl;
	return 0;
}

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

void chmin(int& x, int y)
{
  x = min(x, y);
}
void chmax(int& x, int y)
{
  x = max(x, y);
}

int main()
{
  int Q, H, W;
  string S[50];

  cin >> Q;
  while(Q--) {
    cin >> H >> W;

    string chars = "";
    for(int i = 0; i < H; i++) {
      cin >> S[i];
      chars += S[i];
    }
    sort(chars.begin(), chars.end());
    chars.erase(unique(chars.begin(), chars.end()), chars.end());
    vector< int > x1(chars.size(), W), x2(chars.size(), 0);
    vector< int > y1(chars.size(), H), y2(chars.size(), 0);
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        int pos = chars.find(S[i][j]);
        chmin(x1[pos], j);
        chmax(x2[pos], j);
        chmin(y1[pos], i);
        chmax(y2[pos], i);
      }
    }
    map< char, int > xx1, xx2, yy1, yy2;
    // ???????????¨???????????????????????¨???????????????
    for(int i = 0; i < chars.size(); i++) {
      xx1[chars[i]] = x1[i];
      xx2[chars[i]] = x2[i];
      yy1[chars[i]] = y1[i];
      yy2[chars[i]] = y2[i];
    }

    bool Judge = false;
    bool used[50][50];

    do {
      Judge = true;
      memset(used, false, sizeof(used));
      for(int i = 0; i < chars.size(); i++) {
        for(int j = xx1[chars[i]]; j <= xx2[chars[i]]; j++) {
          for(int k = yy1[chars[i]]; k <= yy2[chars[i]]; k++) {
            if(used[j][k]++) continue;
            if(S[k][j] != chars[i]) {
              Judge = false;
              goto myon;
            }
          }
        }
      }
    myon: ;
    } while(!Judge && next_permutation(chars.begin(), chars.end()));
    if(Judge) cout << "SAFE" << endl;
    else cout << "SUSPICIOUS" << endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define inin(a, n, i) memset(a, i, sizeof(a[0])*(n))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define trav(x, c) for(auto& x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))
	
template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }
template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; }

void read() {}
void print() {}
template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); }
template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); }
template<class... Args> void println(Args... args) { print(args...); cout << '\n'; }

#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

const int INF = 0x3F3F3F3F;
const int MAXN = (int) 1e6;
const int MOD = (int) 1e9+7;

//=========================

void run_test() {
	ll d, t, s;
	read(d, t, s);

	if(s * t >= d) println("Yes");
	else println("No");
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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(nullptr);
    int i,j;
    ll n,x,t;
    cin >> n >> x >> t;
    cout << (n+x-1)/x * t << endl;
  
}

Measured memory_bytes: 3604
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def solve():
    L = 100
    G = [[] for i in range(L)]
    for line in readlines():
        a, b = map(int, line.split())
        if a != 0 != b:
            G[a-1].append(b-1)
            G[b-1].append(a-1)
            continue
        ok = 1
        if len(G[0]) % 2 == 0 and len(G[1]) % 2 == 0:
            ok = 0
        else:
            for i in range(2, L):
                if len(G[i]) == 0:
                    continue
                if len(G[i]) % 2 == 1:
                    ok = 0
        write("OK\n" if ok else "NG\n")

        G = [[] for i in range(L)]
solve()



Measured memory_bytes: 5620
#include <iostream>
#include <array>

int main(int argc, char const* argv[])
{
	int c,r;
	std::array<std::array<unsigned,101>,101> table{};
	std::cin >> r >> c;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			std::cin >> table[i][j];
		}
	}

	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];
		}
	}
	for (int j = 0; j < c; j++) {
		table[r][c] += table[r][j];
	}

	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			if (j) {
				std::cout << " ";
			}
			std::cout << table[i][j];
		}
		std::cout << std::endl;
	}

	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> a(N);
    for (auto &i : a) cin >> i;

    vector<int> box(N);
    repr(i, N) {
        int X = i + 1;
        bool res = 0;
        for (int j = 2; j * X <= N; ++j) {
            res ^= box[j*X-1];
        }
        if (a[i] != res) box[i] = 1;
    }

    vector<int> ans;
    rep(i, N) {
        if (box[i]) ans.push_back(i+1);
    }

    cout << ans.size() << endl;
    for (auto &i : ans) cout << i << " ";
    cout << endl;
}

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

int main()
{
  string s;
  cin >> s;
  
  int sz = s.size();
  rep(i, sz){
    if(s[i] != s[sz - i - 1]){
      cout << "No" << endl;
      return 0;
    }
  }
  int sz1 = (sz - 1)/2;
  int sz2 = (sz + 3)/2;
  rep(i, sz1){
    if(s[i] != s[sz1 - i - 1]){
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; sz2 < sz; sz2++){
    if(s[sz/2+1+i] != s[sz - i - 1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define int long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define endl "\n"
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());

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

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

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

int power(int x, int y, int mod = 2e18) { int ans = 1; x %= mod; while (y) {if (y & 1)ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1;} return ans;}
int modinv(int a, int m) {return power(a, m - 2, m);}


int dp[3001][3001][2];
vector<int> a(3001);
int n;
int ans(int l , int r, int chance) {
	trace(l, r, chance);
	if (l <= 0 || l > n || r <= 0 || r > n || l > r) {
		return (chance == 1 ? LLONG_MIN : LLONG_MAX);
	}
	if (l == r) {
		return (chance == 1 ? a[l] : -a[l]);
	}
	if (dp[l][r][chance] != -1)
		return dp[l][r][chance];
	if (chance) {
		return dp[l][r][chance] = max(ans(l + 1, r, 1 - chance) + a[l], ans(l, r - 1, 1 - chance) + a[r]);
	}
	else {
		return dp[l][r][chance] = min(ans(l + 1, r, 1 - chance) - a[l], ans(l, r - 1, 1 - chance) - a[r]);
	}
}

void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	memset(dp, -1, sizeof(dp));
	cout << ans(1, n, 1) << endl;
}
signed main() {
	IOS
	int t = 1, T = 1;
	// cin>>t;
	while (t--) {
		// cout<<"Case #"<<T<<": ";
		solve();
		// ++T;
	}
	return 0;
}

Measured memory_bytes: 141184
#include <iostream>

using namespace std;

int main()
{
	long double W, H, x, y;
	cin >> W >> H >> x >> y;
	
	cout << ((W * H) / 2.0) << " " << (((W / 2 == x) && (H / 2 == y))?'1':'0') << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int main() {
    int x=0;
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(A>=0&&C>=0&&A<B&&C<D&&B<=100&&D<=100){
        if(A<C){
            if(B>D){
                x=C-D;
            }
            else if(D>B){
                if (B>C){
                    x=C-B;
                }
            }
            else{
                x=C-B;
            }

        } else if (A>C){
             if(B>D){
                 if(D>A)
                 x=A-D;
             }else if(D>B){
                 if(B>C){
                     x=A-B;
                 }
             }else{
                 x=A-B;
             }
        }else{
            if(B>D){
                x=A-D;
            }else if(B<D){
                x=A-B;
            } else{
                x=A-B;
            }
        }

 printf("%d",abs(x));
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
int main(){
	string str;
	getline(cin, str);
	int str_size = str.size();
	for(int i=0;i<str_size;i++){
		if(islower(str[i]))
			str[i] = toupper(str[i]);
	}
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef long long LL;
const int INF = 999999999;

int main(){
    string s;
    cin >> s;
    bool f = 0;
    if(s[5] - '0' > 0) f=1;
    else if(s[6] - '0' > 4) f=1;
    cout << (f ? "TBD" : "Heisei" ) << endl;

}



Measured memory_bytes: 256
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/28 06:48:30 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

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

// TOP
void	Main()
{
	int	n;
	cin >> n;

	vector<int>	V(n);
	rep(i, n)
		cin >> V.at(i);

	sort(V.begin(), V.end());
	int	cnt;
	cnt = 0;
	rep(i, n - 2)
	{
		for (int j = i + 1; j < n - 1; j++)
		{
			for (int k = j + 1; k < n; k++)
			{
				if (V.at(k) < V.at(i) + V.at(j))
					cnt++;
			}
		}
	}
	cout << cnt << endl;
}
// END

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


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

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

int main(void){
    int N;cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N;i++)cin >> A[i];
    sort(A.begin(),A.end(),greater<long long>());
    
    if(N%2 == 0){
        long long res = 0;
        for(int i = 0; i < N/2 -1 ;i++)res += A[i] * 2;
        res += A[N/2 - 1];
        res -= A[N/2];
        for(int i = N/2 + 1; i < N; i++)res -= A[i] * 2;
        cout << res << endl;
    }else{
        long long res1 = 0;
        for(int i = 0; i < N/2 -1 ;i++)res1 += A[i] * 2;
        res1 += A[N/2 - 1] + A[N/2];
        for(int i = N/2 + 1; i < N; i++)res1 -= A[i] * 2;
        
        long long res2 = 0;
        for(int i = 0; i < N/2 ;i++)res2 += A[i] * 2;
        res2 -= A[N/2] +  A[N/2 + 1];
        for(int i = N/2 + 2; i < N; i++)res2 -= A[i] * 2;        
        cout << max(res1,res2) << endl;        
        
        
        
        
        
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb(x) push_back((x))
#define line() cerr << "DEBUG @" << __LINE__ << endl;
#define debug(x) \
  cerr << "DEBUG @" << __LINE__ << " -> " << #x << " = " << x << endl;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> v(n);
  for (ll &x : v) cin >> x;
  vector<int> pre(n + 1);
  const ll mod = 1e9 + 7;
  for (int i = 1; i <= n; i++) pre[i] = (pre[i - 1] + v[i - 1]) % mod;
  auto get = [&](int l, int r) {
    return (pre[r] - pre[l] + mod) % mod;
  };
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans = (ans + (v[i] * get(i + 1, n) % mod)) % mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 5544
//
//  main.cpp
//  6
//
//  Created by 5201-mac on 17/8/12.
//  Copyright © 2017年 5201-mac. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;
int main() {
    int a,b,c,d;
    int x[105]={0};
    cin>>a>>b>>c>>d;
    for(int i=a;i<=b;i++)
        x[i]++;
    for(int i=c;i<=d;i++)
        x[i]++;
    int s=0;
    for(int i=1;i<=100;i++)
        if(x[i]==2&&x[i-1]==2)
            s++;
    printf("%d\n",s);
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>

using namespace std;

int main ()
{
    int y , m ,d ;
    while (scanf ("%d/%d/%d",&y,&m,&d)!=EOF)
    {
        if (m>9&&d>9)
        printf ("2018/%d/%d\n",m,d);
        else if(m>9)  printf ("2018/%d/0%d\n",m,d);
        else if (d>9) printf ("2018/0%d/%d\n",m,d);
        else printf ("2018/0%d/0%d\n",m,d);
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;

int main(){
    int N; cin >> N;
    cout << N*N*N << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<17,INF=1<<30;

template<typename T>
struct SegmentTree{
    using F=function<T(T,T)>;
    
    int n;
    vector<T> dat;
    F f;
    T ti;
    
    SegmentTree(int n_ ,F f ,T ti) :f(f),ti(ti){
        n=1;
        while(n<n_) n*=2;
        dat.assign(2*n-1,ti);
    }
    
    SegmentTree(int n_ ,vector<T> &v ,F f,T ti) :f(f),ti(ti){
        n=1;
        while(n<n_) n*=2;
        dat.assign(2*n-1,ti);
        
        for(int i=n-1;i-(n-1)<v.size();i++) dat[i]=v[i-(n-1)];
        
        for(int i=n-2;i>=0;i--) dat[i]=f(dat[i*2+1],dat[i*2+2]);
    }
    
    void update(int k,T x){
        k+=n-1;
        dat[k]=x;
        
        while(k){
            k=(k-1)/2;
            dat[k]=f(dat[k*2+1],dat[k*2+2]);
        }
    }
    
    T query_(int a,int b,int k,int l,int r){
        if(r<=a||b<=l) return ti;
        if(a<=l&&r<=b) return dat[k];
        else{
            T vl=query_(a,b,2*k+1,l,(l+r)/2);
            T vr=query_(a,b,2*k+2,(l+r)/2,r);
            return f(vl,vr);
        }
    }
    
    T query(int a,int b){
        return query_(a,b,0,0,n);
    }
    
    T get(int k){
        return dat[k+n-1];
    }
    
};

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

int main(){
    
    int N;cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    SegmentTree<int> seg(N,A,[](int a,int b){return gcd(a,b);},0);
    
    int ans=0;
    
    for(int i=0;i<N;i++){
        int a=seg.get(i);
        seg.update(i,0);
        ans=max(ans,seg.query(0,N));
        seg.update(i,a);
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 1664
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    t = 0
    for i in range(n-1, -1, -1):
        while True:
            if (ab[i][0] + t) % ab[i][1] == 0:
                break
            else:
                t += (ab[i][1] - (ab[i][0] + t) % ab[i][1])
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 56028
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>	
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int ketawa(int a) {
	if (a < 10)return a;
	else return a % 10 + ketawa(a / 10);
}

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;

int main()
{
	cin >> s;
	if (s.substr(0, 4) == "YAKI")
		cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N,M,a,b; cin>>N>>M;
	vector<int> node(N,0);
	rep(i,M){
		cin>>a>>b;
		node[--a]++;
		node[--b]++;
	}
	bool ans = true;
	rep(i,N)if(node[i]%2 == 1)ans = false;
	cout<<((ans)?"YES":"NO")<<endl;
	return 0;
}

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

int main() {
	long long x, y;
	cin >> x >> y;
	if (x % y == 0) {
		cout << -1;
		return 0;
	}
	if ((x * 2) % y != 0)
		cout << x * 2;
	else 
		cout << x * 3;
	
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

const ll INF = (1ll<<60);

void rotate(vl &x, vl &y, vl &p){
    ll N = x.size();
    REP(i, N) swap(x[i], y[i]);
    REP(i, N) x[i] *= -1;
    REP(i, N) p[i] = (p[i]+1)%4;
    return;
}

ll tate(vl &X, vl &Y, vl &P){
    ll res = INF;
    ll N = X.size();
    map<ll, map<ll, set<int>>> mp1;
    REP(i, N){
        mp1[X[i]][P[i]].insert(Y[i]);
    }
    for(auto &m: mp1){
        auto &r = m.second;
        for(auto &s: r[1]){
            auto itr = r[3].lower_bound(s);
            if(itr != r[3].end()){
                chmin(res, (*itr-s)*5ll);
            }
        }
    }
    //dump(res)
    return res;
}

ll yoko(vl &X, vl &Y, vl &P){
    ll res = INF;
    ll N = X.size();
    map<ll, map<ll, set<int>>> mp2;
    REP(i, N){
        mp2[X[i]+Y[i]][P[i]].insert(Y[i]);
    }
    for(auto &m: mp2){
        auto &r = m.second;
        for(auto &s: r[1]){
            auto itr = r[0].lower_bound(s);
            if(itr != r[0].end()){
                chmin(res, (*itr-s)*10ll);
            }
        }
    }
    //dump(res)
    return res;
}

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

    map<char, ll> mp;
    mp['R'] = 0;
    mp['U'] = 1;
    mp['L'] = 2;
    mp['D'] = 3;

    ll N;
    cin >> N;
    vl X(N), Y(N), P(N);
    REP(i, N){
        cin >> X[i] >> Y[i];
        char tmp;
        cin >> tmp;
        P[i] = mp[tmp];
    }

    ll res = INF;
    REP(t, 4){
        ll tt = tate(X, Y, P);
        ll yy = yoko(X, Y, P);
        chmin(res, tt);
        chmin(res, yy);
        rotate(X, Y, P);
    }

    if(res == INF) cout << "SAFE\n";
    else cout << res << endl;

    return 0;
}

Measured memory_bytes: 72848
package main

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

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt64()
	tmp := N
	var res int64
	for tmp > 0 {
		res += tmp % 10
		tmp /= 10
	}
	if N%res == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>

int main(){
    double a, b, x;
    std::cin >> a >> b >> x;

    double ref = a * b / 2, filled = x / a, ans = 0;
    if(filled <= ref){
        ans = M_PI / 2 - std::atan2(2 * filled, std::pow(b, 2));
    }else{
        ans = std::atan2(2 * (a * b - filled), std::pow(a, 2));
    }
    
    std::cout << std::fixed << std::setprecision(7) << ans / M_PI * 180 << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n;
  cin>>n;

  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
  }

  int x=1;
  int ans=n;
  rep(i,n){
    if(p[i]==x) {
      ans--;
      x++;
    }
  }
  if(ans==n) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 3976
#include<iostream>
#include<string>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    switch(a+b){
        case 3 : cout << "3";  break;
        case 4 : cout << "2";  break;
        default : cout << "1"; break;
    }
    return 0;
}

Measured memory_bytes: 256
import Data.List

mPrime = 10^9 + 7

mAdd :: Int -> Int -> Int
mAdd x y = (x + y) `mod` mPrime

mSub :: Int -> Int -> Int
mSub x y = (mPrime + x - y) `mod` mPrime

mMul :: Int -> Int -> Int
mMul x y = (x * y) `mod` mPrime

mInv :: Int -> Int
mInv x = let (_, a, _) = eGCD x mPrime in if a < 0 then a + mPrime else a

eGCD :: Int -> Int -> (Int,Int,Int)
eGCD 0 b = (b, 0, 1)
eGCD a b = let (g, s, t) = eGCD (b `mod` a) a
           in (g, t - (b `div` a) * s, s)

mLstMul = foldl1' mMul

solve :: Int -> Int -> Int
solve n 1 = 1
solve n m = mLstMul $ map f (primeFact m)
  where f k = combi (n+k-1) k

sieve :: [Int]
sieve = 2 : sieve_sub [2] [3..]

sieve_sub :: [Int] -> [Int] -> [Int]
sieve_sub (n:yet) cand =
  let
    (cnfmd, rem) = span (< n*n) cand
    newcand = filter (\i -> i `mod` n /= 0) rem
  in cnfmd ++ sieve_sub (yet ++ cnfmd) newcand

primes = takeWhile (< 32000) sieve

primeFact :: Int -> [Int]
primeFact x = pf0 x sieve

pf0 1 _ = []
pf0 x [] = [1]
pf0 x (p:sieves)
  | p*p > x = [1]
  | kk > 0 = kk : pf0 yy sieves
  | otherwise = pf0 x sieves
  where (kk, yy) = pf1 p x
        pf1 p x | mm > 0 = (0, x)
                | otherwise = let (kk', yy') = pf1 p dd in (kk'+1, yy')
          where (dd,mm) = divMod x p

combi n0 r0 | r0 > (n0 - r0) = combi n0 (n0 - r0)
combi n0 0 = 1
combi n0 r0 = (mLstMul [n0,n0-1..(n0-r0+1)]) `mMul` (mInv (mLstMul [r0,r0-1..1]))

main = do
  cont <- getContents
  let [n,m] = map read $ words cont
      ans = solve n m
  putStrLn $ show $ ans


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll A, B, C;

int main() {
    cin >> A >> B >> C;
    if(A % 2 && B % 2 && C % 2) {
        cout << min(A * B, min(B * C, C * A)) << "\n";
    } else {
        cout << 0 << "\n";
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
struct unifnd{
  VI ht,pr;
  in fnd(in a){
    in ta=a;
    while(a!=pr[a])a=pr[a];
    in tt=ta;
    while(ta!=a){
      tt=pr[ta];
      pr[ta]=a;
      ta=tt;
    }
    return a;
  }
  void uni(in a, in b){
    a=fnd(a);
    b=fnd(b);
    if(a==b)return;
    if(ht[b]<ht[a])swap(a,b);
    pr[a]=b;
    ht[b]+=(ht[a]==ht[b]);
  }
  void ini(in n){
    ht.resize(n);
    pr.resize(n);
    forn(i,n){
      ht[i]=0;
      pr[i]=i;
    }
  }
};
unifnd tf1,tf2;
map<pair<in,in>,in> ct;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,k,l;
  cin>>n>>k>>l;
  tf1.ini(n);
  tf2.ini(n);
  in ta,tb;
  forn(z,k){
    cin>>ta>>tb;
    tf1.uni(ta-1,tb-1);
  }
  forn(z,l){
    cin>>ta>>tb;
    tf2.uni(ta-1,tb-1);
  }
  forn(i,n)
    ++ct[MP(tf1.fnd(i),tf2.fnd(i))];
  forn(i,n)
    cout<<(ct[MP(tf1.fnd(i),tf2.fnd(i))])<<" ";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 18176
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000

vector<vector<int>> table;
int K;

int calc(int i, int j) {
    int sum = 0;
    if (i + K - 1 >= 2 * K) {
        sum += table[(i + K - 1) % (2 * K)][min(j + K - 1, 2 * K - 1)];
        if (j > 0) sum -= table[(i + K - 1) % (2 * K)][j - 1];
    }
    if (j + K - 1 >= 2 * K) {
        sum += table[min(i + K - 1, 2 * K - 1)][(j + K - 1) % (2 * K)];
        if (i > 0) sum -= table[i - 1][(j + K - 1) % (2 * K)];
    }
    if (j + K - 1 >= 2 * K && i + K - 1 >= 2 * K) {
        sum += table[(i + K - 1) % (2 * K)][(j + K - 1) % (2 * K)];
    }
    sum += table[min(i + K - 1, 2 * K - 1)][min(j + K - 1, 2 * K - 1)];
    if (i > 0) sum -= table[i - 1][min(j + K - 1, 2 * K - 1)];
    if (j > 0) sum -= table[min(i + K - 1, 2 * K - 1)][j - 1];
    if (i > 0 && j > 0) sum += table[i - 1][j - 1];
    return sum;

}


int main() {
    int N;
    cin >> N >> K;
    table = vector<vector<int>>(2 * K, vector<int>(2 * K, 0));
    int x, y;
    char c;
    rep(i, N) {
        cin >> x >> y >> c;
        if (c == 'W') x += K;
        table[x % (K * 2)][y % (K * 2)]++;
    }
    rep(i, 2 * K) {
        rep(j, 2 * K) {
            if (i > 0) table[i][j] += table[i - 1][j];
            if (j > 0) table[i][j] += table[i][j - 1];
            if (i > 0 && j > 0) table[i][j] -= table[i - 1][j - 1];

        }
    }
    int ans = -INF;
    int sum;
    rep(i, 2 * K) {
        rep(j, 2 * K) {
            sum = calc(i, j);
            //sum += calc(i, j);
            int ii = (i + K) % (2 * K);
            int jj = (j + K) % (2 * K);
            sum += calc(ii, jj);

            ans = max(ans, sum);
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 16000
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        if ((b - a) % 2 == 0) {
            System.out.println((b - a) / 2);
            return;
        }
        System.out.println(Math.min(a - 1, n - b) + 1 + (b - a - 1) / 2);
    }

}


Measured memory_bytes: 21972
import java.util.Scanner;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) {

		//
		ArrayList<Integer> big_list = new ArrayList<Integer>();
		ArrayList<Integer> small_list = new ArrayList<Integer>();

		int big = 0;
		int small = 0;

		// テキスト入力
		Scanner sc = new Scanner(System.in);

		while (true) {
			// 入力文字を取得
			int first = sc.nextInt();
			int second = sc.nextInt();

			//
			if (first == 0 && second == 0) {
				break;
			}

			// 小さい順に並べる
			if (first >= second) {
				//
				big = first;
				small = second;
			} else {
				big = second;
				small = first;
			}

			// リストに入れる
			big_list.add(big);
			small_list.add(small);
		}

		// ループ
		for (int i = 0; i < big_list.size(); i++)
			// 出力
			System.out.println(small_list.get(i) + " " + big_list.get(i));
	}
}

Measured memory_bytes: 27756
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	h, w, k = map(int, sys.stdin.readline().split())
	c = []
	for i in range(h):
		c.append(list(input()))
	log.print(c)
	ans = 0
	for i in range(2**h):
		gyou = []
		for l in range(h):
			if i >> l & 1:
				gyou.append(l)
		for j in range(2**w):
			retu = []
			for l in range(w):
				if j >> l & 1:
					retu.append(l)
			count = 0
			for l in range(h):
				for m in range(w):
					if l in gyou or m in retu:
						continue
					if c[l][m] == "#":
						count += 1
			if count == k:
				ans += 1
	print(ans)


main()

Measured memory_bytes: 70000
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1LL<<55LL; 
int cnt;
void merge(int *A,int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int L[n1+1],R[n2+1];
  for(int i=0;i<n1;i++) L[i]=A[left+i];
  for(int i=0;i<n2;i++) R[i]=A[mid +i];
  L[n1]=INF;
  R[n2]=INF;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]) A[k]=L[i++];
    else A[k]=R[j++];
  }
}
void mergeSort(int *A,int left,int right){
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;
  cin>>n;
  int S[n];
  for(int i=0;i<n;i++) cin>>S[i];
  cnt=0;
  mergeSort(S,0,n);
  for(int i=0;i<n;i++) cout<<S[i]<<" \n"[i==n-1];
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 11032
#include <bits/stdc++.h>
using namespace std;
const int N = 200003;
int n, sum[N][2];
char s[N];
int main()
{
  cin >> n;
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i+=1)
    sum[i][0] = sum[i - 1][0] + (s[i] == 'R'),
    sum[i][1] = sum[i - 1][1] + (s[i] == 'W');
  int ans = N;
  for (int i = 0; i <= n; i+=1)
    ans = min(ans, sum[i][1] + sum[n][0] - sum[max(0, i - 1)][0]);
  int mr = sum[n][0];
  ans = min(ans, sum[mr][1]);
  cout << ans << endl;
}


Measured memory_bytes: 5496
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X, N; cin >> X >> N;
  vector<int> p(N);
  
  
  for (int i = 0; i < N; i++) {
	cin >> p.at(i);

  }
  for (int dist = 0; dist < 100; dist++) {
//    cout << "チェックするのは" << X - dist << endl;
    bool hasMinus = false;
    bool hasPlus = false;
  	for (int i = 0; i < N; i++ ) {
      if (X - dist == p.at(i)) {
  //    	cout << "ありましたわー" << endl;
        hasMinus = true;
        break;
      }
    }
    if (hasMinus) {
    //  cout << "チェックするのは" << X + dist << endl;
      for (int i = 0; i < N; i++ ) {
        if (X + dist == p.at(i)) {
      //    cout << "ありましたわー" << endl;
          hasPlus = true;
          break;
        }
      }
    } else {
      cout << X - dist << endl;
      return 0;
    }
    if (hasPlus) {
      continue;
    } else {
      cout << X + dist << endl;
      return 0;
    }
    
  }


}

Measured memory_bytes: 3596
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
for i in range(1,n+1):
    A[i-1] -= i
#print(A)
medi = median(A)
medi = int(medi) if medi - int(medi) < 0.5 else int(medi) + 1
ans = 0
for i in range(n):
    ans += abs(A[i] - medi)
print(ans)


Measured memory_bytes: 27236
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val h = sc.nextInt()
    val w = sc.nextInt()
    val k = sc.nextInt()

    val grid = Array(h) { sc.next() }

    val count = Array(h) { mutableListOf<Int>() }
    for (y in 0 until h) {
        for (x in 0 until w) {
            if (grid[y][x] == '#') count[y].add(x)
        }
    }

    val res = Array(h) { Array(w) { 0 } }


    var c = 1

    var t = 0
    var b = 0
    while (t < h) {
        while (b < h && count[b].size == 0) b++

        val st = count[b]
        while (b + 1 < h && count[b + 1].size == 0) b++

        var j = 1
        for (x in 0 until w) {
            if (j < st.size && st[j] == x) {
                j++
                c++
            }
            for (y in t..b) {
                res[y][x] = c
            }
        }
        c++
        t = b + 1
        b = b + 1
    }

    println(res.joinToString("\n") { it.joinToString(" ") } )

}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input())
    if n % 1000 == 0:
        print(0)
    else:
        print(1000 - n % 1000)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
dishes = int(input())
seq_dish = list(map(int,input().split()))
sat_dish = list(map(int,input().split()))
add_sat = list(map(int,input().split()))
sat = 0
for i in range(0,len(seq_dish)):
    sat += sat_dish[seq_dish[i]-1]
    if i != 0:
        if (seq_dish[i] - seq_dish[i-1]) == 1:
            sat += add_sat[seq_dish[i-1]-1]
print(sat)

Measured memory_bytes: 3064