akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> p(n), C(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
        --p[i];
    }
    bool minus_flag = true;
    for (int i = 0; i < n; i++)
    {
        cin >> C[i];
        if (C[i] >= 0)
        {
            minus_flag = false;
        }
    }
    // cが全て負の数の時の処理
    if (minus_flag)
    {
        ll maxi = -LINF;
        for (ll c_i : C)
        {
            maxi = max(maxi, c_i);
        }
        cout << maxi << endl;
        return 0;
    }
    vector<bool> seen(n);
    vector<vector<ll>> cost;
    // 鎖の作成
    for (int i = 0; i < n; i++)
    {
        if (seen[i])
        {
            continue;
        }
        int now = i;
        vector<ll> tmp(1, 0);
        while (!seen[now])
        {
            seen[now] = true;
            int next = p[now];
            tmp.push_back(tmp[tmp.size() - 1] + C[next]);
            now = next; // 更新
        }
        cost.push_back(tmp);
    }

    ll maxi = 0;
    for (auto c : cost)
    {
        for (int i = 0; i < c.size(); i++)
        {
            for (int j = 0; j < c.size(); j++)
            {
                if (i + j > k)
                {
                    continue;
                }
                ll total = 0;
                total += c[i];
                total += c[c.size() - 1] - c[c.size() - 1 - j];
                maxi = max(maxi, total);
                total += ((k - (i + j)) / (c.size() - 1)) * c[c.size() - 1];
                maxi = max(maxi, total);
                // cout << "maxi:" << maxi << endl;
            }
        }
        for (int i = 0; i < c.size(); i++)
        {
            for (int j = i + 1; j < c.size(); j++)
            {
                if (j - i > k)
                {
                    break;
                }
                maxi = max(maxi, c[j] - c[i]);
            }
        }
    }
    cout << maxi << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3772
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    
    class Program
    {

        

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] c = new int[N ];
            int[] s = new int[N];
            int[] f = new int[N];
            long time = 0;

            for (int i = 0; i < N -1; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                c[i] = int.Parse(str[0]);
                s[i] = int.Parse(str[1]);
                f[i] = int.Parse(str[2]);
            }
                    
            //i駅からN駅までの時間を求める
            for(int i = 0; i < N - 1; i++)
            {
                time = s[i] + c[i];
                
                //今いるj駅からj + 1駅まで行く
                for(int j = i + 1; j < N - 1; j++)
                {
                    
                    //出発まで
                    if(time < s[j])
                    {
                        time = s[j];
                    }
                    else if(time > s[j] && (time - s[j]) % f[j] != 0)
                    {
                        
                        time += (f[j] - (time - s[j]) % f[j]);
                    }

                    //出発
                    time += c[j];                    

                }

                Console.WriteLine(time);
                
            }

            Console.WriteLine(0);

        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define ll long long//为了世界和平,用long long吧 
using namespace std;
inline int read()//快读,20万以上用快读吧 
{
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
ll n,x,a[100005],ans=0;//按题来定义 
int main()
{
    n=read(),x=read();//读入 
    for(int i=1;i<=n;i++) 
	{
		a[i+1]=read();//因为下边是比较上一个所以i+1 
	}
    for(int i=1;i<=n;i++)
	{
        if(a[i+1]+a[i]>x) 
		{
			ans+=a[i+1]+a[i]-x;//加上 
			a[i+1]=x-a[i];//上边加了,下边减 
		}
    }
    cout<<ans;//输出吧,阿西吧 
}

Measured memory_bytes: 1024
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [-a[i] for i in range(n)]
a.sort()
from heapq import heappush, heappop
for i in range(m):
  t = -heappop(a)
  t //= 2
  heappush(a, -t)
print(-sum(a))

Measured memory_bytes: 64364
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N, M; cin >> N >> M;
	vector<ll> A(M); rep(i, M) cin >> A[i];

	ll sum = 0;
	rep(i, M)sum += A[i];

	if (sum > N)cout << -1 << endl;
	else cout << N - sum << endl;
}

