akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long double ld;
typedef pair<ld,ld> P;
int n;
P p[50];

bool equal(ld a,ld b){
  return a-(1e-5)<=b&&b<=a+(1e-5);
}

ld getdis(P a,P b){
  return (a.f-b.f)*(a.f-b.f)+(a.s-b.s)*(a.s-b.s);
}

P cal(){
  ld a=0,cx=0,cy=0;
  for (int i=n,u=0;i-->0;u=i) {
    ld k=p[i].f*p[u].s-p[u].f*p[i].s;
    a+=k;
    cx+=k*(p[u].f+p[i].f);
    cy+=k*(p[u].s+p[i].s);
  }
  cx/=3*a;
  cy/=3*a;
  return P(cx,cy);
}

int main(){
  bool an=1;
  cin>>n;
  for(int i=0;i<n;i++)cin>>p[i].f>>p[i].s;
  P a=cal();
  for(int i=0;i<n/2;i++){
    if(getdis(a,p[i])!=getdis(a,p[n/2+i]))an=0;
  }
  double x=a.f,y=a.s;
  if(!an||n%2)cout<<"NA"<<endl;
  else printf("%.8f %.8f\n",x,y);
  return 0;
}

Measured memory_bytes: 3264
import java.util.Scanner;

public class Main {

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

	    int a=gi();
	    String o= gs();
	    int b=gi();

	    if(o.equals("+")) {
        System.out.print(a+b);
	    }else {
	    	System.out.print(a-b);
	    }
        
	   
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 35688
a, b, c, d = map(int, input())
if a + b + c + d == 7: print('{}+{}+{}+{}=7'.format(a, b, c, d))
elif a + b + c - d== 7: print('{}+{}+{}-{}=7'.format(a, b, c, d))
elif a + b - c + d == 7: print('{}+{}-{}+{}=7'.format(a, b, c, d))
elif a + b - c - d == 7: print('{}+{}-{}-{}=7'.format(a, b, c, d))
elif a - b + c + d == 7: print('{}-{}+{}+{}=7'.format(a, b, c, d))
elif a - b + c - d == 7: print('{}-{}+{}-{}=7'.format(a, b, c, d))
elif a - b - c + d == 7: print('{}-{}-{}+{}=7'.format(a, b, c, d))
elif a - b - c - d == 7: print('{}-{}-{}-{}=7'.format(a, b, c, d))


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

int N;
vector<pair<int,int>> V(200200);

main()
{
        cin>>N;
        for(int i=0;i<N-1;i++)
        {
                int a; cin>>a;
                V[a-1].second++;
        }
        for(int i=0;i<N;i++)cout<<V[i].second<<endl;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(S) cout<<(S)<<endl;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define beginend(v) v.begin(),v.end()
#define Foreach(item,collection) for(auto item : collection)

using pii=pair<int,int>;
using vb=vector<bool>;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vvc=vector<vector<char>>;
using ti3=tuple<int,int,int>;
using ulong=unsigned long;
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
#define OCB(c) (c&1)|(c&2)<<2|(c&4)<<4|(c&8)<<6|(c&16)<<8|(c&32)<<10|(c&64)<<12|(c&128)<<14

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

    set<int> st;

    rep(i,k) if(a+i<=b){
        st.insert(a+i);
    }
    rep(i,k) if(b-k+i+1>=a){
        st.insert(b-k+i+1);
    }

    for(auto i:st) out(i)
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		List<Integer> list = new LinkedList<>();
		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			b--;
			list.add(b);
		}
		
		List<Integer> ansList = new ArrayList<>();
		outer:
		for (int i = 0; i < n; i++) {
			for (int j = list.size() - 1; j >= 0; j--) {
				int num = list.get(j);
				if (j == num) {
					list.remove(j);
					ansList.add(num);
					continue outer;
				}
			}
			break;
		}
		
		if (list.isEmpty()) {
			Collections.reverse(ansList);
			for (int num : ansList) System.out.println(num + 1);
		} else {
			System.out.println(-1);
		}
		
		sc.close();
	}
}



Measured memory_bytes: 27452
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)

	var e = make([]int, n)

	for x := 0; x < n; x++ {
		fmt.Fscan(r, &e[x])
	}

	a, c := bubbleSort(e, n)
	fmt.Printf("%v\n%d\n", strings.Trim(fmt.Sprint(a), "[]"), c)
}

func bubbleSort(e []int, n int) ([]int, int) {
	flag := true
	c := 0
	for flag {
		flag = false
		for j := n - 1; j > 0; j-- {
			if e[j] < e[j-1] {
				tmp := e[j]
				e[j] = e[j-1]
				e[j-1] = tmp
				flag = true
				c++
			}
		}
	}
	return e, c
}



