akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int SIZE=100010;
int n,m;
vector<pair<int,int> > G[SIZE];
vector<int> vec;
int D[SIZE];
bool vis[SIZE];
pair<int,int> pii[SIZE];
set<int> ans;
void dfs(int x)
{
    vis[x]=true;
    for(auto v:G[x]) 
	{
		if(vis[v.first]==false)
	    {
	        dfs(v.first);
	        if(D[v.first]) 
	        {
	            D[x]=D[x]^1; 
				D[v.first]=D[v.first]^1;
	            ans.insert(v.second);
	        }
	    }
	}
}
int main()
{
    int n,m; 
	cin>>n>>m;
    for (int i=1;i<=n; i++) 
    {
        scanf("%d%d",&pii[i].first,&pii[i].second); 
        vec.push_back(pii[i].first);
    }
    sort(pii+1,pii+1+n);
    sort(vec.begin(),vec.end());
    D[1]=pii[1].second;
    for(int i=2;i<=n;i++) 
		D[i]=pii[i-1].second^pii[i].second;
    D[n+1]=pii[n].second;
    for (int i=1;i<=m;i++)
    {
    	int l,r;
        scanf("%d%d",&l,&r);
        l=lower_bound(vec.begin(),vec.end(),l)-vec.begin()+1;
        r=upper_bound(vec.begin(),vec.end(),r)-vec.begin()+1;
        G[l].push_back({r,i});
        G[r].push_back({l,i});
    }
    for(int i=1;i<=n+1;i++) 
	{
		if(vis[i]==false)
	    {
	        dfs(i);
	        if(D[i]!=0) 
			{
				puts("-1");
				return 0;
			}
	    }
	}
    cout<<ans.size()<<endl;
    for(auto x:ans) 
		printf("%d ",x);
    return 0;
}

Measured memory_bytes: 16248
import sys
sys.setrecursionlimit(10**5)
n, k = map(int, input().split())
mod = 10 ** 9 + 7
adjacent_list = [[] for i in range(n+1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
finished = set([1])
ans = k
def dfs(current, finished,num):
    global ans
    global k
    unsearched = set(adjacent_list[current]) - finished
    num = max(k - 1, num)
    if len(unsearched) == 0:
        return
    for i in unsearched:
        finished.add(i)
        num -= 1
        ans *= num
        ans %= mod
        dfs(i,finished, num)
dfs(1,finished,k)
print(ans)

Measured memory_bytes: 176928
k = int(input())
s = list(input())
n = len(s)


mod = 10**9+7 #出力の制限
N = k + n + 1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

ans = 0
for i in range(k+1):
    ans += pow(26, k-i, mod) * pow(25, i, mod) * cmb(i+n-1, n-1, mod) % mod

print(ans % mod)


Measured memory_bytes: 280408
H,W = map(int,input().split())

S = [input() for i in range(H)]

L = [[0 for x in range(W)] for y in range(H)]
R = [[0 for x in range(W)] for y in range(H)]
U = [[0 for x in range(W)] for y in range(H)]
D = [[0 for x in range(W)] for y in range(H)]


for i in range(H) :
    flg = 0
    for j in range(W) :
        if S[i][j] == "#" :
            flg = 1
        elif flg :
            flg = 0
        elif j == 0 :
            L[i][j] = 0
        else :
            L[i][j] = L[i][j-1] + 1
    
    flg = 0
    for j in range(W-1,-1,-1) :
        if S[i][j] == "#" :
            flg = 1
        elif flg :
            flg = 0
        elif j == W-1 :
            R[i][j] = 0
        else :
            R[i][j] = R[i][j+1] + 1

for j in range(W) :
    flg = 0
    for i in range(H) :
        if S[i][j] == "#" :
            flg = 1
        elif flg :
            flg = 0
        elif i == 0 :
            U[i][j] = 0
        else :
            U[i][j] = U[i-1][j] + 1
    
    flg = 0
    for i in range(H-1,-1,-1) :
        if S[i][j] == "#" :
            flg = 1
        elif flg :
            flg = 0
        elif i == H-1 :
            D[i][j] = 0
        else :
            D[i][j] = D[i+1][j] + 1

ans = 0
for i in range(H) :
    for j in range(W) :
        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j])

ans += 1

print(ans)


Measured memory_bytes: 184836
#include <iostream>
#include <map>

using namespace std;