Measured memory_bytes: 11008
#include "bits/stdc++.h"
using namespace std;

int N;
string S[100005];

int K[5];

long long int ans = 0;

void solve(int pos = 0, int k = 0, long long int tmpAns = 1)
{
	if(k == 3) {
		ans += tmpAns;
		return;
	} else if(pos == 5) {
		return;
	}

	//選択しない
	solve(pos+1, k, tmpAns);

	//選択する
	solve(pos+1, k+1, tmpAns * K[pos]);
}

int main()
{
	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> S[i];
		switch (S[i][0]) {
			case 'M':
				K[0]++;
				break;
				case 'A':
					K[1]++;
					break;
					case 'R':
						K[2]++;
						break;
						case 'C':
							K[3]++;
							break;
							case 'H':
								K[4]++;
								break;

		}
	}

	solve();
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
 
 
namespace io{
    const int L = (1 << 20) + 1;
    
    char buf[L], *S , *T, c;
     
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
    
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
    
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
    
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
        
        if(!a)*--outs = '0';
        else 
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
        
        if(x)
            *--outs = x;
        
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};
 
using io :: print;
using io :: inp;
using io :: inp_ll;
const int maxN = 1000010;
int L;
int a[maxN];
int n= 0;
int len=0;
void build(int L)
{
	if(L == 2)
	{
		n = 1;
		printf("%d %d 0\n",n,n+1);
		printf("%d %d 1\n",n,n+1);
		n++;
		len+=2;
		return;
	}
	if(L == 3)
	{
		n = 1;
		printf("%d %d 0\n",n,n+1);
		printf("%d %d 1\n",n,n+1);
		printf("%d %d 2\n",n,n+1);
		n++;
		len+=3;
		return;	
	}
	if(L%2 == 0)
	{
		int m = L/2;
		build(m);
		printf("%d %d 0\n",n,n+1);
		printf("%d %d %d\n",n,n+1,m);
		len += 2;
		n++;
	}
	else
	{
		int m = L/2;
		build(m);
		printf("%d %d 0\n",n,n+1);
		printf("%d %d %d\n",n,n+1,m);
		printf("1 %d %d\n",n+1,L-1);
		n++;
		len += 3;
	}
	
}
 
 
void builda(int L)
{
	if(L == 2)
	{
		n = 1;
//		printf("%d %d 0\n",n,n+1);
//		printf("%d %d 1\n",n,n+1);
		n++;
		len+=2;
		return;
	}
	if(L == 3)
	{
		n = 1;
//		printf("%d %d 0\n",n,n+1);
//		printf("%d %d 1\n",n,n+1);
//		printf("%d %d 2\n",n,n+1);
		n++;
		len+=3;
		return;	
	}
	if(L%2 == 0)
	{
		int m = L/2;
		builda(m);
//		printf("%d %d 0\n",n,n+1);
//		printf("%d %d %d\n",n,n+1,m);
		len += 2;
		n++;
	}
	else
	{
		int m = L/2;
		builda(m);
//		printf("%d %d 0\n",n,n+1);
//		printf("%d %d %d\n",n,n+1,m);
//		printf("1 %d %d\n",n+1,L);
		len += 3;
		n++;
	}

}
int main()
{
	L = inp();
	builda(L);
	printf("%d %d\n",n,len);
	n = 0;
	len = 0;
	build(L);
    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    ll n;
    cin >> n;
    ll ans=1e18;
    for(ll i=1;i*i<=n;i++){
        if(n%i!=0) continue;

        ll j=n/i;
        ans=min(ans,i+j-2);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AFrog1 solver = new AFrog1();
        solver.solve(1, in, out);
        out.close();
    }

    static class AFrog1 {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int arr[] = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.scanInt();
            }
            long dp[] = new long[n];
            Arrays.fill(dp, Long.MAX_VALUE / 2);


            dp[0] = 0;
            for (int i = 1; i < n; i++) {
                if (i - 1 >= 0) dp[i] = Math.min(dp[i - 1] + Math.abs(arr[i] - arr[i - 1]), dp[i]);
                if (i - 2 >= 0) dp[i] = Math.min(dp[i - 2] + Math.abs(arr[i] - arr[i - 2]), dp[i]);
            }
            out.println(dp[n - 1]);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



Measured memory_bytes: 24020
import sys

def solve(x, y):
    ans = 0
    prize = [300000, 200000, 100000]
    if x - 1 < 3:
        ans += prize[x-1]
    if y - 1 < 3:
        ans += prize[y-1]
    if x == 1 and y == 1:
        ans += 400000
    print(ans)

if __name__ == '__main__':
    x, y = map(int, sys.stdin.readline().strip().split())
    solve(x, y)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define N 2010
using namespace std;
int ch[N*3][N*3];
int M;
int C(int a,int b){
	if(a<b||b<0) return 0;
	if(a==b||b==0) return 1;
 	if(ch[a][b]) return ch[a][b];
	return ch[a][b]=(C(a-1,b)+C(a-1,b-1))%M;
}
int main(){
	int n;
	scanf("%d%d",&n,&M);
	int p2[N],ch2[N],ch3[N];
	p2[0]=ch2[0]=ch3[0]=1;
	for(int i=1;i<=n;i++){
		p2[i]=p2[i-1]*2%M;
		ch3[i]=1LL*C(i*3-1,2)*ch3[i-1]%M;
		ch2[i]=1LL*(i*2-1)*ch2[i-1]%M;
	}
	long long ans=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			ans+=1LL*C(n*3,i*2)*C(n*3-i*2,j*3)%M*ch2[i]%M*ch3[j]%M*p2[j]%M;
			ans%=M;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 140160
a,b,c,k=(int(x) for x in input().split())

a1 = a
nokori = 0
nokori_1 = 0
nokori_2 = 0
tensuu = 0

if k-a1 > 0:
   tensuu +=a1
   nokori = k-a

if nokori > 0:
   tensuu +=0
   nokori2 =nokori - b
   if nokori2 > 0:
        tensuu -= nokori2
if k - a1 <= 0:
    tensuu = k
print(tensuu)

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}



int main(){
	ll n;
	cin>>n;
	vector<ll> a(n);
	rep(i,0,n) cin>>a[i];
	ll ans = 0;
	rep(i,1,n){
		if(a[i]<a[i-1]) ans+=a[i-1]-a[i],a[i]=a[i-1];
	}
	cout<<ans<<endl;
	
}
		 

Measured memory_bytes: 4840
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
a_set = set(a)

if len(a_set)==1:
    if sum(a_set)==0:
        print('Yes')
    else:
        print('No')
elif len(a_set)==2:
    a_1,a_2 = sorted(a_set)
    if a_1==0:
        if a.count(a_1)*3==n:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(a_set)==3:
    a_1,a_2,a_3= a_set
    if a.count(a_1)==a.count(a_2) and a.count(a_2)==a.count(a_3):
        if a_1^a_2==a_3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')    

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

int main(){
  int N,d=0;
  cin >> N;
  vector<char> H(N);
  for(int i=0;i<N;i++)cin >> H.at(i);
  for(int i=0;i<N;i++)if(H.at(i)=='Y' && d==0)d++;
  if(d==0)cout << "Three" << endl;
  else cout << "Four" << endl;
  return 0;
}


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string w = Console.ReadLine();
            Dictionary<char, int> wmap = new Dictionary<char, int>();
            foreach (var item in w)
            {
                if(wmap.ContainsKey(item))
                {
                    wmap[item] += 1;
                }
                else
                {
                    wmap.Add(item, 1);
                }
            }
            if(wmap.Values.All(f => f%2 == 0))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 3160
N,M=map(int,input().split())
KS=[list(map(int,input().split())) for _ in range(M)]
p=list(map(int,input().split()))
ans=0
for i in range(1<<N):
  judge=1
  for j in range(M):
    cnt=0
    for k in KS[j][1:]:
      if i>>(k-1)&1:
        cnt+=1
    if (cnt%2)!=p[j]:
      judge=0
  if judge==1:
    ans+=1
print(ans)

Measured memory_bytes: 9212
import java.io.*;
import java.util.*;
import java.util.Stack;
import java.util.regex.Pattern;


public class Main {

	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

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

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long)(1e9+7);
	public static void main(String[] args) {
		 FastReader sc = new FastReader();
		 
		int n = sc.nextInt();
		int l = sc.nextInt();
		long ans = 0;
		for(int i=1;i<=n;++i) {
			ans+=l+i-1;
		}
	//	out.println(ans);
		int diff = Integer.MAX_VALUE;
		long val = 0;;
		for(int i=1;i<=n;++i) {
			int cur = l+i-1;
			//out.println(cur);
			if(Math.abs(cur)<diff) {
				diff = (int) Math.abs(cur);
				val = ans - cur;
		
			}
			//out.println(diff+" "+val);
		}
		out.println(val);
		 out.close();
		 
	}

}		 





