akhauriyash/Code-Regression huggingface dataset:
// AOJ 0563: Walking Santa
// 2017.10.25 bal4u@uu
// 2018.1.2

#include <stdio.h>
#include <stdlib.h>

typedef struct { int x, y; } PP;
PP pp[100002];
int x[100002], y[100002];

int cmp(int *a, int *b) { return *a - *b; }

//#define getchar_unlocked()  getchar()
int in()
{
	int n, c;

	while ((c = getchar_unlocked()) < '0');
	n = 0;
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

long long calc(int x0, int y0, int n)
{
	int i;
	long long sum, ans, dx, dy, max;
	PP *p;

	sum = 0, max = 0, ans = 1LL << 60;
	for (p = pp, i = n; i--; p++) {
		dx = x0 - p->x, dy = y0 - p->y;
		if (dx < 0) dx = -dx;
		if (dy < 0) dy = -dy;
		dx += dy;
		sum += dx << 1;
		if (dx > max) max = dx;
	}
	if (sum - max < ans) ans = sum - max;
	return ans;
}

int main()
{
	int w, h, n, i, xpos, ypos, m;
	long long ans, a;

	w = in(), h = in(), n = in();
	for (i = 0; i < n; i++) {
		pp[i].x = x[i] = in(), pp[i].y = y[i] = in();
	}
	qsort(x, n, sizeof(int), cmp), qsort(y, n, sizeof(int), cmp);

	m = (n-1)>>1, xpos = x[m], ypos = y[m];
	ans = calc(xpos, ypos, n);
	if (!(n & 1)) {
		if (x[m] == x[m+1] && y[m] == y[m+1]);
		else if (x[m] == x[m+1]) {
			a = calc(xpos, y[m+1], n);
			if (a < ans) ans = a, ypos = y[m+1];
		} else if (y[m] == y[m+1]) {
			a = calc(x[m+1], ypos, n);
			if (a < ans) ans = a, xpos = x[m+1];
		} else {
			a = calc(x[m], y[m+1], n);
			if (a < ans) ans = a, xpos = x[m], ypos = y[m+1];
			a = calc(x[m+1], y[m], n);
			if (a < ans) ans = a, xpos = x[m+1], ypos = y[m];
			a = calc(x[m+1], y[m+1], n);
			if (a < ans) ans = a, xpos = x[m+1], ypos = y[m+1];
		}
	}
	printf("%lld\n%d %d\n", ans, xpos, ypos);
	return 0;
}



Measured memory_bytes: 3728
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(r, &n)
	fmt.Fscan(r, &m)

	ans := 0
	ans += n * (n - 1) / 2
	ans += m * (m - 1) / 2

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
#define h 131071
int data[262144][2];//値//番号
int ti[100002];
int last,now,top=1;

void update(int n){
	if(data[n*2][0]>=data[n*2+1][0]){
		data[n][0]=data[n*2][0];
		data[n][1]=data[n*2][1];
	}
	else{
		data[n][0]=data[n*2+1][0];
		data[n][1]=data[n*2+1][1];
	}
	
	if(n==1){
		ti[top]+=(now-last);
		top=data[1][1];
		last=now;
		return;
	}
	update(n/2);
}

int main(){
	
	int n,r,l;
	cin>>n>>r>>l;
	for(int i=1;i<=n;i++){
		data[h+i][1]=i;
	}
	for(int i=0;i<r;i++){
		int d,x;
		cin>>d>>now>>x;
		data[h+d][0]+=x;
		update((h+d)/2);
	}
	now=l;
	update(1);
	int sum=0,ans=0;
	for(int i=1;i<=n;i++){
		
		if(ti[i]>sum){
			sum=ti[i];
			ans=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3152
#include <stdio.h>
#define INF 100000000
 
void dijkstra();
void initializeSingleSource();
 
int n,h[100],d[100],dis[100],pi[100],G[100][100];

int main(){
  int i,j,c,u,k,v;
   
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)   G[i][j]=-1;    
  }
   
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&c,&v);
      G[u][c]=v;
    }
  }
  dijkstra();
 
  for(i=0;i<n;i++) printf("%d %d\n",i,d[i]);
 
  return 0;
}
 
void dijkstra(){
  int i,j,u,v,min;
   
  initializeSingleSource();
 
  while(1){
    min=INF;
    for(i=0;i<n;i++){
      if(h[i]!=1&&d[i]<min){
    min=d[i];
    u=i;
      }
    }
 
    if(min==INF) break;
 
    h[u]=1;
 
    for(v=0;v<n;v++){
      if(h[v]!=1&&d[u]+G[u][v]<d[v]&&G[u][v]!=-1){
    pi[v]=u;
    d[v]=G[u][v]+d[u];
      }
    }
  }
   
}
 
