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

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

#define DEBUG(x) cerr << #x << ": " << x << endl

#define BITCOUNT(mask) ( __builtin_popcount((mask)) )

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> II;

#define MAXH 10
#define MAXW 1000
int H, W, K;
char B[MAXH+4][MAXW+4];

int psum_col[MAXW+4][MAXH+4];

const int INF = 100000000;

vector<II> get_horiz_intervals(int mask) {
   vector<II> res;
   res.emplace_back(1, 1);
   REP(k, H-1) {
      if (mask & (1<<k)) {
         // cut between indices k+1 and k+2
         res.back().second = k+1;
         res.emplace_back(k+2, k+2);
      }
   }
   res.back().second = H;
   return res;
}

int get_num_vert_cuts(const VVI& rows, bool trace = false) {
   int res = 0;
   const int nrows = SZ(rows);
   VI sums(nrows, 0);
   REP(c, W) {
      bool split = false;
      REP(i, nrows) {
         if (rows[i][c] > K)
            return INF;
         sums[i] += rows[i][c];
         if (sums[i] > K)
            split = true;
      }
      if (split) {
         ++res;
         REP(i, nrows) {
            sums[i] = rows[i][c];
         }
      }
   }
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   cin >> H >> W >> K;
   FOR(r, 1, H)
      cin >> B[r];

   REP(c, W) {
      FOR(r, 1, H) {
         psum_col[c][r] = psum_col[c][r-1] + (B[r][c]-'0');
      }
   }

   /*
   FOR(r, 1, H) {
      REP(c, W)
         cerr << psum_col[c][r] << ' ';
      cerr << endl;
   }
   */

   int res = INF;
   for (int mask = (1<<(H-1))-1; mask >= 0; --mask) {
      vector<II> hintervals = get_horiz_intervals(mask);
   // bool trace = mask == 0;
      VVI aggr_rows;
      for (II hint : hintervals) {
         VI row(W);
         REP(c, W)
            row[c] = psum_col[c][ hint.second ] - psum_col[c][ hint.first-1 ];
         aggr_rows.push_back(row);
      }
      int cur = BITCOUNT(mask) + get_num_vert_cuts(aggr_rows);
   // cerr << "mask:" << mask << "  cur:" << cur << endl;
      res = min(res, cur);
   }

   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 384
// D - Friend Suggestions
// UnionFinde version (None rank)
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

class UnionFind{//union-find class (None rank)
	vector<int> parent;//parent number
	vector<int> group_size;
	public:
	UnionFind(int n){
		parent.resize(n);
		group_size.resize(n);
		init();
	}
	void init(){//initialize all parent to root
		for(int v=0; v<parent.size(); ++v){
			parent[v] = v;
			group_size[v] = 1;
		}
	}
	int root(int v){//get root
		if(parent[v]==v) return v;//root
		return parent[v] = root(parent[v]);//path compression
	}
	bool same(int v, int u){//v & u the same set
		return root(v)==root(u);
	}
	void unite(int v, int u){
		v = root(v); u = root(u);
		if(v==u) return;
		parent[v] = u;
		group_size[u] += group_size[v];
		group_size[v] = 0;
	}
	int size(int v){
		return group_size[root(v)];
	}
};

#define MAX 100000+1

int main(){
	int N,M,K; cin>>N>>M>>K;

	UnionFind uf(N+1);

	vi C(MAX);//count: friend, block

	rp(i,0,M){
		int s,t; cin>>s>>t;
		uf.unite(s,t);
		C[s]++; C[t]++;
	}

	rp(i,0,K){
		int s,t; cin>>s>>t;
		if(uf.same(s,t)) C[s]++, C[t]++;
	}

	rp(i,1,N+1) cout<< uf.size(i)-C[i]-1 <<" ";

}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

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

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//bool f[100001];//1000000以下の素数を調べよう！
//rrep(i,2,100001){
  //      f[i]=false;
    //}
//rrep(i,2,100001){
  //      if(!f[i]){
    //        for(int j=i+i;j<=100000;j+=i){
      //          f[j]=true;
        //    }
        //}
    //}
    //for(int i=3;i<=100000;i+=2){
      //  if(!f[i]){
        //    c[i]++;
      //  }
   // }

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp[10000000],cmpp,m,k,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin >> n >> k;
       rep(i,n){cin>>a;
           cmp[a]++;
       }
       sort(cmp,cmp+10000000);
       reverse(cmp,cmp+10000000);
       rrep(i,k,10000000){
           ans+=cmp[i];
       }
       Cout(ans);
       
return 0;
}


