akhauriyash/Code-Regression huggingface dataset:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    if N == 1:
        print(1)
        exit()

    b, p = 2, 1
    ret = []
    while b ** p <= N:
        if b ** (p + 1) <= N:
            p += 1
            ret.append(b ** p)
        else:
            b += 1
            p = 1

    ret.sort(reverse=True)
    print(ret[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 10248
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int ans = 0;
    REP(i, A + 1){
        REP(j, B + 1){
            REP(k, C + 1){
                int tmp = 500 * i + 100 * j + 50 * k;
                if(tmp == X) ans++; 
            }
        }
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int sum(int a,int b){
  
  if(a*b%2==0)
    return "Even";
  else 
    return "Odd";
}
int main(){
  int a,b;
  scanf("%d %d", &a,&b);
  printf("%s",sum(a,b));
  return 0;
}


Measured memory_bytes: 2152
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <functional>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 100000000
template<class T, class C> void chmax(T& a, C b) { a>b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a<b ? : a = b; }

int main() {
	int n;
	cin >> n;
	int a[105] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long dp[105][25] = { 0 };
	dp[0][a[0]] = 1;
	for (int i = 1; i < n - 1; i++) {
		for (int j = 0; j <= 20; j++) {
			if (j - a[i] >= 0) dp[i][j] += dp[i - 1][j - a[i]];
			if (j + a[i] <= 20) dp[i][j] += dp[i - 1][j + a[i]];
		}
	}
	cout << dp[n - 2][a[n - 1]] << endl;
	return 0;
}

Measured memory_bytes: 3124
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let s=read::<String>().to_string();
    let t="2019/05".to_string();
    println!("{}",if s>t{"TBD"}else{"Heisei"})
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    char a[4];
    rep(i, 4){
        cin >> a[i];
    }
    char b;
    int c = 0;
    rep(i, 4){
        b = a[i];
        rep(j, 4){
            if(b == a[j]){
                c++;
            }else{
                c = 0;
            }
            if(c >= 3){
                yes;
                return 0;
            }
        }
        c = 0;
    }
    no;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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; }

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    ll N, Z, W;
    cin >> N >> Z >> W;
    vector<ll> a(N);
    rep(i,N)cin >> a[i];
    if(N == 1){
        cout << abs(W - a[0]) << endl;
        return 0;
    }
    cout << max(abs(a[N-1] - a[N-2]), abs(W - a[N-1])) << endl;
}
/*
どちらかが最後のカードを持つ

*/

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

int main(void) {
    int A,B,X;cin>>A>>B>>X;
    if (A > X) cout << "NO" << endl;
    else if (A <= X && X <= A + B) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main()
{
    double a[100];
    int i=0,j,k;
    double n,t;
    while(~scanf("%lf",&n))
    {
        i++;
        a[i]=n;
    }
    for(j=1; j<i; j++)
    {
        for(k=1; k<=i-j; k++)
        {
            if(a[k]>a[k+1])
            {
                t=a[k];
                a[k]=a[k+1];
                a[k+1]=t;
            }
        }
    }
    t=a[i]-a[1];
    printf("%.1lf",t);
    return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	double c;
	cin>>a>>b;
	
		if((a+b)%2!=0)
	{
		cout<<(a+b)/2+1;
	}
  else
  {
  	cout<<(a+b)/2;
  }
	return 0; 
}

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

using namespace std;

const int inf = 1e9;

int k;
vector <int> g[2010];
int sz[2010];
int sum[2010];
int f[2010][2010];

void dfs(int x, int pa = -1) {
  sz[x] = 1;
  for (int y : g[x]) {
    if (y != pa) {
      dfs(y, x);
      sz[x] += sz[y];
    }
  }
  for (int i = 0; i <= k; ++i) {
    sum[i] = 0;
    for (int y : g[x]) {
      if (y != pa) {
        sum[i] += f[y][i];
      }
    }
  }
  f[x][0] = sz[x] - 1;
  for (int i = 1; i <= k; ++i) {
    //int mn[3] = {inf, inf, inf};
    for (int y : g[x]) {
      if (y != pa) {
        f[x][i] = min(f[x][i], (sz[x] - 1) + f[y][i - 1] - sz[y]);

        //mn[2] = f[y][i - 1] - sz[y];
        //sort(mn, mn + 3);
      }
    }
   // if (mn[0] == inf) {
     // continue;
   // }
   // f[x][i] = (sz[x] - 1) + mn[0];
   // if (mn[1] == inf) {
     // continue;
    //}
    if (i + i <= k) {
      f[x][i] = min(f[x][i], sum[i - 1]);
      //f[x][i] = min(f[x][i], (sz[x] - 1) + mn[0] + mn[1]);
    } else {
      if (k - i - 1 >= 0) {
        for (int y : g[x]) {
          if (y != pa) {
            f[x][i] = min(f[x][i], sum[k - i - 1] + f[y][i - 1] - f[y][k - i - 1]);
          }
        }
      }
    }
  }
  for (int i = 0; i < k; ++i) {
    f[x][i + 1] = min(f[x][i + 1], f[x][i]);
  }
}

int main() {
  int n;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    g[i].clear();
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= k; ++j) {
      f[i][j] = inf;
    }
  }
  dfs(0);
  int ans = inf;
  for (int i = 0; i < n; ++i) {
    ans = min(ans, (n - sz[i]) + f[i][k]);
  }
  printf("%d\n", ans);
  return 0;
}

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

