akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vll H(n),I(n);
    rep(i,n) cin>>H[i];
    vector<bool> ok(n,true);
    rep(i,m){
        int a,b; cin>>a>>b; a--; b--;
        if (H[b]>=H[a]) ok[a]=false;
        if (H[a]>=H[b]) ok[b]=false;
    }
    int ans=0;
    rep(i,n){
        if (ok[i]) ans++;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 4768
package main

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

func main()  {
	var (
		n int
	)
	fmt.Scan(&n)
	
	a := make([][]int, n)
	reader := NewReader()
	for i := range a {
		a[i] = reader.ReadInts()
	}

	dp := make([][]int, n + 1)
	for i := range dp {
		dp[i] = make([]int, 3)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < 3; k++ {
				if j == k { continue }
				dp[i + 1][k] = Max(dp[i + 1][k], dp[i][j] + a[i][k])	
			}
		}
	}
	ans := 0
	for i := 0; i < 3; i++ {
		ans = Max(ans, dp[n][i])
	}
	fmt.Println(ans)
}

func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
 
func MaxInts(n ...int) int {
	max := n[0]
	for _, v := range n[1:] {
		if v > max {
			max = v
		}
	}
	return max
}
 
type Reader struct {
	r    *bufio.Reader
	size int
	sep  string
}
 
func NewReader() *Reader {
	size := 4096
	return &Reader{
		r:    bufio.NewReaderSize(os.Stdin, size),
		size: size,
		sep:  " ",
	}
}
 
