akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int a[] = fs.nextIntArray(n);
		
		long sum[] = new long[n+1];
		for(int i=0;i<n;i++)sum[i+1]=sum[i]+a[i];
		
		long dp[][] = new long[404][404];
		long inf = Long.MAX_VALUE/3;
		for(int i=0;i<404;i++)for(int j=0;j<404;j++) {
			if(i==j)dp[i][j]=0;
			else dp[i][j]=inf;
		}
		for(int i=0;i<402;i++) {//区間の幅
			for(int j=0;j<402;j++) {
				if(j+i>=n)break;
				for(int k=j;k<j+i;k++) {
					dp[j][j+i] = Math.min(dp[j][j+i],dp[j][k] + dp[k+1][j+i] + sum[j+i+1] - sum[j]);
				}
			}
		}
		System.out.println(dp[0][n-1]);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 24512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int n,t;
	cin >> n >> t;
	vector<int> a(n);
	REP(i,n) cin >> a[i];
	
	int profit = 0;
	int amin = a[0]; 
	int count = 1;
	FOR(i,1,n){
		if(profit == a[i]-amin){
			count++;
		}else if(profit < a[i]-amin){
			profit = a[i]-amin;
			count=1;
		}
		chmin(amin, a[i]);
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 3744
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,j,n,red=0,blue=0;
    string s;
    cin>>n>>s;
    for(i=0; s[i]; i++)
        if(s[i]=='R')
            red++;
        else
            blue++;
    if(red>blue)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;



    return 0;
}





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

int main() {

    int n;
    while (cin >> n, n) {

        int hws[24][60][60];
        rep(i, 24) rep(j, 60) rep(k, 60) hws[i][j][k] = 0;

        rep(i, n) {
            string s, e;
            cin >> s >> e;

            int h1 = stoi(s.substr(0, 2));
            int m1 = stoi(s.substr(3, 2));
            int s1 = stoi(s.substr(6, 2));

            int h2 = stoi(e.substr(0, 2));
            int m2 = stoi(e.substr(3, 2));
            int s2 = stoi(e.substr(6, 2));

            hws[h1][m1][s1] += 1;
            hws[h2][m2][s2] -= 1;
        }

        int t = 0, ans = 0;
        rep(i, 24) rep(j, 60) rep(k, 60) {
            t += hws[i][j][k];
            ans = max(t, ans);
        }

        cout << ans << endl;

    }

}

Measured memory_bytes: 3416
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String str, sub;
		int m, h;
		ArrayList<String> ans = new ArrayList<String>();
		
		while(true){
			str = sc.next();
			if(str.equals("-")){
				break;
			}
			
			StringBuilder sb = new StringBuilder(str);
			
			m = sc.nextInt();
			
			for(int i = 0; i < m; i++){
				h = sc.nextInt();
				
				sub = sb.substring(0, h);
				sb.delete(0, h);
				sb.append(sub);
			}
			
			ans.add(sb.toString());
		}
		
		for(String s : ans){
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 26252
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;


int main() {
  int n;
  scanf("%d\n", &n);
  bool e=false;
  for(int i=0; i<n; ++i) {
    char s[10];
    scanf("%s", s);
    if(s[0]=='Y') {
      e=true;
    }
  }
  printf("%s\n", e ? "Four" : "Three");
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<utility>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
string s;
int a[30],x;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++)
		a[s[i]-'A']++;
	for(int i=0;i<26;i++)
		if(a[i]==2)
			x++;
	if(x==2)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
const double PI=3.14159265358979323846;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
double a,b,h,m;
cin>>a>>b>>h>>m;
double theta=abs((2*PI*m/60)-(2*PI*((h/12)+(m/(12*60)))));
double ans=sqrtl(a*a+b*b-2*a*b*cosf64(theta));
cout<<fixed<<setprecision(10)<<ans<<endl;
return 0;
}

