akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  string S;
  cin>>S;
  int n=0;
  int w=0;
  int s=0;
  int e=0;
  rep(i,S.length()){
    if(S[i]=='N') n++;
    if(S[i]=='W') w++;
    if(S[i]=='S') s++;
    if(S[i]=='E') e++;
  }
  bool ja=true;
  if(n>0){
    if(s==0) ja=false;
  }
  if(w>0){
    if(e==0) ja=false;
  }
  if(s>0){
    if(n==0) ja=false;
  }
  if(e>0){
    if(w==0) ja=false;
  }
  if(ja){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char s[100010];
int n, ans;
int main() {
    scanf("%s", s + 1);
    ans = n = strlen(s + 1);
    for (int i = 1; i < n; ++i)
        if (s[i] != s[i+1])
            ans = min(ans, max(i, n - i));
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
import re

A, B = [int(x) for x in input().split()]
S = input()

def main():
    pattern = r"[0-9]{{{0}}}-[0-9]{{{1}}}".format(A, B)
    ans = "Yes" if re.match(pattern, S) else "No"
    print(ans)

if __name__ == '__main__':
    main()

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

int main(void) {
	long long int a, b, x, i;
	long long int p,q;
	cin >> a >> b >> x;
	if (a%x == 0) {
		p = a / x;
	}
	else {
		p = (a / x) + 1;
	}
	if (b%x == 0) {
		q = b / x;
	}
	else {
		q = b / x;
	}
	cout << q-p+1 << endl;
	return 0;
}

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

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

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

int N, K;

vector<vector<int>> tree;

int dfsGT(int v, int u, int d0, int d) {
    int ans = d > d0;
    for (int w : tree[v])
        if (w != u)
            ans += dfsGT(w, v, d0, d + 1);
    return ans;
}

int dfsEQ(int v, int u, int d0, int d) {
    if (d == d0)
        return 1;
    int ans = 0;
    for (int w : tree[v])
        if (w != u)
            ans += dfsEQ(w, v, d0, d + 1);
    return ans;
}

int chop(int v) {
    if (K % 2) {
        int ans = dfsGT(v, v, (K + 1) / 2, 0);
        vector<int> subtrees;
        for (int w : tree[v])
            subtrees.push_back(dfsEQ(w, v, (K + 1) / 2, 1));
        sort(subtrees.begin(), subtrees.end(), greater<int>());
        for (int i = 1; i < (int) subtrees.size(); i++)
            ans += subtrees[i];
        return ans;
    } else {
        return dfsGT(v, v, K / 2, 0);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    cin >> N >> K;
    tree.resize(N);
    forn(i, N - 1) {
        int A, B;
        cin >> A >> B;
        A--, B--;
        tree[A].push_back(B);
        tree[B].push_back(A);
    }

    int ans = INT_MAX;
    forn(v, N)
        ans = min(ans, chop(v));

    cout << ans << endl;
}


Measured memory_bytes: 512
using System;
using System.Linq;

namespace BBalance
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var n = int.Parse(Console.ReadLine());
            var weights = Console.ReadLine().Split().Select(int.Parse).ToArray();

            // 重さの和の最小の差を計算
            var minDiff = int.MaxValue;
            for (var i = 1; i < n; i++)
            {
                var sum1 = weights.Take(i).Sum();
                var sum2 = weights.Skip(i).Sum();

                var diff = Math.Abs(sum2 - sum1);
                if (diff < minDiff) minDiff = diff;
            }
            
            // 解答の出力
            Console.WriteLine(minDiff);
        }
    }
}


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

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

	vector<int> ps;
	for (int i = 0; i < n - 1; i++)
	{
		if (s[i] == 'A' && s[i + 1] == 'C')
		{
			ps.emplace_back(i);
		}
	}

	for (int t = 0; t < q; t++)
	{
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		r--;
		cout << distance(lower_bound(ps.begin(), ps.end(), l), upper_bound(ps.begin(), ps.end(), r)) << endl;
	}

	return 0;
}

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