func (rdr *Reader) ReadLine() string {
	buf := make([]byte, 0, rdr.size)
	for {
		line, isPrefix, err := rdr.r.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}
 
func (rdr *Reader) ReadStrs() []string {
	return strings.Split(rdr.ReadLine(), rdr.sep)
}
 
func (rdr *Reader) ReadInts() []int {
	a := rdr.ReadStrs()
	b := make([]int, len(a))
	for i, v := range a {
		b[i], _ = strconv.Atoi(v)
	}
	return b
}


Measured memory_bytes: 14464
import java.util.*;
public class Main{
	Scanner sc = new Scanner(System.in);
	int a,b,c;
	
	void bc(){
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		
		if(a<b && b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
	
	public static void main(String[] args){     
		new Main().bc();     
		} 
	}

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

int main() {

  int a, b, c ,d;
  cin >> a >> b >> c >> d;
  
  if (a+b == c+d){
    cout << "Balanced";
  }
  else if (a+b<=c+d){
    cout << "Right";
  }
  else if (a+b>=c+d){
    cout << "Left";
  }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
dp = [[[-10**15, -10**15] for i in range(4)] for j in range(n+1)]
#dp = [[[0,0] for i in range(4)] for j in range(n+1)]

dp[0][0][0] = 0


for i in range(n):
    for j in range(4):
        for k in range(2):
            if j == 3:
                dp[i+1][3][0] = max(dp[i][3][1],dp[i+1][3][0])
                dp[i+1][3][1] = max(dp[i][3][0]+a[i],dp[i+1][3][1])
            elif j == 2:
                dp[i+1][2][0] = max(dp[i][2][1],dp[i+1][2][0])
                dp[i+1][2][1] = max(dp[i][2][0]+a[i],dp[i+1][2][1])
                dp[i+1][3][0] = max(dp[i][2][0],dp[i+1][3][0])
            elif j == 1:
                dp[i+1][1][0] = max(dp[i][1][1],dp[i+1][1][0])
                dp[i+1][1][1] = max(dp[i][1][0]+a[i],dp[i+1][1][1])
                dp[i+1][2][0] = max(dp[i][1][0],dp[i+1][2][0])
            else:
                dp[i+1][0][0] = max(dp[i][0][1],dp[i+1][0][0])
                dp[i+1][0][1] = max(dp[i][0][0]+a[i],dp[i+1][0][1])
                dp[i+1][1][0] = max(dp[i][0][0],dp[i+1][1][0])


ans = 0
if n % 2 == 0:
    ans = max(max(dp[n][0]), dp[n][1][1])
else:
    ans = max(max(dp[n][0]), max(dp[n][1]), dp[n][2][1])

print(ans)


Measured memory_bytes: 183040
let n = Scanf.scanf " %d" (+) 0
let rec f n = if n mod 2 <> 0 then 0 else 1 + f (n / 2)
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ fun a -> f a
let _ = Printf.printf "%d\n" @@ Array.fold_left (+) 0 a_s

Measured memory_bytes: 2688
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long  ←保留
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

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

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

/*signed*/int main() {
    int N;
    cin >> N;
    long double sum = 0;
    for (int i = 0; i < N; i++) {
        double x;
        string v;
        cin >> x >> v;
        if (v == "JPY") {
            sum += x;
        }
        else {
            sum += 380000 * x;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int k,s,x,y,z,count;
    count=0;
    cin>>k>>s;
    for(int i=0;i<=k;i++){
      x=i;
      for(int j=0;j<=k;j++){
        y=j;
        z=s-x-y;
        if(z<=k&&z>=0){
          count++;
        }
      }
    }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i&1)
        cnt++;
    }
    cout<<fixed<<setprecision(10)<<(double)cnt/n;
	return 0;
}


Measured memory_bytes: 256
#define pi 3.141592653589793238462643383279
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main(void){
	double a, b, x; cin >> a >> b >> x;
	// 二分探索
	double ld = 0, rd = pi/2, all = a*a*b;
	for(int i=0; i<100; i++) {
		double y, nw = (ld + rd) / 2.0;
		if (a*tan(nw) < b) y = all - a*a*a*tan(nw) / 2;
		else y = a*b*b*tan(pi/2-nw) / 2;
      //cout << y << " " << nw / pi * 180 <<  endl;
		if (x == y) break;
		else if (x < y) ld=nw;
		else rd=nw;
	}
    cout << fixed << setprecision(10);
	cout << (ld + rd) / 2 * 180 / pi << endl;
}

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


int main()
{
	int n;
	cin >> n;
	vector<int> sum(n);
	for (int i = 0; i < n; i++) {
		int c_in;
		cin >> c_in;
		if (i == 0) {
			sum.at(i) = c_in;
		} else {
			sum.at(i) = sum.at(i - 1) + c_in;
		}
	}

	int goukei = sum.at(n - 1);
	int ans = 100000;
	for (int i = 0; i < n; i++) {
		int zenhann = sum.at(i);
		int kouhann = sum.at(n - 1) - sum.at(i);
		int diff = abs(zenhann - kouhann);
		if (diff < ans) {
			ans = diff;
		}
	}

	cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

int main() {
  ll N; cin >> N;
  ll Q; cin >> Q;
  string S; cin >> S;
  vector<ll> l(Q);
  vector<ll> r(Q);
  for (ll j=0; j < Q; ++j) cin >> l[j] >> r[j];
  vector<ll> mark(N+1);
  ll count = 0;
  for (ll k=0; k < N; ++k) {
    if (k < N-1 && S[k] == 'A' && S[k+1] == 'C') {
      count += 1;
    }
    mark[k+1] = count;
  }
  for (ll j=0; j < Q; ++j) {
    cout << mark[r[j]-1]-mark[l[j]-1] << endl;
  }
  return 0;
}

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

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

    map<string, map<int, int, greater<int>>> data;

    for (int i = 0; i < n; i++){
        string name;
        int point;
        cin >> name >> point;

        data[name][point] = i + 1;
    }

    auto itr = data.begin();
    while(itr != data.end()){
        auto itr2 = itr->second.begin();
        while(itr2 != itr->second.end()){
            cout << itr2->second << endl;
            itr2++;
        }
        itr++;
    }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
vector <int> g[N]; 
int used[N];
int dp[N];
int a[N];
void solve(){
    int n;
    cin >> n;
    dp[1] = n - 1;
    for(int i = 2; i <= n; ++i) {
        cin >> a[i];
        g[a[i]].pb(i);
        g[i].pb(i);
    }
    cout << g[1].size() << "\n";
    for(int i = 2; i <= n; ++i){
        cout << (int)g[i].size() - 1 << "\n";
    }
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 15908
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
X = LIST()

a = sum(X) / N
ans1 = 0
ans2 = 0

big = int(a) + 1
small = int(a)
for i in range(N):
    ans1 += (X[i] - big) ** 2
    ans2 += (X[i] - small) ** 2
print(min(ans1, ans2))





Measured memory_bytes: 5704
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;

int w,h;
int tx,ty;
int kx,ky;
int maze[100][100]; //y,x
bool d[55][55][55][55];
int dx[] = {1,0,0,-1};
int dy[] = {0,1,-1,0};
struct P{
  int f,s,sf,ss,c;
  P (int f,int s,int sf,int ss,int c):f(f),s(s),sf(sf),ss(ss),c(c) {};
};

int bfs(){
  queue < P > que;
  que.push( P(tx,ty,kx,ky,0) );
  d[tx][ty][kx][ky] = true;

  while( !que.empty() ){
    P p = que.front(); que.pop();

    if(p.c == 100) return -1;
    if(p.f == p.sf && p.s == p.ss) return p.c;

    for(int i=0;i<4;i++){
      int ntx = p.f + dx[i];
      int nty = p.s + dy[i];
      int nkx = p.sf - dx[i];
      int nky = p.ss - dy[i];


      if(ntx < 0 || nty < 0 || ntx == w || nty == h || maze[nty][ntx] == 1){
	ntx = p.f;
	nty = p.s;
      }

      if(nkx < 0 || nky < 0 || nkx == w || nky == h || maze[nky][nkx] == 1){
	nkx = p.sf;
	nky = p.ss;
      }

      if(ntx == p.f && nty == p.s && nkx == p.sf && nky == p.ss) continue;

      if(!d[ntx][nty][nkx][nky]){
	d[ntx][nty][nkx][nky] = true;
	que.push( P(ntx,nty,nkx,nky,p.c+1) );
      }

    }
  }

  return -1;

}

int main(){

  while(true){
    cin >> w >> h;
    if(!w && !h) break;

    cin >> tx >> ty;
    cin >> kx >> ky;

    tx--; ty--; kx--; ky--;

    memset(maze,0,sizeof(maze));
    memset(d,false,sizeof(d));

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++) cin >> maze[i][j];
    }

    int ans = bfs();

    if(ans < 0) cout << "NA\n";
    else cout << ans << endl;

  }
}

Measured memory_bytes: 10332
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    String S=gs();
	    String T=gs();
	    String Sq=new String(S);

	    int ind=T.length()-1;
	    boolean f=false;

	    for (int i=0; i<S.length(); i++) {
	    	char c=S.charAt(S.length()-1-i);
	        if (c=='?' || c==T.charAt(T.length()-1)) {
	        	String ns=new String(Sq);
	        	boolean sf =true;
	        	for (int j=0; j<T.length(); j++) {
	        		if (ns.length()-1-i-j<0) {
	        			sf=false;
	        			break;
	        		}
	        		char c2=ns.charAt(ns.length()-1-i-j);
	        		if (c2=='?') {
	        			ns=ns.substring(0, S.length()-1-i-j) + T.charAt(T.length()-1-j) + ns.substring(ns.length()-i-j);
	        	    } else if (c2!=T.charAt(T.length()-1-j)) {
	        	    	sf=false;
	        	    }
	        	}
	        	if(sf) {
	        		f=true;
	        		S=ns;
	        	}
	        }

	    	if(f)break;
	    }
//	    System.out.print(c);
        if (f) {
    	    String a=Sq.substring(0, S.lastIndexOf(T)) + T + Sq.substring(S.lastIndexOf(T)+T.length());
    	    System.out.print(a.replaceAll("\\?", "a"));
        }else {
        	System.out.print("UNRESTORABLE");
        }
	}

	// 文字列として入力を取得
	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());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<< "\n"

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a<b&&b<c)printf("Yes\n");
    else printf("No\n");
    return 0;
}



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