int main(){
  long long N;
  map<long long,char> price_for_double;
  long long Q,H,S,D;
  long long sum=0;
  cin >> Q >> H >> S >> D;
  cin >> N;
  price_for_double.insert(make_pair(Q*8,'Q'));
  price_for_double.insert(make_pair(H*4,'H'));
  price_for_double.insert(make_pair(S*2,'S'));
  price_for_double.insert(make_pair(D,'D'));
  
  auto iter = price_for_double.begin();

  if (iter->second=='D'){
    sum = (N/2)*(iter->first);
    iter=next(iter,1);
    if (N%2==1) sum+= iter->first/2;
  }else{
    sum = N*(iter->first/2);
  }
  cout <<sum<<endl;
    
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back




int main(){

  int n,k;
  cin>>n>>k;
  vi data(n);
  rep(i,n){
    int tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  vector<double> avg(n,0);
  rep(i,n){
    avg.at(i)=(1.0+data.at(i))/2;
  }
  
  vector<double> sumavg(n,0);
  sumavg.at(0)=avg.at(0);
  for (int i=1;i<n;i++){
    sumavg.at(i)=sumavg.at(i-1)+avg.at(i);
  }

  
  
  double answer=0;
  for (int i=0;i<=n-k;i++){
    double tmp;
    tmp=sumavg.at(i+k-1)-sumavg.at(i)+avg.at(i);
    answer=max(answer,tmp);
  }
  
  
  
  
  cout<<fixed<<setprecision(20);
  
  cout<<answer<<endl;

}




















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

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> A[i];
        --A[i];
    }
    ll town = 0;
    vector<bool> flg(N, false);
    queue<ll> q;
    q.push(town);
    bool roop = false;
    flg[0] = true;
    for (ll i = 0; i < K; i++)
    {       
        //cerr <<"i=" <<i << endl;
        town = A[town];
        //cerr <<"town" << endl;
        if (flg[town] && !roop)
        {
            ll count = 0;
            while (!q.empty())
            {
                if (q.front() != town)
                {
                    count++;
                    q.pop();
                } else
                {
                    break;
                }
                
            }
            if (K - i - 1 >= i - count + 1)
            {
                //cerr <<"i-count" << i-count << endl;
                i += (((K - 1 - i) / (i - count + 1)) * (i - count + 1));
                //cerr <<"b" << endl;
                roop = true;
            }
            
        } else
        {
            flg[town] = true;
            q.push(town);
        }
        
    }
    
    cout << town + 1 << endl;
    return 0;
}

Measured memory_bytes: 6152
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a;
	cin>>a;
	cout<<180*(a-2)<<endl;
}

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