Measured memory_bytes: 23252
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int n,m;
vector<vector<int>> g;
vector<int> visited;

void dfs( int x , int &cnt ){
    cnt++;
    visited[x] = 1;
    for ( auto v : g[x] ){
        if(!visited[v]){
            dfs(v,cnt);
        }
    } 
}

//START OF CODE ->->->->->->->

void solve()
{
    cin>>n>>m;
    g = vector<vector<int>>(n+1);
    visited = vector<int>(n+1,0);
    rep(i,0,m){
        int a,b;
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    int ans = 0;
    rep(i,1,n+1){
        int cnt = 0;
        if ( !visited[i] ){
            dfs(i,cnt);
            ans = max(ans,cnt);
        }
    }

    cout<<ans<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}




Measured memory_bytes: 21800
#include <vector> 
#include <list> 
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

const LL mod = (LL)1e9 + 7;


int main() {
	//0が二人いるのはおかしい
	//その他の値は二人いないといけない
	map<int, int> A;
	int N;
	cin >> N;
	REP(i, N) {
		int a;
		cin >> a;
		A[a]++;
	}
	for (auto a : A) {
		if (a.first == 0) {
			if (a.second != 1) { cout << 0 << endl;  return 0; }
		}
		else {
			if(a.second!=2){ cout << 0 << endl;  return 0; }
		}
	}

	LL ans = 1LL;
	for (auto a : A) {

		if (a.first == 0) {
			ans *= 1;
		}
		else {
			ans *= 2;
			ans %= mod;
		}

	}
	cout << ans << endl;
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,c,x,tmp;
    scanf("%d",&n);
    int a[n+2];
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    if((n%2)==1)
    {
        c=1;
        x=2;
        if(a[0]==0)
        {
            for(i=1; i+1<n; i+=2)
            {
                if(a[i]==a[i+1] && a[i]==x)
                {
                    c=c*2%1000000007;
                    x+=2;
                }
                else
                {
                    c=0;
                    break;
                }
            }
        }
    }
    else
    {
        x=1;
        c=1;
        for(i=0; i+1<n; i+=2)
        {
            if(a[i]==a[i+1] && a[i]==x)
            {
                c=c*2%1000000007;
                x+=2;
            }
            else
            {
                c=0;
                break;
            }
        }
    }
    printf("%d\n",c);
    return 0;
}



Measured memory_bytes: 640
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    int[] prime = new int[60000];
    for(int i=0; i<60000; i++) {
      prime[i]=0;
    }
    for(int i=2; i<60000; i++) {
      if(prime[i] == 1) {
        continue;
      }
      prime[i] = 2;
      int j=i+i;
      while(j<60000) {
        prime[j]=1;
        j+=i;
      }
    }
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      int n = sc.nextInt();
      int lower=0;
      for(int i=n-1;i>0;i--) {
        if(prime[i]==2) {
          lower=i;
          break;
        }
      }
      int upper=0;
      for(int i=n+1;i<60000;i++) {
        if(prime[i]==2) {
          upper=i;
          break;
        }
      }
      System.out.print(lower);
      System.out.print(" ");
      System.out.println(upper);
    }
  }
}