int main(void)
{
    int K;
    cin >> K;
    queue<ll> rNumber;
    if(K<=12){
        cout << K << endl;
        return 0;
    }
    for(ll i=1;i<10;i++){
        rNumber.push(i);
    }
    int k = 9;
    while(true){
        ll n = rNumber.front();
        ll addN;
        rNumber.pop();
        if(n%10 != 0){
            k++;
            addN = n * 10 + (n%10 - 1);
            rNumber.push(addN);
            if(k==K){
                cout << addN << endl;
                return 0;
            }
        }
        // same
        k++;
        addN = n * 10 + (n % 10);
        rNumber.push(addN);
        if(k==K){
            cout << addN << endl;
            return 0;
        }
        // plus 1
        if(n%10 != 9){
            k++;
            addN = n * 10 + (n%10 + 1);
            rNumber.push(addN);
            if(k==K){
                cout << addN << endl;
                return 0;
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 768
# -*- coding: utf-8 -*-
import pprint

H,W = list(map(int, input().rstrip().split()))
a_list=[list(input().rstrip()) for i in range(H)]
#-----

row_del_list=[]
for i,v in enumerate(a_list):
    if v.count(".") == W:
        row_del_list.append(i)

for i in row_del_list[::-1]:
    del a_list[i]
    H -= 1

       
column_del_list=[]
for j in range(W):
    cnt_white=0
    for i in range(H):
        if a_list[i][j] == ".":
            cnt_white += 1
    
    if cnt_white == H:
        column_del_list.append(j)
        
for j in column_del_list[::-1]:
    for i in range(H):
        del a_list[i][j]
        W -= 1


for row in a_list:
    print(*row,sep="")


Measured memory_bytes: 5108
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 1000050

struct Point {
    ll x,y,z;
    Point(ll a=0,ll b=0,ll c=0) {
        x=a;y=b;z=c;
    }
};

struct LiChaoTree {
    vector<Point> line;
    LiChaoTree() {
        line.resize(4 * N + 5,Point(0,0,inf));
    }
    ll dot(Point a,Point b) {
        return (a.x*b.x+a.y*b.y+a.z*b.z);
    }
    ll f(Point a,ll x) {
        return dot(a,Point(x,x*x,1));
    }
    void add(Point nw,int l=0,int r=N,int pos=1) {
        int m = (l+r)/2;
        bool lef = f(nw,l) < f(line[pos],l);
        bool mid = f(nw,m) < f(line[pos],m);
        if(mid) swap(line[pos],nw);
        if(r-l == 1) return;
        if(lef!=mid) add(nw,l,m,2*pos);
        else add(nw,m,r,2*pos+1);
    }
    ll query(ll x,int l=0,int r=N,int pos=1) {
        int m = (l+r)/2;
        if(r-l == 1) return f(line[pos],x);
        if(x<m) return min(f(line[pos],x),query(x,l,m,2*pos));
        return min(f(line[pos],x),query(x,m,r,2*pos+1));
    }
};

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

    int n;ll c;
    cin>>n>>c;
    ll a[n];
    ifr(i,0,n) cin>>a[i];
    LiChaoTree li;
    ll dp[n];
    dp[0] = 0;
    li.add(Point(-2*a[0],1,(a[0]*a[0])));
    ifr(i,1,n) {
        dp[i] = c + li.query(a[i]);
        // cout<<li.query(a[i])<<" "<<dp[i]<<endl;
        li.add(Point(-2*a[i],1,(a[i]*a[i]+dp[i])));
    }
    // cout<<endl;
    cout<<dp[n-1]<<endl;
    return 0;
}

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

    int H;
    cin >> H;
    int A;
    cin >> A;

    int C;
    if(H%A>0){
        C=1;
    } else{
        C=0;
    };

    // 出力
    cout << (H/A)+C << endl;
    return 0;
}

Measured memory_bytes: 888
import java.util.*;

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

        Map<Integer, List<Integer>> graph = new HashMap<>();
        int n = sc.nextInt();

//        for (int i = 1; i <= n; i++) {
//            graph.put(i, new ArrayList<>());
//        }

        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            List<Integer> edges = graph.get(x);
            if(edges == null) {
                edges = new ArrayList<>();
                graph.put(x, edges);
            }
            edges.add(y);
        }

        Integer[] maxes = new Integer[n+1];
        int maxPath = 0;
        for (int i = 1; i <= n; i++) {
            maxPath = Math.max(maxPath, maxPath(graph, i, maxes));
        }

        System.out.println(maxPath);
    }

    private static int maxPath(Map<Integer, List<Integer>> graph, int i, Integer[] maxes) {
        if(maxes[i] != null) {
            return maxes[i];
        }

        List<Integer> edges = graph.get(i);
        if(edges == null || edges.isEmpty()) {
            return 0;
        }

        int max = 0;
        for (int edge: edges) {
            int path = maxPath(graph, edge, maxes);
            max = Math.max(path, max);
        }

        max++;
        maxes[i] = max;
        return max;
    }

  
}