Measured memory_bytes: 78336
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            int ret = 0;
            for (int i = 0; i < N; i++)
            {
                var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = r[0]; j <= r[1]; j++)
                {
                    ret++;
                }
            }
            Console.WriteLine(ret);
        }
        
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}
char s[1010],t[1010];
int ans;
int main()
{
	scanf("%s%s",s,t);
	int l1=strlen(s),l2=strlen(t);
	ans=l1;
	for(int i=0;i<=l1-l2;i++)
	{
		int cnt=0;
		for(int j=0;j<l2;j++)
		{
			if(t[j]!=s[i+j])cnt++;
		}
		ans=min(ans,cnt);
	}
	printf("%d\n",ans);
	return 0;
}
/*
i 最大值：
i+j l1-1
j l2-1
i l1-l2 
l1-l2-1+l2-1
*/


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

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		//		new Main().solveC();
		new Main().solveC2();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			if (numN % 2 == 0) {
				System.out.println(numN);
			} else {
				System.out.println(numN * 2);
			}

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			int[] wk = new int[numN];

			for (int i = 0; i < wk.length; i++) {
				wk[i] = scanner.nextInt();
			}
			Arrays.sort(wk);

			System.out.println(wk[wk.length - 1] - wk[0]);

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private int getCry(int b, int currentI, int maxI, int[] wk) {
		if (currentI == maxI) {
			return 0;
		}

		return getCry(b, currentI + 1, maxI, wk) + Math.abs(wk[currentI] - (b + currentI + 1));
	}

	private void solveC2() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - (i + 1);
		}
		sc.close();
		Arrays.sort(A);
		int med = N % 2 == 0 ? N / 2 - 1 : N / 2;
		int b = A[med];
		long ans = 0;
		for (int a : A) {
			ans += Math.abs(a - b);
		}

		System.out.println(ans);
	}

	/**
	 * ⅰ)abs(xi-a)の総和(aとの距離の総和)を最小にするのは中央値で、
	 * ⅱ)(xi-a)^2の総和を最小にするのは平均値
	 */
	private void solveC() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			int[] resArray = new int[numN];

			for (int i = 0; i < numN; i++) {
				resArray[i] = scanner.nextInt();
			}

			int[] wk = new int[numN];
			for (int i = 0; i < numN; i++) {
				wk[i] = resArray[i] - (i + 1);
			}
			Arrays.sort(wk);

			int b = 0;
			if (numN % 2 == 0) {
				b = wk[numN / 2 - 1];
			} else {
				b = wk[numN / 2];
			}
			int res = 0;

			for (int a : resArray) {
				res += Math.abs(a - b);
			}
			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 83332
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int n, a, b; cin >> n >> a >> b;
    int t[1010]; rep(i,0,n) cin >> t[i];

    int ans = n;
    rep(i,0,n) {
        if(a <= t[i] && t[i] < b) ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

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

		long ans = a == b ? 1 : n - 2 < 0 || a > b ? 0 : (n - 2) * (b - a) + 1;
		System.out.println(ans);

		sc.close();
	}

}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

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

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    string S;
    cin >> S;
    int N = (int)S.size();

    Vi Ridxs;
    Vi nR, nL;

    bool is_R = true;
    int cnt = 1;
    for (int i = 1; i < N; i++) {
        if (is_R) {
            if (S[i] == 'R') {
                ++cnt;
            }
            else {
                Ridxs.emplace_back(i - 1);
                nR.emplace_back(cnt);
                cnt = 1;
                is_R = false;
            }
        }
        else {
            if (S[i] == 'R') {
                nL.emplace_back(cnt);
                cnt = 1;
                is_R = true;
            }
            else {
                ++cnt;
            }
        }
    }

    nL.emplace_back(cnt);

    Vi ans(N);
    int K = (int)Ridxs.size();
    for (int i = 0; i < K; i++) {
        ans[Ridxs[i]] = (nR[i] + 1) / 2 + nL[i] / 2;
        ans[Ridxs[i] + 1] = (nL[i] + 1) / 2 + nR[i] / 2;
    }

    for (int i = 0; i < N - 1; i++) {
        cout << ans[i] << ' ';
    }
    cout << ans[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 1736
package main

import "fmt"

const (
	MIN = -1000000
	MAX = 1000000
)

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

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func main() {
	var k, x int

	fmt.Scan(&k)
	fmt.Scan(&x)

	a := max(x-k+1, MIN)
	b := min(x+k-1, MAX)

	for i := a; i <= b; i++ {
		if i == a {
			fmt.Printf("%d", i)
		} else {
			fmt.Printf(" %d", i)
		}
	}
	fmt.Println()
}


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

int main() {
    int n, m; cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int a; cin >> a;
        sum += a;
    }
    if (sum > n) {
        cout << -1 << endl;
    } else {
        cout << (n - sum) << endl;
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e7+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    pair<ll,ll>p[x];
    for (int i=0; i<x; i++)
        cin>>p[i].first>>p[i].second;
    sort(p,p+x);
    int ans=0,ans2=0;
    ll o=p[0].first+p[0].second;
    for (int i=1; i<x; i++)
    {
        if (o>p[i].first-p[i].second)
        {
            if (o>=p[i].first+p[i].second)
            {
                o=p[i].first+p[i].second;
                ans++;
                continue;
            }
            else
            {
                ans++;
            }
        }
        else
        {
            o=p[i].first+p[i].second;
        }
    }
    cout<<x-ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
mod = 10**9+7

ans = sum(A)**2
ans %= mod
a = sum(A[i]**2 for i in range(N))
a %= mod
ans -= a
ans *= pow(2,mod-2,mod)
ans %= mod
print(ans)


Measured memory_bytes: 94088
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const lli inf=1e18;
const int mod=1e9+7;
int main(){
IOS;
int n,i,j,x,y,z,k;
cin>>n;
vector<vector<pair<int,int> > > v(n+1);
for(i=0;i<n;i++){
    cin>>x;
    for(j=0;j<x;j++){
        cin>>y>>z;
        v[i].pb({y,z});
    }
}
int maxi=0;
for(i=0;i<(1<<n);i++){
    int honest[n];
    memset(honest,0,sizeof(honest));
    for(j=0;j<n;j++){
        if(i&(1<<j))
            honest[j]=1;
    }
    for(j=0;j<n;j++){
        if(honest[j]){
            for(k=0;k<v[j].size();k++){
                x=v[j][k].first;
                y=v[j][k].second;
                if(honest[x-1]!=y)
                    break;
            }
            if(k<v[j].size())
            break;
        }
    }
    if(j!=n)
        continue;
    maxi=max(maxi,__builtin_popcount(i));
}
cout<<maxi<<endl;
}


Measured memory_bytes: 256
/* */
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
const int MAX_LEN = 1010;
#define GETLINE(x) fgets(x,MAX_LEN,stdin);
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<double, double> dd;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<ll> vll;
#ifdef XVENOM
  #define errp(...) fprintf(stderr, __VA_ARGS__)
  #define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
  #define errp(...)
  #define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
  string s_ = "[ ";
  for (const auto& x_ : e_) s_ += to_string(x_) + " ";
  return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
  return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
   errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
const ll N=55555;
vll primes;
bitset<N> bs;
void sieve(){
    bs.set();
    bs[0]=bs[1]=0;
    for(ll i=2;i<=N;i++)if(bs[i]){
        for(ll j=i*i;j<=N;j+=i)
            bs[j]=0;
        if(i%5==1)primes.push_back((int)i);
    }
}
int n;
int main () { 
  sieve();
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    printf("%d ",primes[i]);
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var weekday=[
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
];
for(var i=0;i<Arr.length;i++){
var v=Arr[i];
if(v=="0 0")break;
var str="2004/"+v.replace(/\s/,"/");
var today = new Date(str) ;
console.log(weekday[today.getDay()]);
}

Measured memory_bytes: 7620
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = n-1; i > 0; i--)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};


template<class T>
T gcd(T a,T b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(a%b,b);
}

bool solve(){
  ll n,k;cin>>n>>k;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  ll ans=INF;
  rep(i,n){
    if(i+k>n)continue;
    ans=min(ans,min(abs(a[i]),abs(a[i+k-1]))+abs(a[i+k-1]-a[i]));
  }  
  cout<<ans<<endl;
  return false;
}


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


Measured memory_bytes: 1024
H, W, K = map(int,input().split())
S = [list(input()) for _ in range(H)]
cnt = 1
x = 0
for i in range(H):
  if "#" not in S[i]:
    x += 1
    if i == H-1:
      for i in range(x):
        print(*ans)
    continue
  j = 0
  std = 0
  ans = []
  for j in range(W):
    if S[i][j] == "#":
      for k in range(j-std+1):
        ans.append(cnt)
      if j < W - 1 and "#" not in S[i][j+1:]:
        for l in range(W-j-1):
          ans.append(cnt)
      std = j+1
      cnt += 1
  print(*ans)
  while x:
    print(*ans)
    x -= 1
    

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

int main()
{
  int r, D, x0;
  cin >> r >>  D >>  x0;

  int x=x0;
  rep(i,10){
    x = r*x-D;
    cout << x << endl;
  }

}


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

int main() {
    string n;
    cin >> n;
    // cout << n;
    string ss = n.substr(n.size() - 1,1);
    // cout << ss << " " << ss << endl;
    if (ss[0] == '3')
        cout << "bon" << endl;
    else if (ss[0] == '0' || ss[0] == '1' || ss[0] == '6' || ss[0] == '8')
        cout << "pon" << endl;
    else
        cout << "hon" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    vector<int> W(N + 2), E(N + 2);
    W[0] = 0; E[0] = 0;
    for (int i = 1; i <= N; i++) {
        if (S[i - 1] == 'W') {
            W[i] = W[i - 1] + 1;
            E[i] = E[i - 1];
        } else {
            W[i] = W[i - 1];
            E[i] = E[i - 1] + 1;
        }
    }
    W[N + 1] = W[N]; E[N + 1] = E[N];

    int ans = N + 1;
    for (int i = 1; i <= N; i++) {
        int num = W[i - 1] + E[N + 1] - E[i];
        ans = min(ans, num);
    }

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

Measured memory_bytes: 3076
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if(2*n <= m){
        ans = n;
        m -= 2*n;
        n = 0;
    }
    else{
        ans = m/2;
        n -= m/2;
        m %= 2;
    }
    ans += m / 4;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
#define pl pair<ll,ll>
#define pi pair<int,int>
#define pll pair< ll, pair<ll,ll> > 
#define pii pair< int, pair<int,int> >
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll l,t,T,x,y,z;
    string s,ss;
    cin>>s;
    cin>>ss;
    ll ans = INT_MAX;
    ll n = s.length();
    ll m = ss.length();
    rep(i,0,n-m){
    	x= 0;
		rep(j,0,m-1){
    		if(s[i+j] != ss[j]) x++;
		}
		ans =  min(ans,x);
	}
	cout<<ans;
}

Measured memory_bytes: 3616
#include <stdio.h>
int main(){
    int a,b,c,d;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);
    if(a+b>c+d){
        printf("Left");
        return 0;
    }
    if(a+b==c+d){
        printf("Balanced");
        return 0;
    }
    else
    printf("Right");
    return 0;
}