Measured memory_bytes: 26476
import math
A, B, H, M = map(int, input().split())

long = M * 6
short = (H*60 + M) * 0.5
k = short - long
if k > 180:
    k = 360 - k
a = (A**2) + (B**2) - (2*A*B*math.cos(math.radians(k)))
print(a**(1/2))

Measured memory_bytes: 9544
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(n: usize, ab: [(usize, usize); n]);

    if !ab.iter().any(|&(a, b)| a != b) {
        println!("0");
        return;
    }

    let min = ab
        .iter()
        .filter(|&&(a, b)| a > b)
        .map(|&(_, b)| b)
        .min()
        .unwrap();
    let sum = ab.iter().map(|&(a, _)| a).sum::<usize>();
    println!("{}", sum - min);
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int DP[3005][3005];
string S, T;
char ans[3005];

int main(){
  cin >> S >> T;
  int N = S.length(), M = T.length();
  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= M; j++){
      if (S[i-1] == T[j-1]){
        DP[i][j] = DP[i-1][j-1] + 1;
      }else{
        DP[i][j] = max(DP[i-1][j], DP[i][j-1]);
      }
    }
  }

  int I = N, J = M;
  while (DP[I][J] > 0){
    while (DP[I][J] == DP[I-1][J]) I--;
    while (DP[I][J] == DP[I][J-1]) J--;
    ans[DP[I][J]] = S[I-1];
    I--; J--;
  }

  for (int i = 1; i <= DP[N][M]; i++) cout << ans[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 38820
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (s == u) --a;
    else --b;
    printf("%d %d\n", a, b);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    fast;
    ll a,b,c,d,i,j,k,l,ans;
    cin>>a>>b>>c>>d;
    i=a*c;
    j=a*d;
    k=b*c;
    l=b*d;
    ans=max(max(i,j),max(k,l));
    cout<<ans<<endl;
}


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