Measured memory_bytes: 109044
#include<iostream>
#include<cmath>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	int a,b;
   int sum1=0;
  int sum2=0;
  
  cin>>a>>b;
  
	for(int i=0;i<b;i++)
    {
      sum1=sum1+a*pow(10,i);
    }
  for(int j=0;j<a;j++)
      {
        sum2=sum2+b*pow(10,j);
      }
      
      if(a<=b)
      {
        cout<<sum1<<endl;
      }
      else
      {
        cout<<sum2<<endl;
      }

	return 0;
}

Measured memory_bytes: 512
def f_c():
    n = int(input())
    s = input()
    q = 10**9 + 7

    stack, c = 0,1
    for i in range(2*n):
        if i % 2 == 0:
            if s[i] == "B":
                stack += 1
            else:
                c *= stack
                stack -= 1
        else:
            if s[i] == "B":
                c *= stack
                stack -= 1
            else:
                stack += 1
        c %= q
    if c == 0 or stack != 0:
        print(0)
    else:
        for i in range(1,n+1):
            c *= i
            c %= q
        print(c)

if __name__ == "__main__":
    f_c()

Measured memory_bytes: 3572
a,b,c = map(int,input().split())
k = int(input())

score = 0
for bx2 in range(k+1):
    cx2 = k-bx2
    
    if a < b*2**bx2 < c*2**cx2:
        print("Yes")
#        print(bx2, cx2)
        score = 1
        break
        
if score == 0:
    print("No")

Measured memory_bytes: 61772
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int n,b,t,ban;
	float y,r,data,max_m;
	while(1){
		max_m = 0.0;
		cin >> n;
		if(n == 0) break;
		cin >> y;
		for(int i=0;i<n;i++){
			cin >> b >> r >> t;
			if(t == 1)
				data = 1.0 + y * (r/100.0);
			else
				data = pow( 1+(r/100), y);
			if(max_m < data){
				ban = b;
				max_m = data;
			}
			//cout << "data = " << data << endl;
		}
		cout << ban << endl;
	}
	return 0;
}

Measured memory_bytes: 1320
# https://atcoder.jp/contests/agc022/tasks/agc022_a
# いままで登場してない文字で最小のものをappendすれば良い
# ただし26文字すべて出現している場合には考える必要あり
# つまり後ろからi文字目はそれ以降に出現した文字を使って一つだけ大きくできれば良い

S = input()
abc = list(reversed('zyxwvutsrqponmlkjihgfedcba'))

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(S) < 26:
    for s in S:
        abc.remove(s)
    print(S + abc[0])
else:
    canuse = set()
    for i in range(25, -1, -1):
        canuse.add(S[i])
        add = None
        for can in sorted(canuse):
            if can > S[i]:
                add = can
                break
        if add != None:
            print(S[:i] + add)
            exit()