Measured memory_bytes: 128
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	fa := float64(a)
	fanswer := math.Abs(fa)
	return int(fanswer)
}

// DeleteElement returns a *NEW* slice, that have the same and minimum length and capacity.
// DeleteElement makes a new slice by using easy slice literal.
func DeleteElement(s []int, i int) []int {
	if i < 0 || len(s) <= i {
		panic(errors.New("[index error]"))
	}
	// appendのみの実装
	n := make([]int, 0, len(s)-1)
	n = append(n, s[:i]...)
	n = append(n, s[i+1:]...)
	return n
}

// Concat returns a *NEW* slice, that have the same and minimum length and capacity.
func Concat(s, t []rune) []rune {
	n := make([]rune, 0, len(s)+len(t))
	n = append(n, s...)
	n = append(n, t...)
	return n
}

// sort package (snippets)
//sort.Sort(sort.IntSlice(s))
//sort.Sort(sort.Reverse(sort.IntSlice(s)))
//sort.Sort(sort.Float64Slice(s))
//sort.Sort(sort.StringSlice(s))

// copy function
//a = []int{0, 1, 2}
//b = make([]int, len(a))
//copy(b, a)

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

var a, b int

func main() {
	tmp := NextIntsLine()
	a, b = tmp[0], tmp[1]
	var str string
	if a != 1 && b != 1 {
		if a > b {
			str = "Alice"
		} else if a < b {
			str = "Bob"
		} else {
			str = "Draw"
		}
	} else {
		if a == 1 && b == 1 {
			str = "Draw"
		} else if a == 1 {
			str = "Alice"
		} else {
			str = "Bob"
		}
	}
	fmt.Println(str)
}