#define N 300010 

using namespace std;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int rd() {
	int x = 0, f = 1;
	char c = nc();
	while (c < 48) {
		if (c == '-')
			f = -1;
		c = nc();
	}
	while (c > 47) {
		x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
	}
	return x * f;
}

vector <int> v[N];

bool vis[N];

int main() {
	int h = rd(), w = rd(), n = rd();
	for (int i = 1; i <= n; i ++ ) {
		int x = rd(), y = rd();
		v[y].push_back(x);
	}

	for (int i = 1; i <= w; i ++ ) {
		v[i].push_back(h + 1);
	}
	sort(v[1].begin(), v[1].end());

	int ans = v[1][0] - 1;
	int t = 0;
	for (int i = 2; i <= w; i ++ ) {
		sort(v[i].begin(), v[i].end());
		int s = v[i].size(), m = 0;
		for (int k = 0; k < s; k ++ ) {
			if (v[i][k] <= i + t) {
				vis[v[i][k]] = 1;
				m = max(v[i][k], m);
			}
			else if (vis[v[i][k] - 1]) {
				vis[v[i][k]] = 1;
				m = max(v[i][k], m);
			}
			else {
				ans = min(ans, v[i][k] - 1);
				break;
			}
 		}
		t = max(t, m - i + 1);
	}
	cout << ans << endl ;
	return 0;
}

Measured memory_bytes: 13952
import std.stdio;
import std.string;
import std.conv;

int count(int n) {
  int ans = 0;
  for(int a = 0; a < 10; a++)
    for(int b = 0; b < 10; b++)
      for(int c = 0; c < 10; c++)
        for(int d = 0; d < 10; d++)
          if(a + b + c + d == n) ans++;
  return ans;
}

void main() {
  int[] data;
  while(true) {
    auto input = readln();
    if(stdin.eof()) break;
    data ~= to!int(chomp(input));
  }

  foreach(i ; data) {
    writeln(count(i));
  }
}