Measured memory_bytes: 62072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

/* --------- ここから --------- */
using ll = long long;

#define PRIME_FACTORIZE_MAX 2000010
ll primes[PRIME_FACTORIZE_MAX];

void pre_osa_k() {
    for(ll i = 0; i < PRIME_FACTORIZE_MAX; i++) {
        primes[i] = 1;
    }
    for(ll i = 2; i < PRIME_FACTORIZE_MAX; i++) {
        if(primes[i] != 1) continue;
        for(ll j = i; j <= PRIME_FACTORIZE_MAX; j += i) {
            primes[j] = i;
        }
    }
}

vector<pair<ll,ll>> factorize(ll n){
    vector<pair<ll,ll>> res;
    while(n != 1) {
        ll cur = primes[n];
        ll cnt = 0;
        while(n % cur == 0) {
            n /= cur;
            cnt++;
        }
        res.push_back({cur, cnt});
    }
    reverse(res.begin(), res.end());
    return res;
}
/* --------- ここまで --------- */

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

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    bool pair_wise = true;
    set<ll> seen;
    pre_osa_k();
    rep(i, 0, n) {
        auto v = factorize(a[i]);
        for(auto e : v) {
            if(seen.count(e.first)) {
                pair_wise = false;
                break;
            }
            seen.insert(e.first);
        }
        if(!pair_wise) break;
    }
    if(pair_wise) {
        cout << "pairwise coprime" << endl;
        return 0;
    }
    ll g = a[0];
    rep(i, 0, n) g = gcd(g, a[i]);
    if(g == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
    return 0;
}


Measured memory_bytes: 26676
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
 
#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/
 
typedef long long  ll;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
int main() {
    int n;
    cin>>n;
    if(n%2==0){
        cout<<0.5<<endl;
    }
    else{
        cout<<(double)((double)(n/2+1)/n)<<endl;
    }
 
 
 
 
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
edges=[list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]

adj=[set() for _ in range(N)]

for a,b in edges:
    adj[a].add(b)
    adj[b].add(a)

start=0
dst=[-1]*N
visited={0}

Q={start}

while Q:
    tmp=set()
    for cur in Q:
        for nex in adj[cur]:
            if nex in visited:
                continue
            dst[nex]=cur
            visited.add(nex)
            tmp.add(nex)
    Q=tmp

print("Yes")
print("\n".join(map(str,[v+1 for v in dst[1:]])))


Measured memory_bytes: 164256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll power(ll n, ll p, ll mod) {
    ll ans = 1;
    while (p > 0) {
        if (p & 1) ans = ans * n % mod;
        n = n * n % mod;
        p >>= 1;
    }
    return ans;
}

int main() {
    int N, K; cin >> N >> K;
    vector<ll> gcds(K + 1, 0);
    for (int i = K; i > 0; i--) {
        gcds[i] = power(K / i, N, MOD);
        for (int j = 2; j * i <= K; j++) gcds[i] = (gcds[i] - gcds[i * j] + MOD) % MOD;
        // cout << "i : " << i << " : " << gcds[i] << endl;
    }    

    ll ans = 0;
    REP(i, 1, K + 1) ans = (ans + (i * gcds[i]) % MOD) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3936
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();

      if((A-(2*B) < 0))
          System.out.print(0);
      else
          System.out.print(A-(2*B));

    }
}

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

using namespace std;
int dp[1001];

int main() {
    int D,G;
    int p[10],c[10];

    cin >> D >> G;
    for(int i=0; i<D; i++) cin >> p[i] >> c[i];
    for(int i=0; i<D; i++) {
        for(int k=1000; k>=1; k--) {
            for(int j=1; j<=p[i] && j<=k; j++) {
                dp[k] = max(dp[k],dp[k-j]+(i+1)*100*j+(j==p[i]?c[i]:0));
            }
        }
    }
    for(int i=0; i<=1000; i++) {
        if(dp[i] >= G) {
            cout << i << endl;
            return 0;
        }
    }
}

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

using namespace std;