using namespace std;
using ll =long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    string str;
    int k;
    cin>>n>>str>>k;
    char c = str[k-1];
    string ans = str;
    for(int i=0;i<n;++i){
        if(c != ans[i]) ans[i] = '*';
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
z,x,c,v=0,0,0,0
while True:
  try:
    q,w = map(str,raw_input().split(","))
    if w == "A":z+=1
    elif w == "B":x+=1
    elif w =="AB":c+=1
    elif w =="O": v+=1
  except EOFError: 
    print "%d\n%d\n%d\n%d"%(z,x,c,v)
    break

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;


int main() {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> ac(N - 1, 0);
  for (int i = 1; i < N; ++i) {
    char cur_si = S[i - 1];
    char next_si = S[i];
    if (cur_si == 'A' && next_si == 'C') {
      ac[i] = ac[i - 1] + 1;
    } else {
      ac[i] = ac[i - 1];
    }
  }
  
  for (int i = 0; i < Q; ++i) {
    int l, r;
    cin >> l >> r;
    int buf = ac[r - 1] - ac[l - 1];
    cout << buf << endl;
  }
}

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


vector<pair<long long, long long> > prime_factorize(long long n) {
  
    vector<pair<long long, long long> > res;
  
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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


int main() {
    long long A, B;
    cin >> A >> B;
    long long cd = gcd(A, B);
  
    auto pf = prime_factorize(cd);
  
    cout << pf.size() + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int main(){
	int N; 
	cin >> N; 
	int H[25] = {}; 
	cin >> H[0]; 
	int mx = H[0]; 
	int ans = 1; 
	for(int i = 1; i < N; i++){
		cin >> H[i]; 
		if(H[i] >= mx){
			ans ++; 
			mx = H[i]; 
		}
	}
	cout << ans << endl; 
}

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

int main(){
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int a[55], b[55];
int x[25], y[25];
int ok[55];
int col[55];
vector<int> adjlist[55];
void dfs(int u){
    for (auto v : adjlist[u]){
        if (col[v] == -1){
            col[v] = col[u];
            dfs(v);
        }
    }
}
ll memo[55][(1<<20)];
ll dp(int x, int mask){
    if (x == n-1) return mask == ((1<<m)-1);
    if (memo[x][mask] != -1) return memo[x][mask];
    memo[x][mask] = dp(x+1,mask)+dp(x+1,mask|ok[x]);
    //printf("%d %d %d\n",x,mask,memo[x][mask]);
    return memo[x][mask];
}
int main(){
    scanf("%d",&n);
    for (int i = 0; i < n-1; i++){
        scanf("%d%d",&a[i],&b[i]);
        adjlist[a[i]].push_back(b[i]);
        adjlist[b[i]].push_back(a[i]);
    }
    scanf("%d",&m);
    for (int j = 0; j < m; j++){
        scanf("%d%d",&x[j],&y[j]);
    }
    for (int i = 0; i < n-1; i++){
        memset(col,-1,sizeof(col));
        col[a[i]] = 0;
        col[b[i]] = 1;
        dfs(a[i]);
        dfs(b[i]);
        for (int j = 0; j < m; j++){
            //printf("%d %d\n",col[x[j]],col[y[j]]);
            if (col[x[j]] != col[y[j]]) ok[i] |= (1<<j);
        }
    }
    memset(memo,-1,sizeof(memo));
    printf("%lld",dp(0,0));




}


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

Measured memory_bytes: 24404
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
	string str = "";

	while (getline (cin, str ) ){
		int a,b,n;
		stringstream ss(str);

		ss >> a >> b >> n;
		if (a % b == 0){
			cout << '0' << endl;
			continue;
		} // end if

		while (a > b){
			a -= b;
		} // end if	

		int sum = 0;
		
		for (int i = 0; i < n; ++i){
			int c = (10*a)/b;
			int d = (10*a % b);
			a = d;
			sum += c;
		} // end for
		cout << sum << endl;

	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

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

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int N;
std::vector<int> S, T, W;

int compress(std::vector<int> &v1, std::vector<int> &v2){
    std::vector<int> v;
    REP(i, N){
        v.push_back(v1[i]);
        v.push_back(v2[i]);
    }

    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());
    
    REP(i, N){
        v1[i] = std::lower_bound(v.begin(), v.end(), v1[i]) - v.begin();
        v2[i] = std::lower_bound(v.begin(), v.end(), v2[i]) - v.begin();
    }
    
    return v.size();
}

int main(){
    while(std::cin >> N, N){
        S.clear(); T.clear(); W.clear();
        REP(i, N){
            int m, a, b;
            std::cin >> m >> a >> b;
            W.push_back(m);
            S.push_back(a);
            T.push_back(b);
        }

        int w = compress(S, T);
        int ts[200];
        std::fill(ts, ts+200, 0);
        REP(i, N){
            int s = S[i], t = T[i];
            FOR(j, s, t){
                ts[j] += W[i];
            }
        }

        bool dame = false;
        REP(i, w){
            if(ts[i] > 150){
                dame = true;
            }
        }

        if(!dame){
            std::cout << "OK" << std::endl;
        }else{
            std::cout << "NG" << std::endl;
        }
    }
}

Measured memory_bytes: 1220
def showList(A, N):
    for i in range(N-1):
        print(A[i],end=' ')
    print(A[N-1])

def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                v = A[i]
                A[i] = A[i-1]
                A[i-1] = v
                flag = 1
                count += 1
    showList(A, N)
    print(count)

N = int(input())
A = [int(x) for x in input().split(' ')]
bubbleSort(A, N)


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
    int n;cin >> n;
    vector<int> w(n);
    for(int i=0;i<n;i++)cin >> w[i];

    ll count = INF;
    for(int i=1;i<=n;i++){
        ll a = 0,b=0;
        for(int j=0;j<n;j++){
            if(j+1 <= i) a+=w[j];
            else b+=w[j];
        }
        count = min(count, abs(a-b));
    }
    cout << count << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

type UnionFind struct {
	root []int
	size []int
}

func NewUnionFind(x int) *UnionFind {
	u := UnionFind{make([]int, x), make([]int, x)}
	for i := 0; i < x; i++ {
		u.root[i] = i
		u.size[i] = 1
	}
	return &u
}

func (u UnionFind) Root(x int) int {
	if u.root[x] == x {
		return x
	}
	u.root[x] = u.Root(u.root[x])
	return u.root[x]
}

func (u UnionFind) Same(x, y int) bool {
	return u.Root(x) == u.Root(y)
}

func (u UnionFind) Unite(x, y int) {
	x = u.Root(x)
	y = u.Root(y)
	if x == y {
		return
	}
	if u.size[x] > u.size[y] {
		x, y = y, x
	}
	u.size[x] += u.size[y]
	u.root[y] = x
}

func (u UnionFind) Size(x int) int {
	return u.size[u.Root(x)]
}

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)

	f := make([]int, n+1)
	b := make([]int, n+1)
	u := NewUnionFind(n + 1)

	for i := 0; i < m; i++ {
		var f1, f2 int
		fmt.Scan(&f1, &f2)
		f[f1]++
		f[f2]++
		u.Unite(f1, f2)
	}

	for i := 0; i < k; i++ {
		var b1, b2 int
		fmt.Scan(&b1, &b2)
		if u.Same(b1, b2) {
			b[b1]++
			b[b2]++
		}
	}

	for i := 1; i < n+1; i++ {
		ret := u.Size(i) - f[i] - b[i] - 1
		fmt.Print(ret, " ")
	}
	fmt.Println()
}


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

int main()
{
	int N, res = 0;
	vector<int> L;
	cin >> N;
	L.reserve(N);
	for (int i = 0, tmp;i < N * 2;i++) {
		cin >> tmp;
		L.push_back(tmp);
	}
	sort(L.begin(),L.end());
	for (int i = 0; i < N; i++) {
		res += L[i * 2];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;


int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector <int> a(N, 0);
    vector <int> wa(N, 0);

    ll ac = 0;
    ll souwa = 0;
    //最終的にwaのままの場合は、ペナに足さない

    REP(i, M)
    {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if(s[0] == 'A')//AC
        {
            if(a[p] == 0)
            {
                ++ac;
                a[p] = 1;
            }
        }
        else
        {
            if(a[p] == 0)
            {
                ++wa[p];
            }
        }
    }

    REP(i,N)
    {
        if(a[i] == 1)
        {
            souwa += wa[i];
        }

    }

    cout << ac << " " << souwa << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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(){
    ll n; cin>>n;
    vector<vector<ll>> a(n,vector<ll>(n));
    vector<vector<bool>> used(n,vector<bool>(n,false));
    ll res=0;
    rep(i,n){
        rep(j,n){
            cin>>a[i][j];
            res+=a[i][j];
        }
    }
    bool ifexist=true;
    res/=2;
    rep(i,n){
        rep(j,n){
            rep(k,n){
                if(i==j || i==k || j==k) continue;
                if(a[i][j]+a[j][k]<a[i][k]) ifexist=false;
                if(a[i][j]+a[j][k]==a[i][k] && !used[i][k]){
                    res-=a[i][k];
                    used[i][k]=used[k][i]=true;
                }
            }
        }
    }
    if(!ifexist){
        cout<<-1<<endl;
        return 0;
    }
    cout<<res<<endl;
    return 0;
}

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

std::string s;
int main() {
	std::cin >> s;

	int ans = 999999999;
	for (char c = 'a'; c <= 'z'; ++c) {
		auto tmp = s;
		int res = 0;
		while (!tmp.empty()) {
			bool check = true;
			for (size_t i = 0; i < tmp.size(); ++i)
				if (tmp[i] != c) {
					check = false;
					break;
				}
			if (check)
				break;
			for (size_t i = 1; i < tmp.size(); ++i)
				if (tmp[i] == c)
					tmp[i - 1] = c;
			tmp = tmp.substr(0, tmp.size() - 1);
			++res;
		}
		ans = std::min(ans, res);
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(long long i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    priority_queue<ll> fac;
    for (ll i=1; i*i<=sum; i++) {
        if (sum%i==0) {
            fac.push(i);
            if (i*i!=sum) {
                fac.push(sum/i);
            }
        }
    }

    bool ok = false;
    while (!fac.empty() && !ok) {
        ll now = fac.top();
        fac.pop();
        ll num = 0;
        vector<ll> r(n);
        rep(i, n) r[i] = a[i] % now;
        sort(r.begin(), r.end());
        vector<ll> v1(n);
        vector<ll> v2(n);
        rep(i, n) {
            if (i==0) {
                v1[i] = r[i];
                v2[n-1-i] = now - r[n-1-i];
            }
            else {
                v1[i] = v1[i-1] +r[i];
                v2[n-1-i] = v2[n-i] + now - r[n-1-i];
            }
            
        }
        ll res = 0;
        ll yy = v1[n-1]/now;
        res = v1[n-1-yy];
        /*
        rep(i, n-1) {
            if (v1[i]==v2[i+1]) {
                res = v1[i];
                break;
            }
        }
        */
        if (res<=k) {
            ok = true;
            cout << now << endl;
            return 0;
        }
    }

    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
int main() {

	int X, A;
	cin >> X >> A;
	if (X < A) { cout << 0 << endl; }
	else { cout << 10 << endl; }
	return 0;

}

Measured memory_bytes: 256
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pb push_back
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    string s;
    static int dp[1 << 20];
    dp[0] = 1;
    fi>>s;
    s = "$" + s;
    int n = s.length() - 1;
    for (int i = 1;i <= n;++i)
    {
        if (i >= 5)
            dp[i] |= dp[i - 5] * (s.substr(i - 4,5) == "dream" || s.substr(i - 4,5) == "erase");
        if (i >= 6)
            dp[i] |= dp[i - 6] * (s.substr(i - 5,6) == "eraser");
        if (i >= 7)
            dp[i] |= dp[i - 7] * (s.substr(i - 6,7) == "dreamer");
    }
    puts(dp[n] ? "YES" : "NO");
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    int m; cin >> m;
    cout << (24 - m) + 24 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;

#define P 1000000007

int n;
vector <int> ve[210000], ve2[210000], vv[210000], S;
int ans = 1;
int fac[210000];
bool used[210000];
int fa[210000], fa_val[210000], dp[210000], size[210000];
int xx, yy, zz;
int CC = 0;

void dfs(int x) {
	used[x] = true;
	S.push_back(x);
	for (int i = 0; i < (int) ve[x].size(); i++)
		if (!used[ve[x][i]])
			dfs(ve[x][i]);
}

void dfs2(int x, int fa) {
	used[x] = true;
	for (int i = 0; i < (int) ve[x].size(); i++)
		if (used[ve[x][i]] && ve[x][i] != fa) {
			xx = x;
			yy = ve[x][i];
			zz = ve2[x][i];
		}else if (!used[ve[x][i]]) {
			dfs2(ve[x][i], x);
		}
}

void dfs3(int x, int f, int val) {
	fa[x] = f;
	fa_val[x] = val;
	used[x] = true;
	for (int i = 0; i < (int) ve[x].size(); i++) {
		if ((xx == x && ve[x][i] == yy) || (x == yy && ve[x][i] == xx))
			continue;
		if (!used[ve[x][i]]) {
			dfs3(ve[x][i], x, ve2[x][i]);
		}
	}
}

int Pow(int x, int y) {
	int ans = 1;
	for (int i = 1; i <= y; i *= 2, x = 1LL * x * x % P)
		if (i & y)
			ans = 1LL * ans * x % P;
	return ans;
}

int C(int x, int y) {
	return 1LL * fac[x] * Pow(1LL * fac[y] * fac[x - y] % P, P - 2) % P;
}

void dfs4(int x) {
	dp[x] = 1;
	size[x] = 0;
	for (int i = 0; i < (int) vv[x].size(); i++) {
		// printf("! %d %d\n", x, vv[x][i]);
		dfs4(vv[x][i]);
		dp[x] = 1LL * dp[x] * C(size[x] + size[vv[x][i]], size[vv[x][i]]) % P * dp[vv[x][i]] % P;
		size[x] += size[vv[x][i]];
	}
	size[x] += 1;
}

int calc(int x) {
	S.clear();
	dfs(x);
	int count = 0;
	for (int i = 0; i < (int) S.size(); i++)
		count += ve[S[i]].size();
	if (count != S.size() * 2)
		return 0;
	int ans = 0;
	for (int i = 0; i < (int) S.size(); i++)
		used[S[i]] = false;
	dfs2(x, 0);

	for (int i = 0; i < (int) S.size(); i++) {
		used[S[i]] = false;
		vv[S[i]].clear();
	}
	vv[0].clear();

	dfs3(xx, yy, zz);
	for (int i = 0; i < (int) S.size(); i++) {
		if (fa_val[fa[S[i]]] > fa_val[S[i]])
			vv[fa[S[i]]].push_back(S[i]);
		else
			vv[0].push_back(S[i]);
	}

	dfs4(0);

	ans = (ans + dp[0]) % P;

	for (int i = 0; i < (int) S.size(); i++) {
		used[S[i]] = false;
		vv[S[i]].clear();
	}
	vv[0].clear();

	dfs3(yy, xx, zz);
	for (int i = 0; i < (int) S.size(); i++) {
		if (fa_val[fa[S[i]]] > fa_val[S[i]])
			vv[fa[S[i]]].push_back(S[i]);
		else
			vv[0].push_back(S[i]);
	}
	dfs4(0);

	ans = (ans + dp[0]) % P;

	CC += S.size();
	return ans;
}

int main() {
	fac[0] = 1;
	for (int i = 1; i <= 200000; i++)
		fac[i] = 1LL * fac[i - 1] * i % P;
	scanf("%d", &n);
	for (int i = 1; i <= n * 2; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		ve[x].push_back(y + n);
		ve2[x].push_back(x + y);
		ve[y + n].push_back(x);
		ve2[y + n].push_back(x + y);
	}
	n *= 2;
	int pre_count = 0;
	for (int i = 1; i <= n; i++)
		if (!used[i]) {
			ans = 1LL * ans * calc(i) % P * C(CC, pre_count) % P;
			pre_count = CC;
		}
	printf("%d\n", ans);
}


Measured memory_bytes: 40052
#include<bits/stdc++.h>
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; for(int i = 0; i < l; i++) cout<<' '<<i<<':'<<*(x+i)<<endl;
#define pb push_back
using namespace std;

int n,x,y;
int ans[2005];

int main(void)
{
	cin >> n >> x >> y;
	x--;
	y--;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			ans[min(j-i,(abs(x-i)+abs(y-j))+1)]++;
	for(int i=1;i<n;i++)
		cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
	int a,b,c,x,d;
	d = 0;

	scanf("%d %d %d",&a,&b,&c);

	for(x=a; x<=b; x++)
	{
		if(c%x==0)
		{
			d = d +1;
		}
	}

	printf("%d\n",d);

	return 0;
}

Measured memory_bytes: 596
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderCs
{

    class Program
    {

        const int Mod = 1000000007;

        static void Main()
        {

            var arg = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var num = arg[0];
            var max = arg[1];
            var quest = new List<int[]>[num];

            for (int i = 0; i < num; i++) quest[i] = new List<int[]>();

            for (int i = 0; i < arg[2]; i++)
            {

                var buf = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                quest[buf[1] - 1].Add(buf);

            }

            var result = 0;
            var bufs = new int[num];

            Solve(0, 0);

            Console.WriteLine(result);

            void Solve(int Gen, int Sum)
            {

                if (Gen == num - 1)
                {

                    for (bufs[Gen] = (Gen == 0 ? 1 : bufs[Gen - 1]); bufs[Gen] <= max; bufs[Gen]++)
                    {

                        var buffer = Sum + quest[Gen].Where(x => bufs[Gen] - bufs[x[0] - 1] == x[2]).Sum(x => x[3]);
                        if (result < buffer) result = buffer;

                    }

                }
                else
                {

                    for (bufs[Gen] = (Gen == 0 ? 1 : bufs[Gen - 1]); bufs[Gen] <= max; bufs[Gen]++)
                    {

                        Solve(Gen + 1, Sum + quest[Gen].Where(x => bufs[Gen] - bufs[x[0] - 1] == x[2]).Sum(x => x[3]));

                    }

                }

            }

        }


    }
}


Measured memory_bytes: 41352
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define vs vector<string>
#define ss second
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define tr1(x)                cout<<#x<<": "<<x<<endl
#define tr2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define tr4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl
#define tr3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define db1(x) cerr << #x << ": " << x <<'\n'
#define db2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define db3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int, int> &a,const pair<int, int> &b)
{
    return (a.ss<b.ss);
}
int min(int a, int b){
    if(a<b){
        return a;
    }
    else{
        return b;
    }
}
int max(int a, int b){
    if(a>b){
        return a;
    }
    else{
        return b;
    }
}
int max(int a, int b, int c){
    return(max( max(a,b), c ));
}
int min(int a, int b, int c){
    return (min ( min(a,b) , c));
}
int poww(int a, int b)
{
    int res = 1;
    for(int i = 1; i<=b; ++i)
        res *= a;
 
    return res;
}
int findlcm(int arr[], int n)
{
    // Initialize result
    int ans = arr[0];
 
    // ans contains LCM of arr[0], ..arr[i]
    // after i'th iteration,
    for (int i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (__gcd(arr[i], ans)));
 
    return ans;
}
bool prime[100001];
void SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));
 
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
  }
}
 
//Define mx for maximum range and MOD for large numbers
#define mx 500005
#define mod 1000000007
// Declare all the variables and global functions here -
 
int32_t main(){
    IOS;
    int n,w;
    cin >> n >> w;
    int we[n+1], v[n+1];
    for(int i = 0;i<n;i++){
        cin >> we[i+1] >> v[i+1];
    }

    int dp[n+1][w+1];
    memset(dp, 0, sizeof(dp));
    for(int i = 1;i<n+1;i++){
        for(int j = 0;j<=w;j++){
            if(we[i] <= j){
                dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-we[i]]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    cout << dp[n][w];
}  

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

signed main() {
    //cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<T> l;
    rep(i, N) {
        string S; cin >> S;
        int P; cin >> P;
        l.push_back(make_tuple(S, -P, i+1));
    }
    sort(l.begin(), l.end());
    rep(i, N) cout << get<2>(l[i]) << endl;
}

Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    x = int(input())
    if x == 0:
        print(1)
    else:
        print(0)

Measured memory_bytes: 68616
/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/21 8:23:51
File Name     :TEST.cpp
************************************************ */
 
#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i,x,y) for(int i = x;i <= y;++i)
#define fori(i,x,y) for(int i = x;i >= y; -- i)
#define bug puts("--------------")
#define out(x) cout<<x<<'\n';
inline char gc(){char op[2];scanf("%s",op);return op[0];}
const int N = 2e5+10;
const double eps = 0.00000001;
const ll mod = 998244353 ;
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
char s[N];
int L[N],R[N];
int main(){
    int n,k,c;
    cin >> n >> k >> c;
    cin >> (s+1);
    int idx1 = 0,idx2 = 0;
    for(int i = 1;i <= n;){
        if(s[i]=='o'){
            L[++idx1] = i;  
            i += c; 
        }
        if(idx1 == k) break;
        i ++;
    }
    for(int i = n;i >= 1;){
        if(s[i]=='o'){
            R[++idx2] = i;
            i -= c;
        }
        i --;
        if(idx2 == k) break;
    }
    for(int i = 1;i <= idx1;++i){
        if(L[i] == R[idx1-i+1]) cout<<L[i]<<endl;
    }

}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	cout << (a+b+1)/2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
using namespace std;

int main() {
	stack<int> S1;
	stack<pair<int, int> > S2; // 水たまりの最も左の\の位置、その時点での水たまりの面積のペア

	char ch;
	int sum = 0;
	for (int i = 0; cin >> ch; i++) {
		if (ch == '\\') S1.push(i);
		else if (ch == '/' && S1.size() > 0){
			int j = S1.top(); S1.pop();
			sum += i - j;
			int a = i - j;
			while (S2.size() > 0 && S2.top().first > j) {
				a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j, a)); // 上の段の水たまりの面積追加
		}
	}

	vector<int> ans;
	while (S2.size() > 0) {
		ans.push_back(S2.top().second); S2.pop();
	}
        reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++) {
		cout << " ";
		cout << ans[i];
	}
	cout << endl;

	return 0;
}


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

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

    vector<pair<int, int> > s;
    REP(i, n) {
        int tmp; cin >> tmp;
        s.push_back(make_pair(tmp, i + 1));
    }
    sort(s.begin(), s.end());

    REP(i, n) {
        cout << s[i].second;
        if (i != n - 1) cout << ' ';
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 1780
var
	n,i,ans:Longint;
	A:Array[1..100000]of Longint;
function gcd(a,b:Longint):Longint;
begin
	if b=0 then gcd:=a else gcd:=gcd(b,a mod b);
end;
begin
	read(n);
	for i:=1 to n do begin
		read(A[i]);
		ans:=gcd(ans,A[i]);
	end;
	writeln(ans);
end.

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
#レート 1-399：灰色 :gray
#レート 400-799：茶色 :brown
#レート 800-1199：緑色 : green
#レート 1200-1599：水色 :skyblue
#レート 1600-1999：青色 :blue
#レート 2000-2399：黄色 :yellow
#レート 2400-2799：橙色 :orange
#レート 2800-3199：赤色 :red

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

gray = 0
brown = 0
green = 0
skyblue = 0
blue = 0
yellow = 0
orange = 0
red = 0
other = 0

for i in range(x):
    z = int(y[i]) 
    if z < 400:
       gray = 1 
    elif z < 800:
        brown = 1
    elif z < 1200:
        green = 1
    elif z < 1600:
        skyblue = 1
    elif z < 2000:
        blue = 1
    elif z < 2400:
        yellow = 1
    elif z < 2800:
        orange = 1
    elif z < 3200:
        red = 1
    else:
        other = other + 1

if other >= 1:
    ans_max = gray + brown + green + skyblue + blue + yellow + orange + red + other
    ans_min = gray + brown + green + skyblue + blue + yellow + orange + red + 0
    
    if ans_min == 0:
        ans_min = 1
    
    print(str(ans_min) + " " + str(ans_max))

else:
    ans = gray + brown + green + skyblue + blue + yellow + orange + red + other
    
    print(str(ans) + " " + str(ans))
    


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int H, W; cin >> H >> W;

  vstr b(H + 2);
  b[0] = string(W + 2, '.');
  reps(i, H) {
    string s; cin >> s;
    s = "." + s + ".";
    b[i] = s;
  }
  b[H + 1] = string(W + 2, '.');

  vector<vector<char>> ans(H, vector<char>(W));
  reps(i, H) reps(j, W) {
    if (b[i][j] == '#') {
      ans[i - 1][j - 1] = '#';
      continue;
    }
    int cnt = 0;
    for (int k = -1; k <= 1; k++)
    for (int l = -1; l <= 1; l++) {
      if (k == 0 && l == 0) continue;
      if (b[i + k][j + l] == '#') cnt++;
    }
    ans[i - 1][j - 1] = '0' + cnt;
  }
  
  rep(i, H) { rep(j, W) cout << ans[i][j]; cout << '\n'; }
}


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s[1]  == 'B'){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }
    
}

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

ll L, R;



int main(){
	cin >> L >> R;
	
	ll result = 2019;
	for ( ll i = L; i < R && i < L+2019; i++ ){
		for ( ll j = i+1; j <= R && j < i+1+2019; j++ ){
			result = min( result, (i*j) % 2019 );
		}
	}
	
	
	cout << result << endl;
	
	
	return 0;
}



Measured memory_bytes: 256
class Array
  # k <= self[i]である最小のiを求める
  # 存在しない場合はi=n
  # (lo, hi]
  def lower_bound(k)
    lo = -1
    hi = size
    while hi - lo > 1
      mid = (lo + hi) / 2
      k <= at(mid) ? hi = mid : lo = mid
    end
    return hi
  end

  # k < self[i]である最小のiを求める
  # 存在しない場合はi=n
  # (lo, hi]
  def upper_bound(k)
    lo = -1
    hi = size
    while hi - lo > 1
      mid = (lo + hi) / 2
      k < at(mid) ? hi = mid : lo = mid
    end
    return hi
  end

  # kより真に大きい要素の個数
  def count_greater(k)
    size - upper_bound(k)
  end

  # kより真に小さい要素の個数
  def count_less(k)
    lower_bound(k)
  end
end

n = gets.to_i
a = gets.split.map &:to_i
b = gets.split.map &:to_i
c = gets.split.map &:to_i
a.sort!
b.sort!
c.sort!

ans = 0
b.each do |b|
  ans += a.count_less(b) * c.count_greater(b)
end
puts ans


Measured memory_bytes: 23148
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()

N, K = ints()
D = [False]*10

for d in ints():
    D[d] = True

while any([D[int(d)] for d in str(N)]):
    N+=1

print(N)

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

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

int main() {
  int t,n,T,ans=0; cin >> n >> T;
  int y=0;
  REP(i,n) {
    cin >> t;
    ans += min(T,t-y);
    y = t;
  }
  cout << ans + T << endl;
  return 0;
}

Measured memory_bytes: 256
import math
import sys
from itertools import combinations

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


def circumcircle(ax, ay, bx, by, cx, cy):
    if (bx - ax) * (cy - ay) - (by - ay) * (cx - ax) == 0:
        return None
    D = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by))
    X = ((ax * ax + ay * ay) * (by - cy) + (bx * bx + by * by)
         * (cy - ay) + (cx * cx + cy * cy) * (ay - by)) / D
    Y = ((ax * ax + ay * ay) * (cx - bx) + (bx * bx + by * by)
         * (ax - cx) + (cx * cx + cy * cy) * (bx - ax)) / D
    R = math.sqrt((X - ax) * (X - ax) + (Y - ay) * (Y - ay))
    return X, Y, R