void initializeSingleSource(){
  int v; 
  for(v=0;v<n;v++){
    d[v]=INF;
    pi[v]=-1;
    h[v]=-1;
  }
  d[0]=0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int n,m;
int dp[110][110][2],a[110][110];

int solve(int x, int y, int c){
	if(x==n-1&&y==m-1) return a[x][y]!=c&&!c;
	int &r=dp[x][y][c];
	if(r>=0)return r;
	r=1e9;
	if(x+1<n) r=min(r,(a[x][y]!=c&&!c)+solve(x+1,y,a[x][y]));
	if(y+1<m) r=min(r,(a[x][y]!=c&&!c)+solve(x,y+1,a[x][y]));
	return r;
}

int main(){FIN;
	cin>>n>>m;
	fore(i,0,n){
		string s; cin>>s;
		fore(j,0,m) a[i][j]=s[j]=='#';
	}
	memset(dp,-1,sizeof(dp));
	int ans=solve(0,0,0);
	cout<<ans<<"\n";
}

Measured memory_bytes: 384
N,M=gets.split.map(&:to_i)
A=Array.new(N){gets.split.map(&:to_i)}

conduct_flag=Array.new(M+1,true)


ans=N

M.times do |x|

  # generate counter of each game
  counter=Array.new(M+1,0)
  A.each do |ai| # N times
    counter[ai[0]]+=1
  end

  # get max and max_by of counter
  max=0
  max_by=-1
  (M+1).times do |i|
    if counter[i]>max
      max=counter[i]
      max_by=i
    end
  end

  ans=max if ans>max
  break if x==M-1

  # remove games from each players
  conduct_flag[max_by]=false
  A.each do |ai|
    while true
      break if conduct_flag[ai[0]]
      ai.shift
    end
  end
end

p ans


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int ms = 21;
int dp[ms][(1<<ms) + ms], n;
int matrix[ms][ms];

ll M = 1e9+7;

ll solve(int id, int mask){

  if(mask + 1 == (1 <<n))
    return 1;


  int &ans = dp[id][mask];
  if(~ans)
    return ans;

  ans = 0;

  ll soma = 0;

  for(int i = 0; i < n; i++){
    if( (mask & (1 << i) ) or !matrix[id][i])
      continue;

    soma = (soma + solve(id+1, mask | (1<<i)))%M;
  }
  
  ans = soma;

  return ans;
}



int main(){
  // cin >> n;
  scanf("%d",&n);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      scanf("%d",&matrix[i][j]);
    }
  }

  memset(dp, -1, sizeof dp);
  cout<<solve(0,0);
}

Measured memory_bytes: 172288
import numpy as np
N = 10**9+7
n = int(input())
a = np.array(input().split(), np.int64)

ans = 0

po = 1
for i in range(61):
    bit = (a>>i) & 1
    s=np.count_nonzero(bit)
    ans+=s*(n-s)%N*po
    ans%=N
    po*=2
    po%=N
print(ans)


Measured memory_bytes: 62788
import itertools
import math

n=int(input())
a=list(map(int,input().split(" ")))

#n=5
#a=[6,9,4,2,11]

a1=max(a)
a.remove(a1)
a2=a1/2
b=[]
for i in a:
  b.append(abs(i-a2))

print(a1,a[b.index(min(b))])

Measured memory_bytes: 14436
# coding: utf-8

num = int(input())
line = input().split(" ")
result = []

for i in range(num):
    line[i] = int(line[i])

for i in range(num):
    if line[i] % 2 == 0:
        result.append(line[i])

count = 0
for i in range(len(result)):
    if result[i] % 3 == 0 or result[i] % 5 == 0:
        count += 1

if count == len(result):
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define mod 1000000007
int a[2000005];
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if(s[n-1]=='s')
        s+="es";
    else
        s+="s";
    cout <<s << endl;
}


Measured memory_bytes: 3628
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;
#define NIL -1
#define fi first
#define sec second
#define MAX INT_MAX
#define INF 99999999
#define ll long long
#define PI acos(-1.0)
#define MOD 1000000007
#define PLL pair<ll,ll>
#define PII pair<int,int>
#define ull unsigned long long
#define triplell pair<pair<ll,ll> , ll>
#define triple pair<pair<int,int> , int>
#define For(i,n) for(int i=0;i<(int)n;i++)
#define Forn(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define forba(i,a,b) for(int i=(int)b;i>=(int)a;i--)

int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */
    
    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;
    
    vector<int>vec(5);
    for(i=0;i<5;i++)
    {
    	cin>>vec[i];
	}
	
	int ans = INF;
	sort(vec.begin(),vec.end());
	do
	{
		int res = vec[0];
		k=vec[0];
		
		for(i=1;i<5;i++)
		{
			if(k%10==0)
			{
				res+=vec[i];
				k+=vec[i];
			}
			else
			{
				k=(k/10+1)*10;
				res=k;
				
				k+=vec[i];
				res+=vec[i];
			}
		}
		
	//	cout<<res<<" ";
		ans=min(ans,res);
	}while(next_permutation(vec.begin(),vec.end()));

	cout<<ans<<endl;
	