Measured memory_bytes: 640
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = bin(int(input()))[2:]
    ans = [100, 100] + list(range(1, len(N))) + list(range(1, len(N)))
    k = len(N)
    for i in range(len(N) - 1):
        if N[-i-1] == "1":
            for j in range(len(ans)):
                if ans[j] == i+1:
                    ans.insert(j, k)
                    k += 1
                    break
    ans += list(range(k-1, len(N) - 1, -1))
    print(len(ans))
    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63448
#include<bits/stdc++.h>
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n,r;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>r;
	if(n>=10){//converge
		cout<<r<<endl;
		return 0;
	}
	else{
		cout<<(r+100*(10-n))<<endl;
	}
	return 0;
}


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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'

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

    ll ans=0;

    string temp="";
    ffor(i,n,2*n) temp+=s[i];

    map<pair<string,string>,int> m;
    ffor(i,0,1<<n)
    {
        string xx="",yy="";
        ffor(j,0,n)
        {
            if(i&(1<<j)) xx+=temp[j];
            else yy+=temp[j];
        }
        reverse(all(xx));
        reverse(all(yy));
      //  if(xx>yy) swap(xx,yy);
        m[{xx,yy}]++;
     //   cout<<xx<<" "<<yy<<endl;
    }

    ffor(i,0,1<<n)
    {
        string a="", b="";
        ffor(j,0,n)
        {
            if(i&(1<<j)) a+=s[j];
            else b+=s[j];
        }
     /*   string a1="",b1="";
        int c=0;
        bfor(i,2*n,n)
        {
            if(c<sz(a)&&s[i]==a[c]) { b1+=s[i]; c++; }
            else a1+=s[i];
        }
       // cout<<endl;
        reverse(all(a1));
        reverse(all(b));*/
       // cout<<a+a1<<" "<<b+b1<<endl;
     //   reverse(all(a));
     //   reverse(all(b));
      //  cout<<a<<" "<<b<<endl;
        ans+=m[{a,b}];
    }
    cout<<ans;
    
    return 0;
}



