akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll dp[1 << 16];

int main() {
    init();
    ll N;
    cin>>N;
    vvc<ll> A(N, vl(N));
    rep(i, N) rep(j, N) cin >> A[i][j];

    repe(bit, 1, 1 << N) {
        rep(i, N){
            if (!(bit & 1 << i)) continue;
            repe(j, i + 1, N){
                if (!(bit & 1 << j)) continue;
                dp[bit] += A[i][j];
            }
        }
        for (ll c = (bit - 1) & bit; c > 0; c = (c - 1) & bit){
            chmax(dp[bit], dp[c] + dp[bit ^ c]);
        }
    }

    cout << dp[(1 << N) - 1] << endl;
}

Measured memory_bytes: 4184
package main

import (
  "fmt"
)

func main(){
  
  var N int
  var A [200000] int
  var max_num int
  var max_num2 int
  fmt.Scan(&N)
  max_num = 0
  max_num2 = 0
  
  for i := 0; i < N; i++ {
    fmt.Scan(&A[i])
    if (A[i] >= max_num){
      max_num2 = max_num
      max_num = A[i]
    }
    if (A[i] > max_num2 && A[i] < max_num){
      max_num2 = A[i]
    }
  }
  for i := 0; i < N; i++ {
    if (max_num == A[i]){
      fmt.Println(max_num2)
    }else if(max_num == 0 || max_num2 == 0){
      fmt.Println(A[i])
    }else{
      fmt.Println(max_num)
    }
  }
}

Measured memory_bytes: 6400
#include<iostream>
using namespace std;
int a,b;
string s[100];
main()
{
	cin>>a>>b;
	cout<<"100 100"<<endl;
	for(int i=0;i<50;i++)s[i]=string(100,'.');
	for(int i=50;i<100;i++)s[i]=string(100,'#');
	for(int i=0;i<50;i+=2)for(int j=0;j<100;j+=2)if(b>1)b--,s[i][j]='#';
	for(int i=51;i<100;i+=2)for(int j=0;j<100;j+=2)if(a>1)a--,s[i][j]='.';
	for(int i=0;i<100;i++)cout<<s[i]<<endl;
}

Measured memory_bytes: 256
package main

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

// func init() { Println("----------------------------------------") }

func main() {
    var n, m, x int
    Scanf("%d %d %d", &n, &m, &x)

    var sc = bufio.NewScanner(os.Stdin)
    sc.Scan()
    s := sc.Text()
    s2 := strings.Split(s, " ")
    nums := make([]int, 0, 100)
    for _, v := range s2 {
        i, _ := strconv.Atoi(v)
        nums = append(nums, i)
    }

    l, r := 0, 0
    for _, v := range nums {
        if v < x {
            l++
        } else {
            r++
        }
    }
    Println(math.Min(float64(l), float64(r)))
}


Measured memory_bytes: 640
from bisect import bisect_left
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))

cumsum = list(accumulate(A))
cumsum.insert(0, 0)

ans = float('inf')
# 真ん中区切り全探索
for m in range(2, N-1):
    # 左
    Lmid = cumsum[m] / 2
    Lx = bisect_left(cumsum, Lmid)

    # 境界チェック
    if abs(Lmid - cumsum[Lx]) > abs(Lmid - cumsum[Lx-1]):
        Lx -= 1


    # 右
    Rmid = (cumsum[m] + cumsum[N]) / 2
    Rx = bisect_left(cumsum, Rmid)

    # 境界チェック
    if abs(Rmid - cumsum[Rx]) > abs(Rmid - cumsum[Rx-1]):
        Rx -= 1

    P, Q, R, S = cumsum[Lx], cumsum[m]-cumsum[Lx], cumsum[Rx]-cumsum[m], cumsum[N]-cumsum[Rx]
    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))

print(ans)


Measured memory_bytes: 24180
#include<iostream>

using namespace std;

#define MAX 10000

int N, M, A,B;

int D[MAX];
int trash[MAX];


int main(){
    int i=0;
    for(i=0;i<MAX;i++){
        D[i]=0;
        trash[i]=0;
    }
    cin>>N;
    cin>>M;
    cin>>A;
    cin>>B;
    for(i=0;i<N;i++){
        cin>>D[i];
    }
    
    int j=0;
    for(i=0;i<N;i++){
        if(A<=D[i]){
            trash[j]=D[i];
            j++;
        }else{
            break;
        }
    }
    if(M<=(N-j)){
        cout<<j<<endl;
        return 0;
    }
    else{
        for(i=j-1;0<=i;i--){
            if(B<trash[i]){
                cout<<i+1<<endl;
                return 0;
            }
        }
    cout<<0<<endl;
    }

    return 0;
}

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

class UnionFind {
public:
    vector<int> par, rank, siz;
    
    UnionFind(int n) {
        par.resize(n);
        for (int i=0; i<par.size(); ++i) par[i] = i;

        rank.resize(n, 0);
        siz.resize(n, 1);
    }
    
    int root(int a) {
        if (par[a] == a) return a;
        return par[a] = root(par[a]);
    }