Measured memory_bytes: 4240
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n;
    cin >> n;
    VI a(n);
    int s = 0;
    REP(i,n){
        scanf("%d", &a[i]);
        s ^= a[i];
    }

    VI d(31);
    REP(i,n){
        int x = 0;
        REP(j,31) if ((a[i] >> j) & 1) {x = j; break;}
        d[x] = 1;
    }

    // int p;
    // FORR(i,30,0) if ((s >> i) & 1){p = i; break;}

    // cout << s << endl;
    // REP(i,31) cout << d[i] << " ";
    // cout << endl;

    int ans = 0;
    FORR(i,30,0){
        int x = (s >> i) & 1;
        int y = (s >> (i+1)) & 1;
        if (x != y){
            ans++;
            if (!d[i]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;

    return 0;
}






Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,K,sum=0;
    cin >> A >> B >> C >> K;

    for(int i=0;i<K;i++){
        if(A>0){
            A--;
            sum++;
        } else if(B>0){
            B--;
        } else if(C>0){
            C--;
            sum--;
        }
    }
    cout << sum;
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 1000111

typedef long long ll;
typedef long double ld;

multiset<int> s;

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		s.insert(a);
	}

	int m;
	scanf("%d", &m);
	for(int i = 0; i < m; i++){
		int a;
		scanf("%d", &a);
		auto it = s.find(a);
		if(it == s.end()){
			printf("NO\n");
			return 0;
		}
		else
			s.erase(it);
	}
	printf("YES\n");
	return 0;
}

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

int main() {
  int A;
  int B;
  cin >> A >> B;
  int ans;
  ans = A*B;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
n,m=[int(_) for _ in input().split()]
k=[]
for i in range(m):
    k.append([int(_) for _ in input().split()])
    k[-1].append([int(_) for _ in input().split()])
dp=[10**9 for _ in range(2**n)]
dp[0]=0
for i in range(m):
    id=0
    for j in range(k[i][1]):id+=2**(k[i][2][j]-1)
    for j in range(2**n):dp[j|id]=min(dp[j|id],dp[j]+k[i][0])
if dp[-1] == 10**9:
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 45544
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//みなさん天才的ですよね

ll num[2000000];
const int ma = (1 << 19) - 1;
bool query(ll n) {
	int n2 = (n * 3 & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) return 1;
		n2++;
	}
	return 0;
}
void add(ll n) {
	int n2 = (n * 3 & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) {
			return;
		}
		n2++;
	}
	num[n2] = n + 1;
}

int KH[300001], KW[300001];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int H, W, M;
	cin >> H >> W >> M;

	rep(i, M) {
		int h, w;
		cin >> h >> w;

		KH[h]++;
		KW[w]++;
		add(ll(h) * W + w);
	}

	int saidaih = -1;
	int *hh = KH, h = 0;
	rep1(i, H) {
		if (saidaih < KH[i]) {
			saidaih = KH[i];
			h = 1;
			hh[0] = i;
		}
		else if (saidaih == KH[i]) {
			hh[h++] = i;
		}
	}
	int saidaiw = -1;
	int *ww = KW, w = 0;
	rep1(i, W) {
		if (saidaiw < KW[i]) {
			saidaiw = KW[i];
			w = 1;
			ww[0] = i;
		}
		else if (saidaiw == KW[i]) {
			ww[w++] = i;
		}
	}

	if (ll(h) * w > M) {
		co(saidaih + saidaiw);
		return 0;
	}
	int atta = 0;
	rep(i, h) rep(j, w) {
		if (!query(ll(hh[i]) * W + ww[j])) {
			atta = 1;
			break;
		}
	}

	if (atta) co(saidaih + saidaiw);
	else co(saidaih + saidaiw - 1);

	Would you please return 0;
}

Measured memory_bytes: 10044
#include <iostream>
#include <vector>
#include <cstdio>

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> net(n);
    REP(i, m){
        int si, ti;
        cin >> si >> ti;
        si--; ti--;
        net.at(si).push_back(ti);
    }

    double ans = n + 1;
    for(int ng = -1; ng < n - 1; ++ng){
        if(ng != -1 && net.at(ng).size() == 1){
            continue;
        }
        vector<double> exp(n, 0);
        for(int x = n - 2; x >= 0; x--){
            double tmp = 0;
            double maxval = 0;
            for(int nxt : net.at(x)){
                tmp += exp.at(nxt) + 1.0;
                maxval = max(maxval, exp.at(nxt) + 1.0);
            }
            if(ng != x){
                exp.at(x) = tmp / (double)net.at(x).size();
            }else{
                exp.at(x) = (tmp - maxval) / (double)(net.at(x).size() - 1);
            }
        }
        ans = min(ans, exp.at(0));
    }
    printf("%.8f\n", ans);
    return 0;
}


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

