akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#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;

int main() {
    int N;
    cin >> N;
    
    cout << N * (N - 1) / 2 - N / 2 << endl;
    if (N % 2) {
        for (int i = 1; i <= N; ++i) {
            for (int j = i + 1; j <= N; ++j) {
                if (i + j != N) {
                    cout << i << " " << j << endl;
                }
            }
        }
    } else {
        for (int i = 1; i <= N; ++i) {
            for (int j = i + 1; j <= N; ++j) {
                if (i + j != N + 1) {
                    cout << i << " " << j << endl;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a > 9 || b > 9){
      System.out.println("-1");
    } else {    	
      System.out.println(a * b);
    }
  }
}

Measured memory_bytes: 23892
def swap(dice,i,j,k,l):#diceの目をi→ｊ→ｋ→ｌ→iの順に入れ替える
    x=dice[l]
    dice[l]=dice[k]
    dice[k]=dice[j]
    dice[j]=dice[i]
    dice[i]=x
    return dice


dice=list(map(int,input().split()))
Dice=[0]
dice=Dice +dice
roll=list(input())
for i in range(0,len(roll)):
    if(roll[i]=="S"):
        dice=swap(dice,1,2,6,5)
    elif(roll[i]=="E"):
        dice=swap(dice,1,3,6,4)
    elif(roll[i]=="W"):
        dice=swap(dice,1,4,6,3)
    elif(roll[i]=="N"):
        dice=swap(dice,1,5,6,2)
print(dice[1])


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     int n,m;
     cin>>n>>m;
     set<int>factor;
     for(int i=1;i<=sqrt(m);i++)
     { 
         if(m%i==0)
         {
             factor.insert(i);
             factor.insert(m/i);
         }
     }
     if(m%n==0)
     {
         cout<<m/n;
         return 0;
     }
     int x=m/n;
     for(set<int>::iterator it=factor.begin();it!=factor.end();it++)
     {
          if(*it>x)
          {
             it--;
             cout<<*it;
             return 0;
          }
          if(*it==x)
          {
             cout<<*it;
             return 0;
          }
     }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF){
		if((a-b)==(b-c)){
			printf("YES\n");
		}
		else printf("NO\n");
	}
	return 0;
} 

Measured memory_bytes: 128
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int x,maxx;
int main()
{
	fast;
	cin>>x;
	for (int i=1;i<=x;i++)
	   for (int j=2;j<=10;j++)
	      if (pow(i,j)<=x && pow(i,j)>=maxx)
	         maxx=pow(i,j);
	cout<<maxx<<endl; 
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    int n;cin>>n;
    int a[n+1];
    rep(i,1,n+1)cin>>a[i];
    int b[n+1];
    int cnt[n+1];
    fill(cnt,cnt+n+1,0);
    rrep(i,n,1){
        int r=cnt[i]%2;
        b[i]=r^a[i];
        if(b[i]==1){
            for(int j=1;j*j<=i;j++){
                if(i%j==0){
                    cnt[j]++;
                    if(i!=j*j)cnt[i/j]++;
                }
            }
        }
    }
    int sum=0;
    rep(i,1,n+1)if(b[i]==1)sum++;
    cout<<sum<<endl;
    vector<int> v;
    if(sum==0)return 0;
    rep(i,1,n+1){
        if(b[i]==1)v.push_back(i);
    }
    rep(i,0,v.size()-1)cout<<v[i]<<" ";
    cout<<v[v.size()-1]<<endl;
}


Measured memory_bytes: 3832
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_N 100
int N;
ll T[MAX_N];

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

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, 0, N) cin >> T[i];

	if(N == 1) {
		cout << T[0] << endl;
		return 0;
	}
	ll res = lcm(T[0], T[1]);
	rep(i, 2, N) {
		res = lcm(res, T[i]);
	}
	cout << res << endl;

}


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

using graph = std::vector<std::vector<int>>;