Measured memory_bytes: 1236
A, B, K = (int(i) for i in input().split())

ans_list=[]

maximum=max(A,B)

for num in range(1, maximum+1, 1):
    if((A%num == 0)and (B%num == 0)):
        ans_list.append(num)

print(ans_list[::-1][K-1])


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline


def distance(X1, X2):
    r = 0
    for i in range(len(X1)):
        r += (X1[i] - X2[i]) ** 2
    return r ** 0.5


def main():
    N, D = map(int, input().split())
    X = [None for i in range(N)]

    for i in range(N):
        X[i] = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            r = distance(X[i], X[j])
            if r.is_integer():
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
string t,s[100005];
long long sum,ans=0;
int n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t;
		sort(t.begin(),t.end());
		s[i]=t;
	}
	sort(s+1,s+n+1);
	for(int i=1;i<n;i++){
		sum=0;
		for(int j=i+1;j<=n;j++){
			if(s[i]==s[j]){
				i++;
				sum++;
			}
			else break;
		}
		ans+=(sum*(sum+1)/2);
	}
	cout<<ans;
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 5760
import sys
sys.setrecursionlimit(10000)

x,y = map(int,input().split())

if y == 1:
    print(1)
    exit()

if y == x:
    print(1)
    exit()



asn = 0
def dfs(x,y,n):
    
    n += 1
    ans = x*2**n
    if ans > y:
        return n
    else:
        return dfs(x,y,n)

a = dfs(x,y,1)

print(a)

Measured memory_bytes: 38384
#include <iostream>
using namespace std;
int main() {
    int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
    a--; b--; c--; d--;
    string s; cin >> s;
    for (int i = a; i < c; i++)
        if (s[i+1] == '#' && s[i] == '#') { cout << "No\n"; return 0; }
    for (int i = b; i < d; i++)
        if (s[i+1] == '#' && s[i] == '#') { cout << "No\n"; return 0; }
    if (c < d) { cout << "Yes\n"; return 0; }
    
    for (int i = b; i <= d; i++)
        if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.')
            { cout << "Yes\n"; return 0; }
    cout << "No\n";
}


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

int n;
bool first;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int a; scanf("%d", &a);
        if (a % 2) first = true;
    }
    if (first) printf("first\n");
    else printf("second\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	//input
	int n, k;
	cin>>n;
	cin>>k;
	int num;
	num=1;
	for(int i=0;i<n;i++){
		if(num*2<num+k){
			num=num*2;
		}else{
			num=num+k;
		}
	}
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {
	int N;
	scanf("%d", &N);

	ll ans = 1;

	for (int i = 1; i <= N; i++) {
		ans *= i;
		ans %= c_div;
	}

	printf("%lld", ans);





}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;



signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int l=1,r=1e10;
    int mn=1e10;
    while (l<=r)
    {
        int mid=l+(r-l)/2;
        int temp=0;
        for(int i=0;i<n;i++)
            temp+=(a[i]-1)/mid;
        if(temp>k)
        {
            l=mid+1;
        }
        else
        {
            mn=min(mn,mid);
            r=mid-1;
        }
        
    }
    cout<<mn;

    

}