int main() {
  int N,K,X,Y;
  cin >> N;
  cin >> K;
  cin >> X;
  cin >> Y;
  
  if(N<=K){
    cout << N*X << endl;
  }
  else if(N>K){
  cout << K*X+(N-K)*Y << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int h, w;
bool isRectangle(vector<string> &image, char target) 
{
    int left = w, right = 0, top = h, botton = 0;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(image[i][j] == target)
            {
                left = min(left, j);
                right = max(right, j);
                top = min(top, i);
                botton = max(botton, i);
            }
        }
    }
    for(int i = top; i <= botton; i++)
    {
        for(int j = left; j <= right; j++)
        {
            if(image[i][j] == target || image[i][j] == '?') continue;
            return false;
        }
    }
    for(int i = top; i <= botton; i++)
    {
        for(int j = left; j <= right; j++)
        {
            image[i][j] = '?';
        }
    }
    return true;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    while(n--)
    {
        cin >> h >> w;
        vector<string> image(h);
        for(int i = 0; i < h; i++) cin >> image[i];
        while(true)
        {
            // for(int i = 0; i < h; i++)
            // {
            //     for(int j = 0; j < w; j++) cout << image[i][j]; cout << endl;
            // }
            bool success = false;
            bool object = false;
            for(int i = 0; i < h; i++)
            {
                for(int j = 0; j < w; j++)
                {
                    if(image[i][j] == '.' || image[i][j] == '?') continue;
                    object = true;
                    if(isRectangle(image, image[i][j]))
                    {
                        success = true;
                    }
                }
            }
            if(object == false)
            {
                cout << "SAFE" << endl;
                break;
            }
            if(not success)
            {
                cout << "SUSPICIOUS" << endl;
                break;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 3172
use text_io::*;
// use std::collections::*;
// use std::process::exit;

fn main() {
    let n:String = read!();
    if n=="SSS" {
        println!("0");
    }
    if n=="RSS" {
        println!("1");
    }
    if n=="SRS" {
        println!("1");
    }
    if n=="SSR" {
        println!("1");
    }
    if n=="RRS" {
        println!("2");
    }
    if n=="RSR" {
        println!("1");
    }
    if n=="SRR" {
        println!("2");
    }
    if n=="RRR" {
        println!("3");
    }
}

Measured memory_bytes: 2112
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
import string
#======================================================#
def main():
    s = IS()
    n = len(s)
    sc = set(s)
    ans = 10**9
    for c in string.ascii_lowercase:
        if c not in sc: continue
        cnt = 0
        t = s
        for l in range(n):
            u = ''
            if set(t) == {c}: break
            for i in range(len(t)-1):
                if t[i] == c or t[i+1] == c:
                    u += c
                else:
                    u += t[i]
            cnt += 1
            t = u
        ans = min(cnt, ans)
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

int main() {
    ll  N, M;
    cin >> N >> M;
    vector<ll> a(M, 0);
    for(int i = 0; i < M; i++) cin >> a[i];
    ll ans = 0;
    ll dp[N + 1] = {0};

    for(int i = 0; i < M; i++){
        dp[a[i]] = -1;

        if(a[i] + 1 == a[i + 1]){
            cout << 0 << endl;
            return 0;
        }

    }

    if(dp[0] == 0){
        dp[0] = 1;
    }
    else{
        dp[1] = 1;
    }

    for(int i = 0; i < N; i++){
        ll tmp1, tmp2;
        if(dp[i + 1] == -1) continue;

        if(dp[i] == -1){
            tmp1 = 0;
        }
        else{
            tmp1 = dp[i];
        }

        if(i == 0 || dp[i - 1] == -1){
            tmp2 = 0;
        }
        else{
            tmp2 = dp[i - 1];
        }
        dp[i + 1] = (tmp1 + tmp2) % MOD;

    }

    cout << dp[N] << endl;

}


Measured memory_bytes: 4808
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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,K; cin>>N>>K;
  vector<ll> P(N); rep(i,N) {cin>>P[i]; P[i]--;}
  vector<ll> C(N); rep(i,N) cin>>C[i];
  
  ll ans=-INF;
  rep(i,N){
    ll next=P[i];
    vector<ll> score(1,C[next]);
    vector<ll> max_score(1,C[next]);
    for(int j=0;;j++){
      next=P[next];
      score.push_back(score[j]+C[next]);
      max_score.push_back(max(max_score[j],score[j+1]));
      if(i==next) break;
    }
    ll roop=score.size();
    
    if(K<=roop) {chmax(ans,max_score[K-1]); continue;}
    if(score[roop-1]<=0) chmax(ans,max_score[roop-1]);
    else{
      ll f=K/roop,amari=K%roop;
      ll sans=f*score[roop-1];
      if(amari>0) sans+=max_score[amari-1];
      chmax(ans,sans);
      chmax(ans,(f-1)*score[roop-1]+max_score[roop-1]);
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3820
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    res = 0
    if B == 1:
        res = 0
    elif B <= A:
        res = 1
    else:
        B -= A
        res = 1
        res += B // (A-1)
        if B % (A-1) > 0:
            res += 1
    
    print(res)
        

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


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

map<int,int> m;
int32_t main(){
	int n,tmp;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>tmp;
		m[tmp]++;
	}
	for(auto x=m.begin();x!=m.end();){
		if(x->second<2){
			x = m.erase(x);
		}
		else {
			++x;
		}
	}
	if(!m.size()){
		cout<<0;
		return 0;
	}
	int a1;
	auto t = m.end();
	t--;
	t->second-=2;
	a1 = t->first;
	if(t->second<2){
		m.erase(t);
	}
	if(!m.size()){
		cout<<0;
		return 0;
	}
	int a2;
	auto t2 = m.end();
	t2--;
	a2 = t2->first;
	cout<<a1*a2;
}


Measured memory_bytes: 6528
using System;
using System.Collections.Generic;

class Program {
    static int Main(string[] args) {

        for (int x = 1; x <= 9; x++) {
            for (int y = 1; y <= 9; y++) {
                Console.WriteLine(string.Format("{0}x{1}={2}", x, y, x * y));
            }
        }

        return 0;
    }
}

Measured memory_bytes: 9060
def distance(a,b):
    return abs((a-b)**2)

import math

n,d = map(int,input().split())
x = []
for i in range(n):
    x.append(list(map(int,input().split())))
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        current = 0
        for k in range(d):
            current += distance(x[i][k],x[j][k])
        current = math.sqrt(current)
        if float.is_integer(current):
            ans += 1
print(ans)

Measured memory_bytes: 9208
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main()
{
  string str;
  cin >> str;

  int len = str.length();

  if (str[0] != 'A')
  {
    cout << "WA" << endl;
    return 0;
  }

  int count = 0;
  for (int i = 2; i < len - 1; ++i)
  {
    if (str[i] == 'C')
      ++count;
  }
  if (count != 1)
  {
    cout << "WA" << endl;
    return 0;
  }

  count = 0;
  for (int i = 0; i < len; ++i)
  {
    if (isupper(str[i]) != 0)
      ++count;
  }
  if (count != 2)
  {
    cout << "WA" << endl;
    return 0;
  }

  cout << "AC" << endl;

  return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a[ohara],b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>n>>k;
      ll ma=0;
      rep(i,n){
        cin>>a[i];
        ma=max(ma,a[i]);
      }
      if(ma<k)Cout("IMPOSSIBLE");
      else{
        pos=a[0];
        rrep(i,1,n){
          pos=__gcd(pos,a[i]);
        }
        //Cout(pos);
        if(k%pos==0)Cout("POSSIBLE");
        else Cout("IMPOSSIBLE");
      }
    
       
return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()

int main(){
    int n, w;
    while(cin >> n >> w, n|w){
        vector<int> v(11);
        int h;
        while(n--){
            cin >> h;
            v[h/w]++;
        }
        h = *max_element(all(v));
        n = v.rend() - find_if(rall(v), [](int x){return x != 0;}) - 1;
        double ans = 0.01;
        rep(i, n)ans += 1.0 * v[i] / h * (n - i) / n;
        cout << fixed << setprecision(6) << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    
    //最下点、最終的な和 
    vector<pair<int,int>> p_plus;//最終的な和がプラスのもの
    vector<pair<int,int>> p_minus;//最終的な和がマイナスのもの
    int sum = 0;
    rep(i,n) {
        string s;
        cin >> s;
        pair<int,int> p(0,0);
        rep(i,s.size()) {
            if(s[i] == '(') p.second++;
            else {
                p.second--;
                chmin(p.first, p.second);
            }
        }
        sum+=p.second;
        if(p.second >= 0) p_plus.push_back(p);
        else p_minus.push_back(p);
    }
    if(sum != 0) {
        cout << "No" << endl;
        return 0;
    }
    int now_pos = 0;
    sort(p_plus.begin(), p_plus.end(), greater<pair<int,int>>());
    rep(i,p_plus.size()) {
        if(now_pos+p_plus[i].first < 0 ) {cout << "No" << endl;return 0;}  
        now_pos += p_plus[i].second;  
    }

    now_pos = 0;
    rep(i, p_minus.size()) {
        p_minus[i].second *= -1;
        p_minus[i].first += p_minus[i].second;
    }
    sort(p_minus.begin(), p_minus.end(), greater<pair<int,int>>());
    rep(i,p_minus.size()) {
        if(now_pos+p_minus[i].first < 0 ) {cout << "No" << endl;return 0;}  
        now_pos += p_minus[i].second;  
    }
    cout << "Yes" << endl;    
}

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

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

    bool ok = true;

    if (s.size() % 2 == 0) {
        for (int i = 0; i < s.size(); i+=2) {
            if (s.substr(i, 2) != "hi") ok = false;
        }
    } else {
        ok = false;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main()
{

    int l,r,d;

    cin>>l>>r>>d;

    int counts=0;

    for(int i=l;i<=r;i++){
        if(i%d==0){
            counts++;
        }
    }

    cout<<counts<<endl;
    return 0;
}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

using namespace std;

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

bool is_change(string str,char* tmp,int pos, int len){
	const char A[] = {'p','e','a','c','h'};
	const char B[] = {'a','p','p','l','e'};
	if(str.substr(pos,len) == "apple"){
		for(int i=pos,j=0;i<pos+len,j<5;i++,j++){
			tmp[i] = A[j];
		}
		return true;
	}

	else if(str.substr(pos,len) == "peach"){
		for(int i=pos,j=0;i<pos+len,j<5;i++,j++){
			tmp[i] = B[j];
		}

		return true;
	}

	return false;
}

int main(){

	string str;
	while(getline(cin,str)){
		char tmp[1024];
		strcpy(tmp,str.c_str());
		for(int i=0;i+4<str.size();i++){
			if(is_change(str,tmp,i,5)) i+=5;
		}

		cout << tmp << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    int p[m], y[m];
    vector<set<pii>> s(n + 1);
    rep(i, m) {
        cin >> p[i] >> y[i];
        s[p[i]].insert({y[i], i});
    }
    vector<string> ans(m);
    for (int i = 1; i <= n; i++) {
        int cnt = 0;
        for (pii x : s[i]) {
            string t1 = to_string(i);
            while ((int)t1.size() < 6) {
                t1 = '0' + t1;
            }
            string t2 = to_string(++cnt);
            while ((int)t2.size() < 6) {
                t2 = '0' + t2;
            }
            ans[x.second] = t1 + t2;
        }
    }
    rep(i, m) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 16272
import math
N, K = map(int, input().strip().split())

ret = 0

for i in range(N):
    if (i + 1) < K:
        ret += (1.0 / N) * (0.5 ** (math.ceil(math.log2(K / (i+1)))))
    else:
        ret += (1.0 / N)
print(ret)

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

using namespace std;

int main()
{
    int n ;
    cin>>n ;
    int arr[n] , dp[n];
    for(int i = 0 ; i < n ; ++i)
        cin>>arr[i] ;
    dp[n-1] = 0 ;
    for(int j = n-2 ; j >= 0 ; --j)
    {
        if(j == n-2)
            dp[j] = abs(arr[n-1] - arr[j]);
        else
            dp[j] = min(dp[j+1] + abs(arr[j+1] - arr[j]) , dp[j+2] + abs(arr[j+2] - arr[j]));
    }
    return cout<<dp[0]<<"\n" , 0 ;
}


Measured memory_bytes: 1024
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n=gets.to_i
s=gets.chomp
if n.odd?
  puts "No"
else
  t=s.split("").slice(0,n/2).join("")
  if t+t==s
    puts "Yes"
  else
    puts "No"
  end
end

Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    string S; cin >> S;
    bool frag=false;
    int pos=0,ans=0;
    rep(i,SZ(S)){
        if(S[i]=='A') {if(i&&S[i-1]=='B')pos=0; pos++; frag=false;}
        if(S[i]=='B') {
            if(!frag) frag=true; 
            else pos=0;
        }
        if(S[i]=='C') {
            if(frag) {
                ans+=pos; frag=false;
            }
            else{
                pos=0;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 720
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = readInt >>= flip replicateM getLine >>= print . sum . map ( \( x :: Integer ) -> x * ( x - 1 ) `div` 2 ) . map ( fromIntegral . length ) . group . sort . map sort

Measured memory_bytes: 113020
n = int(input())
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))

c = 0
ans = 0
for i in range(n):
    c += a[0][i]
    ans = max(ans, c + sum(a[1][i:]))

print(max(c+a[1][n-1], ans))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
//使い方　インスタンス化(頂点数)　uniteつなぐ(双方向注意) same判定
int main()
{
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind tree(n);
    for (int i = 0; i < k; i++)
    {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        tree.unite(p, q);
        tree.unite(q, p);
    }
    UnionFind tree1(n);
    for (int i = 0; i < l; i++)
    {
        int r, s;
        cin >> r >> s;
        r--;
        s--;
        tree1.unite(r, s);
        tree1.unite(s, r);
    }
    using pint = pair<int, int>;
    map<pint, int> mp;
    for (int i = 0;i<n;i++){
        pint p  (tree.root(i), tree1.root(i));
        mp[p]++;
    }
    for (int i = 0; i < n;i++){
        pint p(tree.root(i), tree1.root(i));
        cout << mp[p] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 13568
#include <cstdio>
using namespace std;
int a,b,cnt;
int n;
bool flag=false;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		scanf("%d%d",&a,&b);
		if(a==b)++cnt;
		else cnt=0;
		if(cnt==3)flag=true;
	}
	if(flag)printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 1660
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    print(int((n//500)*1000+((n%500)//5)*5))
if __name__ == "__main__":
    main()

Measured memory_bytes: 63980
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

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

  string s;
  cin >> s;
  if(s[s.size()-1] == '2') {cout << "hon" << endl; return 0; }
  if(s[s.size()-1] == '4') {cout << "hon" << endl; return 0; }
  if(s[s.size()-1] == '5') {cout << "hon" << endl; return 0; }
  if(s[s.size()-1] == '7') {cout << "hon" << endl; return 0; }
  if(s[s.size()-1] == '9') {cout << "hon" << endl; return 0; }
  if(s[s.size()-1] == '0') {cout << "pon" << endl; return 0; }
  if(s[s.size()-1] == '1') {cout << "pon" << endl; return 0; }
  if(s[s.size()-1] == '6') {cout << "pon" << endl; return 0; }
  if(s[s.size()-1] == '8') {cout << "pon" << endl; return 0; }
  if(s[s.size()-1] == '3') {cout << "bon" << endl; return 0; }
  return 0;
}

Measured memory_bytes: 3640
ans i =
  let r = i `mod` 7
  in
    case r of
      0 -> "thu"
      1 -> "fri"
      2 -> "sat"
      3 -> "sun"
      4 -> "mon"
      5 -> "tue"
      6 -> "wed"

main = do
  l <- getLine
  let i = read l :: Int
      o = ans i
  putStrLn o
  

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

using namespace std;
typedef long long LL;

int h,m;
char a[55][55];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int ans;
int dfs(int x, int y, int ans)
{
	a[x][y] = '.';

	for(int i = 0;i < 4;i++)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx > 0 && nx <= h && ny > 0 && ny <= m && a[nx][ny] == '#')
		{
			ans++;
		//	cout << ans << "   K:" << nx <<"  nnnn" << ny << endl;
			dfs(nx, ny, ans);

		}
	}
	return ans;
}


int main()
{
	scanf("%d %d",&h,&m);
	for(int i = 1;i <= h;i++)
	{
		for(int j = 1;j <=m;j++)
		{
			scanf(" %c",&a[i][j]);
		}
	}
	for(int i = 1;i <= h;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			ans = 0;
			if(a[i][j] == '#')
			{
			//	cout << i << j << "i  j" << endl;
				int y  = dfs(i ,j,1);
			//	cout << y << endl;
				if(y == 1)
				{
					printf("No\n");
					return 0;
				}
			}
		}
	}
	printf("Yes\n");
}

Measured memory_bytes: 384
a = [0] * 100
while True:
    try:
        a[int(input()) - 1] += 1
    except:
        break

flag = False
for i in range(100)[::-1]:
    if flag:
        exit()
    for j in range(100):
        if a[j] == i:
            flag = True
            print(j + 1)


Measured memory_bytes: 5592
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include <functional>
#include <queue>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

int main() {
	char b; cin >> b;

	if (b == 'A') {
		cout << "T" << endl;
	}
	else if (b == 'T') {
		cout << "A" << endl;
	}
	else if (b == 'C') {
		cout << "G" << endl;
	}
	else if (b == 'G') {
		cout << "C" << endl;
	}









}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



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

    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;
 
#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
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;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}
 
 
void Dijkstra(Graph& G, ll s, Array& d, Array& u, ll l) {//O(|E|log|V|)
	d.resize(G.size());
	u.resize(G.size());
	REP(i, d.size())d[i] = INF;
	REP(i, u.size())u[i] = INF;
	d[s] = 0;
	u[s] = 0;
	priority_queue<pair<pair<ll, ll>, ll>,vector< pair<pair<ll, ll>, ll>>,greater<pair<pair<ll, ll>, ll>>> q;
 
	q.push(make_pair(make_pair(0, 0), s));
	while (!q.empty()) {
		ll k = q.top().first.first;
		ll dd = q.top().first.second;
		ll v = q.top().second;
		q.pop();
		if (u[v] < k)continue;
		if (d[v] < dd)continue;
 
		REP(i, G[v].size()) {
			Edge e = G[v][i];
			ll nd = dd + e.cap;
			ll nk = k;
			if (nd > l) {
				nd = e.cap;
				nk++;
			}
			if (u[e.to] > nk) {
				u[e.to] = nk;
				d[e.to] = nd;
				q.push(make_pair(make_pair(nk, nd), e.to));
			}
			else if (u[e.to] == nk && d[e.to] > nd) {
				d[e.to] = nd;
				q.push(make_pair(make_pair(nk, nd), e.to));
			}
		}
	}
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
 
	ll n, m, l;
	cin >> n >> m >> l;
	Graph g(n);
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		if(c<=l) add_edge(g, a, b, c, true, c);
	}
 
	Matrix ans(n);
	Matrix d(n);
 
	REP(i, n) {
		Dijkstra(g, i, d[i], ans[i], l);
	}
	/*
	for (auto i : ans) {
		for (auto j : i) {
			cout << j << " ";
		}
		cout << endl;
	}
	*/
 
	ll q;
	cin >> q;
 
	REP(i, q) {
		ll s, t;
		cin >> s >> t;
		s--; t--;
		if (ans[s][t] != INF) {
			cout << ans[s][t] << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
 
	return 0;
}

Measured memory_bytes: 7296
a,b = map(int,input().split(" "))
ar = []
for i in range(a):
    l = list(input())
    ar.append(l)
count = 0
for i in range(a):
    for j in range(b):
        if ar[i][j] == "#":
            if i == 0:
                if j == 0:
                    if ar[i+1][j] == "." and ar[i][j+1] == ".":
                        count += 1
                        break
                elif j == b-1:
                    if ar[i+1][j] == "." and ar[i][j-1] == ".":
                        count += 1
                        break
                else:
                    if ar[i+1][j] == "." and ar[i][j-1] == "." and ar[i][j+1] == ".":
                        count += 1
                        break
            elif i == a-1:
                if j == 0:
                    if ar[i-1][j] == "." and ar[i][j+1] == ".":
                        count += 1
                        break
                elif j == b-1:
                    if ar[i-1][j] == "." and ar[i][j-1] == ".":
                        count += 1
                        break
                else:
                    if ar[i-1][j] == "." and ar[i][j-1] == "." and ar[i][j+1] == ".":
                        count += 1
                        break
            else:
                if j == 0:
                    if ar[i+1][j] == "." and ar[i][j+1] == "." and ar[i-1][j] == ".":
                        count += 1
                        break
                elif j == b-1:
                    if ar[i+1][j] == "." and ar[i][j-1] == "." and ar[i-1][j] == ".":
                        count += 1
                        break
                else:
                    if ar[i+1][j] == "." and ar[i][j-1] == "." and ar[i][j+1] == "." and ar[i-1][j] == ".":
                        count += 1
                        break
if count == 0:
    print("Yes")
else:
    print("No")

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

public class SegmentTree
{
    public int N { get; private set; }
    public int[] Node;
    public int InvalidVal { get; private set; }

    public SegmentTree(int[] a, int invVal)
    {
        InvalidVal = invVal;
        for (N = 1; N < a.Length; N *= 2) ;
        Node = new int[2 * N - 1];
        for (int i = 0; i < Node.Length; i++)
        {
            Node[i] = InvalidVal;
        }
        for (int i = 0; i < a.Length; i++)
        {
            Node[N + i - 1] = a[i];
        }
        for (int i = N - 2; i >= 0; i--)
        {
            Node[i] = Sum(Node[2 * i + 1], Node[2 * i + 2]);
        }
    }

    public void Update(int x, int v)
    {
        x += (N - 1);
        Node[x] = v;

        while (x > 0)
        {
            x = (x - 1) / 2;
            Node[x] = Sum(Node[2 * x + 1], Node[2 * x + 2]);
        }
    }

    public int Get(int a, int b)
    {
        return Get(a, b, 0, 0, N);
    }

    private int Get(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
        {
            return InvalidVal;
        }
        if (a <= l && r <= b)
        {
            return Node[k];
        }

        var vl = Get(a, b, 2 * k + 1, l, (l + r) / 2);
        var vr = Get(a, b, 2 * k + 2, (l + r) / 2, r);
        return Sum(vl, vr);
    }

    private static int Sum(int a, int b)
    {
        return a + b;
    }
}

public class Query
{
    // 1オリジン [L,R)
    public int L;
    public int R;
    public int Answer;

    public Query(string s)
    {
        var vals = s.Split(' ').Select(int.Parse).ToArray();
        L = vals[0];
        R = vals[1] + 1;
    }
}

public static class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var Q = vals[1];
        // 1オリジン c[0]はダミー
        var c = new int[1].Concat(Console.ReadLine().Split(' ').Select(int.Parse)).ToArray();
        var queries = new List<Query>();
        for (int q = 0; q < Q; q++)
        {
            queries.Add(new Query(Console.ReadLine()));
        }

        var segtree = new SegmentTree(c, 0);
        var cur = 1;
        var lastIndex = new int[N + 1];
        foreach (var q in queries.OrderBy(q => q.R))
        {
            for (; cur < q.R; cur++)
            {
                var v = c[cur];
                segtree.Update(lastIndex[v], 0);
                segtree.Update(cur, 1);
                lastIndex[v] = cur;
            }
            q.Answer = segtree.Get(q.L, q.R);
        }

        Console.WriteLine(string.Join(Environment.NewLine, queries.Select(q => q.Answer)));
    }
}

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

int main(){
    int n,k;
    cin >> n >>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int ans =0;
    for(int i=0;i<k;i++)ans += a[i];
    cout << ans << endl;
 }


Measured memory_bytes: 256
MOD=2019

S=list(int(s) for s in input()[::-1])
T=[S[0]]
for i in range(1,len(S)):
    T.append(T[-1]+S[i]*pow(10,i,MOD))
cnt={}
for i in range(2019):
    cnt[i]=0
for t in T:
    cnt[t%MOD]+=1
ans=0
for i in range(2019):
    c=cnt[i]
    if c>=2:
        ans+=c*(c-1)//2
ans+=cnt[0]
print(ans)

Measured memory_bytes: 18808