Measured memory_bytes: 87040
#include<iostream>
#include<algorithm>
const int maxn = 2000 + 10;
using namespace std;
bool cmp(int a,int b)
{
	return a < b;
}
int main()
{
	int n,i,j,pos,t; int s[maxn];
	long ans;
	cin >> n; ans = 0;
	for (i = 1; i <= n; i++) cin >> s[i];
	sort(s + 1, s + n + 1, cmp);
	for (i = 1; i <= n - 2; i++)
		for (j = i + 1; j <= n - 1; j++)
		{
			t = s[i] + s[j];
			pos = (int)(lower_bound(s + j + 1, s + n + 1, t)-s);
			ans += (pos - j - 1);
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int DP[401][401];//DP[i][j]:min(cost((A,B)=(i,j)))

int main(){
  int N,Ma,Mb,a,b,c,ans=INF;
  FOR(i,0,401)FOR(j,0,401)DP[i][j] = INF;
  DP[0][0] = 0;
  cin >> N >> Ma >> Mb;
  vector<tuple<int,int,int>> product;
  FOR(i,0,N){
    cin >> a >> b >> c;
    product.push_back(make_tuple(a,b,c));
  }
  for(auto p:product){
    REP(i,0,401)REP(j,0,401){
      if(0 <= i-get<0>(p) && 0 <= j-get<1>(p)){
        DP[i][j] = min(DP[i][j],DP[i-get<0>(p)][j-get<1>(p)]+get<2>(p));
      }
    }
  }
  for(int i = 1;max(Ma*i,Mb*i) <= 400;i++){
    ans = min(ans,DP[i*Ma][i*Mb]);
  }
  if(ans != INF)cout << ans << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 1024
using System;

namespace dotnet_test
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();

            int Q = int.Parse(Console.ReadLine());

            bool rev = false;
            char[] front = new char[200001];
            char[] back = new char[200001];
            int nfront=0, nback=0;

            for(int iq = 0; iq < Q; iq++){
                string line = Console.ReadLine();
                var T = line[0];
                if(T == '1'){
                    rev = !rev;
                    continue;
                }

                var F = line[2];
                var C = line[4];
                if((F == '1' && !rev) || (F == '2' && rev)){
                    front[nfront] = C;
                    nfront++;
                }else{
                    back[nback] = C;
                    nback++;
                }
            }

            if(rev){
                for (int i = nback - 1; i >= 0 ; i--)
                {
                    Console.Write(back[i]);
                }
                for (int i = S.Length - 1; i >= 0 ; i--)
                {
                    Console.Write(S[i]);
                }
                for (int i = 0; i < nfront; i++)
                {
                    Console.Write(front[i]);
                }
            }else{
                for (int i = nfront - 1; i >= 0 ; i--)
                {
                    Console.Write(front[i]);
                }
                for (int i = 0; i < S.Length; i++)
                {
                    Console.Write(S[i]);
                }
                for (int i = 0; i < nback; i++)
                {
                    Console.Write(back[i]);
                }
            }

            Console.WriteLine("");
        }
    }
}