using namespace std;
 
#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP(x)	make_pair(x)
 
#define debug(_x)		cerr << #_x << '=' << _x << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << _x << ' ' << #_y << '=' << _y << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << _x << ' '; cerr << endl;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

const int N = 200005;

vi a;
int dp[N][2];
int vis[N][2];

int solve(int n, int cnt) {
	if (!(cnt == n/2 || cnt == (n+1)/2)) return NINF;
	
	if (n <= 0) return 0;
	
	if (cnt == n/2 && vis[n][0]) return dp[n][0];
	else if (cnt == (n+1)/2 && vis[n][1]) return dp[n][1];
	
	int ans1 = solve(n-1, cnt);
	int ans2 = solve(n-2, cnt-1) + a[n-1];
	
	if (cnt == n/2) {
		vis[n][0] = true;
		return dp[n][0] = max(ans1, ans2);
	} else {
		vis[n][1] = true;
		return dp[n][1] = max(ans1, ans2);
	}
}

int32_t main() {
	FAST_IO;

	int n;
	cin >> n;
	
	a.resize(n);
	for (int& x: a) cin >> x;
	
	cout << solve(n, n/2) << endl;
	
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 17220
s = gets.chomp
n=s.length
unless s == s.reverse
    puts 'No'
    exit
end
s_b =s.slice(0..((n-1)/2-1))
unless s_b == s_b.reverse
    puts 'No'
    exit
end
s_c = s.slice(((n+3)/2-1)..(n-1))
unless s_c == s_c.reverse
    puts "No"
    exit
end
puts 'Yes'

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include  <math.h>
int main()
{
	int N,K,A;
	scanf("%d%d",&N,&K);
	1<=N<=1000;
	2<=K<=1000;
	
	if(N==1)
	{	
		A=K;
		printf("%d",A);		 
	}
	else
	{
		A=K*pow((K-1),(N-1));
		printf("%d",A); 
	 } 
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>

using namespace std;

using ll = long long;

const ll MN = 200005;

ll n,q;

struct S{
	ll a,b,x;
};

vector<S> v;
#define son (p<<1)
#define mid ((L+R)>>1)
vector<S> rt[MN*4];
void build(ll L, ll R, ll p){
	for(ll i=L; i<=R; ++i){
		rt[p].push_back(v[i]);
	}
	sort(rt[p].begin(),rt[p].end(),[](const S& a, const S& b){return a.b<b.b;});
	for(ll i=rt[p].size()-2; i>=0; --i){
		rt[p][i].x=min(rt[p][i].x,rt[p][i+1].x);
	}
	if(L==R)return;
	build(L,mid,son);
	build(mid+1,R,son+1);
}
const ll inf = 1e9+7;
ll query(ll L, ll R, ll p, ll l, ll r, ll minb){
	 if(L>r||R<l)return inf;
	 if(L>=l&&R<=r){
		//auto lb = lower_bound(rt[p].begin(),rt[p].end(),minb);
		ll lb=-1,ub=rt[p].size(),m;
		while(lb<ub-1){
			m=(lb+ub)>>1;
			if(rt[p][m].b>=minb)ub=m;
			else lb=m;
		}
		if(ub==(ll)rt[p].size())return inf;
		return rt[p][ub].x;
	 }
	 return min(query(L,mid,son,l,r,minb),query(mid+1,R,son+1,l,r,minb));
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>q;
	for(ll i=0; i<n; ++i){
		ll a,b,x;
		cin>>a>>b>>x;
		a-=x;
		b-=x;
		v.push_back({a,b,x});
	}
	sort(v.begin(),v.end(),[](const S& a, const S& b){return a.a<b.a;});
	build(0,n-1,1);
	for(ll i=0; i<q; ++i){
		ll d;
		cin>>d;
		//ll l=lower_bound(v.begin(),v.end(),d+1)-v.begin()-1;
		ll lb=-1,ub=v.size(),m;
		while(lb<ub-1){
			m=(lb+ub)>>1;
			if(v[m].a<=d)lb=m;
			else ub=m;
		}
		ll res=query(0,n-1,1,0,lb,d+1);
		cout<<(res==inf?-1:res)<<'\n';
	}
	cout<<flush;
	return 0;
}


Measured memory_bytes: 138004
#include <cstdio>
#include <iostream>

int main(int argc, char const* argv[]) {
	int N;
	scanf("%d", &N);
	long A[210];
	for (int i = 0; i < N; i++) {
		scanf("%ld", &A[i]);
	}
	int ans = 0;
	while (1) {
		bool flag = true;
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 == 1) {
				flag = false;
				break;
			} else {
				A[i] /= 2;
			}
		}
		if (flag) {
			ans++;
		} else {
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3828
L,R=map(int,input().split())
if R-L+1>=671:
    print(0)
else:
    m=2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            x=(i*j)%2019
            if x<m:
                m=x
    print(m)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
#include <ctime>
#include <unistd.h>

using namespace std;

#define TRACE(x) cerr << #x <<  " = " << x << endl
#define _ << " " <<
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

#define X first
#define Y second

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

int main()
{
  char s[25];
  char he[5] = "YAKI";
  scanf("%s", s);
  int ok=1;
  REP(i, 4) if (he[i] != s[i])
    ok = 0;
  printf("%s\n", ok ? "Yes" : "No");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int number,a,b,c,d;
    while(scanf("%d",&number)!=EOF)
    {
        a=number/1000;
        b=number/100%10;
        c=number/10%10;
        d=number%10;
        if(a+b+c+d==7) {cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;continue;}
        if(a+b-c+d==7) {cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;continue;}
        if(a-b+c+d==7) {cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;continue;}
        if(a+b+c-d==7) {cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;continue;}
        if(a-b-c+d==7) {cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;continue;}
        if(a+b-c-d==7) {cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;continue;}
        if(a-b+c-d==7) {cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;continue;}
        if(a-b-c-d==7) {cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;continue;}
    }
    return 0;
}

Measured memory_bytes: 256
S = input().split('T')

N = len(S)
X = []
Y = []

for i in range(N):
    if i%2:
        Y.append(len(S[i]))
    else:
        X.append(len(S[i]))

Xsum = sum(X)
Ysum = sum(Y)

from collections import defaultdict,deque

dpx = defaultdict(int)# 初期値を0にした辞書
dpy = defaultdict(int)# 初期値を0にした辞書

dpx[Xsum] = 1
dpy[Ysum] = 1
que = deque()
for i,x in enumerate(X):
    if i == 0:
        continue
    for k,v in dpx.items():
        if v:
            que.append(k-2*x)
    while que:
        q = que.popleft()
        dpx[q] = 1

for i,y in enumerate(Y):
    for k,v in dpy.items():
        if v:
            que.append(k-2*y)
    while que:
        q = que.popleft()
        dpy[q] = 1


x,y = map(int,input().split())
print('Yes' if dpx[x] and dpy[y] else 'No')


Measured memory_bytes: 4280
def main():
    N = int(input())
    A = [0]*N
    B = [0]*N
    for i in range(N):
        A[i],B[i] = map(int,(input().split()))

    A.sort()
    B.sort()
    mi = 0
    ma = 0
    if N % 2 ==0:
        mi = (A[(N-1)//2]+A[((N-1)//2)+1])/2
        ma = (B[(N-1)//2]+B[((N-1)//2)+1])/2
        print(int(((ma-mi)*2)+1))

    else :
        mi = A[N//2]
        ma = B[N//2]
        print(int(ma-mi+1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 25320
#include<bits/stdc++.h>
using namespace std;
//bool compare(string a, string b){
//   // cout << "compare(" << a << "," << b << ")" << endl;
//    return (a.compare(b) < 0);
//}
int main()
{
    int n,l;
    cin>>n>>l;
    vector<string>vs;
    string tem;
    for(int i=0;i<n;i++)
    {
        cin>>tem;
        vs.push_back(tem);
    }
    sort(vs.begin(),vs.end());
//    for(int i=0;i<l;i++)
//    {     tem=vs[i];
//        for(int j=i+1;j<l;j++)
//        {
//           if(tem.compare(vs[j])<=0)
//           {
//
//           }
//           else
//           {
//               tem=vs[j];
//           }
//
//        }
//        cout<<tem;
//    }
    for(int i=0;i<n;i++)
    {
        cout<<vs[i];
    }


    cout<<"\n";


return 0;}


Measured memory_bytes: 3632
from itertools import permutations
inf=10**9
n,m,R=map(int,input().split())
r=list(map(int,input().split()))
rr=permutations(r,R)
dis=[[inf]*n for _ in range(n)]
for i in range(m):
	a,b,c=map(int,input().split())
	dis[a-1][b-1]=c
	dis[b-1][a-1]=c
for i in range(n):
	for j in range(n):
		for k in range(n):
			dis[j][k]=min(dis[j][i]+dis[i][k],dis[j][k])
ans=10**12
for x in rr:
	e=0
	for i in range(R-1):
		e+=dis[x[i+1]-1][x[i]-1]
	ans=min(ans,e)
print(ans)


Measured memory_bytes: 46424
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); 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; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  ll n; cin >> n;
  vector<ll> a(n);
  ll n_minus = 0;
  rep(i, n) {
    cin >> a[i];
    if (a[i] < 0) n_minus++;
    a[i] = abs(a[i]);
  }

  n_minus %= 2;

  sort(ALL(a));
  ll ans = 0;
  rep(i, n_minus) {
    ans -= a[i];
  }
  for (int i = n_minus; i < n; i++) {
    ans += a[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >> readInts >>= print . sum . map ( `div` 2 ) . map length . group

Measured memory_bytes: 892
l = list(input())
k = int(input())
for i in range(len(l)):
  if l[i] == "a":
    continue
  if 123 - ord(l[i]) <= k:
    k -= 123 - ord(l[i])
    l[i] = "a"
k %= 26
l[-1] = chr((ord(l[-1])-97+k)%26+97)
print("".join(l))
    

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

int main() {
    int H, W, M;
    cin >> H >> W >> M;
    map<int, map<int, bool>> mp;
    vector<int> cntH(H), cntW(W);
    rep(i, M) {
        int h, w;
        cin >> h >> w;
        h--, w--;
        cntH[h]++;
        cntW[w]++;
        mp[h][w] = true;
    }
    int mh = *max_element(cntH.begin(), cntH.end());
    int mw = *max_element(cntW.begin(), cntW.end());
    vector<int> idh, idw;
    rep(i, H) if(cntH[i] == mh) idh.push_back(i);
    rep(i, W) if(cntW[i] == mw) idw.push_back(i);
    for(auto &h : idh) for(auto &w : idw) {
        if(!mp[h][w]) {
            cout << mh + mw << '\n';
            return 0;
        }
    }
    cout << mh + mw - 1 << '\n';
    return 0;
}


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

int main() {
	string str;
	cin >> str;
	int q, count = 0;
	cin >> q;
	while (count < q) {
		string c;
		int a, b;
		string p;
		cin >> c;
		if (c == "print") {
			cin >> a >> b;
			cout << str.substr(a, b - a + 1) << endl;
		}
		if (c == "reverse") {
			cin >> a >> b;
			string target = str.substr(a, b - a + 1);
			//reverse(target.begin(), target.end());
			string reversed = target; 
			for (size_t i = 0; i < target.size(); i++) {
				reversed[target.size() - i - 1] = target[i];
			}
			//cout << target << " " << reversed << endl;
			str.replace(a, target.size(), reversed);
		}
		if (c == "replace") {
			cin >> a >> b >> p;
			str.replace(a, p.size(), p);
		}
		count += 1;
	}
	return 0;
}


Measured memory_bytes: 3204
N, M, X, Y = map(int, raw_input().split())
A = map(int, raw_input().split())
B = map(int, raw_input().split())
a = max(A)
b = min(B)

for i in xrange(-110, 110):
    if a < i <= b and X < i <= Y:
        print "No War"
        exit()
print "War"


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
 
int n,T;
vector<int>a;
 
signed main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>T;
		a.push_back(T);
	}
	sort(a.begin(),a.end());
	int ans=1e9,t;
	if(a[n-1]%2){
		int x1=(a[n-1])/2,x2=a[n-1]/2+1;
		for(int i=0;i<n-1;i++){
			int p=min(abs(a[i]-x1),abs(a[i]-x2));
			//cout<<p<<endl;
			if(p<ans){
				ans=p;
				t=a[i];
			}
		}
	}
	else{
		for(int i=0;i<n-1;i++){
			int p=abs(a[n-1]/2-a[i]);
			if(p<ans){
				ans=p;
				t=a[i];
			}
		}
	}
	cout<<a[n-1]<<' '<<t<<endl;
}

Measured memory_bytes: 892
#include<stdio.h>

#define SIZE 100000
#define L 10

typedef struct{
	char name[L];
	int time;
}process;

process queue[SIZE];
int head=0;
int tail=0;

void enq(process n){
	queue[tail++]=n;
	tail%=SIZE;
}

process deq(){
	process n=queue[head++];
	head%=SIZE;
	return n;
}

int main(void){
	int n,q;
	int i;
	int t=0;
	process p;
	scanf("%d %d",&n,&q);
	
	for(i=0;i<n;i++){
		scanf("%s",p.name);
		scanf("%d",&p.time);
		enq(p);
	}
	
	while(n>0){
		p=deq();
		if(p.time<=q){
			t+=p.time;
			printf("%s %d\n",p.name,t);
			n--;
		}else{
			p.time-=q;
			enq(p);
			t+=q;
		}
	}
	
	return 0;
}

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

int main() {
    
    string x, y; cin >> x >> y;
    string ans;
    if (x == y) ans = "=";
    if (x < y) ans = "<";
    if (y < x) ans = ">";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s,t; cin >> s >> t;
    if (s[0]==t[2] && s[1]==t[1] && s[2]==t[0]) cout << "YES";
    else cout << "NO";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine ().Split ();
            int S = int.Parse (input[0]);
            int N = int.Parse (input[1]);
            if (S <= N) {
                Console.WriteLine ("unsafe");
            } else {
                Console.WriteLine ("safe");
            }
        }
    }
}


Measured memory_bytes: 27468
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};
const int mod = 3;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  string s, t;
  int q;
  cin >> s >> t >> q;
  vi a(q), b(q), c(q), d(q);
  rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  int m = s.size();
  int n = t.size();
  vector<mint> ss(m + 1, 0), st(n + 1, 0);
  rep(i, m) {
    ss[i + 1] = ss[i];
    if(s[i] == 'A')
      ss[i + 1] += 1;
    else
      ss[i + 1] += 2;
  }
  rep(i, n) {
    st[i + 1] = st[i];
    if(t[i] == 'A')
      st[i + 1] += 1;
    else
      st[i + 1] += 2;
  }
  rep(i, q) {
    mint ms = ss[b[i]] - ss[a[i] - 1];
    mint mt = st[d[i]] - st[c[i] - 1];
    cout << (ms.x == mt.x ? "YES" : "NO") << endl;
  }
}

Measured memory_bytes: 4096
s = input()

s_len = len(s)
s_1 = s[:(s_len-1)//2]
s_2 = s[(s_len+3)//2-1:]
test_1 = s
test_2 = s[::-1]

is_ok = True

if not test_1==test_2:
    is_ok = False

if not s_1==s_1[::-1]:
    is_ok = False

if not s_2==s_2[::-1]:
    is_ok = False

if is_ok:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
def main():
    K = int(input())
    A, B = map(int, input().split())

    # for i in range(A, B + 1):
    #     if i % K == 0:
    #         print("OK")
    #         exit()

    # print("NG")

    if A % K == 0:
        print("OK")
        exit()
    
    if B // K > A // K:
        print("OK")
    else:
        print("NG")

if __name__ == '__main__':
    main()

Measured memory_bytes: 61812
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int n,m,p;
    string s;
    cin >> n >> m;
    
    int ac[n]={0};
    int wa[n]={0};
         
    for(int i=0;i<m; i++){
        cin >> p >> s;
        if(s=="AC"){
            ac[p-1]=1;
        }else{
            if(ac[p-1]==0){
                wa[p-1] ++;
            }
        }
    }
    
    int ac_sum = 0;
    int wa_sum = 0;
    for(int i=0;i<n; i++){
        if(ac[i]==1){
            ac_sum ++;
            wa_sum += wa[i];
        }
    }
    
/*
    for(int i=0;i<n; i++){
        cout << ac[i] << " ";
    }
    cout << endl;
    for(int i=0;i<n; i++){
        cout << wa[i] << " ";
    }
    cout << endl;
*/    
    cout << ac_sum << " "  << wa_sum <<  endl;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

ll N, a[100000 * 2 + 10], sum[100000 * 2 + 10], ans = 1000000000000000000;

int main() {
	rd(N);
	repi(i, 0, N) {
		rd(a[i]);
		if (i == 0) sum[i] = a[i];
		else sum[i] = sum[i - 1] + a[i];
	}
	repi(i, 0, N - 1) {
		ans = min(ans, abs(sum[i] - (sum[N - 1] - sum[i])));
	}
	wrln(ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const ll INF = 1000000001;

int main(){
    ll n, t;
    // f(n) * t <= 10^9
    while(cin >> n >> t){
        string s;
        cin >> s;
        ll sum = 0;
        for(auto c : s) if(isdigit(c)){
            int p = c - '0';
            ll x = 1;
            REP(i, p) if(x < INF) x *= n;
            sum = min(INF, sum + x);
        }
        if(sum * t <= 1000000000){
            cout << sum * t << endl;
        }else{
            cout << "TLE" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1200
import sys

h,w,n=map(int,input().split())
A = [map(int,input().split()) for _ in range(n)]

dict = {}
ans = [0]*10
ans[0] = (w-2)*(h-2)

for item in A:#for every paint
    cord = list(item)
#    print("----{},{}----".format(cord[0],cord[1]))
    #update candidate
    upcand = []#max9
    for i in range(cord[0]-1,cord[0]+2):
        for j in range(cord[1]-1,cord[1]+2):
#            print("----({},{})----".format(i,j))
            upcand.append([i,j])
#    print(upcand)
    for cand in upcand:
#        print(cand)
        if 1 < cand[0] < h and 1 < cand[1] < w:
#            print(cand)
            dict[(cand[0],cand[1])] = dict.get((cand[0],cand[1]), 0) + 1
#        print(dict)
for k,v in dict.items():
    ans[v] += 1
    ans[0] -= 1

for i in ans:
    print(i)


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

int main()
{
  int h, a;
  cin >> h >> a;

  int ans = h / a;
  if (h % a > 0)
    ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   /// https://ideone.com/Fd5s8n

 string s;
 cin>>s;
 cout << ((int)s.find("7")+1?"Yes":"No") << endl;
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void){
	long long int n, m;

	cin >> n >> m;

	if (n == 1)
		if (m == 1)
			cout << 1 << endl;
		else
			cout << m - 2 << endl;
	else
		if (m == 1)
			cout << n - 2 << endl;
		else
			cout << (n-2)*(m-2) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
  int n,i,j,count=0,num;
  
  scanf("%d",&n);
  count=n;
  for(i=0; i<n; i++){
    scanf("%d",&num);
    if(num%2==0 && num>2)count--;
    else{
      for(j=3; j<=sqrt(num); j+=2){
	if(num%j==0){
	  count--;
	  break;
	}
      }
    }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2052
for i in range(input()):
    base, result, out = 0, 0, 0
    while out != 3:
        cmd = raw_input()
        if cmd == "HIT":
            if base == 3:
                result += 1
            else:
                base += 1
        elif cmd == "HOMERUN":
            result += base + 1
            base = 0
        else:
            out += 1
    print result

Measured memory_bytes: 4208
def calc(width, height)
  return 0 if (height % 3).zero?
  s = [width]
  (1..(width / 2)).each do |x|
    r1 = x * height
    r2 = (width - x) * (height / 2)
    r3 = (width - x) * (height - height / 2)
    s.push([r1, r2, r3].max - [r1, r2, r3].min)
  end
  s.min
end
h, w = gets.split.map(&:to_i)
p [calc(w, h), calc(h, w)].min


Measured memory_bytes: 4220
// C - Align

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[100000];

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

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

	sort(A, A+N);

	int L = A[0];
	int R = A[0];
	int l = 1;
	int r = N-1;

	ll ans = 0;

	while(l <= r) {
		int max_dif;
		int max_dif_case;

		max_dif = abs(L - A[l]);
		max_dif_case = 1;

		if (abs(L - A[r]) > max_dif) {
			max_dif = abs(L - A[r]);
			max_dif_case = 2;
		}

		if (abs(R - A[l]) > max_dif) {
			max_dif = abs(R - A[l]);
			max_dif_case = 3;
		}

		if (abs(R - A[r]) > max_dif) {
			max_dif = abs(R - A[r]);
			max_dif_case = 4;
		}

		switch (max_dif_case) {
			case 1:
				ans += abs(L - A[l]);
				L = A[l];
				l++;
				break;

			case 2:
				ans += abs(L - A[r]);
				L = A[r];
				r--;
				break;

			case 3:
				ans += abs(R - A[l]);
				R = A[l];
				l++;
				break;

			case 4:
				ans += abs(R - A[r]);
				R = A[r];
				r--;
				break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4024
n = gets.to_i
as = gets.split(" ").map(&:to_i)
bs = gets.split(" ").map(&:to_i)
cs = gets.split(" ").map(&:to_i)

as.sort!
cs.sort!

count = 0
bs.each do |b|
  a_i = as.bsearch_index{|a| b <= a}
  c_i = cs.bsearch_index{|c| b < c}
  if !a_i
    a_i = n
  end
  if c_i
    count += a_i * (n - c_i)
  end
end

puts count

Measured memory_bytes: 23020
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    r, g, b, n = ns()
    ans = 0
    for i in range(n // r + 1):
        for j in range(n // g + 1):
            tmp = n - r * i - g * j
            if tmp < 0:
                break
            if tmp % b == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

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

    int n {};
    cin >> n;

    vector<bool> visited (n);
    int val {7};
    for (int ind {1}; ; ++ind) {
        int rem {val%n};
        if (rem == 0) {
            cout << ind << endl;
            return 0;
        }
        else if (visited.at(rem)) break;
        else visited.at(rem) = true;
        val = rem*10 + 7;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3740
import sys

input_lines = sys.stdin.readlines()


lines = map(lambda x: x[:-1], input_lines)

lines = map(lambda x: x.split(" "), lines)

#print lines

for l in lines:
    a, b, c, d, e, f = map(float, l)

    x = (c*e - b*f) / (e*a - b*d)
    y = (f*a - c*d) / (e*a - b*d)

    if x == -0.0:
        x = 0
    if y == -0.0:
        y = 0

    print "%.3f %.3f" % (x, y)

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

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

  int N; cin >> N;
  N *= 2;
  vector<int> L(N);
  for(int i = 0; i < N; i++){
    cin >> L[i];
  }

  sort(L.begin(), L.end());
  reverse(L.begin(), L.end());

  int ans = 0;
  for(int i=1; i < N; i+=2){
    ans += L[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func findSumOfDigits(n int) int {
	sum := 0
	for n > 0 {
		sum += n % 10
		n = n / 10
	}
	return sum
}

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	ans := 0
	for i := 0; i <= n; i++ {
		sum := findSumOfDigits(i)
		if sum >= a && sum <= b {
			ans += i
		}
	}
	fmt.Println(ans)
}


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



main()
{
    string s,t;
    cin>>s>>t;
    int m=s.size(),n=t.size();
    int ans=1e9;
    for(int i=0;i<m-n+1;i++)
    {
        int count=0;
        string a = s.substr(i,n);
        for(int j=0;j<n;j++)
        {
            if(a[j]!=t[j])
            {
                count++;
            }
        }
        ans = min(ans,count);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = double.Parse(Console.ReadLine());
            var a = (3.141592653589 * r * r);
            var b = (6.283185307178 * r);
            Console.WriteLine("{0:F10} {1:F10}",a,b);
        }
    }
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> a >> b;
    int n = 100;
    vector< vector<char> > odp(n, vector<char>(n, '#'));
    if (a >= b)
    {
        vector< vector<char> > odp(n, vector<char>(n, '#'));
        int ile = 0;
        for (int i = 0; i < n; i += 4)
        {
            for (int j = 0; j < n; j += 4)
            {
                if (ile == a)
                    continue;
                for (int k = 0; k < 3; ++k)
                {
                    for (int l = 0; l < 3; ++l)
                    {
                        odp[i + k][j + l] = '.';
                    }
                }
                ++ile;
            }
        }
        ile = 0;
        for (int i = 1; i < n; i += 4)
        {
            for (int j = 1; j < n; j += 4)
            {
                if (ile == b - 1)
                    continue;
                odp[i][j] = '#';
                ++ile;
            }
        }
        cout << "100 100" << endl;
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
                cout << odp[i][j];
            cout << endl;
        }
    }
    else
    {
        vector< vector<char> > odp(n, vector<char>(n, '.'));
        int ile = 0;
        for (int i = 0; i < n; i += 4)
        {
            for (int j = 0; j < n; j += 4)
            {
                if (ile == b)
                    continue;
                for (int k = 0; k < 3; ++k)
                {
                    for (int l = 0; l < 3; ++l)
                    {
                        odp[i + k][j + l] = '#';
                    }
                }
                ++ile;
            }
        }
        ile = 0;
        for (int i = 1; i < n; i += 4)
        {
            for (int j = 1; j < n; j += 4)
            {
                if (ile == a - 1)
                    continue;
                odp[i][j] = '.';
                ++ile;
            }
        }
        cout << "100 100" << endl;
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
                cout << odp[i][j];
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;

int main() {
  int m, n;
  cin >> m >> n;
  vi a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.rbegin(), a.rend());
  cout << max(0, a[0] - (m-a[0]+1)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, a, b, c, cnt[50] = {0};
int main()
{

    char ch;

    cin >> n >> m;

    for(i = 0; i < n; ++i)
    {
        for(j = 0; j < m; ++j)
        {
            cin >> ch;
            cnt[ch - 'a']++;
        }
    }
    if(n % 2 == 1 && m % 2 == 1)
        a = 1;
    b = (n / 2) * (m % 2) + (m / 2) * (n % 2);
    c = (n / 2) * (m / 2);
    for(i = 0; i < 26; ++i)
    {
        if(c - cnt[i] / 4 < 0)
        {
            cnt[i] -= c * 4;
            c = 0;
        }
        else
        {
            c -= cnt[i] / 4;
            cnt[i] %= 4;
        }
    }
    for(i = 0; i < 26; ++i)
    {
        if(b - cnt[i] / 2 < 0)
        {
            cnt[i] -= b * 2;
            b = 0;
        }
        else
        {
            b -= cnt[i] / 2;
            cnt[i] %= 2;
        }
    }
    for(i = 0; i < 26; ++i)
    {
        if(a - cnt[i] < 0)
        {
            cnt[i] -= a;
            a = 0;
        }
        else
        {
            a -= cnt[i];
            cnt[i] = 0;
        }
    }
    if(a + b + c == 0)
        cout << "Yes";
    else
        cout << "No";

return 0;
}


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

using namespace std;

int cnt[2][500001];
char str[500001];
int ans = 0x3f3f3f3f;
int n;
int main( ) {
	scanf("%d", &n);
	scanf("%s", str + 1);
	for (int i = 1; i <= n; i ++) {
		int tmp = str[i] == 'E';
		cnt[tmp][i] = cnt[tmp][i - 1] + 1;
		cnt[tmp ^ 1][i] = cnt[tmp ^ 1][i - 1];
	}
	for (int i = 1; i <= n; i ++) {
		ans = min(ans, cnt[0][i - 1] + cnt[1][n] - cnt[1][i]);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3712
package sample

//基本メソッド
fun <T>MutableList<T>.swap(i:Int, j:Int){
    var tmp = this[i]
    this[i]=this[j]
    this[j]=tmp
}
fun IntArray.swap(i:Int,j:Int){
    var tmp = this[i]
    this[i]=this[j]
    this[j]=tmp
}
fun CharArray.swap(i:Int,j:Int){
    var tmp = this[i]
    this[i]=this[j]
    this[j]=tmp
}
fun IntArray.print_splitself(){
    this.forEach { it->print(it) ;print(" ")}
}
fun IntArray.println_splitself(){
    this.forEach { it->print(it) ;print(" ")}
    println()
}
fun CharArray.print_splitself(){
    this.forEach { it->print(it) ;print(" ")}
}
fun CharArray.println_splitself(){
    this.forEach { it->print(it) ;print(" ")}
    println()
}
//array,arraysize,distance
fun insertionSortShellCustom(A:IntArray,n:Int,g:Int):Int
{
    var cnt=0
    for(i in g..n-1){
        var v=A[i]
        var j=i-g
        while(j>=0 && A[j]>v){
            A[j+g]=A[j]
            j=j-g
            cnt+=1
        }
        A[j+g]=v
        //A.println_splitself()
    }
    return cnt
}

fun shellSort(A:IntArray,n:Int):Int
{
    var cnt=0
    var Garraylist= arrayListOf<Int>()
    var h=1
    if(n<=1)
    {
        Garraylist.add(1)
    }
    while(h<n)
    {
        Garraylist.add(h)
        h=h*3+1
    }
    var G= Garraylist.reversed().toIntArray()
    var m=G.size

    println(m)
    G.println_splitself()
    for (i in 0..m-1)
    {
        //A.print_splitself()
        //println("${n},${G[i]}")
        cnt+=insertionSortShellCustom(A,n,G[i])
    }
    return cnt
}

fun main(args:Array<String>)
{
    var n=readLine()!!.toInt()
    var arrlist=ArrayList<Int>()
    for(i in 0..n-1)
    {
        //println(i)
        arrlist.add(readLine()!!.toInt())
    }
    var arr=arrlist.toIntArray()
    var cnt=shellSort(arr,n)
    println("$cnt")
    for(e in arr)
    {
        println(e)
    }
}


Measured memory_bytes: 119828
#include <stdio.h>

int main()
{
	char a;
	scanf("%c", &a);
	if(a >= 'a' && a <= 'z')
	{
		printf("a\n");
	} else if(a >= 'A' && a <= 'Z')
	{
		printf("A\n");
	}
	return 0;
}

Measured memory_bytes: 1556
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long ll;
int main(){
  ll n,k;
  cin >> n >> k;
  if(n<=k){
    cout << 0 << endl;
    return 0;
  }
  vector<ll> h(n);
  for(ll i=0; i<n; i++){
  	cin >> h[i];
  }
  sort(h.begin(),h.end());
  
  ll ans=0;
  for(ll i=0; i<n-k;i++){
  	ans+=h[i];
  }
  cout << ans<< endl;
}

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

namespace Atc_0027
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> strs = new List<string>();

            for (int i = 0; i < 3; i++)
            {
                strs.Add(Console.ReadLine());
            }

            int N = int.Parse(Console.ReadLine());
            List<int> bns = new List<int>();

            for (int j = 0; j < N; j++)
            {
                bns.Add(int.Parse(Console.ReadLine()));
            }

            List<int[]> bingos = new List<int[]>();

            for (int i = 0; i < 3; i++)
            {
                int[] tmp = { int.Parse(strs[i].Split(' ')[0]), int.Parse(strs[i].Split(' ')[1]), int.Parse(strs[i].Split(' ')[2]) };

                bingos.Add(tmp);
            }

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (bns[i] == bingos[j][0])
                    {
                        bingos[j][0] = -1;
                    }
                    else if (bns[i] == bingos[j][1])
                    {
                        bingos[j][1] = -1;
                    }
                    else if (bns[i] == bingos[j][2])
                    {
                        bingos[j][2] = -1;
                    }
                }
            }

            for (int i = 0; i < 3; i++)
            {
                if (-1 == bingos[i][0] && -1 == bingos[i][1] && -1 == bingos[i][2])
                {
                    Console.WriteLine("Yes");
                    return;
                }

                if (-1 == bingos[0][i] && -1 == bingos[1][i] && -1 == bingos[2][i])
                {
                    Console.WriteLine("Yes");
                    return;
                }

            }

            if (-1 == bingos[0][0] && -1 == bingos[1][1] && -1 == bingos[2][2])
            {
                Console.WriteLine("Yes");
                return;
            }

            if (-1 == bingos[2][0] && -1 == bingos[1][1] && -1 == bingos[0][2])
            {
                Console.WriteLine("Yes");
                return;
            }

            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 27688
"use strict";

const main = arg => {
  const n = parseInt(arg.split("\n")[0], 10)
  const xy = arg.split("\n").slice(1).map(e => e.split(" "))
  let total = 0
  for (let i = 0; i < n; i++) {
    for (let j = i + 1; j < n; j++) {
		const diffx = xy[j][0] - xy[i][0]
		const diffy = xy[j][1] - xy[i][1]
        const r = Math.sqrt(diffx * diffx + diffy * diffy)
        total += r
    }
  }
  console.log(total * 2 / n)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372