def diametercircle(ax, ay, bx, by):
    X = (ax + bx) / 2
    Y = (ay + by) / 2
    R = math.sqrt((X - ax) * (X - ax) + (Y - ay) * (Y - ay))
    return X, Y, R


def distance(ax, ay, bx, by):
    return math.sqrt((ax - bx) ** 2 + (ay - by) ** 2)


def intersectioncircle(ax, ay, ra, bx, by, rb):
    d = distance(ax, ay, bx, by)
    if d > ra + rb:
        return None
    if d < abs(ra - rb):
        return None
    if d == 0:
        return None
    t = (ra**2 - rb**2 + d**2) / (2 * d)
    h = math.sqrt(ra**2 - t**2 + sys.float_info.epsilon)
    x2 = ax + t * (bx - ax) / d
    y2 = ay + t * (by - ay) / d
    x3 = x2 + h * (by - ay) / d
    y3 = y2 - h * (bx - ax) / d

    x4 = x2 - h * (by - ay) / d
    y4 = y2 + h * (bx - ax) / d

    return x3, y3, x4, y4


def eat_count(cx, cy, t):
    eat = 0
    for xyc in XYC_array:
        dx, dy, c = xyc
        if distance(cx, cy, dx, dy) <= (t / c + 10 ** -8):
            eat += 1
    return eat