Measured memory_bytes: 16476
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
ll q, a, b;
ll calc(ll a, ll b){
  if(a > b) swap(a, b);
  ll r = a*2-2, p = a*b-1, q=sqrt((long double)p);
  if(b<=a+1) return r;
  r += (q-a)*2+1;
  if(q==p/q) r--;
  return r;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> q;
  FOR(_, 0, q){
    ll a, b;
    cin >> a >> b;
    cout << calc(a, b) << endl;
  }
}

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

int main(){
	int A,B,C;
	cin >> A >> B >> C;
	
	if(A >= B && A >= C){
		cout << 10*A + B + C << endl;
	}
	else if(B >= A && B >= C){
		cout << 10*B + A + C << endl;
	}
	else{
		cout << 10*C + A + B << endl;
	}

	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main(){
    int n, q; cin >> n >> q;
    vector<vector<int>> event;
    int s, t, x;
    for(int i=0; i<n; i++){
        cin >> s >> t >> x;
        event.push_back(vector<int>{s-x, 0, x});
        event.push_back(vector<int>{t-x, 1, x});
    }
    int d;
    for(int i=0; i<q; i++){
        cin >> d;
        event.push_back(vector<int>{d, 2, 0});
    }
    sort(event.begin(), event.end());
    multiset<int> ms;
    for(auto& e:event){
        // for(auto& v:e){
        //     cout << v << " ";
        // }
        // cout << "\n";
        if(e[1] == 0){
            ms.insert(e[2]);
        }
        else if(e[1] == 1){
            ms.erase(ms.lower_bound(e[2]));
        }
        else if(e[1] == 2){
            // for(auto& v:ms){
            //     cout << v << " ";
            // }
            // cout << "\n";
            if(ms.empty()){
                cout << "-1" << "\n";
            }
            else{
                cout << *ms.begin() << "\n";
            }
        }
    }
    return 0;
}

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

string s1, s2, s3;

string s[3];
int main() {
    rep(i, 3) {
        cin >> s[i];
    }

    rep(i, 3) {
        printf("%c", toupper(s[i][0]));
    }


    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,r;
	cin>>n>>r;
	if(n>=10) cout<<r;
	else
	{
	    cout<<r+100*(10-n);
	}
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i,0,n)
#define BFOR(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define BREP(bit,n) BFOR(bit,0,n)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n,vector<int> (26));
  vector<string> s(n);
  
  REP(i,n){
    cin >> s[i];
    int m = s[i].size();
    REP(j,m){
      int b = s[i][j] - 'a';
      a[i][b]++;
    }
  }
  
  vector<int> cnt(26,10000);
  REP(i,n){
    REP(j,26){
      cnt[j] = min(cnt[j],a[i][j]);
    }
  }
  
  string op = "";
  REP(i,26){
    REP(j,cnt[i]){
      op += i+'a';
    }
  }

  cout << op << endl;


}

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