Measured memory_bytes: 5200
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
const long long mod = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>x(n), y(n), h(n);
	rep(i, n) {
		cin >> x[i] >> y[i] >> h[i];
	}
	rep(i, 101) {
		rep(j, 101) {
			int cnt = 0;
			rep(k, n) {
				if (h[k]) {
					cnt = h[k] + abs(i - x[k]) + abs(j - y[k]);
					break;
				}
			}
			rep(k, n) {
				if (h[k] != max((ll)0, cnt - abs(i - x[k]) - abs(j - y[k]))) {
					goto a;
				}
			}
			cout << i << " " << j << " " << cnt << endl;
		a:;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long L,R,d,count;
  cin >> L >> R >> d;
  count = 0;
 
  for (long i = L; i < R+1; i++) {
    if (i % d == 0){
        count += 1;
    }
  }
     
    cout << count <<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  
  bool f=false;
  for(int i=1;i<=b;i++){
    
    if(a*i%b==c){
      f=true;
      break;
    }
  }
  if(f)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
# E - Bomber
H,W,M = map(int,input().split())
bomb = set()
height = dict()
width = dict()
for i in range(M):
    h,w = map(int,input().split())
    bomb.add((h,w))
    if h in height:
        height[h] += 1
    else:
        height[h] = 1
    if w in width:
        width[w] += 1
    else:
        width[w] = 1
hei = dict()
wi = dict()
for h in height:
    if height[h] in hei:
        hei[height[h]].append(h)
    else:
        hei[height[h]] = [h]
for w in width:
    if width[w] in wi:
        wi[width[w]].append(w)
    else:
        wi[width[w]] = [w]
max_h = max(hei)
max_w = max(wi)
tmp = 1
for h in hei[max_h]:
    for w in wi[max_w]:
        if (h,w) not in bomb:
            tmp = 0
            break
print(max_h+max_w-tmp)

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

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

int n;

void solve(vector <int> &v, bool flip = false){
  int mod[2] = {0, 0};
  REP(i, n)
    mod[ v[i] % 2 ] ++;

  if(mod[0] % 2){
    cout << (flip ? "Second" : "First");
    return;
  }
  if(mod[0] % 2 == 0 && mod[1] >= 2){
    cout << (flip ? "First" : "Second");
    return;
  }
  int gcd = 0;

  REP(i, sz(v)){
    if(v[i] % 2){
      v[i] --;
      if(v[i] == 0){
        cout << (flip ? "First" : "Second");
        return;
      }
      gcd = __gcd(gcd, v[i]);
    }
    else
      gcd = __gcd(gcd, v[i]);
  }
  REP(i, sz(v))
    v[i] /= gcd;

  solve(v, !flip);
}

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

  vector <int> v;
  cin >> n;
  v.resize(n);

  REP(i, n)
    cin >> v[i];
  solve(v);
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>
using namespace std;
vector<int> dp(10001,-100000);
int match[10]={0,2,5,5,4,5,6,3,7,6};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<int>a(m);
  for(int i=0;i<m;i++)
  {
    cin>>a[i];
  }
  sort(a.begin(),a.end(),[](int a,int b){return match[a]<match[b];});
  dp[0]=0;
  for(int i=1;i<n+1;i++)
  {
    for(int ai:a)
    {
      if(i-match[ai]<0)break;
      dp[i]=max(dp[i-match[ai]]+1,dp[i]);
    }
  }
  sort(a.begin(), a.end(), greater<int>());
  int cnt=n;
  for(int i=0;i<dp[n];i++)
  {
    for(int ai:a)
    {
      if(cnt-match[ai]<0)continue;
      if(dp[cnt-match[ai]]==dp[cnt]-1)
      {
        cout<<ai;
        cnt-=match[ai];
        break;
      }
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x;
	cin>>x;
	string s;
	cin>>s;
	int R=0;
	for(int i=0;i<x;i++){
		if(s[i]=='R')R++;
	}int ans=0;
	for(int i=0;i<R;i++){
		if(s[i]=='W')ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3720
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int dp[5001][5001];
typedef pair<int, int>pii;
int main()
{
	int num;
	scanf("%d", &num);
	vector<pii>v;
	for (int i = 0; i < num; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		v.push_back(make_pair(za + zb, zb));
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	for (int i = 0; i <= num; i++)for (int j = 0; j <= num; j++)dp[i][j] = -1;
	dp[0][0] = 2100000000;
	for (int i = 0; i < num; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			if (dp[i][j] >= 0)
			{
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], min(dp[i][j], v[i].first) - v[i].second);
			}
		}
	}
	int maxi = 0;
	for (int i = 0; i <= num; i++)if (dp[num][i] >= 0)maxi = max(maxi, i);
	printf("%d\n", maxi);
}

Measured memory_bytes: 98176
import kotlin.math.absoluteValue

private const val MOD = 1_000_000_007

fun main() {
    val (n, k) = nextIntList()
    val nums = nextLongList().groupBy { it >= 0 }.mapValues { (_, value) ->
        value.sortedByDescending { it.absoluteValue }
    }
    val positives = nums.getOrDefault(true, emptyList())
    val negatives = nums.getOrDefault(false, emptyList())
    var posIndex = 0
    var negIndex = 0
    val res = mutableListOf<Long>()
    when {
        n == k -> {
            res.addAll(positives)
            res.addAll(negatives)
        }
        positives.isEmpty() && k % 2 == 1 -> res.addAll(negatives.sortedDescending().take(k))
        else -> while (res.size < k) {
            when {
                res.size == k - 1 -> {
                    res.add(positives[posIndex])
                    posIndex++
                }
                negIndex >= negatives.lastIndex -> {
                    res.add(positives[posIndex])
                    posIndex++
                }
                posIndex >= positives.lastIndex -> {
                    res.add(negatives[negIndex])
                    res.add(negatives[negIndex + 1])
                    negIndex += 2
                }
                positives[posIndex] * positives[posIndex + 1] > negatives[negIndex] * negatives[negIndex + 1] -> {
                    res.add(positives[posIndex])
                    posIndex++
                }
                else -> {
                    res.add(negatives[negIndex])
                    res.add(negatives[negIndex + 1])
                    negIndex += 2
                }
            }
        }
    }
    println(res.stream().map { it.plus(MOD).rem(MOD) }.reduce { acc, l -> acc.times(l).rem(MOD) }.get())
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}


Measured memory_bytes: 78676
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N,P;cin>>N>>P;
  string s;cin>>s;
  if(P==2){
  int64_t ans=0;
    for(int64_t i=N-1;0<=i;i--){
    int64_t b=s.at(i)-'0';
      if(b%2==0)ans+=i+1;
    }
    cout<<ans<<endl;
  }else if(P==5){
  int64_t ans=0;
    for(int64_t i=N-1;0<=i;i--){
    int64_t b=s.at(i)-'0';
      if(b==0 || b==5)ans+=i+1;
    }cout<<ans<<endl;
   }else{
  map<int64_t,int64_t>M;M[0]=1;
    int64_t a=1; int64_t c=0;
    for(int64_t i=N-1;0<=i;i--){
    int64_t b=s.at(i)-'0';
      c+=b*a;c%=P;
      if(!M.count(c))M[c]=1;
      else
        M[c]++;
      a=(a*10)%P;
    }int64_t ans=0;
    for(auto p:M){
    int64_t v=p.second;
      ans+=(v*(v-1))/2;
    }cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 4140
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int n,b;
int a[100010];
int x(int x){
if(x>=0)
return x;
return -x;}
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=0;i<=n+1;i++)
b+=x(a[i]-a[i-1]);
for(int i=1;i<=n;i++){
if(a[i]>a[i-1]&&a[i]>a[i+1])
cout<<b-(a[i]-max(a[i-1],a[i+1]))*2<<endl;
else
if(a[i]<a[i-1]&&a[i]<a[i+1])
cout<<b-(min(a[i-1],a[i+1])-a[i])*2<<endl;
else
cout<<b<<endl;}
system("pause");
return 0;
}

Measured memory_bytes: 1792
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

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

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

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N, M, C := sc.nextInt(), sc.nextInt(), sc.nextInt()
	B := sc.nextIntSlice(M)
	A := make([][]int, N)
	for i := 0; i < N; i++ {
		A[i] = sc.nextIntSlice(M)
	}
	ans := 0
	for i := 0; i < N; i++ {
		sum := 0
		for j := 0; j < M; j++ {
			sum += A[i][j] * B[j]
		}
		if sum+C > 0 {
			ans++
		}
	}
	fmt.Println(ans)
}


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

int main() {
	int N;
	cin >> N;
	map<int,int> mp;
	for (int n = 0; n <N; ++n) {
		int num;
		cin >> num;
		mp[num] = n + 1;
	}
	map<int, int >::iterator it;
	for (it = mp.begin(); it != mp.end(); it++){
		if (mp.begin() != it) {
			cout << " ";
		}
		cout << (*it).second;
	}
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  int N = s.size();
  
  int a_i, z_i;
  
  for (int i = 0; i < N; i++) {
    if (s[i] == 'A') {
      a_i = i;
      break;
    }
  }

  for (int i = 0; i < N; i++) {
    if (s[N-i-1] == 'Z') {
      z_i = N-i-1;
      break;
    }
  }

  cout << z_i - a_i +1 << endl;
  
}



Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <vector>
#define rep(i,n) for (int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main()
{
	ll x;
	cin >> x;
	for (int i=1; i<=1000; i++) {
		for (int j=-1000; j<=1000; j++) {
			ll a5 = 1;
			ll b5 = 1;
			rep(m, 5) {
				a5 *= i;
				b5 *= j;
			} 
			if (a5 - b5 == x) {
				printf("%d %d\n", i, j);
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        cin.ignore();
        map<string,int> cnt;
        string line, word;
        for (int i=0; i<n; ++i) {
            getline(cin, line);
            stringstream ss(line);
            while (ss >> word) {
                ++ cnt[word];
            }
        }
        char initial;
        cin >> initial;
        vector<pair<int,string> > v;
        map<string,int>::iterator it = cnt.begin();
        for (; it!=cnt.end(); ++it) {
            if (it->first[0] == initial) {
                v.push_back(make_pair(-it->second, it->first));
            }
        }
        sort(v.begin(), v.end());
        if (v.empty()) {
            cout << "NA" << endl;
        } else {
            for (int i=0; i<5 && i<(int)v.size(); ++i) {
                cout << (i==0 ? "" : " ") << v[i].second;
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
int N, A, B, C, D;
string S;

bool check() {
    bool ret = false;
    for(int i=B-1; i+2<=D+1; ++i) {
        if(i + 2 == N) continue;
        if(S.substr(i, 3) == "...") ret = true; 
    }
    return ret;
}

bool walk(int p) {
    bool ret = true;
    if(p == 0) { // A -> C
        for(int i=A; i+1<=C; ++i) {
            if(S.substr(i, 2) == "##") ret = false; 
        }
    } else {  // B -> D
        for(int i=B; i+1<=D; ++i) {
            if(S.substr(i, 2) == "##") ret = false; 
        }
    }
    return ret;
}

int main() {
    cin >> N >> A >> B >> C >> D;
    --A; --B; --C; --D;
    cin >> S;

    bool yes = true;
    if(C < D) {
        yes &= walk(1);
        yes &= walk(0);
    } else {
        yes &= check();
        yes &= walk(0);
        yes &= walk(1);
    }
    if(yes) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
# ABC 087: B – Coins
a, b, c, x = [int(input()) for _ in range(4)]
comb = 0

for i in range(0, a + 1):
    for j in range(0, b + 1):
        for k in range(0, c + 1):
            comb = comb + 1 if 500 * i + 100 * j + 50 * k == x else comb

print(comb)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int N;
    scanf("%d", &N);
    vector<int> H(N);
    for (int i = 0; i < N; ++i) scanf("%d", &H[i]);
    int index = 0;
    int ans = 0;
    int cnt = 0;
    while (index < N - 1)
    {
        if (H[index] >= H[index + 1])
        {
            ++cnt;
        }
        else
        {
            ans = (std::max)(ans, cnt);
            cnt = 0;
        }
        
        if (index + 1 >= N - 1)
        {
            ans = (std::max)(ans, cnt);
            break;
        }
        ++index;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:


const int inf =  1 << 21;
const int limit = 100010;
int ary[limit];
bool reset[limit];


int main(void){
	int n, m;
	cin >> n >> m;
	
	rep(i,m){
		int p;
		cin >> p;
		reset[p - 1] = true;
	}

	int val = inf;
	
	rep(i, n) {
		if(reset[i]) val = 1;
		ary[i] = val;
		val++; 
	}

	sort(ary, ary + n);

	int q;
	cin >> q;
	rep(loop, q){
		int l;
		cin >> l;

		int ng = 0, ok = 2 * inf;
		while(ok - ng > 1){
			const int mid = (ok + ng) / 2;
			const int val = n - (upper_bound(ary, ary + n, mid) - ary);
			if(val <= l) 
				ok = mid;
			else 
				ng = mid;
		}

		if(n < ok)
			cout << -1 << endl;
		else 
			cout << ok << endl;
	}

	return 0;
}


Measured memory_bytes: 3616
s = input()
if s.count('R') >= 1:
    if s[1] == 'S':
        print(1)
    elif s[0] == 'R' and s[1] == 'R' and s[2] == 'S':
        print(2)
    elif s[1] == 'R' and s[2] == 'R' and s[0] == 'S':
        print(2)
    elif s.count('R') == 3:
        print(3)
    elif s[1] == 'R' and s[0] == 'S' and s[2] == 'S':
        print(1)
else:
    print(0)

Measured memory_bytes: 9052
A = [[],[],[]]
for i in range(3):
    A[i] = list(map(int, input().split()))

N = int(input())
B = [0]*N
for i in range(N):
    B[i] = int(input())

for i in range(3):
    for j in range(3):
        if A[i][j] in B:
            A[i][j] = -1

flag = False
for i in range(3):
    if A[i][0] == -1 and A[i][1] == -1 and A[i][2] == -1:
        flag = True
        break
    if A[0][i] == -1 and A[1][i] == -1 and A[2][i] == -1:
        flag = True
        break

if flag == False:
    if A[0][0] == -1 and A[1][1] == -1 and A[2][2] == -1:
        flag = True
    elif A[0][2] == -1 and A[1][1] == -1 and A[2][0] == -1:
        flag = True

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int a, b, c, t;
	char c1, c2, ct;
	a = 1;
	b = c = t =0;
	
	while (scanf("%c,%c", &c1, &c2) != EOF){
		if (c1 > c2){
			ct = c1;
			c1 = c2;
			c2 = ct;
		}
		
		if (c1 == 'A' && c2 == 'B'){
			t = a;
			a = b;
			b = t;
		}
		else if (c1 == 'A' && c2 == 'C'){
			t = a;
			a = c;
			c = t;
		}
		else if (c1 == 'B' && c2 == 'C'){
			t = b;
			b = c;
			c = t;
		}
	}
	b *= 10;
	c *= 100;
	
	t = a + b + c;
	
	switch (t){
		case 1:
			printf("A\n");
			break;
		case 10:
			printf("B\n");
			break;
		case 100:
			printf("C\n");
			break;
	}
	
	return 0;
}

Measured memory_bytes: 524
import java.util.Scanner;

//internous_atcoder_001 at 2018/02/15

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

	private void solveA081() {
		Scanner sc = new Scanner(System.in);
		char N[] = sc.nextLine().toCharArray();
		int cnt = 0;
		for (char c : N) cnt += c - '0';
		System.out.println(cnt);
	}

	private void solveA065() {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (B - A <= 0) {
			System.out.println("delicious");
		} else if (X < B - A) {
			System.out.println("dangerous");
		} else {
			System.out.println("safe");
		}
	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveD() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveE() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveF() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

}

Measured memory_bytes: 22868
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

const int INF = 1234567890;
typedef pair<int, pair<int, int> > data;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int main() {
  int w, h, n;
  cin >> w >> h;
  vector<string> mp(h);
  rep (i, h) cin >> mp[i];
  cin >> n;
  vector<vector<int> > open(h);
  rep (i, h) rep (j, w) {
    if (mp[i][j] == '#') open[i].push_back(INF);
    else open[i].push_back(0);
  }
  rep (i, n) {
    int x, y;
    cin >> x >> y;
    open[y][x] = i + 1;
  }
  vector<vector<int> > dis(h);
  rep (i, h) rep (j, w) dis[i].push_back(INF);
  priority_queue<data, vector<data>, greater<data> > que;
  que.push(make_pair(0, make_pair(0, 0)));
  while (!que.empty()) {
    data now = que.top();
    que.pop();
    if (dis[now.second.first][now.second.second] <= now.first) continue;
    dis[now.second.first][now.second.second] = now.first;
    //cout << now.second.first << " " << now.second.second << " " << now.first << endl;
    rep (i, 4) {
      data next = now;
      next.second.first += dy[i];
      next.second.second += dx[i];
      if (next.second.first < 0 || h <= next.second.first) continue;
      if (next.second.second < 0 || w <= next.second.second) continue;
      next.first = max(next.first, open[next.second.first][next.second.second]);
      que.push(next);
    }
  }
  int goalX, goalY;
  rep (i, h) rep (j, w) if (mp[i][j] == 't') {
    goalY = i;
    goalX = j;
  }
  if (dis[goalY][goalX] == INF) cout << -1 << endl;
  else cout << dis[goalY][goalX] << endl;
  return 0;
}

Measured memory_bytes: 21732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lean {
    class Program {
        static void Main() {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            double result = 0;
            for(int i = 1; i < 4; i++) {
                result += Math.Pow(a[0], i);
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 28696
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, K;
long long P[1 << 18];
long long C[1 << 18];

long long solve(int pos) {
	vector<long long> vec; int cx = pos;
	while (true) {
		vec.push_back(C[cx]);
		cx = P[cx];
		if (cx == pos) break;
	}

	long long sum = 0;
	for (int i = 0; i < vec.size(); i++) sum += vec[i];

	long long maxn = -(1LL << 60), ret = 0;
	for (int i = 0; i < vec.size(); i++) {
		if (i + 1 > K) continue;
		ret += vec[i];
		if (sum < 0) maxn = max(maxn, ret);
		else {
			long long rem = (K - (i + 1)) / (long long)vec.size();
			maxn = max(maxn, rem * sum + ret);
		}
	}
	return maxn;
}

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> P[i];
	for (int i = 1; i <= N; i++) cin >> C[i];

	long long Answer = -(1LL << 60);
	for (int i = 1; i <= N; i++) Answer = max(Answer, solve(i));
	cout << Answer << endl;
	return 0;
}

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

int main(){
  int n,a[10000000],ans=0,v=0,s=0;
  cin >> n;
  FOR(i,n){
    cin >> a[i];
  }
  sort(a,a+n);
  FOR(i,n){
    if(v==a[i]){
      if(s%2==0){
        ans-=2;
      }
      s++;
    }else{
      s=0;
    }
    v=a[i];
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
import fractions
n,m=map(int,input().split())
s=input()
t=input()
b=0
for i in range(n):
    if (i*m)%n==0 and (i*m)//n<m:
        if not t[(i*m)//n]==s[i]:
            b=1

if b:
    print(-1)
else:
    print(n*m//fractions.gcd(n,m))

Measured memory_bytes: 65644
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;

int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    
    long long int sum=0;
    if(2*c<a && 2*c<b)sum+=2*c*max(x,y);
    else if(a+b<2*c)sum+=a*x+b*y;
    else{
        sum+=2*c*min(x,y);
        if(x>y)sum+=min(a*(x-y),2*c*(x-y));
        else sum+=min(b*(y-x),2*c*(y-x));
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a, b, c, temp;
	scanf("%d %d %d",&a, &b, &c);

	if (b<a){
		temp = b;
		b = a;
		a = temp;
	}
	if (c<b){
		temp = c;
		c = b;
		b = temp;
	}
	if (b<a){
		temp = b;
		b = a;
		a = temp;
	}

	printf("%d %d %d\n",a ,b ,c);
	
	return 0;
}

Measured memory_bytes: 1024
#coding:utf-8
#1_5_C
import math

def koch(n, p1x, p1y, p2x, p2y):
    if n == 0:
        return

    sx = (2*p1x + 1*p2x)/3
    sy = (2*p1y + 1*p2y)/3
    tx = (1*p1x + 2*p2x)/3
    ty = (1*p1y + 2*p2y)/3
    theta = math.pi/3
    ux = math.cos(theta)*(tx-sx) - math.sin(theta)*(ty-sy) + sx
    uy = math.sin(theta)*(tx-sx) + math.cos(theta)*(ty-sy) + sy

    koch(n-1, p1x, p1y, sx, sy)
    print("{:.5f} {:.5f}".format(sx, sy))
    koch(n-1, sx, sy, ux, uy)
    print("{:.5f} {:.5f}".format(ux, uy))
    koch(n-1, ux, uy, tx, ty)
    print("{:.5f} {:.5f}".format(tx, ty))
    koch(n-1, tx, ty, p2x, p2y)

n = int(input())
p1x, p1y = 0.0, 0.0
p2x, p2y = 100.0, 0.0
print("{:.5f} {:.5f}".format(p1x, p1y))
koch(n, p1x, p1y, p2x, p2y)
print("{:.5f} {:.5f}".format(p2x, p2y))

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
std::string s[10005];
int main() {
	std::cin >> n;

	for (int i = 0; i < n; ++i)
		std::cin >> s[i];

	int ab = 0, a = 0, b = 0, ba = 0;
	for (int i = 0; i < n; ++i) {
		int aa = 0, bb = 0;
		auto ssize = s[i].size();

		for (int j = 1; j < ssize; ++j) {
			if (s[i][j - 1] == 'A' && s[i][j] == 'B')
				++ab;
		}

		if (s[i][0] == 'B' && s[i][ssize - 1] == 'A')
			++ba;
		else if (s[i][0] == 'B')
			++b;
		else if (s[i][ssize - 1] == 'A')
			++a;
	}

	auto ans = ab + std::min(a, b);
	if (a > 0 || b > 0)
		ans += ba;
	else if (ba > 1)
		ans += ba - 1;

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


Measured memory_bytes: 768
A_len, B_len, K = map(int, input().split(' '))
#print("Aは{0}冊. Bは{1}冊. 上限{2}分".format(A_len, B_len, K))

A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
#print(A, B)

# A,Bの累積和の配列を出して、A_acc,B_accの要素番地が最大となるような組み合わせを出す

A_acc = []
for idx_A in range(A_len): 
  if(idx_A == 0):
    A_acc.append(A[0])
  else:
    A_acc.append(A_acc[idx_A - 1] + A[idx_A])
A_acc.insert(0, 0)
    
B_acc = []
for idx_B in range(B_len):
  if(idx_B == 0):
    B_acc.append(B[0])
  else:
    B_acc.append(B_acc[idx_B - 1] + B[idx_B])
B_acc.insert(0, 0)

#print(A_acc, B_acc)

max_num = 0
left_time = K
b_num = B_len
for a_num in range(A_len + 1):
  left_time = K - A_acc[a_num]
  #print("Aから{0}冊読んだ場合はそもそも残り{1}分".format(a_num, left_time))
  if(left_time < 0):
    break
  
  while(left_time - B_acc[b_num] < 0):
    #print("Bから{0}冊読んでる場合,残り時間{1}".format(b_num, left_time - B_acc[b_num]))
    
    b_num -= 1
    
  #print("結果,A棚から{0}冊、B棚から{1}冊で合計{2}冊で経過時間{3}"
  #      .format(a_num, b_num, a_num + b_num, A_acc[a_num] + B_acc[b_num]))
  max_num = max(max_num, (a_num + b_num))
  #print("現在max{0}".format(max_num))
  
print(max_num)
    


Measured memory_bytes: 47288
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#define rep(i,N) for(int i=0; i<N;i++)
using namespace std;

int main(){
    long int N;
    long int ans=1;
    string S;
    cin >>N;
    cin >>S;
    char interm=S[0];
    for(int i=1;i<S.size();i++){
        if(S[i]==interm){
            continue;
        }else{
            ans++;
        }
        interm=S[i];
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 3780
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		System.out.println(Math.max(A, B) <= 8 ? "Yay!" : ":(");
	}
}

Measured memory_bytes: 22612
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 c = sc.nextInt();

      if(a+b>=c){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }



  }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int d[3];
	while (cin >> d[0] >> d[1] >> d[2], d[0] | d[1] | d[2] ){
		vector<int> dx(3);
		REP(i, 3){
			dx[i] = d[i] * d[i] + d[(i + 1) % 3] * d[(i + 1) % 3];
		}
		SORT(dx);
		int n;
		cin >> n;
		vector<int> s(n);
		REP(i, n){
			cin >> s[i];
		}
		REP(i, n){
			if (dx[0] < (s[i] * 2)*(s[i] * 2))
				cout << "OK"<<endl;
			else
				cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 3008
#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; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
    int n,m;
    
    
   cin >> n >> m;
    
    int res = (n*(n-1))/2;
    res+=(m*(m-1))/2;
    cout << res;
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 256
// AFTER CONTEST, WIP

#include <bits/stdc++.h>
using namespace std;

// Utility
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
template<typename T> struct is_container {
template<typename C> static char test(typename C::const_iterator*); template<typename> static int test(...);
static bool const value = sizeof(test<T>(nullptr)) == sizeof(char) && !std::is_same<std::string, T>::value;
};
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
istream& operator>>(istream& i, T& x) { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#define DD(X) std::cout << #X ": " << (X) << std::endl << std::flush
#define DD2(X) std::cout << #X ":" << std::endl; for (auto x : (X)) { std::cout << x << std::endl << std::flush; }
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
ostream& operator<<(ostream& o, const T& x) { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Main
void mainCase() {
  ll n, m; // <= 10^5
  cin >> n >> m;
  vector<ll> ls(n, 0); // <= 10^9
  cin >> ls;
  vector<array<int, 2>> edges(m, {0, 0});
  cin >> edges;
  for (auto& [x, y] : edges) { x--; y--; }

  vector<ll> maxi(n, -1);
  for (auto [x, y] : edges) {
    maxi[x] = max(maxi[x], ls[y]);
    maxi[y] = max(maxi[y], ls[x]);
  }

  ll res = 0;
  FOR(i, 0, n) {
    res += ((maxi[i] == -1) || ls[i] > maxi[i]);
  }
  cout << res << endl;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  // [ Single case ]
  mainCase();
  return 0;
  // [ Multiple cases ]
  // int t;
  // cin >> t;
  // FOR(i, 0, t) { mainCase(); }
  // return 0;
}

/*
python misc/run.py atcoder/abc166/c/main.cpp --check

%%%% begin
6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6
%%%%
3
%%%% end
*/


Measured memory_bytes: 5572
n,l=map(int,input().split())
total=0
a=[]
for i in range(n):
    a.append(i+l)
total=sum(a)
ans=1e9
for i in range(n):
    t=total-a[i]
    if abs(total-t)<abs(total-ans):
        ans=t
print(ans)

Measured memory_bytes: 3060
#! /usr/bin/python
# -*- coding:utf-8 -*-
N, W = map(int, input().split())
dp = [0]*(W+1)
max_w = 0
for i in range(N):
    v, w, m = map(int, input().split())
    n = 1
    while m > 0 :
        m -= n
        _v, _w = v*n, w*n
        if max_w + _w > W:
            max_w = W
        else:
            max_w = max_w + _w
        for k in range(max_w, _w-1, -1):
            if dp[k] < dp[k-_w] + _v:
                dp[k] = dp[k-_w] + _v
        if n*2>m:
            n = m
        else:
            n = 2*n

print(max(dp))




Measured memory_bytes: 5924
#include<iostream>
#define ll long long
using namespace std;
int main(){
        ll n,k;
        cin>>n>>k;
        ll a[n],count=0;
        for(ll i=0;i<n;i++){
            cin>>a[i];
            if(a[i]>=k) count++;
        }
        cout<<count<<endl;
}


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


Measured memory_bytes: 2124
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	ll n;
	cin >> n;
	ll m=n, deg=0;
	while(m>0){
		deg+=(m%10);
		m/=10;
	}
	if(n%deg==0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int a, b;
	cin >> a >> b;
	cout << (b - a) * (b - a + 1) / 2 - b << endl;
	return 0;
}


Measured memory_bytes: 256
//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

ll powll(ll n,ll N){

ll ans = 1;
ll i=0;

REP(i,N){

    ans = ans * n% MOD;

}

return ans;


}


signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    
    ll N;

    cin >> N ;
    
    ll ans =(powll(10,N)-powll(9,N)-powll(9,N)+powll(8,N))%MOD;
    ans = (ans+MOD) % MOD;

    cout << ans << endl;
    
}

Measured memory_bytes: 3632