    void unite(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;

        if (rank[a] >= rank[b]) {
            par[b] = a;
            if (rank[a] == rank[b]) {
                rank[a] ++;
            }
            siz[a] += siz[b];
        } else {
            par[a] = b;
            siz[b] += siz[a];
        }
    }

    bool same(int a, int b) {
        return root(a) == root(b);
    }

    int count(int a) {
        return siz[root(a)];
    }
};

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

    int N, M;
    cin >> N >> M;

    vector<int> A(M), B(M);
    for (int i=0; i<M; ++i) {
        cin >> A[i] >> B[i];
        A[i] --;
        B[i] --;
    }
    
    UnionFind uf(N);
    long long pa = 0;

    vector<long long> ans(M);
    ans[M-1] = (long long)N * (N-1) / 2;
    
    for (int i=M-1; i>0; --i) {
        pa += ( ! uf.same(A[i], B[i])) ? (long long)uf.count(A[i]) * uf.count(B[i]) : 0;
        uf.unite(A[i], B[i]);
        ans[i-1] = ans[M-1] - pa;
    }

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

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
  string s;
  int N;
  cin >> N >> s;
  int x =0;
  rep(i, N-2){
    if(s[i]=='A'){
    if(s[i+1]=='B'){
    if(s[i+2]=='C'){
    x++;
    }
    }
    }
    
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<string>

using namespace std;

int main(){
	
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		int pre[n];
		string str;
		for(int i=0;i<n;i++){
			cin >> pre[i];
		}

		cin >> str;
			
		for(int i=0;i<str.size();i++){	
			for(int j=pre[i%n];j>0;j--){
				str[i]--;
				if(str[i]<=('A'-1)) str[i]='z';	
				if(str[i]==96 ) str[i] = 'Z';
			}
		}
		cout << str << endl;
	}
}

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

public class Main {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Main().run();
        // Sworn to fight and die
    }

    void init() throws FileNotFoundException {
        if (1 > 0) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    public int check(int[] a, int start) {
        int current = start;
        for (int i = 0; i < a.length; i++) {
            if (current % a[i] != 0) {
                current = (current / a[i]) * a[i];
            }
        }
        if (current == 2) {
            return 1;
        } else {
            return -1;
        }
    }

    public void solve() throws IOException {
        int k = readInt();
        int[] a = new int[k];
        int max = -1;
        for (int i = 0; i < k; i++) {
            a[i] = readInt();
            max = Math.max(max, a[i]);
        }

        if (a[k - 1] > 2) {
            out.print(-1);
            return;
        }

        long l = 2;
        long r = 2;

        for (int i = k - 1; i >= 0; i--) {
            long x = l / a[i];

            if (l % a[i] != 0) {
                x++;
            }

            if (x * a[i] < l || x * a[i] > r) {
                out.print(-1);
                return;
            }

            long y = r / a[i];

            if (y * a[i] < l || y * a[i] > r) {
                out.print(-1);
                return;
            }

            l = x * a[i];
            r = y * a[i] + (a[i] - 1);
        }
        out.print(l + " " + r);
    }
}

Measured memory_bytes: 38724
#include <bits/stdc++.h>
#define ll long long int
#define K 1000000007
//#define x first
//#define y second
using namespace std;

int main() {
	/*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    */
    string s;
    cin>>s;
    
    int n=s.size();
    if(s[n-1]=='s'){
        //s.pop_back();
        s=s+"es";
    }
    else s+="s";
    cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define READ freopen("in.txt", "r", stdin)
#define WRITE freopen("out.txt", "w", stdout)
#define sz size()
#define number_of_digit(n) __builtin_ffs(n);
#define ll long long
#define T int
#define ld long double
inline void print(T n)
{
	if (n == 0)
	{
		putchar('0');
		putchar('\n');
	}
	else if (n == -1)
	{
		putchar('-');
		putchar('1');
		putchar('\n');
	}
	else
	{
		char buf[11];
		buf[10] = '\n';
		int i = 9;
		while (n)
		{
			buf[i--] = n % 10 + '0';
			n /= 10;
		}
		while (buf[i] != '\n')
			putchar(buf[++i]);
	}
}
int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int ret = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          ret = ret * 10 + cc - '0';
          cc = getc(stdin);
       }
      return ret;
}
ll power(ll num,ll g)
{
	if(g==0)return 1;

	if(g%2==1)return (num*power((num*num)%mod,g/2))%mod;
	return power((num*num)%mod,g/2);
}
bool visit[1000005];
int main()
{
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);

  	int n,k;
  	cin>>n>>k;
  	int a[n];
  	For(i,n)cin>>a[i];
  	int b[n];
  	b[0]=0;
  	for(int i=0;i<min(k,n);i++)b[i]=abs(a[i]-a[0]);
  	for(int i=k;i<n;i++)
  	{
  		b[i]=INT_MAX;
  		For(j,k)
  		{
  			b[i]=min(b[i],b[i-j-1]+abs(a[i]-a[i-j-1]));
  		}
  	}
  	cout<<b[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin >> H >> W;
  vector<char>a(W);
  for (int j=-1;j<W+1;j++){
    cout << "#";
  }
  cout << endl;

  for (int i=0;i<H;i++){
    cout << "#";
    for (int j=0;j<W;j++){
      cin >> a.at(j);
      cout << a.at(j);
    }
    cout << "#" << endl;
  }

  for (int j=-1;j<W+1;j++){
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int num[4][3][10]={};
    for(int i=0;i<n;i++){
        int b,f,r,v;
        cin>>b>>f>>r>>v;
        num[b-1][f-1][r-1] +=v;
    }
    
    for(int i=0;i<4;i++){
        if(i) cout<<"####################"<<endl;
        
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout<<" "<<num[i][j][k];
            }
            cout<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3072
s=input()
i=0
j=len(s)-1
ans=0
while i<j:
    if s[i]==s[j]:
        i+=1
        j-=1
    elif s[i]=="x":
        i+=1
        ans+=1
    elif s[j]=="x":
        j-=1
        ans+=1
    else:
        ans=-1
        break    
print(ans)

Measured memory_bytes: 9200
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

    public static void main(String[] args) throws IOException {
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(reader.readLine());
        long sum=0;

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

            if(i%3==0 && i%5==0)
            {
                //System.out.println("FizzBuzz");
            }
            else if(i%3==0)
            {
                //System.out.println("Fizz");
            }
            else if(i%5==0)
            {
                //System.out.println("Buzz");
            }
            else
            {
                sum+=i;
                //System.out.println(i);
            }
        }

        System.out.println(sum);

    }
}