int main()
{
  int n;
  cin>>n;
  int dmin=0;
  for(int i=0; i<n;i++){
    int a;
    int d=0;
    
    
    cin>>a;
    while(a%2==0){
      a/=2;
      d++;

    }
    if(i==0){
      dmin=d;
    }
    else dmin=min(dmin,d);
    /*if(i==n-1){
      break;
    }*/
  }
  cout<<dmin<<endl;

  
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
        int n = sc.nextInt();
        int x = sc.nextInt();
            if(n == 0 && x == 0) break;
        int s = 0;
        for(int i = 1; i <= n; i++) {
            for(int j = i + 1; j <= n; j++) {
                for(int k = j + 1; k <= n; k++) {
                    if(i + j + k == x) s++;
                }
            }
        }
        System.out.println(s);
        }
    }
}


Measured memory_bytes: 26652
n = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
ans = 0
A.sort()
if n%2==1:
    st = 0
    for i in range(1,n):
        if i%2==1:
            st+=2
        if A[i]!=st:
            print(0)
            exit()
else:
    st =-1
    for i in range(0,n):
        if i%2==0:
            st+=2
        if A[i]!=st:
            print(0)
            exit()
print(pow(2,n//2,mod))


Measured memory_bytes: 14008
#include<stdio.h>
int main(){
  int H,W,h,w,i=1,j;
  scanf("%d%d%d%d",&H,&W,&h,&w);
  if(H%h||W%w) for(puts("Yes");i<=H;++i,puts("")) for(j=0;j<W;++j,printf("%d ",(i%h||j%w)?1000:-1000*(h*w-1)-1));
  else puts("No");
  return 0;
}

Measured memory_bytes: 1536
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	max := 12*a + a/2 + 1
	min := 10 * b
	for i := min; i <= max; i++ {
		if 8*i/100 == a && i/10 == b {
			fmt.Println(i)
			return
		}
	}
	for i := max; i <= min; i++ {
		if 8*i/100 == a && i/10 == b {
			fmt.Println(i)
			return
		}
	}
	fmt.Println("-1")
	return
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int ans = 100000;
        for(int i = 0; i < n; i++){
            ans = (int)Math.ceil(ans * 1.05 / 1000) * 1000;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 26108
import math

N = int(input())

CSFs = [list(map(int, input().split(' '))) for i in range(N - 1)]

for i in range(0, N - 1):
    arrive_time = CSFs[i][0] + CSFs[i][1]
    for j in range(i + 1, N - 1):
        if arrive_time <= CSFs[j][1]:
            arrive_time = CSFs[j][1]
        elif arrive_time % CSFs[j][2] == 0:
            arrive_time = arrive_time
        else:
            # t <= S + F * k (k = integer)
            k = math.ceil((arrive_time - CSFs[j][1]) / CSFs[j][2])
            arrive_time = CSFs[j][1] + CSFs[j][2] * k
        arrive_time += CSFs[j][0]
    print(arrive_time)
print(0)

Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    ll sum = abs(A[0]) + abs(A.back());
    for(int i = 1; i < N; i++) sum += abs(A[i] - A[i - 1]);

    for(int i = 0; i < N; i++){
        ll min_n = sum;
        if(i == 0){
            min_n += -abs(A[i]) - abs(A[i + 1] - A[i]) + abs(A[i + 1]);
        }else if(i == N - 1){
            min_n += -abs(A[i]) - abs(A[i] - A[i - 1]) + abs(A[i - 1]);
        }else{
            min_n += -abs(A[i] - A[i - 1]) - abs(A[i] - A[i + 1]) + abs(A[i + 1] - A[i - 1]);
        }
        cout << min_n << endl;
    }
}

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

int main() {
	int n;
	cin >> n;
	int *a = new int[n + 2];
	int sum = 0;
	a[0] = 0;
	a[n + 1] = 0;
	for (int i = 1; i < n + 1; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n + 1; ++i) {
		sum += abs(a[i] - a[i + 1]);
	}
	for (int i = 1; i < n + 1; ++i) {
		cout << sum -  abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1])
			+ abs(a[i - 1] - a[i + 1])<< endl;
	}
	delete[]a;
}

Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int H,W;
        String work[] = new String[2];
 
        while(true){
 
            try {
                work = br.readLine().split("[\\s]+");
 
                if(work[0].equals("0") && work[1].equals("0"))break;
 
                H = Integer.parseInt(work[0]);
                W = Integer.parseInt(work[1]);
 
                for(int col = 0; col < W; col++){
                    System.out.printf("#");
                }
                System.out.printf("\n");
 
                for(int row = 1; row <= H-2; row++){
                    System.out.printf("#");
                    for(int col = 1; col <= W-2; col++){
                        System.out.printf(".");
                    }
                    System.out.printf("#\n");
                }
 
                for(int col = 0; col < W; col++){
                    System.out.printf("#");
                }
                System.out.printf("\n\n");
 
 
            } catch (IOException e) {
 
                e.printStackTrace();
            }
        }
    }
}


