akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

// 普通に計算して通ってしまったが、恐らく想定の解き方ではない

func main() {
	N := nextInt()
	Ln := make([]int, N)
	for i := range Ln {
		Ln[i] = nextInt()
	}
	sort.Ints(Ln)
	var ans int
	for i := 0; i < N-2; i++ {
		for j := i + 1; j < N-1; j++ {
			for k := j + 1; k < N; k++ {
				a, b, c := Ln[i], Ln[j], Ln[k]
				if c-b < a {
					ans++
				}
				if a+b < c {
					break
				}
			}
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 1856
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 1055050
vector<vec> dp(6000,vector<int>(6000,INF));
main(){
    int n=in();
    vector<pii> v;
    rep(i,n){
        v.pb({in(),in()});
    }
    sort(ALL(v),[](pii a,pii b){
        return a.first+a.second<b.first+b.second;
    });
    /*rep(i,n)cout<<v[i].first<<" ";
    cout<<endl;
    rep(i,n)cout<<v[i].second<<" ";
    cout<<endl;
    */
    dp[0]=vec(6000,0);
    int ans=0;
    rep2(i,1,n){
        int MIN=INF;
        if(i==1)MIN=0;
        rep(j,n){
            //cout<<dp[i-1][j]<<" ";
            if(MIN<=v[j].first){
                dp[i][j]=MIN+v[j].second;
                ans=i;
            }
            MIN=min(MIN,dp[i-1][j]);
        }
        //cout<<endl;
    }
    cout<<ans;
}

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

public class Main {

	int pop_count(int bs) {
		int cnt = 0;
		for (int i = 0; i < 16; ++i) {
			cnt += (bs >> i) & 1;
		}
		return cnt;
	}

	void run() {
		for (;;) {
			int n = ni();
			int c = ni();
			if ((n | c) == 0) {
				break;
			}
			int[] a = new int[n + 1];
			for (int i = 0; i < n; ++i) {
				a[i] = 0;
				for (int j = 0; j < 16; ++j) {
					int v = ni();
					a[i] |= v << j;
				}
			}
			a[n] = 0;
			int[] b = new int[c];
			for (int i = 0; i < c; ++i) {
				b[i] = 0;
				for (int j = 0; j < 16; ++j) {
					int v = ni();
					b[i] |= v << j;
				}
			}

			int[][] dp = new int[2][1 << 16];
			for (int i = 0; i < 2; ++i) {
				Arrays.fill(dp[i], -1);
			}
			dp[0][a[0]] = 0;
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < 1 << 16; ++j) {
					if (dp[(i&1)][j] == -1) {
						continue;
					}
					for (int k = 0; k < c; ++k) {
						int cnt = pop_count(b[k] & j);
						int nbs = ((b[k] ^ j) & j) | a[i + 1];

						dp[(i&1)^1][nbs] = Math.max(dp[(i&1)^1][nbs], dp[(i&1)][j]
								+ cnt);
					}
				}
			}

			int ans = 0;
			for (int i = 0; i < 1 << 16; ++i) {
				ans = Math.max(ans, dp[n&1][i]);
			}
			System.out.println(ans);
		}
	}

	public static void main(String[] args) {
//		new Main().test();
		new Main().run();
	}

	void test() {
		for (int i = 0; i < 1; ++i) {
			System.out.println("30 30");
			for (int j = 0; j < 30; ++j) {
				for (int k = 0; k < 16; ++k) {
					if (k > 0) {
						System.out.print(" ");
					}
					System.out.print(Math.random() > 0.5 ? "1" : "0");
				}
				System.out.println();
			}
			for (int j = 0; j < 30; ++j) {
				for (int k = 0; k < 16; ++k) {
					if (k > 0) {
						System.out.print(" ");
					}
					System.out.print(Math.random() > 0.5 ? "1" : "0");
				}
				System.out.println();
			}
		}
		System.out.println("0 0");
	}

	Scanner sc;

	Main() {
		sc = new Scanner(System.in);
	}

	int ni() {
		return Integer.parseInt(sc.next());
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 48420
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int f[MAX_N]={};
int b[MAX_N]={};

int main() {
	int n,m;
	cin>>n>>m;
	int dp[10][10]={};
	rep(i,m){
		int k;
		cin>>k;
		rep(j,k){
			int s;
			cin>>s;
			dp[s-1][i]=1;
		}
	}
	int p[m]={};
	rep(i,m)cin>>p[i];
	int res=0;
	rep(i,(1<<n)){
		int d[m]={};
		rep(j,n){
			if((i&(1<<j))>0){
				rep(k,m){
					d[k]+=dp[j][k];
				}
			}
		}
		bool flg=true;
		rep(k,m){
			if(p[k]!=(d[k]%2))flg=false;
		}
		if(flg)res++;
	}
	cout<<res<<endl;
	return 0;
}


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

int main() {
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    int x=1;
    int X[2019] = {};
    ++X[0];
    int sum=0;
    int c=0;
    for(int i=0; i<S.size(); ++i) {
        sum += (S[i] - '0')*x;
        sum %= m;
        c += X[sum];
        ++X[sum];
        x *= 10;
        x %= m;
    }
    
    cout << c << endl;
}

Measured memory_bytes: 3760
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;



int main(){
  ios::sync_with_stdio(false);
  int N, L;
  cin >> N >> L;

  vector<string> v;
  rep(i,N){
    string str;
    cin >> str;
    v.push_back(str);
  }

  sort(ALLOF(v));
  rep(i,v.size()){
    cout << v[i];
  }
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 256
import scala.io.StdIn
object Main extends App {
  val input = StdIn.readLine()
  val N = input.split(" ")(0).toInt
  val Y = input.split(" ")(1).toInt
  val answers = for {
    x <- 0 to N
    y <- 0 to (N - x)
    if (10000 * x + 5000 * y + 1000 * (N - x - y) == Y)
  } yield List(x, y, N - x -y)
  if (answers.isEmpty) println("-1 -1 -1") else println(answers(0).mkString(" "))
}


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

def count_loop(start, idx_map):
    count = 1
    idx = start
    while True:
        idx = idx_map[idx]
        count += 1
        if idx == 0:
            break
    return count

X = list(zip(A, B))
X.sort(key=lambda x: x[1])

C = sorted((x[0], i) for i, x in enumerate(X))
idx_map = [C[i][1] for i in range(N)]
A = sorted(A)
B = sorted(B)

if any(A[i] > B[i] for i in range(N)):
    print("No")
    exit()

if any(A[i + 1] <= B[i] for i in range(N - 1)):
    print("Yes")
    exit()

if count_loop(0, idx_map) < N:
    print("Yes")
    exit()

print("No")



Measured memory_bytes: 92392
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

typedef long long ll;


int main(){
  int n;
  char c[101];
  cin >> c;
  int i=0;
  int flagc=0,flagf=0;
  while(c[i]!='\0'){
    if(flagc==0&&c[i]=='C'){
      flagc=1;
    }if(flagc==1&&c[i]=='F'){
      flagf=1;
      break;
    }
    i++;
  }
  if(flagf==1){ cout << "Yes\n";}
  else{ cout << "No\n";}
  return 0;
}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int fun(char c,char cc){
    return (c=='.' and cc=='#');
}

int dp[101][101];
inline void solve(){
    int h,w; 
    cin>>h>>w; 
    string s[h]; 
    for (int i=0;i<h;i++) cin>>s[i]; 
    dp[0][0] = ((s[0][0]=='#')?1:0); 
    for (int i=0;i<h;i++){ 
        for (int j=0;j<w;j++){ 
          	if (i+j) dp[i][j]=100000000;
            if (j!=0) dp[i][j]=min(dp[i][j],dp[i][j-1]+fun(s[i][j-1],s[i][j])); 
            if (i!=0) dp[i][j]=min(dp[i][j],dp[i-1][j]+fun(s[i-1][j],s[i][j])); 
        } 
    } 
    cout << dp[h-1][w-1] << endl; 
}

signed main() 
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

int H, W, C;
int field[8][8];
int dh[] = {0, 0, 1, -1};
int dw[] = {1, -1, 0, 0};

void dfs2(int h, int w, int pc, int nc){
    field[h][w] = nc;
    for(int i=0; i<4; i++){
        int nh = h + dh[i];
        int nw = w + dw[i];
        if(0<=nh&&nh<H && 0<=nw&&nw<W && field[nh][nw]==pc && field[nh][nw]!=nc){
            dfs2(nh, nw, pc, nc);
        }
    }
}


int dfs(int deepth, int changes[]){
    int res;
    int tfield[8][8];
    
    memcpy(tfield, field, sizeof(field));
    dfs2(0, 0, field[0][0], changes[deepth]);
    
    if(deepth < 5){
        res = dfs(deepth+1, changes);
    }else{
        res = 0;
        for(int h=0; h<H; h++){
            for(int w=0; w<W; w++){
                if(field[h][w] == changes[deepth]){
                    res ++;
                }
            }
        }
    }
    memcpy(field, tfield, sizeof(field));
    
    return res;
}

void solve(){
    int ans = 0;
    for(int i1=1; i1<=6; i1++){
        for(int i2=1; i2<=6; i2++){
            for(int i3=1; i3<=6; i3++){
                for(int i4=1; i4<=6; i4++){
                    int i5 = C;
                    int chnges[] = {i1, i2, i3, i4, i5};
                    ans = max(ans, dfs(0, chnges));
                }
            }
        }
    }
    cout << ans << endl;
}

int main(int argc, const char * argv[]){
    while(cin >>H>>W>>C, H|W|C){
        for(int h=0; h<H; h++){
            for(int w=0; w<W; w++){
                cin >> field[h][w];
            }
        }
        solve();
    }
    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  string A,B;
  A=to_string(a);
  B=to_string(b);
  string C,D;
  for(int i=0;i<a;i++){
    C=C+B;
  }
  for(int i=0;i<b;i++){
    D=D+A;
  }
  vector<string>Dic={C,D};
  sort(Dic.begin(),Dic.end());
  cout<<Dic.at(0)<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k <= a)
    {
        cout << k << "\n";
    }
    else if(k <= a + b)
    {
        cout << a << "\n";
    }
    else
    {
        cout << a - (k - (a + b)) << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll a[100010];
int main(){
	ll n,sum=0,max=0;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==i)sum++;
	}
	if(sum==0){
		cout<<0;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(a[i]==i){
			max++;
			swap(a[i],a[i+1]);
		}
	}
	cout<<max;
	return 0;
}

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

string s;
int n, a[26], b[26];

int main() {
    iostream::sync_with_stdio(0); cin.tie(0);
    memset(a, 63, sizeof(a));
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> s;
        memset(b, 0, sizeof(b));
        for(int j = 0; j < s.length(); j++) b[s[j]-'a']++;
        for(int j = 0; j < 26; j++) a[j] = min(a[j], b[j]);
    }
    for(int i = 0; i < 26; i++) {
        for(int j = 0; j < a[i]; j++) cout << (char) ('a' + i);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N,ans=0;
  cin>>N;
  vector<ll> vec(N);
  for(ll i=0;i<N;i++){cin>>vec.at(i);}
  unordered_map<ll,ll> maxcount;
  for(ll i=0;i<N;i++){maxcount[vec.at(i)+i]++;}
  for(ll i=0;i<N;i++){ans+=maxcount[i-vec.at(i)];}
  cout<<ans<<endl;
}


Measured memory_bytes: 20088
//#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set> 
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 200001
#define infm 800009
#define INF (int)1e9
#define mod 1000000007LL
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
int n,m;
 
vector <int> a[inf];
priority_queue <int,vector<int>,greater<int> > q;
int p[inf];
 
int main(){
    rd(n) rd(m)
    int x,y;
    for (int i=1;i<=n;i++){
        rd(x) rd(y)
        a[x].push_back(y);
    }
    int nowL=0,nowR=m+1;
    for (int i=1;i<=m;i++){
        for (int j=0;j<a[i].size();j++){
            int now=a[i][j];
            if (nowL<i){
                nowL++;
                q.push(now);
            }
            else{
                int tmp=q.top();
                (now>tmp)?(q.pop(),q.push(now),p[tmp]++):p[now]++;
            }
        }
    }
    for (int i=0;i<a[0].size();i++){
        p[a[0][i]]++;
    }
    int ans=p[m+1];
    for (int i=m;i>=1;i--){
        for (;p[i];p[i]--){
            (nowR>i && nowR-1>nowL)?nowR--:ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 10108
count = 0

n = int(input())
l = [int(i) for i in input().split()]


def merge_sort(a):
    if len(a) == 1:
        return [a[0]]
    mid = len(a) // 2
    l1 = merge_sort(a[:mid])
    l2 = merge_sort(a[mid:])
    merged = merge(l1, l2)
    return merged


def merge(l1, l2):
    global count
    len_l1 = len(l1)
    len_l2 = len(l2)
    l1c = l1.copy()
    l2c = l2.copy()

    l1c.append(10 ** 10)
    l2c.append(10 ** 10)

    i = 0
    j = 0
    r = []
    # print("l1", l1)
    # print("l2", l2)
    for k in range(len_l1 + len_l2):
        # print("i", i)
        # print("j", j)
        count += 1
        if l1c[i] <= l2c[j]:
            r.append(l1c[i])
            i += 1
        else:
            r.append(l2c[j])
            j += 1
    return r


r = merge_sort(l)
print(" ".join([str(i) for i in r]))
print(count)



Measured memory_bytes: 74636
local s=io.read()
local t=io.read()
local min=math.maxinteger
for i=1,#s-#t+1 do
    local ss=s:sub(i,i+#t-1)
    local counter=0
    for j=1,#t do
        if ss:byte(j)~=t:byte(j) then
            counter=counter+1
        end
    end
    min=math.min(counter,min)
end
print(min)

Measured memory_bytes: 2716
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] nyuryoku = line.split("[\\s]+");

		int tate = Integer.parseInt(nyuryoku[0]);
		int yoko = Integer.parseInt(nyuryoku[1]);

		int menseki = tate * yoko;
		int gaisyu = (tate * 2) + (yoko * 2);
		System.out.println(menseki + " " + gaisyu);
	}
}

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

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)

int a[5050], b[5050];

signed main()
{
    int A, B; cin >> A >> B;

    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];

    int ans = 0;

    for (int i = 0; i < B; ++i) {
        int idx = i;
        int cnt = 0;
        for (int j = 0; j < A; ++j) {
            if (b[idx] == a[j]) {
                idx++;
            }
        }

        ans = max(ans, idx - i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3088
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;

class Graph
{
private:
    int m_vertexNum;
    vector<vector<int>> m_adList;

public:
    Graph(const int N) : m_vertexNum(N)
    {
        m_adList = vector<vector<int>>(N);
    }

    void AddEdge(const int v1, const int v2)
    {
        m_adList[v1].push_back(v2);
        m_adList[v2].push_back(v1);
    }

    const vector<vector<int>> ComputeConnectedComponents() const
    {
        vector<bool> hasNotVisited(m_vertexNum, true);
        vector<vector<int>> ret;
        stack<int> stack;
        for (int v = 0; v < m_vertexNum; ++v)
        {
            if (hasNotVisited[v])
            {
                vector<int> cc;
                stack.push(v);
                hasNotVisited[v] = false;
                while (!stack.empty())
                {
                    const int u = stack.top();
                    stack.pop();
                    cc.push_back(u);
                    for (const int n : m_adList[u])
                    {
                        if (hasNotVisited[n])
                        {
                            stack.push(n);
                            hasNotVisited[n] = false;
                        }
                    }
                }
                ret.push_back(cc);
            }
        }
        return ret;
    }
};

int main()
{
    int H, W;
    cin >> H >> W;
    vector<char> squares(H * W);
    for (int row = 0; row < H; ++row)
    {
        for (int col = 0; col < W; ++col)
        {
            cin >> squares[row * W + col];
        }
    }
    // 隣接する黒マスと白マスを接続したグラフを構築し，連結成分を計算する
    Graph graph(H * W);
    for (int row = 0; row < H; ++row)
    {
        for (int col = 0; col < W; ++col)
        {
            if (col < W - 1 &&
                squares[row * W + col] != squares[row * W + col + 1])
            {
                graph.AddEdge(row * W + col, row * W + col + 1);
            }
            if (row < H - 1 && 
                squares[row * W + col] != squares[(row + 1) * W + col])
            {
                graph.AddEdge(row * W + col, (row + 1) * W + col);
            }
        }
    }
    const auto ccs = graph.ComputeConnectedComponents();
    LLONG ans = 0;
    for (const auto &cc : ccs)
    {
        LLONG blackNum = 0, whiteNum = 0;
        for (const int v : cc)
        {
            if (squares[v] == '#') ++blackNum;
            else ++whiteNum;
        }
        ans += blackNum * whiteNum;
    }
    cout << ans << endl;
}


Measured memory_bytes: 14640
from collections import deque
 
h,w = map(int,input().split())
s = [None]*h
 
for i in range(h):
    s[i] = input()
 
d = [[10000000 for i in range(w)] for j in range(h)]
sharp = 0
 
sx = []
sy = []
            
dx = [1,0,-1,0]
dy = [0,1,0,-1]
 
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            sx.append(j)
            sy.append(i)
            d[i][j] = 0
            
            
def bfs():
    que = deque()
    ans = 0
    for i in range(len(sx)):
        que.append([sy[i],sx[i]])
    
    while que:
        y,x = que.popleft()
        
        for k in range(4):
            nx = x + dx[k]
            ny = y + dy[k]
            
            if 0<=nx and nx<w and 0<=ny and ny<h and d[ny][nx] == 10000000:
                if d[ny][nx] > d[y][x]+1:
                    d[ny][nx] = d[y][x]+1
                    que.append([ny,nx])
                    
                    if d[ny][nx] > ans:
                        ans = d[ny][nx]
    
    print(ans)
        
bfs()

Measured memory_bytes: 149180
from collections import deque
import sys
input=sys.stdin.readline


#-------------------------------------------------------------------------
#白から黒に変えていく

def search() :
    H,W=map(int,input().split())
    pos=deque([])

    D= [[True]*(W+2)]                                  #True True True True
    D+=[[True]+[False]*W+[True] for i in range(H)]     #True FalseFalseTrue
    D.append([True]*(W+2))                             #True True True True

    for i in range(H) :
        maze=input()
        for j in range(W) :
            if maze[j]=="#" :
                pos.append([i+1,j+1,0])
                D[i+1][j+1]=True
 
    while len(pos)>0 :                             #forではなく各if構文だと通った…
        h,w,depth=pos.popleft()
        if not D[h+1][w] :
            pos.append([h+1,w,depth+1])
            D[h+1][w]=True

        if not D[h-1][w] :
            pos.append([h-1,w,depth+1])
            D[h-1][w]=True

        if not D[h][w+1] :
            pos.append([h,w+1,depth+1])
            D[h][w+1]=True

        if not D[h][w-1] :
            pos.append([h,w-1,depth+1])
            D[h][w-1]=True

    return depth            

print(search())


Measured memory_bytes: 168452
#include <stdio.h>

char input[10000];
int decode_num;
int input_decode[1000];

int main(void) {
	int i;
	int max,last;
	int now;
	scanf("%s",input);
	decode_num=1;
	input_decode[0]=100;
	for(i=0;input[i];) {
		if(input[i]=='e') {
			input_decode[decode_num++]=0;
			i+=3;
		} else if(input[i]=='c') {
			input_decode[decode_num++]=1;
			i+=7;
		} else return 1;
	}
	max=last=0;
	now=0;
	for(i=1;i<decode_num;i++) {
		if(input_decode[i-1]+input_decode[i]!=1) {
			if(now>max) {
				max=now;
				last=input_decode[i-1];
			}
			now=0;
		}
		now++;
	}
	if(now>max)last=input_decode[decode_num-1];
	puts(last==0?"egg":"chicken");
	return 0;
}

Measured memory_bytes: 0
s=raw_input()
t=raw_input()
maxx=len(t)
for i in range(len(s)-len(t)+1):
    val=0
    for j in range(i,i+len(t)):
        if s[j]!=t[j-i]:
            val+=1
    maxx=min(maxx,val)
print maxx


Measured memory_bytes: 68096
x, y = map(int, input().split())
ans = 0
if x == 1:
    ans += 300000
elif x == 2:
    ans += 200000
elif x == 3:
    ans += 100000

if y == 1:
    ans += 300000
elif y == 2:
    ans += 200000
elif y == 3:
    ans += 100000

if x == 1 and y == 1:
    ans += 400000
print(ans)

Measured memory_bytes: 38548
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o B.exe B.cpp 
Execute: ./B
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	long long a, v, b, w, t;
	cin >> a >> v >> b >> w >> t; 
	
	if(a < b) {
		if(a+v*t >= b+w*t) {
			cout << "YES" << endl; 
		} else {
			cout << "NO" << endl;
		}
	} else {
		if(a-v*t <= b-w*t) {
			cout << "YES" << endl; 
		} else {
			cout << "NO" << endl;
		}
	}
	
	return 0; 
} 


Measured memory_bytes: 3636
N = int(input())
Ls = [int(L) for L in input().split()]

max_L = max(Ls)
idx = Ls.index(max_L)

total = 0
for i in range(len(Ls)):
    if i != idx:
        total += Ls[i]

if total > max_L:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <stdio.h>

int main(){
  int i,n,m,x;
  int a[101];
  scanf("%d%d%d",&n,&m,&x);
  for(i=0;i<m;i++){
    scanf("%d",&a[i]);
  }
  int j=0,sum=0,tmp=0,min;
  for(i=1;i<=x;i++){
    if(i==a[j]){
      sum++;
      j++;
    }
  }
  min=sum;
  for(i=x;i<n;i++){
    if(i==a[j]){
      tmp++;
      j++;
    }
  }
  if(min>tmp){
    min=tmp;
  }
  printf("%d\n",min);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

struct Edge {int to; int cost;};
using Graph = vector<vector<Edge>>;

Graph G;
vector<vector<int>> DP;

int dfs1(int v = 0, int par = -1) {
    int res = 0;
    for (auto e : G[v]) {
        if (e.to == par) {
            DP[v].push_back(-1);
            continue;
        }
        int d = dfs1(e.to, v);
        DP[v].push_back(d);
        res = max(res, d + e.cost);
    }
    return res;
}

void dfs2(int v = 0, int par = -1, int val = 0) {
    rep(i, DP[v].size()) {
        if (DP[v][i] == -1) DP[v][i] = val;
    }
    vector<int> left(DP[v].size() + 1, 0), right(DP[v].size() + 1, 0);
    rep(i, DP[v].size()) left[i + 1] = max(left[i], DP[v][i] + G[v][i].cost);
    for (int i = (int)DP[v].size() - 1; i >= 0; --i) right[i] = max(right[i + 1], DP[v][i] + G[v][i].cost);
    rep(i, DP[v].size()) {
        if (G[v][i].to == par) continue;
        dfs2(G[v][i].to, v, max(left[i], right[i + 1]));
    }
}

int main() {
    int N;
    cin >> N;
    G = Graph(N);
    rep(i, N - 1) {
        int s, t, w;
        cin >> s >> t >> w;
        G[s].push_back(Edge{t, w});
        G[t].push_back(Edge{s, w});
    }
    
    DP = vector<vector<int>>(N);
    dfs1();
    dfs2();
    int ans = 0;
    rep(v, N) {
        int res = 0;
        rep(i, DP[v].size()) res = max(res, DP[v][i] + G[v][i].cost);
        ans = max(ans, res);
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 29488
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    A,B,C,D = map(int,input().split())
    
    if A+B < C+D:
        print("Right")
    elif A+B == C+D:
        print("Balanced")
    else:
        print("Left")
	
if __name__ == "__main__":
	main()


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

const int N = 2e5 + 10;

vector<int> G[22];
int vis[22][N];
int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        for(int j = 0; j < 20; j++) {
            if((x >> j) & 1) {
                G[j].push_back(i);
                vis[j][i] = 1;
            }
        }
    }
    long long ans = 0;
    int r = n;
    for(int i = n; i >= 1; i--) {
        for(int j = 0; j < 20; j++) {
            if(vis[j][i]) {
                int pos = lower_bound(G[j].begin(), G[j].end(), i) - G[j].begin();
                int sz = G[j].size();
                if(pos != sz - 1) {
                    r = min(r, G[j][pos + 1] - 1);
                }
            }
        }
        // cout << i << ":" << r << endl;
        ans += r - i + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 24640
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int sum=0;
			int r=9;
			while(r-->0)
				sum+=in.nextInt();
			System.out.println(n-sum);
		}
	}
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int MAX_H = 12;
const int MAX_W = 12;
char m[MAX_H+1][MAX_W+1];


inline bool check(int x, int y){ return 0<=x&&x<MAX_H && 0<=y&&y<MAX_W; }

void dfs(int hx, int hy)
{
  rep(i, 4){
    int nx = hx + dx[i];
    int ny = hy + dy[i];

    if(!check(nx, ny)) continue;

    if(m[nx][ny] == '1'){
      m[nx][ny] = '0';
      dfs(nx, ny);
    }
  }
}

int main()
{

  while(true){
    rep(i, MAX_H) rep(j, MAX_W) if(!(cin >> m[i][j])) return 0;

    int res = 0;
    rep(i, MAX_H) rep(j, MAX_W) if(m[i][j] == '1'){
      res += 1;
      dfs(i, j);
    }

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1140
s = input()

if s[0] == '0':
    b = False
else:
    b = True

s = s[1:]

ans = 0
for i in s:
    if i == '1':
        if b:
            ans += 1
            b = False
        else:
            b = True
    else:
        if not b:
            ans += 1
            b = True
        else:
            b = False

print(ans)

Measured memory_bytes: 3188
#include<cstdio>
#include<bitset>
using namespace std;
typedef long long LL;

bitset<4000005> dp;

int main(){
	int x;
	int n,sum = 0; scanf("%d",&n);
	dp[0] = 1;
	for(int i = 1;i <= n;i++){
		scanf("%d",&x);
		dp |= (dp << x);
		sum += x;
	}
	for(int i = (sum + 1) / 2;;i++){
		if(dp[i]){
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    int N=in.nextInt();int i,j,f=0;
    int M=in.nextInt();
    for(i=1;i<=N;i++)
    {
      for(j=i+1;j<=N;j++)
        f++;
    }
    for(i=1;i<=M;i++)
    {
      for(j=i+1;j<=M;j++)
        f++;
    }
    System.out.println(f);
  }
}
      
    

Measured memory_bytes: 22868
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10**9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n, k = LI()

    dp = [[0] * (k + 1) for _ in range(n + 1)]
    dp[0][0] = 1

    for i in range(n):
        for j in range(k):
            dp[i+1][j+1] = dp[i][j] + (j + 1) * dp[i][j+1]
            dp[i+1][j+1] %= MOD

    print(dp[-1][-1])

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 30448
#include<iostream>
#include <string>
#include <algorithm>

using namespace std;
typedef long long ll;


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

    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    string S;
    cin>>S;
    cout << S[0] << S[1] << S[2] << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, c, k;
	cin >> n >> c >> k;
	vector <int> t(n);
	for(int i = 0; i < n; i ++) cin >> t[i];
	sort(t.begin(), t.end());

	int ans = 0, count = 0, min = t[0];
	for(int i = 0; i < n; i++) {
		if((count < c) && (t[i] <= min + k)) {
			count++;
		} else {
			count = 1;
			min = t[i];
			ans++;
		}
	}
	ans++;
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		System.out.println(((n - 1) + (k - 1) - 1) / (k - 1));
	}
}

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

const int S = 1e4 + 10, MAX = 0x3f3f3f3f, MX = 1e4;
int dp[S], c[S], w[S], n, m;

int main() {
	memset(dp, MAX, sizeof(dp));
	scanf("%d%d", &m, &n);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", c + i, w + i);
	dp[0] = 0;
	for (int i = 1; i <= n; i++)
		for (int j = c[i]; j <= MX; j++)
			dp[j] = min(dp[j], dp[j - c[i]] + w[i]);
	int ans = INT_MAX;
	for (int i = m; i <= MX; i++) ans = min(ans, dp[i]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
n,*aa = map(int, open(0).read().split())

from collections import Counter
c = Counter(aa)

MOD = 10**9+7
cand = set(range((n+1)%2, n ,2))

if c.keys() - cand:
    ans = 0
else:
    ans = 1
    for v in cand:
        if v != 0 and c[v] != 2:
            ans = 0
            break
        elif v == 0 and c[v] != 1:
            ans = 0
            break
        elif v != 0:
            ans *= 2
            ans %= MOD

print(ans)

Measured memory_bytes: 110776
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

 
int vector_finder(std::vector<int> vec, int number) {
  size_t index = std::distance( vec.begin(), std::find(vec.begin(), vec.end(), number) );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int gcd(int a,int b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}


int N,K;

int main()
{
	cin >> N>>K;
	int x[N];
	REP(i,N){
		cin >> x[i];
	}
	int ans= INF;
	REP(i, N - K + 1)
	{
		int l = x[i];
		int r = x[i + K-1];

		int cost = min(abs(l) + abs(l - r), abs(r) + abs(l - r));
		ans = min(ans, cost);

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x=0,y=0,z=0;
	long long ans=1,ans1=1,ans2=1;
	scanf("%d",&x);
	if(x==1){
		printf("%d",0);
	}else{
		for(int i=1;i<=x;i++){
			ans*=10;
			ans%=1000000007;
		}
		for(int i=1;i<=x;i++){
			ans1*=9;
			ans1%=1000000007;
		}
		ans1*=2;
		ans1%=1000000007;
		for(int i=1;i<=x;i++){
			ans2*=8;
			ans2%=1000000007;
		}
		ans-=ans1;
		ans+=ans2;
		while(ans>1000000007){
			ans-=1000000007;
		}
		while(ans<0){
			ans+=1000000007;
		}
		printf("%lld",ans);
	}

} 

Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
#define check(n) reverse(all(n));rep(z,0,n.size())cout<<n[z];co("");reverse(all(n));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll a=1,b=1,n;
  cin>>n;
  rep(i,0,1001){
    rep(j,-1000,1001){
      rep(k,0,5) a*=i;
      rep(k,0,5) b*=j;
      if(a-b==n){
        co(i<<" "<<j);
        return 0;
      }
      a=1; b=1;
    }
  }
      
  
  return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 2;

void solve(){
    int N;
    cin >> N;

    vector<int> A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    int ans = 0;
    for(int i = 0; i < N; ++i){ ans ^= A[i];}
    if(ans == 0){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
    return;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long a[200010],b[200010];
long long ans[200010];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i],b[i]=a[i];
	sort(b,b+n+1);
	long long cnt=0;
	long long num=0;
	for(int i=1;i<=n;i++)
	{
		num++;
		if(b[i]!=b[i+1])
		{
			cnt+=num*(num-1)/2;
			ans[b[i]]=num*(num-1)/2-(num-1)*(num-2)/2;
			num=0;
		} 
	}
	for(int i=1;i<=n;i++)
		cout<<(long long)cnt-ans[a[i]]<<endl;
	return 0;
}

Measured memory_bytes: 6272
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;


int MOD=1000000007;
int main(void){
	int A,B;
	cin >> A >> B;
	if(A==1 && B==2 || A==2 && B==1) cout << 3 << endl;
	if(A==1 && B==3 || A==3 && B==1) cout << 2 << endl;
	if(A==2 && B==3 || A==3 && B==2) cout << 1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main () {
	int a, b, c, h;
	scanf("%d %d %d", &a, &b, &c);
	if(a > b){
		h = a;
		a = b;
		b = h;
	}
	if(b > c){
		h = c;
		c = b;
		b = h;
	}
	printf("%d\n", (a * b) / 2);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,Q;
  cin>>N>>Q;
  vector<int> A(N),dp(N,0);
  dp[0]=dp[1]=1;
  int idx=0;
  for(int i=0;i<N;i++){A[i]=i;}
  for(int i=0;i<Q;i++){
    ll a,b;
    cin>>a>>b;
    a--; b--;
    swap(A[a],A[b]);
    if(A[a]==0){idx=a;}
    if(A[b]==0){idx=b;}
    if(idx>0){dp[A[idx-1]]=1;}
    if(idx+1<N){dp[A[idx+1]]=1;}
  }
  ll sum=0;
  for(auto &I:dp){sum+=I;}
  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <set>
#include <map>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define pc putchar
#define mp std::make_pair
#define pr std::pair<int,int>
#define gc() getchar()
typedef long long LL;


inline int read()
{
	int now=0,f=1;register char c=gc();
	for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now*f;
}

int main()
{
	int n=read(),H=read(),W=read();
	printf("%d\n",(n-H+1)*(n-W+1));

	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(N: int, K: int):
    ketamax=K-1
    keta=1
    while(N>ketamax):
        keta+=1
        ketamax=(ketamax+1)*K-1
    print(keta)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N = int(input())
a = list(map(int,input().split()))
col = [0]*8
wild = 0
for i in a:
    if i//400 <= 7:
        col[i//400] = 1
    else:
        wild += 1
minimum = max(1,sum(col))
maximum = sum(col)+wild
print(minimum,maximum)

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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

ll get(ll x, ll y) {
  return (x / y);
}

int main() {
  ll x, y; read(x, y);
  ll ans = 0;
  ll cur = 1ll;
  while(x * cur <= y) {
    ans++;
    cur *= 2ll;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

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

int N;
stack<int> s[1010];
bool checked[1010] = {};
bool possible = true;
int day = 0;
int battle = 0;
int cnt = 0;
clock_t start;
clock_t endt;

int main() {
	start = clock();
	endt = clock();
	cin >> N;
	REP(i, N) {
		REP(j, N - 1) {
			int tmp;
			cin >> tmp;
			s[i].push(tmp - 1);
		}
	}
	//入力完了
	while (true) {

		if (cnt > 10000000) {
			cout << (N - 1) * N / 2 << endl;
			return 0;
		}
		//		cout << (clock() - start) / CLOCKS_PER_SEC << endl;

		possible = false;
		REP(i, N) {
			checked[i] = false;
		}

		REP(i, N) {
			cnt++;
			if (checked[i] || s[i].empty() || checked[s[i].top()] || s[s[i].top()].empty()) continue;
			int ind = s[i].top();

			if (s[ind].top() == i) {
				possible = true;
				battle++;

				checked[ind] = true;
				checked[s[ind].top()] = true;
				//				cout << s[i].top() << " vs " << s[ind].top() << " ";
				s[i].pop();
				s[ind].pop();
			}
		}
		if (!possible) {
			if (battle == (N - 1) * N / 2) {
				//全部おっけ
				cout << day << endl;
			}
			else {
				cout << -1 << endl;
			}
			return 0;
		}
		day++;
		endt = clock();
	}
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ll x;
  cin >> x;
  ll ans = (x / 11) * 2;
  x = x % 11;
  if (x > 6)
    ans += 2;
  else if (x > 0)
    ans += 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Num 1000000007
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    string s;
    cin >> s;
    int cnt = 0;
    if (s[0] != 'A')
    {
        cout << "WA" << endl;
        return 0;
    }
    for (int i = 2; i < s.size() - 1; i++)
    {
        if (s[i] == 'C')
            cnt++;
    }
    if (cnt != 1)
    {
        cout << "WA" << endl;
        return 0;
    }
    cnt=0;
    rep(i,s.size()){
        if('a'<= s[i] &&s[i]<='z'){
            cnt++;
        }
    }
    if(cnt==s.size()-2){
        cout<<"AC"<<endl;
        return 0;
    }
    cout<<"WA"<<endl;
    return 0;
}

Measured memory_bytes: 256
use text_io::*;
use std::process::exit;
use im_rc::HashMap;

fn main(){
    let mut n:isize = read!();
    let mut map= HashMap::new();
    let mut sum:usize = 0;
    for i in 0..n-1 {
        let mut s:usize = read!();
        let mut t: &i32 = map.get(&s).unwrap_or(&0);
        let mut o: &i32 = &1;
        map.insert(usize::from(s),t+o);
    }
    for i in 1..n+1 {
        println!("{}",map.get(&(*&i as usize)).unwrap_or(&0))
    }
}

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

int main(){
  int N;
  cin >> N;
  
  if(N == 1){
    cout << "Hello World"<<endl;
  }else{
    int tmp1,tmp2;
    cin >> tmp1 >> tmp2;
    cout << tmp1 + tmp2 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>
#include <set>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

using namespace std;

int main()
{
    string a, b;
    cin >> a >> b;
    bool f = true;
    if (a.length() == b.length() - 1)
    {
        for (int i = 0; i < a.length(); i++)
        {
            if (a[i] != b[i])
            {
                f = false;
                break;
            }
        }
    }
    else
    {
        f = false;
    }

    if (f)
    {
        cout << "Yes"
             << " " << endl;
    }
    else
    {
        cout
            << "No"
            << " " << endl;
    }
    return 0;
}

Measured memory_bytes: 3628