//	main();
    return 0;
}

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


int main(){
  int s,w;
  cin>>s>>w;
  if(w>=s){
    cout<<"unsafe"<<endl;
  }
  else {
    cout<<"safe"<<endl;
  }

}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
	

	int t = 1;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		std::vector<long long> v(n);
		for(int i = 0; i < n; ++i){
			cin >> v[i];
		}
		stack<int> maxstack, minstack;
		int f1 = 1, f2 = 0;
		long long daulat = 1000, number, stocks = 0;
		maxstack.push(v[0]), minstack.push(v[0]);
		for(int i = 0; i < n - 1; ++i){
			if(v[i] < v[i + 1] && f1){
				number = daulat/v[i];
				stocks+=number;
				daulat -= number * v[i];
				f1 = 0;
				f2 = 1;
			}
			if(v[i] > v[i + 1] && f2){
				daulat += stocks * v[i];
				stocks = 0;
				f2 = 0;
				f1 = 1;
			}
			//cout << stocks << ' ';
		}
		cout << daulat + stocks * v[n-1];
	}
	return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		if(a > b) {
			System.out.println("a > b");
		}else if(a < b) {
			System.out.println("a < b");
		}else {
			System.out.println("a == b");
		}
	}
}


Measured memory_bytes: 26320
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MX = 1e9;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

long long gcd(long long a, long long b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
    return (a * b) / gcd(a, b);
}
long long digits(long long m) {
    long long cnt = 0;
    while (m) {
        cnt++;
        m /= 10;
    }
    return cnt;
}



int main() {
    int N;
    cin >> N;
    long long ans = 0;
    for (int i = 1; i <= N; i++) {
        long long i1 = i;
        long long M = N / i;
        long long cnt = (i1 * M * (M + 1)) / 2;
        ans += cnt;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	while(cin>>n&&n)
	{
		int a[15][15]={};
		for(int i=0;i<n;i++)
		{
			int sum=0;
			for(int j=0;j<n;j++)
			{
				cin>>a[i][j];
				sum+=a[i][j];
			}
			a[i][n]=sum;
		}
		for(int j=0;j<=n;j++)
		{
			int sum=0;
			for(int i=0;i<n;i++)
			{
				sum+=a[i][j];
			}
			a[n][j]=sum;
		}
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=n;j++)
			{
				printf("%5d",a[i][j]);
			}
			printf("\n");
		}
		
	}
	/*
	int ix,*pix;
	double dx,*pdx;
	
	scanf("%d",&ix);
	scanf("%lf",&dx);
	
	pix=&ix;
	pdx=&dx;
	
	
	
	printf("ix = %d, pix = %d\n",ix,*pix);
	printf("dx = %lf, pdx = %lf\n",dx,*pdx);
	*/
}

Measured memory_bytes: 1164
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n, m, k = map(int, input().split())
    fgraph = [list() for i in range(n)]
    bgraph = [list() for i in range(n)]
    cgraph = [list() for i in range(n)]
    
    rks = [None] *n
    sys.setrecursionlimit(10**9)
    # r: どの連結成分に存在するかをメモするid
    def dfs(graph,s,r):
        if rks[s] is None:
            rks[s] = r
        for i in range(len(graph[s])):
            if rks[graph[s][i]-1] is not None:
                continue
            dfs(graph, graph[s][i]-1,r)

    for i in range(m):
        a,b = map(int, input().split())
        fgraph[a-1].append(b)
        fgraph[b-1].append(a)

    # print(fgraph)
    #print(bgraph)
    # 連結成分に対してid的なindexをつける
    c = -1
    for i in range(n):
        if rks[i] is None:
            c += 1
            dfs(fgraph, i, c)
    
    for i in range(k):
        c,d = map(int, input().split())
        if rks[c-1] == rks[d-1]:
            bgraph[d-1].append(c)
            bgraph[c-1].append(d)

    counter = Counter(rks)
    for i in range(n):
        # counter[rks[i]] 連結成分のサイズ
        # len(fgraph[i]) 友達の数
        # len(bgraph[i]) 連結成分内のブロックの数
        # 1 自分
        print(counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 66768
def solve():
    n = int(input())
    dp = [True] + [False]*(n+1)
    way = [1] + [6**i for i in range(1,9) if 6**i <= n] + [9**i for i in range(1,7) if 9**i <= n]
    loop_counter = 0
    while True:
        loop_counter += 1
        newdp = [False] * (n+1)
        for w in way:
            for i in range(w, n+1):
                if newdp[i]: continue
                if dp[i-w]: newdp[i] = True
                if newdp[n]: 
                    return loop_counter
        dp = [x for x in newdp]

print(solve())

Measured memory_bytes: 12028
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    long sum;
    foreach(i; iota(n))
    {
        if((i + 1) % 3 && (i + 1) % 5)
            sum += i + 1;
    }
    sum.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2720
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  long long ans = 0;
  REP(i,n){
    long long a;
    cin >> a;
    long long cnt = 0;
    while(true){
      if(a%2!=0) break;
      a = a/2;
      cnt++;
    }
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();
        double ans = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        System.out.println(ans);
    }
}


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