Measured memory_bytes: 964
#include<bits/stdc++.h>
    #define ull unsigned long long
    #define ll long long
    #define INF 0x3f3f3f3f
    using namespace std;
    void close(){
       	std::ios::sync_with_stdio(false);
       	std::cin.tie(0);
    }
    int n,m;
    int dp[2005][2005];
    int main(){
    	cin>>n>>m;
    	if(n>m)
    	cout<<"No"<<endl;
    	else cout<<"Yes"<<endl;
    }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, bitList, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
int main() {
	cin >> N >> M;
	vl A = {0,0,0,0,0,0,0,0,0};
	for (i = 0; i < M; i++) {
		ll a;
		cin >> a;
		a--; A[a] = 1;
	}
	vl dp(N + 1);
	for (i = 0; i <= N; i++) {
		dp[i] = -1;
	}
	dp[0] = 0;
	vl cost = { 2,5,5,4,5,6,3,7,6 };
	for (i = 0; i < N; i++) {
		if (i != 0 && dp[i] == -1)continue;
		for (j = 0; j < 9; j++) {
			if (A[j] && i+cost[j]<=N) {
				if (dp[i] + 1 > dp[i + cost[j]]) {
					dp[i + cost[j]] = dp[i] + 1;
						//cout << i + cost[j] << " " << dp[i + cost[j]] << endl;
				}
			}
		}
	}
	ll use = 8;
	string S = "";
	while (N > 0 && use>=0) {
		while (!A[use])use--;
		if (use < 0)break;
		if (N - cost[use] < 0) {
			use--;
		}
		else if (dp[N - cost[use]] == dp[N] - 1) {
			char p = '1' + use;
			S += p;
			N -= cost[use];
		}
		else {
			use--;
		}
	}
	cout << S;
}
	


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