int n;
int X, Y;
int p[2000], q[2000], x[2000], y[2000];
char c, d; int e;

int main() {
	cin >> n >> X;
	int cnt = 0;
	for (int i = 0; i < X; i++) {
		cin >> c >> e;
		if (c == 'D') {
			p[cnt] = e;
			cnt++;
		}
	}
	cnt = 0;
	cin >> Y;
	for (int i = 0; i < Y; i++) {
		cin >> c >> d >> e;
		if (c == 'D' && d == 'D') {
			q[cnt] = e;
			cnt++;
		}
	}
	sort(p, p + X);
	sort(q, q + Y);
	cnt = 0;
	for (int i = X - 1; i >= 0; i--) {
		cnt++;
		x[cnt] = x[cnt - 1] + p[i];
	}
	cnt = 0;
	for (int i = Y - 1; i >= 0; i--) {
		cnt++;
		y[cnt] = y[cnt - 1] + q[i];
	}
	int maxn = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i + 2 * j <= n) {
				maxn = max(maxn, x[i] + y[j]);
			}
		}
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>

int main(void){
  int h, w, H, W;
  for(;;){
    scanf("%d %d", &H, &W);
    if(H == 0 && W == 0)
      break;
    for(h = 0; h < H; h++){
      for(w = 0; w < W; w++){
	if((h + w) % 2 == 0){
	  printf("#");
	}else{
	  printf(".");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int a, b;
    cin>>a>>b;
    if (b % a == 0) {
        cout<<a + b<<endl;
    } else {
        cout<<b - a<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
    int n;
     scanf("%d",&n);
         int a[n],i;
         for(i=0;i<n;i++)
         {
             scanf("%d",&a[i]);
         }
         int count=1;
         for(i=0;i<n;i++)
         {
             if(count==a[i])
             {
             count++;
             }
         }
         count=count-1;
         if(count==0)
         {
              printf("-1");
         }
         else
         printf("%d",(n-count));
}

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

using namespace std;

#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using i64 = long long;
using iip = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }

template<typename ...T>
istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

const i64 M = 1e9 + 7;
const int INF = 1e9 + 1;

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

    int n, m;
    while (read(n, m)) {
        svec a(n);
        svec b(m);
        read(a, b);

        bool ok = false;
        forn(i, n) forn(j, n) {
            int cc = 0;
            forn(k, m) forn(p, m) if (i + k < n && j + p < n) {
                cc += a[i + k][j + p] == b[k][p];
            }
            if (cc == m * m) {
                ok = true;
                break;
            }
        }
        if (ok) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 3664
using System;
using System.Collections.Generic;

namespace AGC013A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var target = Console.ReadLine().Split(' ');
            var a = new List<int>();
            for(int i=0;i<N;i++){
               a.Add(int.Parse(target[i]));
            }
            int p1 = 0; int count = 1;
            bool up = false;
            bool down = false;
            while(p1 < a.Count -1 ){
                if(a[p1] != a[p1+1]) {
                    if(up){
                        if(a[p1] > a[p1+1]){
                            up = false; down = false;
                            count++; 
                        }
                    } else if(down){
                        if(a[p1] < a[p1+1]){
                            up = false; down = false;
                           count++; 
                        }
                    } else {
                        if(a[p1] > a[p1+1]) {down = true;}
                        if(a[p1] < a[p1+1]) {up = true;}
                    }
                }
                p1++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 21088
#include <stdio.h>
#define MAX 100000

typedef struct{
  char name[10];
  int time;
} status;
status cpu[MAX];
int q;

void enqueue(status);
status  dequeue();
int compare(int,int);

int head=0,tail;

int main(){
  int i,n,q,count=0,checkcount=0;
  status x;
  scanf("%d%d",&n,&q);
  for(i=0; i<n; i++){
    scanf("%s%d",cpu[i].name,&cpu[i].time);
  }
  tail = n;
  while(1){
    if(head == tail) break;
    x  = dequeue();
    count = compare(q,x.time);
    x.time -= count;
    checkcount += count;
    if(x.time > 0) enqueue(x);
    else printf("%s %d\n",x.name,checkcount);
  }

  return 0;
}

void enqueue(status x){
  cpu[tail] = x;
  tail = (tail + 1) % MAX; 
}

status dequeue(){
  status x;
  x = cpu[head];
  head = (head + 1) % MAX;
  return x;
}

int compare(int a,int b){
  return a < b ? a : b;
}

Measured memory_bytes: 2160
import java.util.*;
import java.io.*;

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

        int ans = 700;
        for(int i = 0; i < c.length; i++){
            if(c[i] == 'o'){
                ans += 100;
            }
        }
        

        System.out.println(ans);

        sc.close();
    }
}

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

int h[100001];
int dp[100001];

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

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

    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);

    for (int i = 3; i <= N; ++i) {
        dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
    }

    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
int main(){
    int n,m;cin>>n>>m;
    int A[MAX];rep(i,m)cin>>A[i];
    if(n>=m){cout<<0<<endl;return 0;}

    sort(A,A+m);
    vector<P>p;
    for(int i=1;i<m;i++){
        p.push_back(P(A[i]-A[i-1],i-1));
    }
    sort(ALL(p));
    reverse(ALL(p));
    VI list;
    list.push_back(-1);
    list.push_back(m-1);
    for(int i=0;i<n-1;i++){
        list.push_back(p[i].se);
    }
    sort(ALL(list));
    int ans=0;
    for(int i=1;i<(int)list.size();i++){
        ans+=A[list[i]]-A[list[i-1]+1];
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    const int inf=1000000000;
    int n,m;
    scanf("%d%d",&n,&m);
    vector<int> a(1<<n,inf),b(1<<n,inf);
    a[0]=b[0]=0;
    for(int o=0;o<m;o++)
    {
        int c,num;
        scanf("%d%d",&c,&num);
        int mask=0;
        for(int i=0;i<num;i++)
        {
            int t;
            scanf("%d",&t);
            mask+=(1<<(t-1));
        }
        for(int i=0;i<(1<<n);i++) b[i|mask]=min(b[i|mask],a[i]+c);
        a=b;
    }
    if(a[(1<<n)-1]!=inf) printf("%d\n",a[(1<<n)-1]);
    else printf("-1\n");
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set> 
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll unsigned long long
#define db double
#define inf 3001
#define INF (int)1e8 
#define mod (int)(1e9+7)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
int f[2][inf*2];

int DP(int n,int m){
    memset(f,0,sizeof(f));
	int now=0;
	for (int i=0;i<=n;i++){
		f[now][i]=1;
	}
	for (int i=1;i<=m;i++){
		now^=1;
		for (int j=0;j<=n;j++){
			f[now][j]=0;
		}
		for (int j=0;j<=n;j++){
			if(j>0){
                f[now][j-1]=(f[now][j-1]+f[now^1][j])%mod;
                f[now][j]=(f[now][j]+f[now^1][j])%mod;
            }
            if(j<n){
                f[now][j+1]=(f[now][j+1]+f[now^1][j])%mod;
                f[now][j]=(f[now][j]+f[now^1][j])%mod;
            }
		}
	}
	int ans=0;
	for (int i=0;i<=n;i++){
		ans=(ans+f[now][i])%mod;
	}
	return ans;
}

int n,m;

int main(){
	rd(n) rd(m)
	printf("%d\n",(DP(n,m)-DP(n-1,m)+mod)%mod);
	return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef pair<int,int> P;
typedef long long ll;

ll p[70];

int main(void){

	ll N;
	cin >> N;

	if(N==0){
		cout << 0 << endl;
		return 0;
	}

	int i;
	p[1]=1;
	for(i=2;;i++){
		p[i]=2*p[i-1];
		if(p[i]>1e18) break;
	}

	int x;
	for(i=1;i<=65;i++){
		if(p[i]>N){
			x=i-1;
			break;
		}
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <cstdio>
#include <climits>

const int N = 300;

int g[N][N];

int main()
{
#ifdef LOCAL_JUDGE
    freopen("D.in", "r", stdin);
#endif
    int n;
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < n; ++ j) {
                scanf("%d", g[i] + j);
            }
        }
        long long result = 0;
        for (int i = 0; i < n && ~result; ++ i) {
            for (int j = 0; j < i && ~result; ++ j) {
                auto mi = INT_MAX;
                for (int k = 0; k < n; ++ k) {
                    if (i != k && j != k) {
                        mi = std::min(mi, g[i][k] + g[k][j]);
                    }
                }
                if (mi > g[i][j]) {
                    result += g[i][j];
                } else if (mi < g[i][j]) {
                    result = -1;
                }
            }
        }
        printf("%lld\n", result);
    }

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt =1;

int main(){
    int n,m;    cin >> n >> m;
    queue <int>a;
    for(int i=0;i<m;i++){
        int b;  cin >> b;
        a.push(b);
    }

    

    vector<ll>dp(n+10,0);//step
    dp[0]=1;
    dp[1]=1;
    int c = a.front();
    if(c == 1){
        dp[1] = 0;
        a.pop();
    }

    for(int i=2;i<=n;i++){

        dp[i] = (dp[i-2]+dp[i-1]) % mod;
        int b=a.front();
        if(i == b){
            a.pop();
            
            dp[i] = 0;
            dp[i+1] = dp[i-1];
        }
    
    }
    cout << dp[n] % mod << endl; 

}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int a[114514],b[114514],c[114514];
signed main(){
	int n,ans=0;
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n)cin>>c[i];
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	rep(i,n){
		ans+=(lower_bound(a,a+n,b[i])-a)*(n-(upper_bound(c,c+n,b[i])-c));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2688
n = int(input())
l = [0] * (10**5)
N = 10**4

for i in range(1, 10**2+1):
    for j in range(1, 10**2+1):
        for k in range(1, 10**2+1):
            a = i*i + j*j + k*k + i*j + j*k + k*i
            l[a] += 1

for i in range(n):
    print(l[i+1])

Measured memory_bytes: 69288
#pragma warning disable
using System.IO;
using System.Linq;
using System;
class E { static void Main() { new J(); } }
class J
{
	int F() { return int.Parse(Console.ReadLine()); }
	int[] G() { return Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray(); }
	public J()
	{
		Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
		while (true)
		{
			var N = F();
			if (N == 0) break;
			int a = 0, b = 0;
			for (var i = 0; i < N; i++)
			{
				var I = G();
				if (I[0] < I[1]) b += I[0] + I[1];
				else if (I[0] > I[1]) a += I[0] + I[1];
				else { a += I[0]; b += I[0]; }
			}
			Console.WriteLine("{0} {1}", a, b);
		}
		Console.Out.Flush();
	}
}

Measured memory_bytes: 9656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        int n = obj.nextInt(),k = obj.nextInt(),arr[] = new int[n];
        for(int i=0;i<n;i++)
            arr[i] = obj.nextInt();
        Arrays.sort(arr);
        int sum=0;
        for(int i=0;i<k;i++) sum+=arr[i];
        System.out.println(sum);
    }
}


Measured memory_bytes: 32980
let [| n; m; x |] = stdin.ReadLine().Split(" ") |> Array.map int

let gates = stdin.ReadLine().Split(" ") |> Array.map int

let costToZero = gates |> Array.filter (fun a -> a < x) |> Array.length
let costToN = gates |> Array.filter (fun a -> a > x) |> Array.length

min costToZero costToN |> printfn "%d"

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

int main(){
  
  while(1){
    
    double n;
    
    cin>>n;
    
    if(n==-1.0) break;
    
    double num=128.0;
    int cnt=0;
    int ans[12]={};
    
    while(n!=0 && cnt < 12){
      if(n-num >= 0){
	ans[cnt]=1;
	n-=num;
      }
      num/=2.0;
      cnt++;
    }
    
    if(cnt == 12 && n != 0) cout<<"NA"<<endl;
    else{
      for(int i=0;i<12;i++){
	if(i == 8) cout<<".";
	cout<<ans[i];
      }
      cout<<endl;
    }
    
  }
  
  return 0;
}



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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i64 n, ans = 0; cin >> n;

    for(i32 i = 1; i < n+1; ++i) {
        ans += (n/i) * (n/i+1) / 2 * i;
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

vector<vector<ll> > Comb(int n){
  vector<vector<ll> > v(n+1,vector<ll>(n+1));
  for(int i=0;i<=n;i++) v[i][i] = v[i][0] = 1LL;
  for(int i=2;i<=n;i++) {
    for(int j=1;j<i;j++) v[i][j] = v[i-1][j] + v[i-1][j-1];
  }
  return v;
}

int main() {
  vector<vector<ll> > c=Comb(63);
  ll n,m;
  while(cin >> n >> m && n) {
    ll k=0;
    for(k=0; k<=n; k++) {
      if(m>c[n][k]) {
        m-=c[n][k];
        continue;
      }
      break;
    }
    string s="";
    for(ll i=n; i>=1; i--) {
      if(k&&m>c[i-1][k]) {
        s+='1';
        m-=c[i-1][k];
        k--;
      } else s+='0';
    }
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 3128
#!/usr/bin/env python3
import sys


def solve(N: int, d: "List[int]"):
    import bisect
    d.sort()
    if(N%2 == 1):
        print(0)
    else:
        print(d[int(N/2)] - d[int(N/2)-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14452
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
for i in range(101):
    for j in range(101):
        H = []
        check = []
        for k in range(n):
            x = a[k][0]
            y = a[k][1]
            h = a[k][2]
            if h ==  0:
                check.append((x, y))
            else:
                H.append(h + abs(x-i) + abs(y-j))
                if len(set(H)) > 1:
                    break
            if k == n-1:
                state = False
                for s,t in check:
                    if H[0] - abs(s-i) - abs(t-j) > 0:
                        state = True
                        break
                if state:
                    break
                print(i, j, H[0])
                exit()



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
  
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;
      
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  char s;
  cin>>s;
  cout<<(char)(s+1)<<'\n';
  return 0;
}


Measured memory_bytes: 256
program sample
    implicit none
    integer(8) ::a, b,c,i,j,m,n,k,a1,b1,c1
    integer(8)::x(5)
    
    read(*,*) x
   
    do i=1,5
        
        if (x(i) ==0) then
           write(*,*)i
      
        end if

    end do
   
    stop
end program sample
  



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

template<typename T>
struct Segtree {
    int n, n_org;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        n_org = n_input;
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.assign(2*n-1, e);
    }

    void build(vector<T>& A){
        for(int k=0; k<int(A.size()); k++) dat[k+n-1] = A[k];
        for(int k=n-2; k>=0; k--) dat[k] = f(dat[2*k+1], dat[2*k+2]);
    }

    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k){
        return dat[k+n-1];
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        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);
    }

    // [S, t] が条件checkを満たす最大のtを求める
    int bisect(int S, function<bool(T a)> check){
        T val = get(S);
        int k = S+n-1, l = S, r = S+1;
        while(true){
            while(k%2) k = (k-1)/2, r += r-l;
            T val2 = f(val, dat[k]);
            if(check(val2)){
                if(r == n) return n_org-1;
                val = val2;
                k++;
                int d = r-l;
                l += d, r += d;
            }else{
                break;
            }
        }
        while(k<n-1){
            T val2 = f(val, dat[2*k+1]);
            if(check(val2)){
                val = val2;
                k = 2*k+2;
                l = (l+r)/2;
            }else{
                k = 2*k+1;
                r = (l+r)/2;
            }
        }
        return min(l, n_org)-1;
    }
};

int main(){
	int N, K;
	cin >> N >> K;
	Segtree<int> st(300001, [](int a, int b){ return max(a, b); }, 0);
	while(N--){
		int a;
		cin >> a;
		st.update(a, st.between(a-K, a+K)+1);
	}
	cout << st.dat[0] << endl;
}


Measured memory_bytes: 7476
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

int H, W, K;
bool h[10] = {}, w[10] = {};
int ans = 0;
char c[10][10];
//これがi番目のビットたってるか調べる

int main() {
    cin >> H >> W >> K;
    rep(i, H) {
        rep(j, W) {
            cin >> c[i][j];
        }
    }
    rep(i, beki(2, H)) {
        int tmp = i;
        rep(x, H) {
            //bitを代入
            h[x] = tmp % 2;
            tmp /= 2;
        }
        rep(j, beki(2, W)) {
            int tmp2 = j;
            rep(y, W) {
                //bitを代入
                w[y] = tmp2 % 2;
                tmp2 /= 2;
            }
            //i行目、j列目のインデックスは数えない
            //bitで管理
            int tmp3 = 0;
            rep(k, H) {
                rep(l, W) {
                    //選べるか、そこが黒かどうか
                    if (!h[k] && !w[l] && c[k][l] == '#') {
                        tmp3++;
                    }
                }
            }
            if (tmp3 == K) ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
  int A,B,C,D;
  string S;
  cin>>S;
  A=S.at(0)-'0';
  B=S.at(1)-'0';
  C=S.at(2)-'0';
  D=S.at(3)-'0';
  
  if(A+B+C+D==7){
    cout<<A<<"+"<<B<<"+"<<C<<"+"<<D<<"=7"<<endl;
    return 0;
  }
  if(A+B+C-D==7){
    cout<<A<<"+"<<B<<"+"<<C<<"-"<<D<<"=7"<<endl;
    return 0;
  }
  if(A+B-C+D==7){
    cout<<A<<"+"<<B<<"-"<<C<<"+"<<D<<"=7"<<endl;
    return 0;
  }
  if(A+B-C-D==7){
    cout<<A<<"+"<<B<<"-"<<C<<"-"<<D<<"=7"<<endl;
    return 0;
  }
  if(A-B+C+D==7){
    cout<<A<<"-"<<B<<"+"<<C<<"+"<<D<<"=7"<<endl;
    return 0;
  }
  if(A-B+C-D==7){
    cout<<A<<"-"<<B<<"+"<<C<<"-"<<D<<"=7"<<endl;
    return 0;
  }
  if(A-B-C+D==7){
    cout<<A<<"-"<<B<<"-"<<C<<"+"<<D<<"=7"<<endl;
    return 0;
  }
  if(A-B-C-D==7){
    cout<<A<<"-"<<B<<"-"<<C<<"-"<<D<<"=7"<<endl;
    return 0;
  }
}

  


Measured memory_bytes: 3600
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}


void func(void)
{
//DEBUG_OUT("----\n");
    
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);
    for(int i=0; i<N; i++){ cin >> A[i]; }
    for(int i=0; i<N; i++){ cin >> B[i]; }
    for(int i=0; i<N; i++){ cin >> C[i]; }
    DEBUG_OUT("----\n");
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    int64 ans = 0;
    vector<int64> histB(N, 0);
    vector<int64> histC(N, 0);

    int c_ = 0;
    for(int b=0; b<N; b++){
        int c;
        for(c=c_; c<N; c++){
            if(B[b] < C[c]){
                histC[b] = N - c;
                c_ = c;
                break;
            }
        }
        if(c == N){
            break;
        }
    }

    histB[N-1] = histC[N-1];
    for(int b=N-2; b>=0; b--){
        histB[b] = histC[b] + histB[b+1];
    }

    int b_ = 0;
    for(int a=0; a<N; a++){
        // search B
        int b;
        for(b=b_; b<N; b++){
            if(A[a] < B[b]){
                DEBUG_OUT("a(%d) BB=%d\n", A[a], histB[b]);
                ans += histB[b];
                b_ = b;
                break;
            }
        }
        if(b == N){
            break;
        }
    }

    DEBUG_OUT("----\n");
    cout << ans << endl;
    return;
}



Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
bool find(int z){
  node *x=root;
  while(x!=NULL){
    if(z==x->key) return true;
    if(z<x->key) x=x->left;
    else x=x->right;
  }
  return false;
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    if(s=="insert"){
      insert(node(x));
    }
    if(s=="find"){
      cout<<(find(x)?"yes":"no")<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 21892
N = int(input())
S = input()

ans = 0
for i in range(1000):
    
    if len(str(i)) != 3:
        V = "0" * (3- len(str(i))) + str(i)
    else:
        V = str(i)
    
    cnt = 0
    for j in S:
        if V[cnt] == j:
            cnt += 1
            
        if cnt == 3:
            ans += 1
            break
print(ans) 

Measured memory_bytes: 41308
import scala.io.StdIn.readInt

object Main extends App {
  def replace(i:Char) = i match {
    case '4' => '5'
    case '5' => '7'
    case '6' => '8'
    case '7' => '9'
    case x => x
  }

  Iterator.continually(readInt).takeWhile( _ != 0 ).foreach { n=>
    println("%o".format(n).map{replace})
  }
}

Measured memory_bytes: 113796
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll m,d;
    cin >> m >> d;
    ll ans=0;
    FOR(i,1,m+1){
        FOR(j,1,d+1){
            if(j%10>=2&&j>=20&&i==(j%10)*(j/10)){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  
  int a,b,c;
  cin >> a >> b >> c;
  
  int x = c - (a-b);
  
  if(x<=0)
    cout << 0 << endl;
  else
    cout << x << endl;
  
  return 0;

}


Measured memory_bytes: 256
while True:
    x = list(map(int,input().split()))
    a = x[0]
    b = x[1]
    c = x[2]

    if a == -1 and b == -1 and c == -1:
        break
    elif a == -1 or b == -1:
        print("F")
    elif a+b >= 80:
        print("A")
    elif a+b >= 65:
        print("B")
    elif a+b >= 50  or c >= 50:
        print("C")
    elif a +b >= 30:
        print("D")
    else:
        print("F")


Measured memory_bytes: 5592
import java.util.*;
import static java.lang.System.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int[][] c=new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                c[i][j]=sc.nextInt();
            }
        }
        int[] a=new int[3];
        int[] b=new int[3];
        for (int i = 0; i <= 100; i++) {
            b[0]=i;
            a[0]=c[0][0]-i;
            a[1]=c[1][0]-i;
            a[2]=c[2][0]-i;
            b[1]=c[0][1]-c[0][0]+i;
            b[2]=c[0][2]-c[0][0]+i;
            int d=0;
            for (int j = 1; j <= 2; j++) {
                for (int k = 1; k <= 2; k++) {
                    if(a[j]+b[k]!=c[j][k])d++;
                }
            }
            if(d==0){
                out.println("Yes");
                break;
            }else if(i==100)out.println("No");
        }
    }
}

Measured memory_bytes: 22740
object Main {
    def queens(n: Int, fixed: List[(Int, Int)]): List[List[(Int, Int)]] = {
        def placeQueens(k: Int): List[List[(Int, Int)]] = {
            if(k == -1) List(List())
            else
                for {
                    queens <- placeQueens(k - 1)
                    col <- 0 to n - 1
                    queen = (k, col)
                    if isSafe(queen, queens)
                } yield queen :: queens
        }
         placeQueens(n - 1).filter(qs => check(fixed, qs))
    }

    def isSafe(queen: (Int, Int), queens: List[(Int, Int)]) = {
        queens.forall(q => !inCheck(queen, q))
    }

    def inCheck(q1: (Int, Int), q2: (Int, Int)) = {
        q1._1 == q2._1 ||
        q1._2 == q2._2 ||
        (q1._1 - q2._1).abs == (q1._2 - q2._2).abs
    }

    def check(fixed: List[(Int, Int)], queens: List[(Int, Int)]) =
        fixed.forall(q => queens.contains(q))

    def main(args:Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        val fixed = List.fill(n)(sc.nextInt, sc.nextInt)
        for(qs <- queens(8, fixed)) {
            for(y <- 0 to 7) {
                for(x <- 0 to 7) {
                    print(if(qs.contains((y, x))) "Q" else ".")
                }
                println
            }
        }
    }
}

Measured memory_bytes: 50884
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;

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

long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

bool IsPrime(int num)//素数判定
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

map< long long int, long long int > prime_factor(long long int n) {//素因数分解
    map< long long int, long long int > ret;
    for(long long int i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}



int main() {

   string S;
   cin >> S;
   int A[4];
   A[0]=stoi(S.substr(0,1));
   A[1]=stoi(S.substr(1,1));
   A[2]=stoi(S.substr(2,1));
   A[3]=stoi(S.substr(3,1));

   long long int result =A[0];

    for (int tmp = 0; tmp < (1 << 3); tmp++) {
        bitset<3> s(tmp);

        int sum = A[0];
        for (int i = 0; i < 3; i++) {
            if (s.test(i)) {
               sum+=A[i+1];
            }else{
                sum-=A[i+1];
            }
        }


        if(sum==7){
            cout << A[0] ;
            for (int i = 0; i < 3; i++) {
                if (s.test(i)) {
                    cout << "+";
                }else{
                    cout << "-";
                }
                cout << A[i+1];
            }

            cout << "=7" << endl;
            break;

        }

    }





}











Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct pp
{
    int x,y;
};
pp p[1010];
bool cmp(const pp&a,const pp&b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
            cin>>p[i].x>>p[i].y;
        sort(p,p+n,cmp);
        int t=p[0].y+1,s=p[0].y-p[0].x+1;
        for(int i=1;i<n;i++)
        {
            if(p[i].x<t)
                p[i].x=t;
            if(p[i].y>=p[i].x)
            s+=p[i].y-p[i].x+1;
            t=p[i].y+1;
        }
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	char s[9];
	int y=700,i;
	scanf("%s",s); //"%s,s"と書いていたことに1か月立って気付く.
	for(i=0;i<3;i++) {
		if (s[i]=='o'){
			y=y+100;
		}
	}
	printf("%d\n",y);
	return 0;
}

Measured memory_bytes: 128
let input = require('fs').readFileSync('/dev/stdin', 'UTF-8');
let array = (input.trim()).split('\n').map(Number);
array.shift();
       
let countPrime = 0;
array.forEach(function(num) {
  if ((Prime(num)) == true) {
    countPrime++;
  }
})
console.log(countPrime);
       
function Prime(num) {
       
  if (num === 2) {
    return true;
  }
  if (num % 2 === 0) {
    return false;
  }
       
  for (let i = 2; i <= Math.sqrt(num); i++) {
    if (num % i === 0) {
      return false;
    }
  }
  return true;
}


Measured memory_bytes: 18200
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ll mod=1e9+7;
const ld PI = 2 * acos(0.0);
ll m(ll a){ return (a+mod)%mod;}
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
	if(b==0)
		return 1;
	ll d=power(a,b/2,m);
	d=(d*d)%m;
	if(b&1)
		d=(d*a)%m;
	return d;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :	
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns ``the first occurenece of qtr in str */
int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	
	string s;cin>>s;
	reverse(all(s));
	map<int,int>freq;
	int rem=0,p=1,ans=0;
	freq[0]=1;
	for(int i=0;i<sz(s);i++)
	{
		int d=s[i]-'0';
		d*=p;
		d%=2019;
		rem+=d;
		rem%=2019;
		ans+=freq[rem];
		freq[rem]++;
		p*=10;
		p%=2019;

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

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

int main(){
  string S;
  bool Alpha[26];
  cin >> S;
  for(int i=0;i<26;i++){
    Alpha[i]= false;
  }
  for(int i=0;i<S.size();i++){
    Alpha[S[i]-'a'] = true;
  }
  for(int i=0;i<26;i++){
    if(!Alpha[i]){
      cout << (char)(i+'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512