int main(){
  int K,S;  cin >> K >> S;
  int count = 0;
  for(int i = 0;i <= K;i++)
    for(int j = 0;j <= K;j++)
      if(S - i - j >= 0 and S - i - j <= K)count++;

  cout << count << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<utility>
#include<bitset>
#include<complex>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=a; i<=b; ++i)
#define FOR(i,a,b) for(int i=a; i<b; ++i)
#define MP make_pair
typedef long long LL;
typedef pair<int,int> pii;

LL Run(LL H, LL W) {
	if(W <= 1) return (1LL << 60);
	LL res = 1LL << 60;
	LL area1, area2, area3, area4, area5;
	for(LL i = 1; i < H; ++i) {
		area1 = i * W;
		area2 = (H - i) * (W / 2);
		area3 = (H - i) * W - area2;
		//printf("area1 = %lld, area2 = %lld, area3 = %lld\n", area1, area2, area3);
		res = min(res, max(area1, max(area2, area3)) - min(area1, min(area2, area3)) );
		if(H - i >= 2) {
			area2 = ((H - i) / 2) * W;
			area3 = (H - i) * W - area2;
			res = min(res, max(area1, max(area2, area3)) - min(area1, min(area2, area3)) );
		}
	}
	return res;
}

int main() {
	int H, W;
	scanf("%d%d", &H, &W);
	/*
	if(H % 3 == 0 || W % 3 == 0) {
		printf("0\n");
		return 0;
	}
	*/
	printf("%lld\n", min( Run(H,W), Run(W,H) ) );
	return 0;
}


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

int main() {
  int a,b,c;
  cin >> a >> b ;
  c = a * b;
  if(c % 2 == 0)
    cout << "Even" <<'\n';
  if(c % 2 != 0)
    cout << "Odd" <<'\n';
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoderTemplate
{
    public class App
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("{3}",args=new string[3],args[0] = Console.ReadLine(),args[1] = args[0].Count()==26?((char)(25 - args[0].Skip(1).Zip(args[0],(a,b)=>a-b).Reverse().TakeWhile(i=>i<0).Count())).ToString():"",args[0].Count()==26?((args[1][0]==0)?"-1":(string.Join("",args[0].Take(args[1][0]).Select((v,i)=>i==args[1][0]-1?args[0].Last(c=>c>args[0][args[1][0]-1]):v)))):(args[0] +(char)('a'+ args[0].OrderBy(c=>c).Where((c,i)=>c-i=='a').Count())));
        }
    }
}


Measured memory_bytes: 13396
A, B, C, D = [int(x) for x in input().split(' ')]

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

A = A - 1
a = B // C
b = B // D
c = B // (C*D // gcd(C,D))
d = A // C
e = A // D
f = A // (C*D // gcd(C,D))
print(B - (a + b - c) - (A - (d + e - f)))


Measured memory_bytes: 3060
import sys
stdin = sys.stdin
from collections import defaultdict

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n = ni()
d = defaultdict(int)
for _ in range(n):
    s = ns()
    d[s] += 1
d = sorted(d.items(), key = lambda x:x[1], reverse=True)
ki, vi = d[0]
k = [ki]
for ki, v in d[1:]:
    if v == vi:
        k.append(ki)
k.sort()
for ki in k:
    print(ki)


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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

int N;
vector<int> v;

void init()
{
	cin >> N;
	v.resize(N);
	rep(i, N) {
		cin >> v[i];
		v[i]--;
	}
}

void solve()
{
	int res = 0;
	rep(i, N) {
		if (i < v[i] && v[v[i]] == i) res++;
	}
	cout << res << endl;

}



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

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

Measured memory_bytes: 3188
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

//Longest Increasing Subsequence
int lis(const vector<int>& a){
    int n = a.size();
    vector<int> dp(n+1, INF);
    dp[1] = a[0];
    for(int i = 1; i < n; i++){
        int l = 0;
        int r = n;
        while(r - l > 1){
            int m = (r + l) / 2;
            if(dp[m] <= a[i]){
                l = m;
            }else{
                r = m;
            }
        }
        dp[l+1] = a[i];
    }
    int ans;
    for(int i = 1; i <= n; i++){
        if(dp[i] != INF){
            ans = i;
        }
    }
    return ans;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> b = a;
    reverse(ALL(b));

    cout << lis(b) << endl;

    return 0;
}