Measured memory_bytes: 57556
n,m,i,j;
main()
{
  char x[99],y[99],t;
  for(;scanf("%d",&n),n;puts(""))
    {
      for(i=0;i<n;i++)
	scanf(" %c %c",&x[i],&y[i]);
      scanf("%d",&m);
      for(j=0;j++<m;putchar(t))
	{
	  scanf(" %c",&t);
	  for(i=0;i<n;i++)
	    if(x[i]==t)t=y[i],i=n;
	}
    }
  exit(0);
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if sum(A) > sum(B):
    counter = 0
    array = []
    num = 0
    for i in range(N):
        if A[i] >= B[i]:
            array.append(A[i] - B[i])

        else:
            counter += 1
            num += (B[i] - A[i])

    array.sort()
    while num > 0:
        counter += 1
        num -= array[-1]
        del array[-1]

    print(counter)
    
else:
    print(-1)


Measured memory_bytes: 18356
#include <stdio.h>
int main(void){
  int i,j;
  int n,m;
  int a[50],b[50];
  int co[50];
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d %d",&a[i],&b[i]);
  }
  for(i=0;i<n;i++) co[i]=0;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      if(a[j]==i+1) co[i]++;
      if(b[j]==i+1) co[i]++;
    }
  }
  for(i=0;i<n;i++){
    printf("%d\n",co[i]);
  }
  return(0);
}
  

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

typedef long long ll;

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  map<int, bool> m;

  for(int i = 0; i < M; i++){
    int tmp;
    cin >> tmp;
    m[tmp] = true;
  }
  
  int ans1 = 0; 
  int ans2 = 0;
  for(int i = X; i >= 0; i--){
    if(m.count(i) != 0){
      ans1++;
    }
  }
  for(int i = X; i <= N; i++){
    if(m.count(i) != 0){
      ans2++;
    }
  }
  cout << min(ans1,ans2) << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int a[2001],d[2001],n;

void dfs(int sum, int k) {
  if(k==n) {
    d[sum]=1;
    return;
  }
  dfs(sum,k+1);
  if(sum+a[k]<=2000) dfs(sum+a[k],k+1);
}

int main() {
  int i,m,x;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  dfs(0,0);
  scanf("%d",&m);
  for(i=0; i<m; i++) {
    scanf("%d",&x);
    if(d[x]) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}


Measured memory_bytes: 588