int main()
{
    int cnt1 = 0, cnt0 = 0;
    string S;
    cin >> S;
    vector<int> A(S.length());
    for (int i = 0; i < S.length(); i++)
    {
        A[i] = S[i] - '0';
        if (A[i] == 1)
            cnt1++;
        if (A[i] == 0)
            cnt0++;
    }
    if (cnt1 >= cnt0)
    {
        cout << cnt0 * 2 << endl;
    }
    else
    {
        cout << cnt1 * 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	int ans = 0;
	for(int i = 0; i < n; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		ans += b - a + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main() {
  /* code */

  int n=0,e,a=0;
  char str[56] = {0};
  int *p;
  //char d="A",b="B",c="C";

  scanf("%d\n", &e);
  scanf("%s\n", str);

  p = (int *)malloc(e * sizeof(int));


  while (str[n+2] != '\0') {  /* str[n] が終端文字（ヌル文字 '\0'）でない間繰り返す */
    if(str[n]=='A'){
       if(str[n+1]=='B'){
         if(str[n+2]=='C'){
           a++;
         }
       }

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



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a<0)
	cout<<(0-a)*c+d+b*e<<endl;
	else  
	cout<<(b-a)*e<<endl;
	return 0;
}



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

int main(){
    long long n, k;
    cin >> n >> k;

    long long r, s, p;
    cin >> r >> s >> p;

    string t;
    cin >> t;

    string ans;
    long long cnt = 0;
    long long point = 0;
    for(long long i = 0; i < n; i++){
        if(t[i] == 'p'){
            ans.push_back('s');
            point = s;
        }
        else if(t[i] == 's'){
            ans.push_back('r');
            point = r;
        }
        else if(t[i] == 'r'){
            ans.push_back('p');
            point = p;
        }

        if(i-k >= 0 and ans[i-k] == ans[i]){
            ans[i] = ' ';
            point = 0;
        }
        cnt += point;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3756
#include <stdio.h>
#include <iostream>
#include <stack>
#include <string>
using namespace std;

#define NUM 101
int node_num;
int V[NUM + 1][NUM + 1];
int d[NUM + 1];
int f[NUM + 1];
string color[NUM + 1];
int t;
int pos;
stack<int> s;

void createAdj(int n){
    for(int j = 0; j <= n; j++){
        if(j == 0){
            V[0][j] = 0;
        }
        V[0][j] = 1;
    }

    for(int i = 1; i < NUM; i++){
        for(int j = 1; j < NUM; j++){
            V[i][j] = 0;
        }
    }

    for(int i = 0; i < n; i++){
        int num1;
        scanf("%d", &num1);

        int n;
        scanf("%d", &n);

        int num2;
        for(int j = 0; j < n; j++){
            scanf("%d", &num2);
            V[num1][num2] = 1;
        }
    }
}

int search(int n){
    for(int i = 1; i <= node_num; i++) {
        if(V[n][i] == 1 && color[i] == "white")
            return i;
    }
    return -1;
}

void dfs_init(){
    t = 0;
    for(int i = 0; i < NUM; i++){
        color[i] = "white";
    }
}

void dfs(){
    s.push(0);
    pos = 0;
    color[0] = "grey";
    d[0] = t;

    while(s.size()){
        int u = s.top();
        int next_node = search(u);
        if(next_node != -1){
            pos = next_node;
            s.push(next_node);
            pos = next_node;
            t++;
            color[next_node] = "grey";
            d[next_node] = t;
        }else{
            s.pop();
            color[u] = "black";
            t++;
            f[u] = t;
        }
    }
}

void print(){
    for(int i = 1; i <= node_num; i++){
        printf("%d %d %d\n", i, d[i], f[i]);
    }
}

int main(void){
    scanf("%d", &node_num);
    createAdj(node_num);

    dfs_init();
    dfs();

    print();
}



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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main(){
  int N; cin >> N;
  int res = 0;
  for(int i=0; i<N; i++){
    long long A; cin >> A;
    res = GCD(res, A);
  }
  cout << res << endl;
}


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

int main()
{
    char n[3];
    scanf("%s", n);
    for(int i=0; i<3; i++){
        if(n[i]=='1') printf("9");
        else if(n[i]=='9') printf("1");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

pic_n, pic_m = [], []
for i in range(n):
    pic_n.append([j for j in input()])
for i in range(m):
    pic_m.append([j for j in input()])

corr = "No"
for i in range(n):
    for j in range(n):
        if pic_n[i][j] == pic_m[0][0]:
            for k in range(m):
                if i + k >= n:
                    break
                for l in range(m):
                    if j + l >= n or pic_n[i+k][j+l] != pic_m[k][l]:
                        break
                else:
                    continue
                break
            else:
                corr = "Yes"

print(corr)


Measured memory_bytes: 3064
package main

import (
	"fmt"
)

var m = map[int]map[int]bool{}

func main() {
	var K int
	fmt.Scan(&K)
	var ctr uint64 = 1
	if K%2 == 0 {
		fmt.Println(-1)
		return
	}
	sum := 7
	e := 1
	k := 10 % K
	for {
		if sum%K == 0 {
			fmt.Println(ctr)
			return
		}
		e *= k
		e %= K
		diff := (7 % K) * e
		if v, ok := m[sum%K]; ok {
			if v[diff] {
				fmt.Println(-1)
				return
			}
			m[sum%K][diff%K] = true
		} else {
			m[sum%K] = map[int]bool{diff % K: true}
		}
		sum += diff
		ctr++
	}
}


Measured memory_bytes: 214372
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N;
  string S;
  cin >> N >> S;

  int ans = 0;
  char last = '"';
  for (char& c : S){
    if (c == last) continue;
    last = c;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]

    def root(self, i):
        if(self.par[i] == i):
          return i
        else:
          self.par[i] = self.root(self.par[i])
          return self.par[i]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        self.par[x] = y

    def same(self, x, y):
        return self.root(x) == self.root(y)

uf = UnionFind(n)
for x, y in xy:
    uf.union(x-1, y-1)
ans = 0
for i in range(n):
    if uf.same(i, p[i]-1):
        ans += 1

print(ans)



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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int MAXN=101010;
int N,h[MAXN],dp[MAXN];


int main(){
//#ifdef Javier
//   freopen(".in", "r", stdin);
//#endif // Javier

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

    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>h[i];
    }

    dp[1]=0;
    dp[2]=abs(h[1]-h[2]);

    for(int i=3;i<=N;i++)
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));

    cout<<dp[N];


    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

ll keta_sum(ll a){
    ll ret = 0;
    while(a > 0){
        ret += a%10;
        a /= 10;
    }
    return ret;
}
int main(){
    ll x;
    cin >> x;
    ll f = keta_sum(x);
    if(x % f == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
7
5 0 7 8 3 3 2
*/

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    int ans = 0;
    rep(i, n) {
        for (int j = i+1; j < n; j++) {
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;
}

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

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

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

#define BIT_ON(x,b) ((x)|=(b))
#define BIT_OFF(x,b) ((x)&=~(b))
#define BIT_IS_ON(x,b) (((x)&(b))==(b))


using namespace std;

int main(void){
  int x, ans;
  cin >> x;

  if(x == 1 ) {cout << 1 << endl; return 0;}
  
  ans = 1;
  for(int b=2; b<1001; b++){
    for(int p=2; p <=10; p++){
      int t = pow(b,p);
      if(ans < t && t <=x) ans = t;
      if(t > x) break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;


int main() {
    int L, R;
    cin >> L >> R;

    int ans = 2019;

    if (R-L >= 2019) {
        ans = 0;
    } else {
        for (int i = L; i <= R; ++i) {
            for(int j = i+1; j <= R; ++j) {
                int l = i % 2019;
                int r = j % 2019;
                ans = min(ans, (l*r) % 2019);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,s=0;
    char str[100];

    scanf("%d",&n);

    for(i=0;i<=n;i++)
    {
        scanf("%c",&str[i]);
    }

    if(n%2!=0) printf("No\n");

    else{
    for(i=0;i<(n/2)+1;i++)
    {
        if(str[i+1]==str[i+(n/2)+1]) s++;

        else break;
    }

    if(s==n/2) printf("Yes\n");

    else printf("No\n");

    }

return 0;
}

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

int n,ans;
int ar[100];

int main() {
	scanf("%d",&n);
	for( int i = 0 ; i < n ; i++ )
		scanf("%d",&ar[i]);
	sort(ar,ar+n);
	for( int i = 0 ; i < n ; i++ )
		for( int j = i+1 ; j < n ; j++ )
			for( int k = j+1 ; k < n ; k++ ) {
				if(ar[i] == ar[j] || ar[j] == ar[k])
					continue;
				if(ar[k] < ar[i]+ar[j])
					ans++;
			}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3768
m=1000000007
n=int(input())
l=list(map(int,input().split()))
ss=0
sum=[]
for i in l:
  ss=(ss+i)%m
  sum.append(ss)
s=0
for i in range(n):
  x=(l[i]*sum[n-1]-l[i]*sum[i])%m
  s=(s+x)%m
print(s)

Measured memory_bytes: 31556
#include<bits/stdc++.h>
using namespace std ;
typedef  long long int ll ;
#define inf 9e18
#define mod 1000000007
#define mod1 998244353
long long int power(long long int a,long long int n,long long int m) ;
 long long int power(long long int a,long long int n,long long int m)
{  if(n==0)
   return 1 ;
   long long int x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}


int main()
{ ll n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,o;
  ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cin>>n ;
   cin>>x>>y ;
   x=(y/n)-((x-1)/n) ;
   if(x!=0)
    cout<<"OK" ;
   else cout<<"NG" ;
   return 0 ; }


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <algorithm>

int n;
int A[111];

int ans[111];
bool vis[111];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)	scanf("%d", &A[i]);
	for(int i = 1; i <= n; i++){
		int k = -1;
		for(int j = 1, mx = n - i + 1; j <= mx; j++)
			if(A[j] == j) k = j;
		if(k == -1) return !printf("-1\n");
		ans[i] = k;
		for(int j = k, mx = n - i + 1; j < mx; j++) A[j] = A[j + 1];
	}
	for(int i = n; i; i--) printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
ts = []
titles = []
cnt = 0
for i in range(N):
    s,t = input().split()
    titles.append(s)
    cnt += int(t)
    ts.append(int(t))
X = input()

for i,s in enumerate(titles):
    if s == X:
        ind = i
        break

print(sum(ts[ind+1:]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A), t(B);
    rep(i, 0, A) cin >> s[i];
    rep(i, 0, B) cin >> t[i];
    rep(q, 0, Q){
        ll x; cin >> x;
        auto jin = lower_bound(s.begin(), s.end(), x);
        auto ter = lower_bound(t.begin(), t.end(), x);
        ll c1 = 1e18, c2 = 1e18, c3 = 1e18, c4 = 1e18;
        if(jin != s.end() && ter != t.end()){
            c1 = max(*jin, *ter) - x;
        }
        if(jin != s.begin() && ter != t.begin()){
            c2 = x - min(*(jin-1), *(ter-1));
        }
        if(jin != s.begin() && ter != t.end()){
            c3 = 2 * min(x - *(jin-1), *ter - x) + max(x - *(jin-1), *ter - x);
        }
        if(jin != s.end() && ter != t.begin()){
            c4 = 2 * min(x - *(ter-1), *jin - x) + max(x - *(ter-1), *jin - x);
        }
        cout << min({c1, c2, c3, c4}) << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
from collections import deque

k = int(input())
limit = 10#最大桁数

start = [i for i in range(1, 10)]#最初にスタートする数
ans = []
def DFS(num):
	if len(str(num))>11:#処理終了
		return 1
	ans.append(num)
	last=str(num)[-1]
	if last == "0":
		add = ['0', '1']
	elif last == '9':
		add = ['8',"9"] 
	else:
		add = [str(int(last) - 1), str(int(last)), str(int(last) + 1)]
	for i in add:
		DFS(int(str(num)+i))

for j in start:
	DFS(j)

ans = sorted(ans)
print(ans[k - 1])#k番目の答えを創出

Measured memory_bytes: 37504
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  string a, b;
  cin >> a >> b;
  bool flag;

  if (a==b){
    print("EQUAL");
    return 0;
  }

  if(a.size() > b.size()){
    flag = true;
  } else if (a.size() < b.size()){
    flag = false;
  } else {
    rep(i, a.size()){
      if(a[i] == b[i]) continue;
      else if(int(a[i]) < int(b[i])){
        flag = false;
        break;
      } else {
        flag = true;
        break;
      }
    }
  }

  if(flag){
    print("GREATER");
  } else {
    print("LESS");
  }
}


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

#define pb push_back
#define pbk pop_back
#define mk_pr make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<string> vss;
typedef queue<int> qi;

const int MX = 123456;
int ar[MX], clr[10], clr1[10];

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

        int n, a, xtr = 0;
        cin >> n;
        for(int i=0; i<n; i++) {
                cin >> a;
                if( a>=1 && a<=399 ) clr[1]++;
                else if( a>=400 && a<=799 ) clr[2]++;
                else if( a>=800 && a<=1199 ) clr[3]++;
                else if( a>=1200 && a<=1599 ) clr[4]++;
                else if( a>=1600 && a<=1999 ) clr[5]++;
                else if( a>=2000 && a<=2399 ) clr[6]++;
                else if( a>=2400 && a<=2799 ) clr[7]++;
                else if( a>=2800 && a<=3199 ) clr[8]++;
                else xtr++;
        }

        int mn = 0, mx = 0;
        for(int i=1; i<=8; i++) if( clr[i] ) mn++;
        mx = (mn+xtr);
        if( mn == 0 && xtr ) mn = 1;

        cout << mn << " " << mx << endl;

        return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.Array
main = do
  [n,m] <- map read . words <$> getLine
  abs <- replicateM m $ map read . words <$> getLine
  let ar = accumArray (+) 0 (1,n) [(i,1) | ab <- abs, i <- ab]
  mapM_ print $ elems $ ar

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

int main() {
  int n;long long ans = 0;
  cin >> n;
  unordered_map<string,int>mp;
  for(int i = 0;i < n;i++){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(mp.find(s) == mp.end()){
      mp[s] = 0;
    }
    else{
      mp[s]++;
      ans += mp[s];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 10660
import java.util.Scanner;
import java.util.*;
public class Main {
	//static int n,k,u[],min[count],max;

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

		int count=-1;
		while(true){
			count++;
			int m = sc.nextInt();
			int nMin=sc.nextInt();
			int nMax=sc.nextInt();
			if(m==0 && nMin==0 && nMax==0){
				break;
			}
			int p[]=new int[m];
			for(int i=0;i<m;i++){
				p[i]=sc.nextInt();
			}
			Arrays.sort(p);
			for(int i=0;i<m/2;i++){
				int temp=p[i];
				p[i]=p[m-1-i];
				p[m-1-i]=temp;
			}
			//System.out.println(Arrays.toString(p));
			int gap=-1;
			for(int i=nMin;i<=nMax;i++){
				int hoge=p[i-1]-p[i];
				//System.out.println(hoge+","+gap[count]);
				if(hoge>=gap || gap==-1){
					gap=hoge;
					ans[count]=i;
					//System.out.println(gap[count]);
				}
			}
		}
		for(int i=0;i<count;i++){
			System.out.println(ans[i]);
		}
	}
}

Measured memory_bytes: 56884