Measured memory_bytes: 3192
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, m, s;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> indeg(n, 0);
    vector<int> par(n, -1);
    queue<pair<int, int>> que;
    for (int i = 0; i < n+m-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        indeg[b]++;
        g[a].emplace_back(b);
    }
    
    for (int i = 0; i < n; i++) if (!indeg[i]) s = i;
    
    que.emplace(s, s);
    while (!que.empty()) {
        int v, p; tie(v, p) = que.front(); que.pop();
        for (auto u : g[v]) {
            if (indeg[u] == 1) { par[u] = v; que.emplace(u, v); }
            else { indeg[u]--; }
        }
    }
    
    for (auto ans : par) cout << ++ans << endl;
    
    return 0;
}

Measured memory_bytes: 10240
s = input()
K = int(input())

a = [0] * len(s)
for i in range(len(s) - 1):
  a[i] =  ((ord('z') - ord(s[i])) + 1)%26
  if a[i] == 0:
    pass
  elif K - a[i] >= 0:
    K -= a[i]
    a[i] = 0

for i in range(len(s)-1):
  print(chr((26-a[i])%26+ord('a')), end = '')

if K != 0:
  b = ord('a') + (ord(s[-1])-ord('a') + K)%26
  print( chr( b ) ) 
else:
  print(s[-1])
  


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

namespace ConsoleApplication1
{
    struct Edge
    {
        internal int u, v, cost;
    }

    class Union_Find
    {
        internal List<int> parents, rank;

        public Union_Find(int n)
        {
            parents = new List<int>();
            rank = new List<int>();

            for (int i = 0; i < n; i++)
            {
                parents.Add(i);
                rank.Add(0);
            }
        }

        public int Find(int x)
        {
            if (parents[x] == x) return x;
            else return parents[x] = Find(parents[x]);
        }

        public void Unite(int x, int y)
        {
            x = Find(x);
            y = Find(y);

            if (x == y) return;

            if (rank[x] < rank[y])
            {
                parents[x] = y;
            }
            else
            {
                parents[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }

        public bool Same(int x, int y)
        {
            return Find(x) == Find(y);
        }
    }

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

            List<Edge> es = new List<Edge>();

            for (int i = 0; i < n; i++)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);

                for (int j = 0; j < n; j++)
                {
                    if (input[j] != -1)
                    {
                        Edge temp;
                        temp.u = i;
                        temp.v = j;
                        temp.cost = input[j];
                        es.Add(temp);
                    }
                }
            }
            Console.WriteLine(Kruskal(es, n));
        }

        static bool Comp(Edge e1, Edge e2)
        {
            return e1.cost < e2.cost;
        }

        static int Kruskal(List<Edge> es, int n)
        {
            es.Sort((a, b) => a.cost - b.cost);
            Union_Find uf = new Union_Find(n);

            int res = 0;

            for (int i = 0; i < es.Count; i++)
            {
                Edge e = es[i];

                if (!uf.Same(e.u, e.v))
                {
                    uf.Unite(e.u, e.v);
                    res += e.cost;
                }
            }
            return res;
        }
    }
}

Measured memory_bytes: 9600
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		String result = "No";

		for (int i = 0; i < S.length(); i++) {
			S = S.substring(S.length() - 1) + S.substring(0, S.length() - 1);
			if (T.equals(S)) {
				result = "Yes";
				break;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 27044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

struct BD{
  ll y,m,d;
  bool operator < (const BD &a) {
    if (y != a.y) return y < a.y;
    if (m != a.m) return m < a.m;
    return d <= a.d;
  }
};
int main(){
  IOS();
  string s;
  cin >> s;
  BD now;
  now.y = 0;
  REP (i,4) now.y = now.y*10 + s[i]-'0';
  now.m = (s[5]-'0')*10 + s[6]-'0';
  now.d = (s[8]-'0')*10 + s[9]-'0';
  debug(now.y,now.m,now.d);
  BD tmp = (BD){2019,4,30};
  if (now < tmp) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	static int LCS(String s1,String s2) {
		int[][] dp = new int[s1.length()+1][s2.length()+1];
		for (int i=0;i<s1.length();i++) {
			for (int j=0;j<s2.length();j++) {
				if (s1.charAt(i)==s2.charAt(j)) {
					dp[i+1][j+1] = dp[i][j]+1;
				} else {
					dp[i+1][j+1] = Math.max(dp[i][j+1],dp[i+1][j]);
				}
			}
		}
		return dp[s1.length()][s2.length()];
	}
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		for (int i=0;i<n;i++) {
			System.out.println(LCS(scan.next(),scan.next()));
		}
	}

}

Measured memory_bytes: 64948
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  int x=0,y=0,z=0;
  rep(i,n){
    if(a[i]==2)x++;
    if(a[i]==-2)y++;
    if(a[i]==-1)z++;
  }

  //  cout<<x<<" "<<y<<" "<<z<<endl;

  if(y%2==1){
    if(z){
      cout<<x+y+1<<endl;
      rep(i,n){
	if(a[i]==2 || a[i]==-2)cout<<i+1<<endl;
	if(a[i]==-1 && z){
	  cout<<i+1<<endl;
	  z=0;
	}
      }
    }else{
	cout<<x+y-1<<endl;
	rep(i,n){
	  if(a[i]==2)cout<<i+1<<endl;
	  if(a[i]==-2 && y-1>0){
	    cout<<i+1<<endl;
	    y--;
	  }
	}

    }

  }else{
    cout<<x+y<<endl;
    rep(i,n)if(a[i]==2 || a[i]==-2)cout<<i+1<<endl;

  }

}