N, K = na()
XYC_array = naa(N)


mint = 0
maxt = 10 ** 6
eps = 10 ** -6

while(maxt - mint > eps):
    t = (mint + maxt) / 2
    ok_flag = 0
    for xyc in XYC_array:
        cx, cy, _ = xyc
        if eat_count(cx, cy, t) >= K:
            ok_flag = 1
            break
    if ok_flag == 1:
        maxt = t
        continue
    for p in combinations(range(N), 2):
        ax, ay, ca = XYC_array[p[0]]
        bx, by, cb = XYC_array[p[1]]
        if intersectioncircle(ax, ay, t / ca, bx, by, t / cb):
            X1, Y1, X2, Y2 = intersectioncircle(ax, ay, t / ca, bx, by, t / cb)
            if eat_count(X1, Y1, t) >= K or eat_count(X2, Y2, t) >= K:
                ok_flag = 1
                break
    if ok_flag == 1:
        maxt = t
    else:
        mint = t

print(t)


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

int main(void){
    int n;
    string a,b,c;
    int ans = 0;
    cin >> n >> a >> b >> c;
    
    for(int i = 0; i < n; i++){
        int count = 0;
        if(a[i] == b[i] && b[i] == c[i]){
            count = 0;
        }else if(a[i] == b[i] || b[i] == c[i] || a[i] == c[i]){
            count = 1;
        }else{
            count = 2;
        }
        ans += count;
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
"""#################################################################
【ABC119】
B - Digital Gifts
#################################################################"""

#インポート
import sys

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def SS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()

sum = 0
N = II()
for i in range(N):
    x, y = SS()
    if y == "JPY":
        sum += float(x)
    else:
        sum += float(x)*380000
print(sum)


Measured memory_bytes: 3064
N, K = map(int, input().split())
x = []
y = []
for i in range(N):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)
x_sorted = sorted(x)
y_sorted = sorted(y)

S_l = [[0 for i in range(N)] for j in range(N)]
S_rs = [[0 for i in range(N)] for j in range(N)]
S_ts = [[0 for i in range(N)] for j in range(N)]
S_s = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(N):
        count_l = 0
        count_rs = 0
        count_ts = 0
        count_s = 0
        for k in range(N):
            if -10 ** 9 <= x[k] <= x_sorted[i] and -10 ** 9 <= y[k] <= y_sorted[j]:
                count_l += 1
            if -10 ** 9 <= x[k] < x_sorted[i] and -10 ** 9 <= y[k] <= y_sorted[j]:
                count_rs += 1
            if -10 ** 9 <= x[k] <= x_sorted[i] and -10 ** 9 <= y[k] < y_sorted[j]:
                count_ts += 1
            if -10 ** 9 <= x[k] < x_sorted[i] and -10 ** 9 <= y[k] < y_sorted[j]:
                count_s += 1
        S_l[i][j] = count_l
        S_rs[i][j] = count_rs
        S_ts[i][j] = count_ts
        S_s[i][j] = count_s


def included(i, j, k, l):
    return S_l[j][l] - S_rs[i][l] - S_ts[j][k] + S_s[i][k]

ans = 4 * 10 ** 18
for i in range(N):
    for j in range(i + 1, N):
        for k in range(N):
            for l in range(k + 1, N):
                num = included(i, j, k, l)
                if num > K:
                    break
                elif num == K:
                    s = (x_sorted[j] - x_sorted[i]) * (y_sorted[l] - y_sorted[k])
                    if ans > s:
                        ans = s
                else:
                    continue
print(ans)


Measured memory_bytes: 3192