bool dfs(graph const& g, int v, std::vector<int>& match, std::vector<bool>& used) {
    used[v] = true;
    for(auto u : g[v]) {
        int w = match[u];
        if(w < 0 || !used[w] && dfs(g, w, match, used)) {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching(graph const& g) {
    const int V = g.size();
    std::vector<int> match(V, -1);
    std::vector<bool> used(V);
    int res = 0;
    for(int v=0; v<V; ++v) {
        if(match[v] < 0) {
            std::fill(used.begin(), used.end(), false);
            if(dfs(g, v, match, used)) {
                ++res;
            }
        }
    }
    return res;
}

constexpr double eps = 1e-8;

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<double> tx(N), ty(N), v(N);
        for(int i=0; i<N; ++i) {
            cin >> tx[i] >> ty[i] >> v[i];
        }
        vector<double> bx(M), by(M);
        for(int i=0; i<M; ++i) {
            cin >> bx[i] >> by[i];
        }
        double lb = -1, ub = 1e9;
        while(abs(ub - lb) > eps) {
            double m = (ub + lb) / 2;
            graph g(N+M);
            for(int i=0; i<N; ++i) {
                for(int j=0; j<M; ++j) {
                    if(hypot(tx[i]-bx[j], ty[i]-by[j]) - eps <= v[i] * m) {
                        g[i].push_back(N+j);
                        g[N+j].push_back(i);
                    }
                }
            }
            if(bipartite_matching(g) == M) {
                ub = m;
            } else {
                lb = m;
            }
        }
        cout << fixed << setprecision(10) << ub << endl;
    }
}

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

int main(){
   int x,a,b;
   cin >> x >>a >> b;
   int disa,disb;
   disa = abs(x-a);
   disb = abs(x-b);
   if (disa<disb) 
      cout << "A" <<endl;
 else
    cout << "B" <<endl;
 return 0;
}


Measured memory_bytes: 256
i = 0
user = {}
while num = gets do
  a = num.split(" ")[0].to_i
  b = num.split(" ")[1].to_i
  if a == 0 && b == 0
    break
  end
  if a < b then
    user[i] = a.to_s + " " + b.to_s
  elsif a > b then
    user[i] = b.to_s + " " + a.to_s
  else
    user[i] = num
  end
  i += 1
end
user.each do |key,value|
  puts "#{value}"
end

Measured memory_bytes: 8712
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define yes cout << "YES\n"
#define no cout << "NO\n" 
#define pi 3.1415926536
#define mod  1000003
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int s,v;
    cin>>s>>v;
    if(s<=v) cout<<"unsafe";
    else cout<<"safe";
    
    
    
    
    
    return 0;
  
}

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

int main(){
  int a,b;
  cin >>a >>b;
  if(a+b==15) cout << '+' << endl;
  else if(a*b==15) cout << '*' << endl;
  else cout << 'x' << endl;
  return 0;
}

Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val A, B, C, X, Y = sc.nextInt()
    // X, Y のピザを用意する必要がある. 単に全探索すると, Aの枚数を決めるのに10^5乗とるので、間に合わない
    // 先にABピザを何枚手に入れるかを考えると, AとBのピザの枚数は絞られる
    // ABが決まると, 自動的にAとBのピザの枚数が決定する
    val r = (for {
      ab <- 0 to (X max Y) * 2
      a = (X - ab / 2) max 0
      b = (Y - ab / 2) max 0
    } yield (A * a + B * b + C * ab)).min

    println(r)
  }

}


Measured memory_bytes: 74260
#include<cstdio>
#include<string>
#include<cstdlib>
#include<iostream>
using namespace std;

struct Node{
  struct Node *right;
  struct Node *left;
  struct Node *parent;
  int key;
};
//#define NIL NULL

Node *root, *NIL;

/*Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted                                                \
                                                                                
  Node x; // child of y                                                        \
                                                                                



}*/

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z =(Node*) malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }


}

void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}
void preorder(Node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);

}


int main(){
  int n, i, x;
  string com;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    cin >> com;
    //if ( com[0] == 'f' ){
      //scanf("%d", &x);
      //Node t = treeSearch(root, x);
      //if ( t != NIL ) printf("yes\n");
      //else printf("no\n");
    //}
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } //else if ( com[0] == 'd' ){
      //scanf("%d", &x);
      //treeDelete(treeSearch(root, x));
    //}
  }

  return 0;
}






Measured memory_bytes: 26768
N = int(input())
ans = 0

def num_divisors_table(n):
    table = [0] * (n + 1)

    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1

    return table

dp = num_divisors_table(N)

for k in range(1, N+1):
    ans += k * dp[k]

print(ans)


Measured memory_bytes: 145960
import itertools
N,C = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(C)]
c = [list(map(int,input().split())) for _ in range(N)]