Measured memory_bytes: 3104
N = int(input())
cards = list(map(int, input().split()))
all_c = sum(cards)
half_c = all_c//2
sum_c = 0
ans = 2*10**14
for idx, num in enumerate(cards):
  if idx == N-1:
    break
  sum_c += num
  ans = min(ans, abs(sum_c*2-all_c))
print(ans)

Measured memory_bytes: 24816
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')
from collections import deque
def solve():
    n, q = MI()
    e = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = MI1()
        e[a].append(b)
        e[b].append(a)

    point = [0] * n
    for _ in range(q):
        p, x = MI()
        p -= 1
        point[p] += x

    d = deque([(0, point[0])])
    used = [False] * n
    used[0] = True

    while len(d) > 0:
        v, p = d.popleft()
        for nv in e[v]:
            if used[nv]: continue
            used[nv] = True
            point[nv] += p
            d.append((nv, point[nv]))

    printlist(point, " ")

if __name__ == '__main__':
    solve()


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

public class Main {

    static class Question {
        int N;

        public ArrayList<Integer> factors(int n) {
            ArrayList<Integer> f = new ArrayList<>();
            for (int x = 2; x*x <= n; x++) {
                while (n%x == 0) {
                    if (x % 2 == 0) f.add(x);
                    n /= x;
                }
            }
            if (n > 1 && n % 2 == 0) f.add(n);
            return f;
        }
        
        public int solve() {
            if (N == 1) return 1;
            
            int max = -1;
            int found = -1;
            for (int i = 2; i <= N; i += 2) {
                ArrayList<Integer> ret = factors(i);
                if (ret.size() > max) {
                    max = ret.size();
                    found = i;
                }
            }
            return found;
        }
        
        public void main(FastScanner in, PrintWriter out) {
            N = in.nextInt();
            out.println( solve() );
        }
        
        public void p(Object o) { System.out.print(o); }
        public void pl(Object o) { System.out.println(o); }
        public void arp(int[] o) { pl( Arrays.toString(o) ); }
        public void arpp(int[][] o) { 
            for (int i = 0; i < o.length; i++) {
                for (int j = 0; j < o[0].length; j++) { p( o[i][j] + " " ); } pl("");
            }
        }
    }

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Question q = new Question();
        q.main(in, out);
        out.close();
        in.close();
    }
    
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try { st = new StringTokenizer(br.readLine()); } 
                catch (IOException e) { e.printStackTrace(); }
            }
            return st.nextToken();
        }
        public void close() throws IOException { br.close(); }
    }
}


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

using namespace std;

using LL = long long;

void solver() {
    int n; cin >> n;
    vector<int>a(n);
    
    map<int,int> freq;

    LL total = 0;

    for(int&x : a) {
        cin >> x;
        freq[x]++;
        total += x;
    }

    int q; cin >> q;

    while(q--) {
        int b, c; cin >> b >> c;
        int seen = freq[b];
        
        total -= seen * 1LL * b;
        freq[b] = 0;

        total += seen *1LL * c;
        freq[c] += seen;

        cout << total << '\n';
    }
}

int main() {

    ios_base :: sync_with_stdio(0); cin.tie(NULL);

    int t = 1;
    //cin >> t;
    
    while(t--)
        solver();

    return 0;
}

Measured memory_bytes: 8240
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,d1,d2,d3,d4,d5,s=0;
  cin >> A >> B;
  for (int i=A;i<=B;i++){
    d1 = i % 10;
    d2 = i % 100 / 10;
    d3 = i % 1000 / 100;
    d4 = i % 10000 / 1000;
    d5 = i / 10000;
    if (d1 == d5 && d2 == d4){
      s += 1;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
import copy

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

B = copy.deepcopy(A)
B.sort()

#print A,B

C = [-1 for i in range(N)]
D = [-1 for i in range(N)]

n = -1
p = -1
for i in range(N):
    if n != B[i]:
        p+=1
        if (p > 0 and D[p-1] == 1): p-=1
        C[p] = B[i]
        D[p] = 1
        n = B[i]
    else:
        D[p] += 1
if D[p] == 1:
    C[p] = -1
    D[p] = -1
    p -= 1

#print C, D
#print "p=",p
p += 1

E = [-1 for i in range(p)]
F = [-1 for i in range(p)]

sum = 0
for i in range(p):
    E[i] = D[i]*(D[i]-1)/2
    sum += E[i]
    F[i] = E[i] - (D[i]-1)*(D[i]-2)/2

#print "C=",C
#print E, F, sum

def binsearch(k, s, e):
    #print k,s,e
    if s == e or s + 1 == e:
        if C[s] == k:
            return s
        elif C[e] == k:
            return e
        else:
            return -1
    elif (C[(s+e)/2] < k):
        return binsearch(k, (s+e)/2, e)
    else:
        return binsearch(k, s, (s+e)/2)

for i in range(N):
    pos = binsearch(A[i], 0, p-1)
    #print "pos = ", pos
    if pos >= 0:
        print sum - F[pos]
    else:
        print sum


Measured memory_bytes: 37408
K = int(input())
S=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(S[K-1])

Measured memory_bytes: 3060
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        int curMaxLength = 0;
        var hash = new RollingHash(s);
        for (int i = 0; i < s.Length; i++)
            for (int j = i; j < s.Length; j++)
                while (curMaxLength < j - i && j + curMaxLength < n && hash.Slice(i, curMaxLength + 1) == hash.Slice(j, curMaxLength + 1)) curMaxLength++;
        Console.WriteLine(curMaxLength);
    }
}