int main() {
  int a, s1, s2, s3;
  cin >> a ;
  s1 = a / 100;
  s2 = a / 10 % 10;
  s3 = (a % 100) % 10;
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){

  int n;
  long ans = 0;
  cin >> n;
  vector<int> B;
  
  for(int i = 0; i < n-1; i++){
    int b;
    cin >> b;
    B.push_back(b);
  }
  

  int res_a = B[n-2];
  int res_b = 0;
  
  for(int i = n-2; i >= 0; i--){
    
    if(res_a > B[i]){
      res_a = B[i];
      ans += res_a;
      res_b = res_a;
    }
    else{
      ans += res_a;
      res_a = B[i];
      res_b = B[i];
    }
    
    
  }
  
  cout << res_b + ans << endl;
  
  
  return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void rec(vector<ll> &b)
{
  if(b.size() <= 1) return;
  bool ok = false;
  for(ll i = b.size()-1; i > 0; i--) {
    cerr << i << ":" << endl;
    if(b[i] == i) {
      ok = true;
            cerr << i << ":" ;rep(i, b.size()) cerr << b[i] << " "; cerr<< endl;
      b.erase(b.begin() + i);
      if(b.size() > 1) rec(b);
      cout << i << endl;
      break;
    }
  }
  if(!ok) {
    cout << -1 << endl;
    exit(0);
  }
}

void solve()
{
  ll N; cin >> N;
  vector<ll> b(N+1); rep1(i, N) cin >> b[i];
  rec(b);
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3636
//BISMILLAHIR RAHMANIR RAHIM
                                               //BY THE NAME OF ALLAH
                                               //FAISAL AHAMMED SHAWON
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<set>
#include<map>
#include<iterator>
#include<numeric>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define SQ(a) (a)*(a)
#define pi acos(-1.0)
const int MAX=100001;
const int MOD=1e9+7;
int ara[MAX];
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}

bool f(ll a,ll b)
{
    return a>b;
}
ll max_sum_subarrays(ll ara[],ll n)
{
    ll ans=0,sum=0;
    for(ll k=0;k<n;k++){
        sum=max(ara[k],sum+ara[k]);
        ans=max(ans,sum);
    }
    return ans;
}
ll num_divisors(ll n)
{
    long long cnt=0;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0 && i*i==n)
            cnt+=1;
        if(n%i==0 && i*i!=n)
                cnt+=2;
    }
    return cnt;
}
ll comb(ll m, ll n)
{
    ll x = max(m-n,n),ans = 1,i=1;
    for(ll k=m;k>=x+1;k--){
        ans*=k;
        ans/=i;
        i++;
    }
    return ans;
}
ll binsearch(ll low,ll high,ll target)
{
    while(low<=high)
    {
        ll mid=(low+high)/2;
        if(ara[mid]>target)
            high=mid-1;
        else if(ara[mid]<target)
            low=mid+1;
        else return mid;
    }
    return -1;
}
void solve()
{
    int a,b;
    cin>>a>>b;

    if(b==a && a!=0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}
int main()
{
    fast();
    solve();
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vec vector
#define vi vec<int>
#define vvi vec<vec<int>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [](auto& i)
#define compare(i, j) [](auto& i, auto& j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(a) (int)(a).size()
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

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

struct union_find {
  vi data;
  union_find(int size) : data(size, -1) { }
  bool union_set(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find_set(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  int n;
  int ans = 0, c = 0;

  cin >> n;
  REP(i, n) {
    int p;
    cin >> p;
    if (p == i + 1) {
      c++;
    } else {
      ans += (c + 1) / 2;
      c = 0;
    }
  }
  ans += (c + 1) / 2;

  cout << ans << endl;
  // REP(i, n) {
  //   cout << v[i];
  // }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


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

int main() {
    // 頂点数と辺数
    int N, M,cnt = 0; cin >> N >> M;
    bool check = 1;
    vector<int>height(N);
    for (int i = 0; i < N; i++) {
      cin >> height.at(i);
    }


    // グラフ
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);

        // 無向グラフの場合は以下を追加
        G[b-1].push_back(a-1);
    }
  for (int i = 0; i < N; i++){
    check= 1;
    for (int j = 0; j < G.at(i).size(); j++) {
      if (height.at(i) <= height.at(G.at(i).at(j))) {
        check = 0;
      }
    }
    if (check == 1) cnt++;
  }
  cout << cnt << endl;
}




Measured memory_bytes: 8804
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	static int N,M,MIN;
	static int[] candles;
	

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
//		long startTime = new Date().getTime();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		N = Integer.valueOf(st.nextToken());
		M = Integer.valueOf(st.nextToken());
		
		candles = new int[N+1];
		
		st = new StringTokenizer(br.readLine());
		for(int i=0;i<N;i++) {
			int zb =  Integer.valueOf(st.nextToken());
			candles[i] = zb;
			
			if(i<M-1) {
				continue;
			}
			int right = candles[i];
			int left = candles[i-M+1];
			
			int total  = right - left;
//			System.out.println("right:"+right+" left:"+left);
//			System.out.println("total1:"+total);
			if(left>=0) {//left都大于0
				total += left;
			}else if(right<=0) {//right小于0
				total += Math.abs(right);
			}else {//跨越0点
				
//				System.out.println("left:"+left+" right:"+right);
				total += Math.abs(left)>right?right:Math.abs(left);
			}
//			System.out.println("total2:"+total);
			if(MIN==0) {
				MIN = total;
			}else {
				if(total<MIN) {
					MIN = total;
				}
			}
		} 
		
		
//		long endTime = new Date().getTime();
//		System.out.println((endTime-startTime)/1000);
		System.out.println(MIN);
		
	}
	
}


Measured memory_bytes: 40448
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] a = new long[N*3];

        for(int i=0;i<N*3;i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);

        for(int i=0;i<N*3;i++){
         //   System.out.print(a[i]);
        }
      //  System.out.print("\n");

        long sum = 0;
        for(int i=N;i<N*3;i+=2){
           // System.out.print(a[i]);

            sum += a[i];
        }

        System.out.print(sum);
    }

}

Measured memory_bytes: 98616
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MAX = 410;
using pint = pair<int,int>;

int H, W;
vector<string> fi;