delta = [[0]*C for _ in range(3)]

for i in range(N):
    for j in range(N):
        for to in range(C):
            delta[(i+j)%3][to] += D[c[i][j]-1][to]
ans = 1e100
for x,y,z in itertools.permutations(range(C),3):
    ans = min(ans, delta[0][x] + delta[1][y] + delta[2][z])
print(ans)


Measured memory_bytes: 44252
import java.util.Scanner;

public class Main {

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

  private Scanner sc;

  private void run() {
    sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[] array = new int[N];

    int left = 0;
    int right = 0;

    int sum = 0;
    for (int i = 0; i < N; i++) {
      array[i] = Integer.parseInt(sc.next());
      sum += array[i];
    }

    left = 0;
    right = sum;

    int ans = Integer.MAX_VALUE;

    for (int i = 0; i < N; i++) {
      left += array[i];
      right -= array[i];

      if (Math.abs(left - right) < ans) {
        ans = Math.abs(left - right);
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <bitset>

#define lp(n) for(int i=0;i<n;i++)
#define LP(n,i) for(int i=0;i<n;i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define intmin -2147483637
#define llmax 9223372036854775807
typedef long long ll;

using namespace std;

int dp[4001][4001],n,ma,mb,a,b,c,ans;


/*ll gcd(ll x,ll y){
	if(y==0)return x;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	ll g=gcd(x,y);
	return x/g*y;
}*/

int main(){
	cin>>n>>ma>>mb;
	lp(4001)
		LP(4001,j)
			dp[i][j]=1234567;
	dp[0][0]=0;
	lp(n){
		cin>>a>>b>>c;
		for(int j=1+i*100;j>=0;j--){
			for(int k=1+i*100;k>=0;k--){
				dp[j+a][k+b]=min(dp[j+a][k+b],dp[j][k]+c);
			}
		}
	}
	ans=1234567;
	for(int i=1;ma*i<=4000&&mb*i<=4000;i++){
		ans=min(ans,dp[ma*i][mb*i]);
//		cout<<i<<sp<<ma*i<<sp<<mb*i<<sp<<dp[ma*i][mb*i]<<endl;
	}
	if(ans==1234567)ans=-1;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 62720
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        for(int i = 0; i < k; i++) {
            if(i%2 == 0) {
                if(a%2 == 1) a--;
                b = b + a/2;
                a = a/2;
            } else {
                if(b%2 == 1) b--;
                a = a + b/2;
                b = b/2;
            }
        }
        System.out.println(a+" "+b);
    }
}

Measured memory_bytes: 22996
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        h: u64,
        w: u64,
    }

    if h == 1 || w == 1 {
        println!("1");
        return;
    }

    let ans = (h as f64 * w as f64 / 2.0).ceil();
    println!("{}", ans as u64);
}


Measured memory_bytes: 2496
// Typical Stairs
#include <cmath>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    vector<bool> broken(n+1, false);
    for(int i = 0; i < m; i++) {
        int x;
        cin >> x;
        broken[x] = true;
    }

    vector<int> dp(n+2);
    const long long mod = 1000000007;
    dp[n] = 1;

    for (int i = n - 1; i >= 0; i--) {
        if (broken[i]){
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i+1] + dp[i+2]) % mod;
        // for (int j = 0; j < n + 1; j++) cout << dp[j] << ' ';
        // cout << endl;
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  string S;
  cin >> S;
  char b = S[0];
  int ans = 0;
  for (int i = 1; i < S.size(); i++) {
    if (b != S[i]) {
      ans++;
      b = S[i];
    }
  }

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


Measured memory_bytes: 512
def print_puddle(puddle):
    n = len(puddle)
    if n > 0:
        print(n, end=' ')
    else:
        print(n)
    for i in range(n):
        if i != n - 1:
            print(puddle[i][1], end=' ')
        else:
            print(puddle[i][1])



def solve(A):
    left = []
    puddle = []
    sum_all = 0
    for i, a in enumerate(A):
        if a == '\\':
            left.append(i)
        elif a == '/' and len(left) > 0:
            left_i = left.pop()
            a = i - left_i
            sum_paddle = i - left_i
            sum_all += a
            while len(puddle) and puddle[-1][0] > left_i:
                tmp = puddle.pop()
                sum_paddle += tmp[1]