Measured memory_bytes: 32620
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Info{
	char name[31];
};

struct Ans{
	char left[31],right[31];
};

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int strCmp2(char* left,char* right){
	int i;

	if(strCmp(left,right))return 3;

	for(i=0;left[i] != '\0' && right[i] != '\0'; i++){
		if(left[i] != right[i]){
			if(left[i] < right[i])return 1;
			else{
				return 2;
			}
		}
	}
	if(left[i] == '\0')return 1;
	else{
		return 2;
	}
}



int main(){

	int F,N,index,base;
	scanf("%d %d",&N,&F);
	int num_of_data[N];
	int** data = new int*[N];
	for(int i = 0; i < N; i++){
		data[i] = new int[10];
	}
	int** checkTable = new int*[1000];
	for(int i = 0; i < 1000; i++){
		checkTable[i] = new int[1000];
		for(int k = 0; k < 1000; k++)checkTable[i][k] = 0;
	}

	Info info[10*N];
	index = 0;

	char buf[31];
	bool FLG;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&num_of_data[loop]);

		for(int i = 0; i < num_of_data[loop];i++){
			scanf("%s",buf);

			FLG = false;
			for(int k = 0; k < index; k++){
				if(strCmp(info[k].name,buf)){
					FLG = true;
					data[loop][i] = k;
					break;
				}
			}
			if(!FLG){
				strcpy(info[index].name,buf);
				data[loop][i] = index;
				index++;
			}
		}
	}

	for(int loop = 0; loop < N; loop++){
		for(int i = 0; i < num_of_data[loop];i++){

			base = data[loop][i];

			for(int k = 0; k < num_of_data[loop];k++){
				if(k != i){
					checkTable[base][data[loop][k]]++;
				}
			}
		}
	}

	Ans* ans = (Ans*)malloc(sizeof(Ans)*(index*index));
	int ans_index = 0;

	for(int i = 0; i < index-1; i++){
		for(int k = i+1; k < index; k++){
			if(checkTable[i][k] >= F){
				if(strCmp2(info[i].name,info[k].name) == 1){
					strcpy(ans[ans_index].left,info[i].name);
					strcpy(ans[ans_index].right,info[k].name);
					ans_index++;
				}else{
					strcpy(ans[ans_index].left,info[k].name);
					strcpy(ans[ans_index].right,info[i].name);
					ans_index++;
				}
			}
		}
	}

	for(int i = 1; i <= ans_index-1; i++){
		for(int k = ans_index-1; k >= i;k--){
			if(strCmp2(ans[k].left,ans[k-1].left) == 1)swap(ans[k],ans[k-1]);
			else if(strCmp2(ans[k].left,ans[k-1].left) == 3 && strCmp2(ans[k].right,ans[k-1].right) == 1)swap(ans[k],ans[k-1]);
		}
	}

	printf("%d\n",ans_index);

	for(int i = 0; i < ans_index; i++){
		printf("%s %s\n",ans[i].left,ans[i].right);
	}

    return 0;
}

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

int main()
{
    set<int> st {1,2,3};
    int a;
    int b;
    cin >> a >> b;
    st.erase(a);
    st.erase(b);
    auto c = st.begin();
    cout << *c << endl;
   return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	int f[27] = {};
	int h[26] = {};
	cin>>n>>k;
	f[0]=n;
	rep(i,n){
		string s;
		cin>>s;
		h[s[0]-'A']++;
	}
	int lb=0,ub=n/k+1;
	while (ub-lb>1){
		int mid = (lb+ub)/2;
		memset(f,0,sizeof(f));
		f[0]=mid;
		rep(i, 26){
			int m = h[i];
			if (m==0)continue;
			int g[27];
			memcpy(g,f,sizeof(f));
			rep(j, k){
				int a = min(m, f[j]);
				g[j + 1] += a;
				g[j] -= a;
				m-=a;
			}
			memcpy(f,g,sizeof(f));
		}
		if (f[k]==mid)lb=mid;
		else ub=mid;
	}
	cout<<lb<<endl;

	return 0;
}