class RollingHash
{
    const ulong MOD1 = 998244353;
    const ulong MOD2 = 1000000007;
    const ulong POSITIVIZER1 = MOD1 << 31;
    const ulong POSITIVIZER2 = MOD2 << 31;
    static uint Base1;
    static uint Base2;
    static ulong[] powMemo1 = new ulong[500000 + 1];
    static ulong[] powMemo2 = new ulong[500000 + 1];

    static RollingHash()
    {
        Base1 = (uint)new Random().Next(129, int.MaxValue);
        powMemo1[0] = 1;
        for (int i = 1; i < powMemo1.Length; i++)
            powMemo1[i] = (powMemo1[i - 1] * Base1) % MOD1;
        Base2 = (uint)new Random().Next(129, int.MaxValue);
        powMemo2[0] = 1;
        for (int i = 1; i < powMemo2.Length; i++)
            powMemo2[i] = (powMemo2[i - 1] * Base2) % MOD2;
    }

    ulong[] hash1;
    ulong[] hash2;

    public RollingHash(string s)
    {
        hash1 = new ulong[s.Length + 1];
        for (int i = 0; i < s.Length; i++)
            hash1[i + 1] = (hash1[i] * Base1 + s[i]) % MOD1;
        hash2 = new ulong[s.Length + 1];
        for (int i = 0; i < s.Length; i++)
            hash2[i + 1] = (hash2[i] * Base2 + s[i]) % MOD2;
    }

    public ulong Slice(int begin, int length)
    {
        return 
            ((hash1[begin + length] + POSITIVIZER1 - hash1[begin] * powMemo1[length]) % MOD1) << 32 |
            ((hash2[begin + length] + POSITIVIZER2 - hash2[begin] * powMemo2[length]) % MOD2);
    }
}


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