            puddle.append((left_i, sum_paddle))
    print(sum_all)
    print_puddle(puddle)


def main():
    A = list(input())

    solve(A)


if __name__ == "__main__":
    main()



Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;

int main() {
	ios_base::sync_with_stdio(0);
	int a,b,n,T,cas=0;
	cin>>a>>b;
	if(b>=a) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
def _print(a,b,s):
    print(s[a:b+1])
def _reverse(a,b,s):
    return s[:a]+s[a:b+1][::-1]+s[b+1:]
def _replace(a,b,p,s):
    return s[:a]+p+s[b+1:]

s = input()
n = int(input())
for i in range(n):
    c = input().split()
    if c[0] == "print":
        _print(int(c[1]),int(c[2]),s)
    elif c[0] == "reverse":
        s = _reverse(int(c[1]),int(c[2]),s)
    else:
        s = _replace(int(c[1]),int(c[2]),c[3],s)


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W ;
  vector<vector<char>> a(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> a.at(i).at(j);
    }
  }
  vector<int> x(0),y(0);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(a.at(i).at(j)=='#'){
        x.push_back(i);
        break;
      }
    }
  }
  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
       if(a.at(i).at(j)=='#'){
        y.push_back(j);
        break;
      }
    }
  }
  for(int i : x){
    for(int j : y){
      cout << a.at(i).at(j);
    }
    cout <<endl;
  }
  
      
  
}

Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    REP(i, n){
        cin >> l[i];
    }
    sort(ALL(l), greater<int>());
    int ans = 0;
    REP(i, k){
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma region Template
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <stack>
#include <set>
#include <algorithm>
#include <bitset>
#include <functional>
#include <ctime>
#include <cassert>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <complex>
#include <regex>
#include <numeric>
#pragma comment(linker, "/STACK:167772160")

using namespace std;
#define mp make_pair
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define print_var(x) cerr << #x << " : " << (x) << endl
#define print_array(arr, len) {cerr << #arr << " : "; for(int i = 0; i < len; ++i) cerr << arr[i] << ' '; cerr << endl;}
#define print_2d_array(arr, len1, len2) {cerr << #arr << endl; for(int i = 0; i < len1; ++i, cerr << endl) for(int j = 0; j < len2; ++j) cerr << arr[i][j] << ' ';}
#define print_iterable(i) {cerr << #i << " : "; for(auto e : i) cerr << e << ' '; cerr << endl;}
#define print_new_line() cerr << endl

template <typename T, typename Q>
void print_pair1(pair<T, Q> x)
{
	cerr << "(" << x.first << ", " << x.second << ")\n";
}

#define print_pair(x) {cerr << #x << " : "; print_pair1(x);}
#else
#define print_pair(x) (void)0
#define eprintf(...) (void)0
#define print_var(x) (void)0
#define print_array(arr, len) {}
#define print_2d_array(arr, len1, len2) {}
#define print_iterable(i) {}
#define print_new_line() (void)0
#endif

#define rand govno_ebanoe

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int INF = (int)1e9 + 10;
const ll LINF = ll(2e18) + 10;
const double PI = acosl(-1);
const double eps = 1e-8;
const ld EPS = 1e-12;
#pragma endregion

#ifdef LOCAL
#define ERR_CATCH
//#define NOERR
#endif

const int N = 2e5 + 10;
ll n;
char s[N];
ll cnt[N];

void solve()
{
	scanf("%s", s);
	n = strlen(s);
	ll ans = (n - 1) * n / 2 + 1;
	for (int i = 0; i < n; ++i)
		++cnt[s[i]];
	for (int i = 0; i < N; ++i)
		ans -= cnt[i] * (cnt[i] - 1) / 2;
	printf("%lld\n", ans);
}

int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#ifdef NOERR
	freopen("err.txt", "w", stderr);
#endif
#else
	//freopen("knight.in", "r", stdin);
	//freopen("knight.out", "w", stdout);
#endif

#ifdef ERR_CATCH
	try
	{
#endif

#ifdef ST
		while (true)
			solve();
#endif
#ifdef CASES
#define MULTITEST
#endif
#ifdef MULTITEST
		int t;
		scanf("%d", &t);
		char endl1[5];
		fgets(endl1, 5, stdin);
		for (int i = 0; i < t; ++i)
		{
#ifdef CASES
			printf("Case #%d: ", i + 1);
#endif
			solve();
#ifdef CASES
			eprintf("Passed case #%d:\n", i + 1);
#endif
		}
#else
		solve();
#endif

#ifdef ERR_CATCH
	}
	catch (logic_error e)
	{
		print_var(e.what());
		puts("___________________________________________________________________________");
		exit(0);
	}
#endif
#ifdef LOCAL
	eprintf("\n\nTime: %.3lf\n", double(clock()) / CLOCKS_PER_SEC);
#endif
}