long long numb = 0, numw = 0;
bool seen[MAX][MAX];
void dfs(int x, int y) {
    seen[x][y] = true;
    if (fi[x][y] == '#') ++numb;
    else ++numw;
    
    for (int dir = 0; dir < 4; ++dir) {
        int nx = x + dx[dir];
        int ny = y + dy[dir];
        if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
        if (fi[x][y] == fi[nx][ny]) continue;
        if (seen[nx][ny]) continue;
        dfs(nx, ny);
    }
}

int main() {
    while (cin >> H >> W) {
        fi.resize(H);
        for (int i = 0; i < H; ++i) cin >> fi[i];
        long long res = 0;
        memset(seen, 0, sizeof(seen));
        for (int x = 0; x < H; ++x) {
            for (int y = 0; y < W; ++y) {
                if (fi[x][y] == '.') continue;
                if (seen[x][y]) continue;
                numb = numw = 0;
                dfs(x, y);
                res += numb * numw;
            }
        }
        cout << res << endl;
    }
}














Measured memory_bytes: 18176
#include <cstdio>
#include <cmath>
using namespace std;
const int M = 90001;
int H, W, D, Q, Ax[M], Ay[M], sum[M];
int main() {
  scanf("%d %d %d", &H, &W, &D);
  for(int i = 1; i <= H; ++i) {
    for(int j = 1, t; j <= W; ++j) {
      scanf("%d", &t); Ax[t] = i, Ay[t] = j;
    }
  }
  for(int i = D+1; i <= H*W; ++i) {
    sum[i] = sum[i-D]+abs(Ax[i]-Ax[i-D])+abs(Ay[i]-Ay[i-D]);
  }
  scanf("%d", &Q);
  for(int i = 1, L, R; i <= Q; ++i) {
    scanf("%d %d", &L, &R);
    printf("%d\n", sum[R]-sum[L]);
  }
}

Measured memory_bytes: 2048
import collections

s = collections.deque(list(input()))
q = int(input())
rev = 0
for i in range(q):
    tfc = list(input().split())
    if tfc[0]=='1':
        rev = abs(rev-1)
    else:
        t,f,c = tfc
        if rev:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
if rev:
    t = []
    for i in range(len(s)):
        t.append(s.pop())
    print(''.join(t))
else:
    print(''.join(s))

Measured memory_bytes: 9180
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

bool check(vector< vector<string> >& a, char c, int m) {
	int n = a.size();
	for (int x = 0; x < n; x++)
		for (int y = 0; y < n; y++)
			for (int z = 0; z < n; z++)
				for (int dx = -1; dx <= 1; dx++)
					for (int dy = -1; dy <= 1; dy++)
						for (int dz = -1; dz <= 1; dz++)
							if (dx || dy || dz) {
								bool flag = true;
								for (int i = 0; i < m; i++) {
									int _x = x + i * dx, _y = y + i * dy, _z = z + i * dz;
									if (_x < 0 || _x >= n || _y < 0 || _y >= n || _z < 0 || _z >= n || a[_x][_y][_z] != c)
										flag = false;
								}
								if (flag) return true;
							}
	return false;
}

int main() {
	for (;;) {
		int n, m, p; cin >> n >> m >> p;
		if (n == 0) break;
		vector<int> X(p), Y(p);
		for (int i = 0; i < p; i++) cin >> X[i] >> Y[i];
		vector< vector<string> > a(n, vector<string>(n, string(n, ' ')));
		int i;
		for (i = 0; i < p; i++) {
			int x = X[i] - 1, y = Y[i] - 1;
			int z;
			for (z = 0; a[x][y][z] != ' '; z++);
			char c = (i % 2 == 0 ? 'B' : 'W');
			a[x][y][z] = c;
			if (check(a, c, m)) break;
		}
		if (i < p) cout << (i % 2 == 0 ? "Black" : "White") << ' ' << i + 1 << endl;
		else cout << "Draw" << endl;
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
int main()
{
  	int m1,m2,d1,d2;
    cin >> m1 >> d1 >> m2 >> d2;
  if (m1==m2) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
    return 0;
}


Measured memory_bytes: 256