int main(){
  int n,k;
  int s[100],b[100][100];
  bool f;

  while(1){
    cin >> n >> k;
    if(!n && !k)break;

    for(int i=0;i<k;i++)cin >> s[i];

    for(int i=0;i<n;i++){
      for(int j=0;j<k;j++)cin >> b[i][j];
    }

    f = true;
    for(int i=0;i<k;i++){
      for(int j=0;j<n;j++){
	s[i] -= b[j][i];
	if(s[i] < 0){
	  f = false;
	  break;
	}
      }
      if(!f)break;
    }
     
    if(f)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
vector<int> dp(100100,-1),graph[100100];

int ans(int curr){
    if(dp[curr] != -1){
        return dp[curr];
    }
    int ret = 0;
    for(int i : graph[curr]){
        ret = max(ret , 1+ans(i));
    }
    dp[curr] = ret;
    return ret;
}

int main()
{
    int n,m,a,b;
    cin >> n >> m;
    for(int i = 0 ; i < m ; i += 1){
        cin >> a >> b;
        graph[a].push_back(b);
    }
    int ansi=0;
    for(int i = 1 ; i <= n ; i += 1){
        ansi = max(ansi,ans(i));
    }
    cout << ansi;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
int main()
{
	fast;
	int n,m;
	cin>>n>>m;
	int i,j, even=0, odd=0;
	int s1=0, s2=0;
	for(i=1; i<= n*2; i++)
	{
		if(i%2==0) even++;
	}
	for(j=1; j<= m*2; j++)
	{
		if(j%2!=0) odd++;
	}
	s1 = s1 + ((even*(even-1))/2);
	s1 = s1 + ((odd*(odd-1))/2);

	cout << s1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>

int main(){
    int n;
    std::cout << std::setprecision(20);

    while(std::cin >> n && n){
        double sum = 0;
        std::vector<double> x;
        for(int i=0; i < n; i++){
            int temp;
            std::cin >> temp;
            x.push_back(temp);
            sum += temp;
        }
        double mean = sum/n;
        double sd = 0;
        for(int i=0; i < n; i++){
            sd += (x[i] - mean) * (x[i] - mean);
        }
        sd /= n;
        sd = std::sqrt(sd);
        std::cout << sd << std::endl;
    }
    
    
}

Measured memory_bytes: 3268
from math import gcd


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

# setwise validation
tmp = 0
for a in A:
    tmp = gcd(tmp, a)
isSetwise = (tmp == 1)

# pairwise validation
M = 10 ** 6
sieve = [0] * (M + 1)
for a in A:
    sieve[a] += 1

cnt = 0
isPairwise = True
for i in range(2, M + 1):
    isPairwise &= (sum(sieve[j] for j in range(i, M + 1, i)) <= 1)

# check
if isPairwise:
    ans = 'pairwise coprime'
elif isSetwise:
    ans = 'setwise coprime'
else:
    ans = 'not coprime'
print(ans)


Measured memory_bytes: 194652
N = int(input())
X, Y = [], []
d = l = 0
for i in range(N):
  x, y = map(int, input().split())
  X.append(x)
  Y.append(y)
  for j in range(i):
    d += ((X[i] - X[j])**2 + (Y[i] - Y[j])**2)**0.5
    l += 1
print(d / l * (N - 1))

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ll n,m;
	cin>>n>>m;
	ll mod = pow(10,9)+7;
	ll a=1,b=1;
	for(ll i=n;i>=2;i--){
		a=a*i%mod;
	}
	for(ll i=m;i>=2;i--){
		b=b*i%mod;
	}
	ll res=a*b%mod;
	if((n-m)>1||(m-n)>1){
		cout<<0<<endl;
		return 0;
	}else{
		if((n+m)%2==0){
			res*=2;
		}
	}
	cout<<res%mod<<endl;
}


Measured memory_bytes: 256
using System;
namespace B_008_53
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            new Logic_A().Start();//
      
        }

        public class Logic_A
        {
            public void Start()
            {
                var A = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine(A < 1200 ? "ABC" : "ARC");
            }
        }
    }
}

Measured memory_bytes: 13268
n = int(input())
ab = [[int(i) for i in input().split()] for j in range(n)]
ab.sort(key=lambda x: x[0])
ab.sort(key=lambda x: x[1])
now = 0
for i in range(n):
    a, b = ab[i]
    now += a
    if b < now:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 41188
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc082/tasks/abc082_a

"""
import sys
from sys import stdin
from math import ceil
from statistics import mean
input = stdin.readline


def solve(data):
    return ceil(mean(data))


def main(args):
    data = [int(x) for x in input().split()]
    ans = solve(data)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 5604
import java.math.*;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
//		int t=sc.nextInt();
//		for(int x=1;x<=t;x++){
			String s=sc.next();
			String ss=sc.next();
			boolean flag=true;
			if(s.length()>=ss.length()){
				System.out.println("No");
				return;
			}else {
				for(int i=0;i<s.length();i++){
					if(s.charAt(i)!=ss.charAt(i)){
						flag=false;
					}
//					System.out.println(i);
				}
			}
			System.out.println(flag?"Yes":"No");
//		}
	}
}

Measured memory_bytes: 35660
#include <iostream>
using namespace std;
int main(void){
    int a, b;
    char op;
    while(1){
        cin >> a >> op >> b;
        if(op=='?') break;
        else if(op=='+') cout << a+b << endl;
        else if(op=='-') cout << a-b << endl;
        else if(op=='*') cout << a*b << endl;
        else if(op=='/') cout << a/b << endl;
    }
}



Measured memory_bytes: 3084
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int C = sc.nextInt();

        int[] b = new int[M];
        int[] a = new int[M];

        for (int i =0; i<M; i++) {
            b[i] = sc.nextInt();
        }

        int result = 0;
        for (int i =0; i<N; i++) {
            int temp = 0;

            for (int j =0; j<M; j++) {
                a[j] = sc.nextInt();
                temp += a[j] * b[j];
            }
            if (temp + C > 0) {
                result ++;
            }
        }

        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 22612
n,m,x=map(int, input().split())
c = []
a = []
for i in range(n):
    t = [int(j) for j in input().split()]
    c.append(t.pop(0))
    a.append(t)

me = [x] * m
min = sum(c)+1
cost = 0

def f(me, books, ctbl, cost):
    global min 
    if len(books) == 0:
        return
    for i,b in enumerate(books):
        t = tuple(map(lambda x:x[0]-x[1], zip(me, b)))
        if len(tuple(filter(lambda x:x>0, t))) > 0:
            f(t, books[i+1:], ctbl[i+1:], cost+ctbl[i])
        else:
            if min > cost+ctbl[i]:
                min = cost+ctbl[i]
    f(me, books[1:], ctbl[1:], cost)

f(me, a, c, 0)
if sum(c) < min:
    print(-1)
else:
    print(min)


Measured memory_bytes: 10828