Measured memory_bytes: 384
#include <iostream>
#include <stack>

using namespace std;

void Solution()
{
    int a[10]={1,2,4,8,16,32,64,128,256,512};
    
    int n;
    
    stack<int> save;
    
    while(cin>>n)
    {
        for(int i = 9; 0 <= i; i--)
        {
            if(n - a[i] > -1)
            {
                save.push(a[i]);
                
                n = n - a[i];
            }
        }
        
        while(1)
        {
            cout<<save.top();
            
            save.pop();
            
            if (save.empty())
            {
                break;
            }
            else
            {
                cout<<" ";
            }
        }
        
        cout<<endl;
    }
}

int main()
{
    Solution();
    return 0;
}

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

int main(void) {
	double A, B, C, D;
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;

	if (ceil(C/B) <= ceil(A/D)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
#include<list>
#include <stdio.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)
#pragma GCC optimize("Ofast")



int main() {
	int n, x, t;
	cin >> n >> x >> t;
	ll count = 0;
	for (int i = 0; i < n; i += x) {
		count += t;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e9+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
typedef vector<ll> vi;
typedef vector < pair<int, int > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main() {
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	ll n, m;
	cin >> n >> m;
	vi v(111111);
	REP(i, n) {
		ll a, b;
		cin >> a >> b;
		v[a] += b;
	}
	REP(i, 111111) {
		sum += v[i];
		if (sum >= m) {
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int H,W;cin>>H>>W;
  vs fi(H);
  rep(i,H){
    cin>>fi[i];
    fi[i] = '#'+fi[i] +'#';
  }
  rep(i,W+2){
    cout<<'#';
  }
  cout<<endl;
  rep(i,H){
   cout<<fi[i]<<endl;
  }
  rep(i,W+2){
    cout<<'#';
  }
  cout<<endl;
  
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
#define ld long double
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactive problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main(){ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ll x;
    cin>>x;
    cout<<1-x;

    return 0;
}

Measured memory_bytes: 3648
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctype.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
    return 0;
}

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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

int main() {
    int a,b,c;
    cin>>a>>b>>c;

    int M=max({a,b,c});
    int sub=M*3-(a+b+c);

    if(sub%2==0)cout<<sub/2<<endl;
    else cout<<((sub+2-1)/2)+1<<endl;

}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int Q = int.Parse(str[1]);
        bool[] B = new bool[N];
        for(int i=0;i<Q;i++){
            str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]) - 1;
            int b = int.Parse(str[1]) - 1;
            B[a] = !B[a];
            B[b] = !B[b];
        }
        bool c = true;
        for(int i=0;i<N;i++){
            c &= !B[i];
        }
        sb.Append((c ? "YES" : "NO")+"\n");
    }
}

Measured memory_bytes: 17232
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<P> p(N);
  REP(i, N)
  {
    ll A, B;
    cin >> A >> B;
    p[i] = make_pair(A, B);
  }
  sort(ALL(p));
  cout << p[N - 1].first + p[N - 1].second << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main() {
  int n;
  string s, t;
  cin >> n;
  cin >> s >> t;
  string ans;
  for(int i=0;i<n;i++){
    ans.push_back(s[i]);
    ans.push_back(t[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static int n, m;
  static int[] x, y;

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

    n = sc.nextInt(); m = sc.nextInt();
    x = new int[m]; y = new int[m];
    for(int i = 0; i < m; i++){
      x[i] = sc.nextInt() - 1;  y[i] = sc.nextInt() - 1;
    }

    int[] c = new int[n];
    for(int i = 0; i < n; i++){
      c[i] = 1;
    }

    boolean[] p = new boolean[n];
    p[0] = true;
    for(int i = 0; i < m; i++){
      if(p[x[i]]){
        p[y[i]] = true;
      }
      --c[x[i]];  ++c[y[i]];
      if(c[x[i]] == 0){
        p[x[i]] = false;
      }
    }

    int count = 0;
    for(int i = 0; i < n; i++){
      if(p[i]){
        ++count;
      }
    }

    System.out.println(count);
  }
}

Measured memory_bytes: 24340
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();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }

        int sum = 0;
        for (int i = 0; i < n; i++) {
            int dis1 = Math.abs(0 - x[i]);
            int dis2 = Math.abs(k - x[i]);
            sum += Math.min(dis1,dis2) * 2;
        }

        System.out.println(sum);
    }
}

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

int N;
int dist[100010] = {};
vector<vector<int>> v(100010);
vector<int> deg;

void dfs(int n,int m){
    for(auto x:v[n]){
        if(x!=m){
            dist[x] = dist[n]+1;
            dfs(x,n);
        }
    }
}

void dfs2(int n,int m){
    deg.push_back((int)v[n].size());
    for(auto x:v[n]){
        if(x!=m && (int)v[x].size()!=1) dfs2(x,n);
    }
}

int main(){
    cin >> N;
    int a,b;
    for(int i=0;i<N-1;i++){
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int cnt = 0;
    for(int i=1;i<=N;i++){
        cnt += max((int)v[i].size()-2,0);
    }
    dist[1] = 0; dfs(1,0);
    int ma = 0,id = 1;
    for(int i=1;i<=N;i++){
        if(ma<dist[i]){
            ma = dist[i]; id = i;
        }
    }
    dist[id] = 0; dfs(id,0);
    ma = 0;
    int id2 = -1;
    for(int i=1;i<=N;i++){
        if(ma<dist[i]){
            ma = dist[i]; id2 = i;
        }
    }
    if(N-1-cnt!=ma){
        cout << -1 << endl;
        return 0;
    }
    dfs2(id,0);
    deg.push_back(1);
    int l = 0,r = (int) deg.size()-1;
    while(l<r){
        if(deg[l]!=deg[r]){
            if(deg[l]>deg[r]){
                reverse(deg.begin(),deg.end());
            }
            break;
        }
        l++; r--;
    }
    //deg.pop_back();
    vector<int> ans;
    for(auto x:deg) cerr << x << endl;
    for(int i=0;i<=N;i++) ans.push_back(i);
    int now = 1;
    for(int i=0;i<deg.size();i++){
        if(deg[i]<=2) now++;
        else{
            int n = deg[i]-2;
            reverse(ans.begin()+now,ans.begin()+now+n+1);
            reverse(ans.begin()+now,ans.begin()+now+n);
            now += n+1;
        }
    }
    for(int i=1;i<=N;i++) cout << ans[i] << (i!=N? " ":"\n");
}

Measured memory_bytes: 13816
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

def bfs(graph, initial):
    n = len(graph) - 1
    dist = [-1] * (n + 1)
    q = deque([initial])
    visited = [False] * (n + 1)
    visited[initial] = True
    dist[initial] = 0

    while len(q) != 0:
        edge = q.popleft()
        nxt = graph[edge]

        for i, e in enumerate(nxt):
            if visited[e] is False:
                q.append(e)
                dist[e] = dist[edge] + 1
                visited[e] = True

    return dist


def main():
    N, M = MI()

    ret = bfs(graph, 1)
    print(ret)


def main():
    N, X, Y = MI()
    graph = [[] for i in range(N+1)]

    for i in range(1, N):
        graph[i].append(i+1)
        graph[i+1].append(i)

    graph[X].append(Y)
    graph[Y].append(X)

    d = defaultdict(int)
    for i in range(1, N+1):
        ret = bfs(graph, i)
        for j in range(1, len(ret)):
            if i != j:
                d[ret[j]] += 1
        # print(ret)

    # print(d)
    for i in range(1, N):
        if i in d:
            print(d[i]//2)
        else:
            print(0)
    # d = defaultdict(int)

    # for i in range(1, N+1):
    #     for j in range(i+1, N+1):
    #         a = abs(j - i)
    #         b = abs(X - i) + 1 + abs(Y - j)
    #         c = abs(Y - i) + 1 + abs(X - j)
    #         d[min(a, b, c)] += 1

    # for i in range(1, N):
    #     if i in d:
    #         print(d[i])
    #     else:
    #         print(0)


if __name__ == '__main__':
    main()


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

using namespace std;

const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0;i<n;i++)
        cin >> v[i];
    vector<int> dp(n + 1,INF);
    dp[0] = 0;
    for(int i = 0;i<n-1;i++){
        dp[i + 1] = min(dp[i + 1],dp[i] + abs(v[i] - v[i + 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(v[i] - v[i + 2]));
    }
    cout << dp[n - 1] << "\n";
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sum = sc.nextInt();  //書かれている整数の数
		int shorui[] = new int[sum];  //書類に書かれてる整数が入ってる配列
		
		//配列に1つずつ数字を入力
		for(int i=0 ; i<sum ; i++) {
			shorui[i] = sc.nextInt();
			
			//偶数なら3または5で割り切れるか判断
			if(shorui[i]%2 == 0) {
				if(shorui[i]%3 == 0 || shorui[i]%5 == 0) {
					continue;  //どちらかで割り切れるならfor文に戻る
				}
				else {  //どちらでも割り切れないならその時点で終了
					System.out.print("DENIED");  
					return;
				}
			}
			else {  //奇数ならfor文に戻る
				continue;
			}
		}
		//途中で"DENIED"にならなかったら"APPROVED"
		System.out.print("APPROVED");
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,A,x[60];
ll dp[60][60][2510];
int main(){
  cin>>N>>A;
  rep(i,N) cin>>x[i];
  fill(dp,0);
  dp[0][0][0]=1;
  rep1(i,N){
    rep(j,N+1){
      rep(k,2501){
	if(k-x[i-1]>=0&&j>=1) dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]];
	else dp[i][j][k]=dp[i-1][j][k];
      }
    }
  }
  ll res=0;
  int B=A,l=1;
  while(l<=N&&B<=2500){
    res+=dp[N][l][B];
    l++;B+=A;
  }
  prin(res);
  
  
  return 0;
}


Measured memory_bytes: 70784
#include<cstdio>
#include<cstring>
int main(){
	int a,b,c,d,i,k,e,j;
	int n[105];
	while(~scanf("%d",&a))
	{	for(i=0;i<a;i++)
		{
			scanf("%d",&n[i]);
			
		}
		d=0;
		for(k=0;k<a-1;k++)
		for(j=k+1;j<a;j++)
		{
			d+=n[k]*n[j];
		
		}
		printf("%d\n",d);
	}
			
}

Measured memory_bytes: 128
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    d = dict()
    for i in range(N):
        s = list(input())
        s.sort()
        s = tuple(s)
        if s in d:
            d[s] += 1
            continue
        d[s] = 0

    ans = 0
    for key, val in d.items():
        if val == 0:
            continue
        ans += (val+1)*val//2

    print(ans)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 23520
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, d;
    cin >> n >> d;
    vector<array<int, 3>> v(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d %d", &v[i][1], &v[i][2], &v[i][0]);
    }
    sort(v.begin(),v.end());
    int l = 0;
    multiset<int> Y, X;
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        Y.emplace(v[i][1]);
        X.emplace(v[i][2]);
        while(v[i][0]-v[l][0] > d){
            Y.erase(Y.find(v[l][1]));
            X.erase(X.find(v[l][2]));
            l++;
        }
        ans = max(ans, (ll)(*X.crbegin() - *X.cbegin())*(*Y.crbegin() - *Y.cbegin()));
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 24040
#include<stdio.h>
int a[50001];
main(){
  int i,j,cnt=0,n=50000,b;
  for(i=2;i<=n;i++){
    if(a[i]==0){
      for(j=2;i*j<=n;j++){
	a[i*j]=1;
      }     
    }
  }
  while(1){
    scanf("%d",&b);
    if(b==0)break;
    for(i=2;i<=b/2;i++){
      if(a[i]==0&&a[b-i]==0)cnt++;
    }
    printf("%d\n",cnt);
    cnt=0;
  }
  return 0;
}

Measured memory_bytes: 792
n = int(input())
a = list(map(int,input().split()))
div_1 = div_2 = div_4 = 0
for i in a:
    if i%4==0:
        div_4 += 1
    elif i%2==0:
        div_2 += 1
    else:
        div_1 += 1

if div_4==div_1 or div_4==div_1+1 or (div_1==0 and div_2!=1) or (div_2==0 and (div_4==div_1 or div_4+1==div_1 or div_4==div_1+1)):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;
 
int n,m,r;
const int INF=1e7;
int d[2][200][200];
typedef pair<int,int> P;
 
int main(){
 
 
    while(scanf("%d %d",&n,&m),n){
	    
	   for(int i=0;i<n;i++){
		  for(int j=0;j<n;j++) d[0][i][j]=d[1][i][j]=INF;
		  d[0][i][i]=d[1][i][i]=0;
	   }
	    
	   for(int i=0;i<m;i++){
		  int x,y,t;
		  char c;
		  scanf("%d %d %d %c",&x,&y,&t,&c);
		  x--; y--;
		  
		  d[c=='L'][x][y]=min(d[c=='L'][x][y],t);
		  d[c=='L'][y][x]=min(d[c=='L'][y][x],t);
	   }
	    
	   for(int k=0;k<n;k++){
		  for(int i=0;i<n;i++){
			 for(int j=0;j<n;j++){
				d[0][i][j]=min(d[0][i][j],d[0][i][k]+d[0][k][j]);
				d[1][i][j]=min(d[1][i][j],d[1][i][k]+d[1][k][j]);
			 }
		  }
	   }
	   
	   int now,z;
	   scanf("%d",&r);
	   scanf("%d",&now); now--;
	   vector<vector<int> > dp(1000,vector<int>(200,INF));
	   dp[0][now]=0;
	    
	   for(int i=0;i<r-1;i++){
		   scanf("%d",&z); z--;
		   
		   for(int j=0;j<n;j++){
			   dp[i+1][j]=min(dp[i+1][j],dp[i][j]+d[1][now][z]);
			   for(int k=0;k<n;k++){
				   // 
				   dp[i+1][k]=min(dp[i+1][k],dp[i][j]+d[1][now][j]+d[0][j][k]+d[1][k][z]);
			   }
			   
			   
		   }
		   now=z;
	   }


/*
	   //int res=INF;
	   for(int i=1;i<r;i++){
		  for(int j=0;j<n;j++){
						    
			 for(int k=0;k<n;k++){
				dp[i][k]=min(dp[i][k],dp[i-1][j]+d[1][z[i-1]][j]+d[0][j][k]+d[1][k][z[i]]);
				//if(i==r-1 && res>dp[i][k]) res=dp[i][k];
			 }
			 dp[i][j]=min(dp[i][j],dp[i-1][j]+d[1][z[i-1]][z[i]]);
			 //if(i==r-1 && res>dp[i][j]) res=dp[i][j];
		  }
	   }
*/
	   printf("%d\n",*min_element(dp[r-1].begin(),dp[r-1].end()));
	    
    }
}

Measured memory_bytes: 3980
#include<stdio.h>
#include<stdlib.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

int isEmpty(){
  if(head == tail) return 1;
  else return 0;
}

int isFull(){
    if(head == (tail + 1) % LEN) return 1;
    else return 0;
}

void enqueue(P x){
  if (isFull()){
    printf("error\n");
    exit(1);
  }
  Q[tail] = x;
  if(tail == LEN) tail = 0;
  else  tail++;
}

P dequeue(){
  P x;

  if(isEmpty()){
    printf("error\n");
    exit(1);
  }

   x = Q[head];
   if(head == LEN) head = 0;
   else head++;
  return x;
}


int main(){
  int timer=0, cnt=0;
  int i,q;
  P u;

  scanf("%d %d", &n, &q);
  head = 1;
  tail = n+1;

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  while(cnt<n){
    if(Q[head].t-q>0){
      timer += q;
      Q[head].t -= q;
      enqueue(Q[head]);
    }
    else{
      timer += Q[head].t;
      printf("%s %d\n",Q[head].name,timer);
      cnt++;
    }
    dequeue();
  }


  return 0;
}



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

int main(){
  int n;
  cin >> n;
  vector<string> w(n);
  rep(i,n) cin >> w[i];
  
  bool ans=true;
  rep(i,n-1){
    if (w[i][w[i].length()-1]!=w[i+1][0]){
      ans=false;
    }
  }
  
  rep(i,n){
    for (int j=0;j<i;++j){
      if (w[i]==w[j]){
        ans=false;
      }
    }
  }
  if (ans) puts("Yes");
  else puts("No");
}

Measured memory_bytes: 256