Measured memory_bytes: 256
import math
 
def solv(a, b, x):
    if x == a ** 2 * b:
        return 0
    elif x <= a**2 * b / 2:
        tanTheta = (2 * x) / (a * b ** 2)
        return 90 - math.degrees(math.atan(tanTheta))
    else:
        tanTheta = (2 * (a ** 2 * b - x)) / (a ** 3)
        return math.degrees(math.atan(tanTheta))
 
a, b, x = map(int, input().split(" "))
print(solv(a, b, x))

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int m = 0;
	int f = 0;
	int r = 0;
	int score;

	while (1) {
		score = 0;

		scanf("%d %d %d", &m, &f, &r);
		
		score = m + f;

		if (m == -1 && f == -1 && r == -1)
			break;
		else if (score < 30 || m == -1 || f == -1)
			printf("F\n");
		else if (score < 50 && r < 50)
			printf("D\n");
		else if (score < 65 || r >= 50)
			printf("C\n");
		else if (score < 80)
			printf("B\n");
		else
			printf("A\n");
	}

	return 0;
}

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

int main() {
	int A, B;
	string S;
	cin >> A >> B >> S;
	for (int i = 0; i < A + B + 1; i++) {
		if (((i<A - 1 || i>A) && (S[i] == '-')) || (i == A && S[i] != '-')) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);    
      int a = sc.nextInt();
  	  int b = sc.nextInt();
  	  int c = sc.nextInt();
	  int d = sc.nextInt();
      
      for(;;){
        c -= b;
        if(c<=0){
          System.out.println("Yes");
          break;
        }
        a -=d;
        if(a<=0){
          System.out.println("No");
          break;
        }
      }
    }
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep2(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = 100100100100;
const int MOD = 1000000007;
const ld EPS = 1e-10;


int fac(int n){
  if (n <= 1) return 1;
  return n * fac(n-1);
}

int dic(string P) {
  if (P == "1") return 1;
  int s = P.size();
  int p1 = P[0] - '1';
  rep2(i, 1, s) {
    if (P[i] > P[0]) P[i]--;
  }
  return p1 * fac(s-1) + dic(P.substr(1, s-1));
}


int main(){
  int N;
  cin >> N;
  string P(N, '0'); string Q(N, '0');
  rep(i, N) cin >> P[i];
  rep(i, N) cin >> Q[i];

  int a = dic(P);
  int b = dic(Q);

  cout << abs(a - b) << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
ans = 0
ls = []
ans = 0
for i in range(N):
  if i == N-1:
    if A[i] == i+1:
      A[i],A[i-1] = A[i-1],A[i]
      ans += 1
  else:
    if A[i] == i+1:
      A[i],A[i+1] = A[i+1],A[i]
      ans += 1
print(ans)

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

int main(){
	int n;
    cin>>n;
    int ar[n];
    int count=0;
   for(int i=0;i<n;i++){
   cin>>ar[i];
  }
for(int i=0;i<n-2;i++){
   for(int j=i+1;j<n-1;j++){
     for(int k=j+1;k<n;k++){
       if(ar[i]+ar[j]>ar[k] && ar[i]+ar[k]>ar[j] && ar[j]+ar[k]>ar[i] && ar[i]!=ar[j] && ar[j]!=ar[k] && ar[i]!=ar[k]){
     count++;
         }
     }
  }
}
   cout<<count;
	return 0;
}

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

using bellman_cost = int;
template<class V, class E>
struct Graph
{
	int sz;
	vector<V> v;
	vector<vector<E>> e;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	inline void assign_vertex(int pos, Args... args) {
		v[pos] = V(args...);
	}
	template<class... Args>
	inline void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
	}
	inline int size() {
		return sz;
	}
};

template<class T>
struct Vertex_Cost
{
	T cost;
	bool valid = false;
	Vertex_Cost(T v1) : cost(v1) {}
	Vertex_Cost() {}
};
using vertex = Vertex_Cost<bellman_cost>;

template<class T>
struct Edge_Cost
{
	int to;
	T cost;
	Edge_Cost(int t, T c) : to(t), cost(c) {}
	Edge_Cost() {}
};
using edge = Edge_Cost<bellman_cost>;
using graph = Graph<vertex, edge>;

template<class T, class V, class E>
void Bellmanford(Graph<V, E>& G, int s, T INF_COST)
{
	auto &v = G.v;
	auto &e = G.e;
	for (auto& vv : v) vv.cost = INF_COST;
	v[s].cost = 0;
	v[s].valid = true;
	for (int i = 0; i + 1 < (int) v.size(); i++) {
		for (int j = 0; j < (int) v.size(); j++) {
			for (auto& x: e[j]) {
				if (v[j].cost == INF_COST) continue;
				v[x.to].cost = min(v[x.to].cost, v[j].cost + x.cost);
				v[x.to].valid = true;
			}
		}
	}
	queue<int> not_valid;
	for (int i = 0; i < (int) v.size(); i++) {
		for (auto& x: e[i]) {
			if (v[i].cost == INF_COST) continue;
			if (v[x.to].cost > v[i].cost + x.cost) {
				not_valid.push(x.to);
			}
		}
	}
	while (!not_valid.empty()) {
		int pos = not_valid.front();
		not_valid.pop();
		if (!v[pos].valid) continue;
		v[pos].valid = false;
		for (auto& x: e[pos]) {
			not_valid.push(x.to);
		}
	}
}


void solve(long long N, long long M, long long P, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C) {
	graph g(N);
	for (int i = 0; i < M; i++) {
		g.add_edge(A[i]-1, B[i]-1, -(C[i] - P));
	}
	Bellmanford(g, 0, INT_MAX);
	if (!g.v[N-1].valid) cout << -1 << endl;
	else cout << max(-g.v[N-1].cost , 0) << endl;
}

signed main() {
	long long N;
	scanf("%lld",&N);
	long long M;
	scanf("%lld",&M);
	long long P;
	scanf("%lld",&P);
	std::vector<long long> A(M);
	std::vector<long long> B(M);
	std::vector<long long> C(M);
	for(int i = 0 ; i < M ; i++){
		scanf("%lld",&A[i]);
		scanf("%lld",&B[i]);
		scanf("%lld",&C[i]);
	}
	solve(N, M, P, std::move(A), std::move(B), std::move(C));
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()
 
int main(){
  ll N,ans=0;
  cin >> N;
  vector<ll> A(N);
  rep(i,N) cin >> A.at(i);
  rep(i,N-2){
    for(ll j=i+1;j<N-1;j++){
      for(ll k=j+1;k<N;k++){
        if(A.at(i)!=A.at(j)&&A.at(j)!=A.at(k)&&A.at(k)!=A.at(i)){
          if(max(A.at(i),max(A.at(j),A.at(k)))<A.at(i)+A.at(j)+A.at(k)-max(A.at(i),max(A.at(j),A.at(k)))){
            ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1010, M = 64;

ll a[N];int n;char s[N];

ll b[N];

ll insert(ll x){
	for(int i=60;~i;i--)if(1&(x>>i)){
		if(!b[i]){b[i]=x;break;}
		else x^=b[i];
	}
	return x;
}

void Main()
{
	for(int i=0;i<M;i++)b[i]=0;
	cin >> n;for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	scanf("%s",s+1);
	bool Ans=0;
	for(int i=n;i;i--){
		if(s[i]=='0'){
			insert(a[i]);
		}else{
			ll d=insert(a[i]);
			// cerr << d << "??" << endl;
			Ans|=d!=0;
		}
	}
	printf("%d\n",(int)Ans);
}

int main()
{
	int T;cin >>  T;while(T--)Main();
}

Measured memory_bytes: 3836
function main(arg) {
  var input = arg.trim().split('\n').map(i => parseInt(i));
  input.shift();

  var b = input.sort((a, b) => b - a).filter((x, i, self) => {
    return self.indexOf(x) === i;
  });
  console.log(b.length);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
import sys
from itertools import combinations, permutations, product, combinations_with_replacement, accumulate
from heapq import heapify, heappop, heappush, heappushpop
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from math import sqrt, log, floor, ceil, factorial, cos, sin, pi #, gcd
from fractions import gcd
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def II(): return int(input())
def IF(): return float(input())
def IS(): return input().replace('\n', '')
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))


def main():
    A,B,C = ILI()

    ans = "No"
    # A + 2sqrt(AB) + B < C
    if C - A - B  > 0 and  4 * A * B < (C- A - B) ** 2:
        ans = "Yes"

    print(ans)


if __name__ == '__main__':
    main()

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

using namespace std;



int main(){

    int n, k;
    scanf("%d", &n);
    vector<pair<int, int> > vp(n);
    for(int i=1; i<=n; i++){
        int x;
        scanf("%d", &vp[i-1].first);
        vp[i-1].second = i;
    }
    sort(vp.begin(), vp.end());

    for(int i=0; i<n; i++)
        printf("%d ", vp[i].second);
}

Measured memory_bytes: 1536
program answer
  implicit none
  integer(16) :: N, A, B

  read(*,*) N, A, B

  if(mod(B-A,2)==0) then
     write(*,*) (B-A)/2
  else
     write(*,*) min(B-1,N-A,A+(B-A-1)/2,N-B+1+(B-A-1)/2)
  end if

  stop
 end program answer

Measured memory_bytes: 2824
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))


l = list(map(int, input().split()))

if (l[0] == l[1] != l[2]):
    print("Yes")
elif (l[0] == l[2] != l[1]):
    print("Yes")
elif (l[0] != l[1] == l[2]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,a[N],pre[N],suf[N],dp[N],ans=-LINF;
void run1()
{
	ll i;
	for(i=0;i<n;i+=2)
	{
		ans=max(ans,pre[i]+suf[i+3]);
	}
	ans=max(ans,pre[n-2]);
	ans=max(ans,suf[1]);
	cout<<ans<<endl;
	return;
}
int main(){
	ll i,j;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	memset(pre,-127,sizeof(pre));
	memset(suf,-127,sizeof(suf));
	memset(dp,-127,sizeof(dp));
	pre[0]=a[0];
	pre[1]=a[1];
	for(i=2;i<n;i++)
	{
		pre[i]=pre[i-2]+a[i];
	}
	suf[n-1]=a[n-1];
	suf[n-2]=a[n-2];
	for(i=n-3;i>=0;i--)
	{
		suf[i]=a[i]+suf[i+2];
	}
	if(n%2==0)
	{
		run1();
		return 0;
	}
	for(i=n-2;i>=0;i-=2)
	{
		if(dp[i+2]>-LINF||suf[i+3]>-LINF)
		{
			dp[i]=max(dp[i+2],suf[i+3])+a[i];
		}
	}
	for(i=0;i<n;i+=2)
	{
		ans=max(ans,pre[i]+suf[i+4]);
		if(dp[i+3]>-LINF)
		{
			ans=max(ans,pre[i]+dp[i+3]);
		}
		ans=max(ans,pre[i]+suf[i+3]);
	}
	ans=max(ans,pre[n-3]);
	ans=max(ans,suf[2]);
	ans=max(ans,suf[1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9876
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;


public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    final int n = scanner.nextInt();
    int min = 200001;
    int count = 0;
    for (int i = 0; i < n; i++) {
      int p = scanner.nextInt();
      if(p <= min) {
        count++;
        min = p;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 62952
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 30
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}


int F[100][10];
int n;
int P[100][11];
int ans = -INF;

int main(){
  scanf("%d",&n);
  REP(i,n){
    REP(j,10){
      scanf("%d",&F[i][j]);
    }
  }

  REP(i,n){
    REP(j,11){
      scanf("%d",&P[i][j]);
    }
  }
  for(int b = 1; b < (1<<10);b++){
    int sum = 0;
    REP(i,n){
      int cnt = 0;
      for(int j=0;j<10;j++){
        if(((b>>j)&1) && F[i][j]) cnt++;
      }
      sum += P[i][cnt];
    }
    ans = max(sum, ans);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    //入力
    int n;
    cin>>n;
    vector<vector<pair<int,int>>> edge(n+5);
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        edge[a].push_back({b,c});
        edge[b].push_back({a,c});
    }
    int q,k;
    cin>>q>>k;
    vector<pair<int,int>> que(q+5);
    for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        que[i]={x,y};
    }
    //ダイクストラ
    vector<ll> dist(n+5,1ll<<60);
    dist[k]=0;
    vector<int> visit(n+5);
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>> > queue;
    queue.push({dist[k],k});
    while(!queue.empty()){
        int sec=queue.top().second;
        queue.pop();
        visit[sec]=1;
        for(int i=0;i<edge[sec].size();i++){
            int e1=edge[sec][i].first,e2=edge[sec][i].second;
            if(visit[e1]==0 && dist[e1]>dist[sec]+e2) {
                dist[e1]=dist[sec]+e2;
                queue.push({dist[e1],e1});
            }
        }
    }
    //出力
    for(int i=0;i<q;i++) cout<<dist[que[i].first]+dist[que[i].second]<<endl;
    return 0;
}


Measured memory_bytes: 11248
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);

		int N = stdIn.nextInt();
		int A = stdIn.nextInt();

		N %= 500;

		if(N <= A)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35528
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll f[2 * ohara + 1000], fr[2 * ohara + 1000], rui1[2 * ohara + 1000],
    rui2[2 * ohara + 1000];

ll mod_pow(ll xx, ll nn, ll mod) {
  ll ret = 1;
  while (nn > 0) {
    if (nn & 1) ret = ret * xx % mod;
    xx = xx * xx % mod;
    nn >>= 1;
  }
  return ret;
}

ll ncr(ll nn, ll r) {
  if (nn < r) return 0;
  return f[nn] * fr[r] % MOD * fr[nn - r] % MOD;
}

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

  cin >> k >> s;
  n = 2 * ohara;
  rui1[0] = 1;
  rui2[0] = 1;
  rrep(i, 1, n) {
    rui1[i] = rui1[i - 1] * 25;
    rui2[i] = rui2[i - 1] * 26;
    rui1[i] %= MOD;
    rui2[i] %= MOD;
  }

  f[0] = 1;
  rrep(i, 1, n + 3) { f[i] = f[i - 1] * i % MOD; }
  fr[n + 2] = mod_pow(f[n + 2], MOD - 2, MOD);
  rrrep(i, n + 1, 0) { fr[i] = fr[i + 1] * (i + 1) % MOD; }

  rep(i, k + 1) {
    ll add = ncr(Size(s) + i - 1, i);
    add *= rui1[i];
    add %= MOD;
    add *= rui2[k - i];
    add %= MOD;
    ans += add;
    ans %= MOD;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 66816
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)


struct Problem {

	void Solve() {
		UL N; cin >> N;
		ULL X[10][10] = {};
		for (UL i = 1; i <= N; i++) {
			UL M, m;
			m = i % 10;
			M = i; while (M >= 10) M /= 10;
			X[M][m]++;
		}
		ULL ans = 0;
		rep(M, 10) {
			rep(m, 10) {
				ans += X[M][m] * X[m][M];
			}
		}
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pri 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
ll dp[100001]={0},vo[100001]={0};
vector <ll> adj[100001];

void run(){
 ll m,n;
 cin>>n>>m;
 for(ll i=0;i<=n;i++)dp[i]=0;
 for(ll i=0;i<m;i++){
 	ll x,y;
 	cin>>x>>y;
 	adj[x].PB(y);
 	vo[y]++;}
 queue <ll> q;
 for(ll i=1;i<=n;i++){
 	
 	if(vo[i]==0){
 		q.push(i);
 	}
 }
 while(!q.empty()){
 	ll x=q.front();
 	
 	q.pop();
 	ll s=adj[x].size();
 	for(ll i=0;i<s;i++)
 	{
 		dp[adj[x][i]]=max(dp[adj[x][i]],dp[x]+1);
 		vo[adj[x][i]]--;
 		if(vo[adj[x][i]]==0)q.push(adj[x][i]);
 	//   cout<<x<<" "<<dp[adj[x][i]]<<" "<<adj[x][i]<<" "<<vo[adj[x][i]]<<endl;
 		
 	}
 }
 ll maxi=0;
  for(ll i=1;i<=n;i++){
   maxi=max(maxi,dp[i]);
  }
  cout<<maxi<<endl;
 
}
int main() {
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)run();
	// your code goes here
	return 0;
}

Measured memory_bytes: 7296
#include<iostream>

using namespace std;
typedef unsigned long long ULL;
typedef long long LL;

int main(){
    ULL H;
    ULL sum=0;
    ULL upper = 1;
    cin >> H;
    while(H != 0){
        sum += upper;
        H = H >> 1;
        upper = upper << 1;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern

let (h, w) = Scanf.sscanf (read_line ()) "%d %d" @@ fun h w -> (h, w)
let s = Array.init h @@ fun _ -> Array.of_list @@ split_string @@ read_line ()

let rec loop dp i j =
  if i = h then Printf.printf "%d\n" dp.(h - 1).(w - 1)
  else begin
    dp.(i).(j) <- min
      (if i > 0 then (dp.(i - 1).(j) + if s.(i - 1).(j) = "." && s.(i).(j) = "#" then 1 else 0) else max_int)
      (if j > 0 then (dp.(i).(j - 1) + if s.(i).(j - 1) = "." && s.(i).(j) = "#" then 1 else 0) else max_int);
    if j = w - 1 then loop dp (i + 1) 0 else loop dp i (j + 1)
  end

let () =
  let dp = Array.init h @@ fun _ -> Array.make w 0 in
  if s.(0).(0) = "#" then dp.(0).(0) <- 1;
  loop dp 0 1

Measured memory_bytes: 2176
function Main(input) {
	input = input.split("\n");
	var N = input[0].split(" ").map(a => parseInt(a));
	var K = N[1];
	N = N[0];
	var x = [], y = [], c = [];
	for(var i = 0; i < N; i++){
		x[i] = input[i+1].split(" ");
		y[i] = parseInt(x[i][1]) % (K * 2);
		c[i] = (x[i][2] === "W" ? 0 : 1);
		x[i] = parseInt(x[i][0]) % (K * 2);
	}
	var ans = 0;
	for(i = 0; i < K; i++){
		var now = 0;
		var Y1 = new Array(K*2).fill(0), Y2 = new Array(K*2).fill(0);
		for(var k = 0; k < N; k++){
			if((((x[k] + i) / K ^ y[k] / K) & 1) === c[k]){
				now++;
				Y1[y[k]]++;
			}else Y2[y[k]]++;
		}
		if(ans < now)ans = now;
		if(ans < N - now)ans = N - now;
		for(var j = 0; j < K - 1; j++){
			now += Y2[j] - Y1[j] + Y2[j+K] - Y1[j+K];
			if(ans < now)ans = now;
			if(ans < N - now)ans = N - now;
		}
	}
	console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 49476
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        s[i] += n;
        if (s[i] > 'Z') s[i] -= 26;
    }
    cout << s << "\n";
}

Measured memory_bytes: 384
import Data.Maybe
f n _ [] = Just n
f n s (a:as) =
  if s' < 0 then Nothing else f n s' as
  where
    s' = s + a - n

ans a@(h:_) = fromJust $ head $ filter (/= Nothing ) $ map (\n -> f n 0 a) $ reverse [1..h]

main = do
  _ <- getLine
  l <- getLine
  let i = map read $ words l
      o = ans i
  print o



Measured memory_bytes: 4160
#include <bits/stdc++.h>
#define plskz ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;

int main() {
    plskz

    int k; string s;
    cin >> k >> s;

    if(s.size() > k)
        s = s.substr(0, k) + "...";
    
    cout << s << '\n';
}   

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

int main(){
  int A , B ,C;
  cin >> A >> B >> C;
  vector<int> iroha (7);
  ++iroha[A];
  ++iroha[B];
  ++iroha[C];
  
  if(iroha[5]==2 && iroha[7] == 1)cout << "YES" << endl;
  else cout <<"NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
struct edge { int from, to, cost; };
struct town { int i, x, y; };

struct union_find{
    vector<int> par,r;

    union_find(int n){
        par.resize(n);
        r.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            r[i]=0;
        }
    }

    int find(int x){
        if(par[x]==x) return x;
        else return find(par[x]);
    }

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(r[x]<r[y]){
            par[x]=y;
        }
        else{
            par[y]=x;
            if(r[x]==r[y]) r[x]++;
        }
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
};

bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
bool comp_x(const town& t1, const town& t2){
  return t1.x < t2.x;
}
bool comp_y(const town& t1, const town& t2){
  return t1.y < t2.y;
}

edge es[200001];
town t_x[100001];
town t_y[100001];

int kruskal(int N, int E){
  sort(es, es + E, comp);
  union_find uf(N);
  int res = 0;

  for(int i=0; i<E; i++){
    edge e = es[i];
    if(!uf.same(e.from, e.to)){
      uf.unite(e.from, e.to); res += e.cost;
    }
  }
  return res;
}

int main(void)
{
    int x, y, N, E, res=0;
    cin>>N;
    for(int i=0; i<N;i++){
      t_x[i].i = i; cin>>t_x[i].x>>t_x[i].y;
      t_y[i].i = i; t_y[i].x = t_x[i].x;  t_y[i].y = t_x[i].y ;
    }
    sort(t_x, t_x + N, comp_x);
    sort(t_y, t_y + N, comp_y);

    for(int i=0; i<N-1;i++){
      es[i].from = t_x[i].i;
      es[i].to = t_x[i+1].i;
      es[i].cost = t_x[i+1].x - t_x[i].x;
    }

    for(int i=N-1; i<2*(N-1);i++){
      int id = i-(N-1);
      es[i].from = t_y[id].i;
      es[i].to = t_y[id+1].i;
      es[i].cost = t_y[id+1].y - t_y[id].y;
    }

    // for(int i=0; i<2*(N-1);i++){
    //    cout<<es[i].from<<" "<<es[i].to<<" "<<es[i].cost<<endl;
    // }
    E = 2*(N-1);
    res = kruskal(N, E);

    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#pragma warning( disable:4996 )
using namespace std;

#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void) {
	int a, b;
	scanf("%d %d", &a, &b);
	if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
		printf("%d\n", a * b);
	}
	else {
		printf("-1\n");
	}

	/*int n;
	scanf("%d", &n);
	for (int i = 9; i >= 1; i--) {
		
		if (n % i == 0) {
			if (n / i <= 9) {
				printf("Yes\n");
				return 0;
			}
			else {
				printf("No\n");
				return 0;
			}
		}
	}
	printf("No\n");*/
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int w, h;
string s[100];

int main() {
	cin >> h >> w;
	rep(i,h) cin >> s[i];
	
	rep(i,h*2) {
		rep(j,w) cout << s[i/2][j];
		cout << ln;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a,b;
	cin>>a>>b;
	cout<<a+b/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define N 15000
using namespace std;

template <typename T>
void print(T x){cout<<x<<"\n";}
template <typename T1, typename T2>
void print2(T1 x,T2 y){cout<<x<<" "<<y<<"\n";}
template <typename T1, typename T2,typename T3>
void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<"\n";}

ll knapsack(ll weights[],ll profit[],ll n,ll net)
{
    ll k[n+1][net+1];

    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=net;j++)
        {
            if(i==0||j==0)
            k[i][j]=0;

            else if(weights[i-1]<=j)
            k[i][j]=max(profit[i-1]+k[i-1][j-weights[i-1]],k[i-1][j]);

            else
            k[i][j]=k[i-1][j];
        }
    }
    
    return k[n][net];
}


int main()
{
    io;
    ll test_case;
    //cin>>test_case;
    test_case=1;
    while(test_case--)
    {
        ll n,net_weight;
        cin>>n>>net_weight;
        ll profit[n],Weights[n];
        for(int i=0;i<n;i++)
        {
            cin>>Weights[i];
            cin>>profit[i];
        }

        cout<<knapsack(Weights,profit,n,net_weight)<<"\n";
    }   
}

Measured memory_bytes: 82524
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){

	string str;
	getline(cin,str);
	for(int i=0;i<str.size();i++){
		str[i] = toupper(str[i]);
	}
	cout<< str<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1176
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;

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

hset<char> lKey = {
    'q', 'w', 'e', 'r', 't',
    'a', 's', 'd', 'f', 'g',
    'z', 'x', 'c', 'v', 'b',
};

int main() {
    string s;
    while (cin >> s) {
        if (s == "#") break;
        bool flg = lKey.find(s[0]) != lKey.end();
        int cnt = 0;
        for (char c : s) {
            if (flg != (lKey.find(c) != lKey.end())) cnt++;
            flg = (lKey.find(c) != lKey.end());
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 3224