akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
public class Main {
 
	static long solve(int n, int[] a) {
		long sum = 0;
		long ans = 0;
		long mod = (long) Math.pow(10, 9) + 7;
 
		for (int i = 0; i < n; i++) {
			sum += a[i];
			sum %= mod;
		}
 
		for (int i = 0; i < n; i++) {
			sum -= a[i];
			if (sum < 0)
				sum += mod;
			ans += a[i] * sum;
			ans %= mod;
		}
 
		return ans;
	}
 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
 
		int n = stdIn.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
		}
		long result = solve(n, a);
		System.out.println(result);
 
		stdIn.close();
	}
}


Measured memory_bytes: 60204
#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	selection_sort(vector<int> &A, int n)
{
	int		sw;

	sw = 0;
	rep(i, n - 1)
	{
		int		minj;

		minj = i;
		for (int j = i + 1; j < n; j++)
		{
			if (A.at(j) < A.at(minj))
				minj = j;
		}
		if (minj != i)
		{
			swap(A.at(i), A.at(minj));
			sw++;
		}
	}
	return (sw);
}

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

	vector<int>	A(n);
	rep(i, n)
		cin >> A.at(i);

	int	sw;

	sw = selection_sort(A, n);
	rep(i, n)
	{
		if (i)
			cout << ' ';
		cout << A.at(i);
	}
	cout << endl;
	cout << sw << endl;
}



Measured memory_bytes: 3132
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_154
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            string s = Read();
            for(int i = 0; i < s.Length; i++)
            {
                Write('x');
            }
            WriteLine();
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
function main(input) {
  const tmp = input.trim().split(' ').map((n) => parseInt(n, 10))
  const a = tmp[0]
  const b = tmp[1]
  const c = tmp[2]
  const d = tmp[3]

  if (Math.abs(a - c) <= d || (Math.abs(a - b) <= d && Math.abs(b - c) <= d)) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29548
from typing import List


class DP:
    N: int
    table: List[List[int]]
    max_all: int
    max_arr: List[int]
    inc: int

    def __init__(self, N: int, x: int, y: int):
        self.N = N
        self.table = [[-(1 << 28)] * (N + 1) for _ in range(N + 1)]
        self.table[x][y] = self.table[y][x] = 0
        self.max_all = 0
        self.max_arr = [-(1 << 28)] * (N + 1)
        self.max_arr[x] = self.max_arr[y] = 0
        self.inc = 0

    def update(self, p: int, q: int, r: int) -> None:
        if p == q == r:
            self.inc += 1
            return

        npqr = self._update_pqr(p, q, r)
        nqrp = self._update_pqr(q, r, p)
        nrpq = self._update_pqr(r, p, q)

        npq = self._update_pq(p, q)
        nqr = self._update_pq(q, r)
        nrp = self._update_pq(r, p)

        np = self._update_p(p)
        nq = self._update_p(q)
        nr = self._update_p(r)

        pq, qr, rp = None, None, None

        if p == q:
            pq = self._update_pair(p, r)

        if q == r:
            qr = self._update_pair(q, p)

        if r == p:
            rp = self._update_pair(r, q)

        self._update_maximum(q, r, npqr)
        self._update_maximum(r, p, nqrp)
        self._update_maximum(p, q, nrpq)

        self._update_maximum(p, q, npq)
        self._update_maximum(q, r, nqr)
        self._update_maximum(r, p, nrp)

        for k in range(self.N + 1):
            self._update_maximum(k, p, np[k])
            self._update_maximum(k, q, nq[k])
            self._update_maximum(k, r, nr[k])

        if pq:
            for k in range(self.N + 1):
                self._update_maximum(k, r, pq[k])

        if qr:
            for k in range(self.N + 1):
                self._update_maximum(k, p, qr[k])

        if rp:
            for k in range(self.N + 1):
                self._update_maximum(k, q, rp[k])


    def _update_maximum(self, x: int, y: int, v: int) -> None:
        self.table[x][y] = self.table[y][x] = max(self.table[x][y], v)
        self.max_all = max(self.max_all, v)
        self.max_arr[x] = max(self.max_arr[x], v)
        self.max_arr[y] = max(self.max_arr[y], v)

    def _update_pair(self, p: int, q: int) -> List[int]:
        return [max(self.table[k][q], self.table[k][p] + 1, self.table[p][k] + 1) for k in range(self.N + 1)]

    def _update_pqr(self, p: int, q: int, r: int) -> int:
        return max(self.table[q][r], self.table[p][p] + 1)

    def _update_pq(self, p: int, q: int) -> int:
        return max(self.table[p][q], self.max_all)

    def _update_p(self, p) -> List[int]:
        return [max(self.table[p][k], self.table[k][p], self.max_arr[k]) for k in range(self.N + 1)]

    def ans(self):
        return self.max_all + self.inc


N = int(input())
A = list(map(int, input().split())) + [0, 0]

dp = DP(N, A[0], A[1])

for i in range(N):
    Z = A[3 * i + 2: 3 * i + 5]
    dp.update(Z[0], Z[1], Z[2])
    # print("out", dp.table, dp.max_all, dp.max_arr)

print(dp.ans())


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

#define endl '\n'

const int N = 1e5+5;
int dp[N][3];
int a[N];
int b[N];
int c[N];


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

    int n;  cin >> n;
    
    for(int i = 0; i < n; i++)
        cin >> a[i] >> b[i] >> c[i];

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i = 1; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j == 0)
                dp[i][j] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
            else if(j == 1)
                dp[i][j] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i]);
            else
                dp[i][j] = max(dp[i-1][0] + c[i], dp[i-1][1] + c[i]);
        }
    }

    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
    return 0;
}


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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  vector<vector<int>> a(n, vector<int> (m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    for (int j = 0; j < m; j++) {
      tmp += a[i][j] * b[j];
    }
    if (tmp + c > 0) {
      ans++;
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cctype>
#include <cmath>
#include <fstream>

using namespace std;

typedef long long ll;
#define REP(i,k) for(int (i)=0;(i)<(k);(i)++)
#define INF ~(1<<31)
#define CLR(a) memset((a),0,sizeof((a)))
#define EPS 1e-9
#define DBG 1
#define D(s,v) if(DBG) cout<<(s)<<": "<<(v)<<endl;
#define DVEC(s,v) if(DBG) {cout<<(s)<<": "; for(int i=0;i<(v).size();i++) cout<<(v)[i]<<" "; cout<<endl;}
#define DARR(s,v,n) if(DBG) {cout<<(s)<<": "; for(int i=0;i<n;i++) cout<<(v)[i]<<" "; cout<<endl;}

int main(){
    ios_base::sync_with_stdio(0);

    int v[3][3]; CLR(v);
    while(cin>>v[0][0]){
        for(int i=0;i<3;i++)
        for(int j=0;j<3;j++){
            if(i==0 && j==0) continue;
            cin>>v[i][j];
        }

        bool good = 0;

        for(int a0=0;a0<=100;a0++){
            for(int a1=0;a1<=100;a1++){
                for(int a2=0;a2<=100;a2++){
                    bool curgood = 1;
                    for(int k=0;k<3;k++){
                        int b = v[k][0] - a0;
                        if(!(b+a1 == v[k][1] && b+a2 == v[k][2])){
                            curgood = 0;
                        }
                    }

                    if(curgood){
                        good = 1;
                    }
                }
            }
        }

        if(good) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

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

#define J 1
#define O 2
#define I 3
#define JO 4
#define JI 5
#define OI 6
#define JOI 7

#define MAX 10007

int dp[8][1005] ={0};

int main(void){
	int n;
	cin >> n;
	string sc;
	cin >> sc;

	dp[J][0] = 1;
	reep(i,1,n+1){
		if(sc[i-1]=='J'){
			dp[J][i] 	+= (dp[J][i-1] + dp[JO][i-1] + dp[JI][i-1] + dp[JOI][i-1])%MAX;
			dp[JO][i] 	+= (dp[J][i-1] + dp[JO][i-1] + dp[JI][i-1] + dp[JOI][i-1] + dp[O][i-1] + dp[OI][i-1])%MAX;
			dp[JI][i] 	+= (dp[J][i-1] + dp[JO][i-1] + dp[JI][i-1] + dp[JOI][i-1] + dp[I][i-1] + dp[OI][i-1])%MAX;
			dp[JOI][i] 	+= (dp[J][i-1] + dp[JO][i-1] + dp[JI][i-1] + dp[JOI][i-1] + dp[I][i-1] + dp[O][i-1] + dp[OI][i-1])%MAX;
		}else if(sc[i-1]=='O'){
			dp[O][i] 	+= (dp[O][i-1] + dp[OI][i-1] + dp[JO][i-1] + dp[JOI][i-1])%MAX;
			dp[OI][i]	+= (dp[O][i-1] + dp[OI][i-1] + dp[JO][i-1] + dp[JOI][i-1] + dp[I][i-1] + dp[JI][i-1])%MAX;
			dp[JO][i]	+= (dp[O][i-1] + dp[OI][i-1] + dp[JO][i-1] + dp[JOI][i-1] + dp[J][i-1] + dp[JI][i-1])%MAX;
			dp[JOI][i]	+= (dp[O][i-1] + dp[OI][i-1] + dp[JO][i-1] + dp[JOI][i-1] + dp[J][i-1] + dp[I][i-1] + dp[JI][i-1])%MAX;
		}else{
			dp[I][i]	+= (dp[I][i-1] + dp[OI][i-1] + dp[JI][i-1] + dp[JOI][i-1])%MAX;
			dp[OI][i]	+= (dp[I][i-1] + dp[OI][i-1] + dp[JI][i-1] + dp[JOI][i-1] + dp[O][i-1] + dp[JO][i-1])%MAX;
			dp[JI][i]	+= (dp[I][i-1] + dp[OI][i-1] + dp[JI][i-1] + dp[JOI][i-1] + dp[J][i-1] + dp[JO][i-1])%MAX;
			dp[JOI][i]	+= (dp[I][i-1] + dp[OI][i-1] + dp[JI][i-1] + dp[JOI][i-1] + dp[J][i-1] + dp[O][i-1] + dp[JO][i-1])%MAX;
		}
	}

	int ans = 0;
	reep(i,1,1<<3){
		ans += dp[i][n];
		ans %= MAX;
	}

	cout << ans << endl;

    /*printf("JOI->%d\n",dp[JOI][1]);
	reep(i,1,1<<3){
        printf("--%d\n",dp[i][2]);
	}*/
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll inv[1000000];
ll FactorialInv[1000000];
ll Factorial[1000000];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    inv[1] = 1;
    FactorialInv[1] = 1;
    Factorial[1] = 1;
    for(int i = 2; i < 1000000; i++){
        inv[i] = beki(i, mod - 2);
        Factorial[i] = Factorial[i - 1] * i % mod;
        FactorialInv[i] = FactorialInv[i - 1] * inv[i] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}
ll dp[3005][3005];
ll A[3005];

int main() {
    //cout.precision(10);
    init_combination();
    ll N, Q;
    cin >> N >> Q;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            if(A[i] > A[j]) {
                dp[i][j] = 1;
            }
        }
    }
    for(int TIME = 1; TIME <= Q; TIME++) {
        ll X, Y;
        cin >> X >> Y;
        ll tmp = (dp[X][Y] + dp[Y][X]) * inv[2] % mod;
        dp[X][Y] = tmp;
        dp[Y][X] = tmp;
        for(int index = 1; index <= N; index++) {
            if(index == X || index == Y) continue;
            tmp = (dp[index][X] + dp[index][Y]) * inv[2] % mod;
            dp[index][X] = tmp;
            dp[index][Y] = tmp;
            tmp = (dp[X][index] + dp[Y][index]) * inv[2] % mod;
            dp[X][index] = tmp;
            dp[Y][index] = tmp;
        }
    }
    ll ans = 0;
    for(int i = 1; i <= N; i++) {
        for(int j = i + 1; j <= N; j++) {
            ans = (ans + dp[i][j]) % mod;
        }
    }
    for(int i = 1; i <= Q; i++) {
        ans = ans * 2 % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 94336
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int main(){
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  int ans;
  if(n>k){
    ans = (k)*x + (n-k)*y;
  }
  else{
    ans = n*x;
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin >> n;
   vector <long> h(n);
    for(long i = 0; i < n; i++)cin>>h[i];
    if(n==1){
        cout << "Yes" << endl;
        return 0;
    }
 
    for(long i = (n-1); i > 0; i--){
        if(h[i-1]>(h[i]+1)){
            cout << "No" << endl;
            return 0;
        }else if(h[i-1]>h[i]){
            h[i-1]--;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    x = sorted(list(map(int, input().split())))
    if n >= m:
        print(0)
    else:
        dis = []
        for i in range(m - 1):
            dis.append(x[i + 1] - x[i])
        dis.sort(reverse=True)
        print(max(x) - min(x) - sum(dis[:n - 1]))



if __name__ == '__main__':
    main()


Measured memory_bytes: 91880
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);	
		String s = sc.next();
		int num = 0;
		
		if(s.equals("SUN")) {
		 num = 7;
		} else if(s.equals("MON")) {
			 num = 6;
			} else if(s.equals("TUE")) {
				 num = 5;
			} else if(s.equals("WED")) {
				 num = 4;
			} else if(s.equals("THU")) {
				 num = 3;
			} else if(s.equals("FRI")) {
				 num = 2;
			} else if(s.equals("SAT")) {
				 num = 1;
			}
	
		
		System.out.println(num);
		
	
		
		
		
	}
}


Measured memory_bytes: 23764
#include <iostream>

using namespace std;

#define IN(v) if (scanf("%d", &v)<1);
#define OUT(v) printf("%d\n", v)

char S[(int)2e5];
bool can_reach(int a, int c) {
  --a; --c;
  int i = a;
  if (a > c)
    return false;
  while (i <= c) {
    if (i == c)
      return true;
    if (S[i+1] == '.')
      ++i;
    else if (S[i+2] == '.')
      i += 2;
    else
      return false;
  }
  return true;
}

int main() {
  int N, A, B, C, D;
  IN(N); IN(A); IN(B); IN(C); IN(D);
  if (scanf("%s", S));

  if (C < D)
    printf(can_reach(B, D) && can_reach(A, C) ? "Yes\n" : "No\n");
  else {
    int a = A - 1, b = B - 1;
    --C;
    --D;

    while (true) {
      while (a < C && (S[a+1] == '.' || S[a+2] == '.')) {
        if (a+1 < N && S[a+1] == '.' && a+1 != b)
          ++a;
        else if (a+2 < N && S[a+2] == '.' && a+2 != b)
          a += 2;
        else
          break;
      }
      if (a > b) {
        printf(can_reach(b+1, D+1) && can_reach(a+1, C+1) ? "Yes\n" : "No\n");
        return 0;
      }
      if (b+1 < N && S[b+1] == '.' && b+1 != a)
        ++b;
      else if (b+2 < N && S[b+2] == '.' && b+2 != a)
        b += 2;
      else {
        printf("No\n");
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 384
#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) << " "

int main(){
    map<string, int>b,r;
    int n,m;
    string tmp;
    cin>>n;rep(i,n){cin>>tmp;b[tmp]++;}
    cin>>m;rep(i,m){cin>>tmp;r[tmp]++;}
    int mx = 0;
    for(auto i=b.begin();i!=b.end();i++){
        mx = max(mx, i->second-r[i->first]);
    }
    co(mx);
}

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

#ifdef INPUT
#include <sstream>
stringstream input(R"(
2 3 2 0
)");
#define cin input
#endif

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

	if (k%2 == 0)
		cout << a-b << endl;
	else
		cout << b-a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000



int main(){
	
	int N;
	cin>>N;
	
	vector<int> C(N-1),S(N-1),F(N-1);
	for(int i=0;i<N-1;i++){
		cin>>C[i]>>S[i]>>F[i];
	}
	
	for(int i=0;i<N;i++){
		int now = 0;
		for(int j=i;j<N-1;j++){
			now = (now+F[j]-1)/F[j];
			now *= F[j];
			if(now<S[j])now=S[j];
			now+=C[j];
		}
		cout<<now<<endl;
	}
	
    return 0;
}


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

typedef struct tag_pair{
	int Pos;
	int Cost;
}Pair;	

Pair nP(int p,int c){Pair P;P.Pos=p;P.Cost=c;return P;}

int cmp(const void *a,const void *b);
int WF[102][102];

Pair E[102][102];
int Ec[102];
int From[6000],To[6000],Cost[6000];

ll dp[102];
ll dp2[102];


int Min(int x,int y){return x>y?y:x;}

int main(){
	int N,M,P;
	int i,j,k;
	int c;
	int now;
	while(1){
		scanf("%d %d %d\n",&N,&M,&P);
		if(N==0&&M==0&&P==0)break;
		int Inf=(int)1e9;
		for(i=0;i<N;i++)for(j=0;j<N;j++)WF[i][j]=(i==j)?0:Inf;
		
		for(i=0;i<M;i++){
			scanf("%d %d %d\n",&From[i],&To[i],&Cost[i]);
			WF[From[i]][To[i]]=WF[To[i]][From[i]]=Cost[i];
		}
		
		for(k=0;k<N;k++){
			for(i=0;i<N;i++){
				for(j=0;j<N;j++){
					WF[i][j]=Min(WF[i][j],WF[i][k]+WF[k][j]);
				}
			}
		}
		
		//0->N-1????????????????????????edge????????????
		for(i=0;i<N;i++)Ec[i]=0;
		for(i=0;i<M;i++){
			if(WF[From[i]][N-1]==WF[To[i]][N-1]+Cost[i]){
				E[From[i]][Ec[From[i]]]=nP(To[i],Cost[i]);
				Ec[From[i]]++;
			}
			if(WF[To[i]][N-1]==WF[From[i]][N-1]+Cost[i]){
				E[To[i]][Ec[To[i]]]=nP(From[i],Cost[i]);
				Ec[To[i]]++;
			}
		}
		
		Pair tmp[N];
		for(i=0;i<N;i++){
			tmp[i]=nP(i,WF[i][N-1]);//???->N-1??????????????¢
		}
		qsort(tmp,N,sizeof(Pair),cmp);
		
		for(i=0;i<N;i++)dp[i]=0;
		dp[0]=1;
		for(i=0;i<N;i++){
			now=tmp[i].Pos;
			for(j=0;j<Ec[now];j++){
				dp[E[now][j].Pos]+=dp[now];
			}
		}
		
		for(;P>0;P--){
			scanf("%d",&c);
			for(i=0;i<N;i++)dp2[i]=0;//dp2[i]:c??????i???????????????????????°
			dp2[c]=1;
			for(i=0;i<N;i++){
				now=tmp[i].Pos;
				for(j=0;j<Ec[now];j++){
					dp2[E[now][j].Pos]+=dp2[now];
				}
			}
			double prob=(double)dp[c];
			prob/=(double)dp[N-1];
			prob*=(double)dp2[N-1];
			printf("%.12f\n",prob);
		}
		puts("");
	}
	return 0;
}


int cmp(const void *x,const void *y){//???????????????
	Pair X=*(Pair *)x;
	Pair Y=*(Pair *)y;
	
	return X.Cost>Y.Cost?-1:X.Cost<Y.Cost?1:0;
}

Measured memory_bytes: 840
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int main ()
{
    int N; cin >> N;
    vector<int> D1(N),D2(N);
    REP(i,N) cin >> D1[i] >> D2[i];

    bool flag = false;
    for (int i = 0; i < N - 2; i++) {
        if (D1[i + 0] == D2[i + 0] &&
            D1[i + 1] == D2[i + 1] &&
            D1[i + 2] == D2[i + 2])
        {
            flag = true;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
import java.util.*

fun main(args : Array<String>) {
    val scanner = Scanner(System.`in`)
    println(inOutExec(scanner))
}

fun inOutExec(scanner: Scanner): String {
    val (numOfPref, numOfCity) = readLine()!!.split(" ").map { it.toInt() }

    val citiesIn = mutableListOf<Pair<Int, Int>>()
    repeat(numOfCity) {
        val (pref, year) = readLine()!!.split(" ").map { it.toInt() }
        citiesIn.add(Pair(pref, year))
    }

    val cityCodeMap = citiesIn
            .groupByTo(mutableMapOf()) { it.first }
            .flatMap { entry ->
                entry.value
                        .sortedBy { info -> info.second }
                        .mapIndexed { index, pair ->
                            pair to "%06d%06d".format(pair.first, index + 1) } } // Pair<Pair<Int, Int>, String>
            .toMap()

    return citiesIn.joinToString(separator = "\n", postfix = "\n") { cityCodeMap[it]!! }
}

Measured memory_bytes: 157484
#include <iostream>
#include "cstdio"
#include "cstring"
using namespace std;
char a[105], b[105], w[205];
int main(int argc, char *argv[]) 
{
	scanf("%s %s", a+1, b+1);
	printf("%s%s\n", b+1, a+1);
	return 0;
}

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

int main (void) {
    string s, t;
    cin >> s >> t;
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 2000001
#define M 10000

int main(){
  unsigned short *a,*c;
  int i,j,n,b[M+1],count=0;
  scanf("%d",&n);
  a=malloc(sizeof(short) * n+1);
  c=malloc(sizeof(short) * n+1);
  for(i=1;i<=n;i++){
    scanf("%hu",&a[i]);
  }
  for(i=0;i<=M;i++){
    b[i]=0;
  }
  for(j=1;j<=n;j++){
    b[a[j]]++;
    }
  for(i=1;i<=M;i++){
    b[i] = b[i] + b[i-1];
  }
   for(i=n;i>0;i--){
     c[b[a[i]]] = a[i];
     b[a[i]]--;
  }
  for(i=1;i<=n;i++){
    printf("%d",c[i]);
    if(i!=n)printf(" ");
    else printf("\n");
  }
  return 0;
}




Measured memory_bytes: 9584
def main():
    N = int(input())
    S = input()

    R_count = 0
    G_count = 0
    B_count = 0

    for s in S:
        if s == "R":
            R_count += 1
        elif s == "G":
            G_count += 1
        else:
            B_count += 1

    # 第一条件だけを考えたときの組み合わせの総数
    answer = R_count * G_count * B_count

    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            # i, j が決まると、第二条件を満たさない k が決まる
            k = 2 * j - i

            # k が文字列の長さを超えたときは、第二条件を満たすことができない
            if k >= N:
                continue

            # 第二条件を満たす i, j, k が、第一条件を満たす場合、
            # 第一条件だけ考えたときの組み合わせの総数から差し引く
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                answer -= 1
            
    print(answer)

if __name__ == '__main__':
    main()

Measured memory_bytes: 73860
#include <stdio.h>

int main(void){
      int num[100]; int i,n;
      scanf("%d",&n);
       for(i=0;i<n;i++){
            scanf("%d",&num[i]);
          }
       for( i=n-1; i>0; i--){
            printf("%d ",num[i]);
          }
           printf("%d\n",num[0]);
        return 0;
}

Measured memory_bytes: 596
score = int(input())
ans = 0
if score < 600:
	ans = 8
elif score < 800:
  	ans = 7
elif score < 1000:
  	ans = 6
elif score < 1200:
  	ans = 5
elif score < 1400:
  	ans = 4
elif score < 1600:
  	ans = 3
elif score < 1800:
  	ans = 2
elif score < 2000:
  	ans = 1
print(ans)

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

using namespace std;

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

#define X first
#define Y second

const int N=2e5+10;

ll solve(ll n,ll L,ll R){
    if (n==1) return (L==R);
    if (L>R) return 0;
    return (R-L)*(n-2)+1;
}
int main(){
    ll n,L,R;
    cin>>n>>L>>R;
    cout<<solve(n,L,R);
}


Measured memory_bytes: 256
fn solve(h: usize, w: usize, v: &Vec<Vec<char>>) -> Vec<String> {
    let in_area = |y: usize, x: usize| {
        y < h && x < w
    };
    let count = |y: usize, x: usize| {
        (0..9).map(|i| {
            let dx = i % 3 - 1;
            let dy = i / 3 - 1;
            let yy = y.wrapping_add(dx as usize);
            let xx = x.wrapping_add(dy as usize);
            (in_area(yy, xx) && v[yy][xx] == '#') as i32
        }).sum::<i32>() as u32
    };
    v.iter().enumerate().map(|(y, s)| {
        s.iter().enumerate()
        .map(|(x, &c)| {
            if c == '#' {
                c
            } else {
                std::char::from_digit(count(y, x), 10).unwrap()
            }
        })
        .collect::<String>()
    }).collect::<Vec<_>>()
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let mut iter = s.split_whitespace().map(|w| w.trim().parse().ok().unwrap());
    let h = iter.next().unwrap();
    let w = iter.next().unwrap();
    let mut v: Vec<_> = Vec::new();
    for _i in 0..h {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let s = s.trim().chars().collect::<Vec<_>>();
        v.push(s);
    }
    let v = solve(h, w, &mut v);
    for i in 0..h {
        println!("{}", v[i]);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#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 srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

map<vi,int> mp;

bool dfs(vi nw,int* cnt,int pos,bool flag)
{
    if(pos == 6){
        return flag && (nw == vi{0,1,2});
    }
    rep(i,cnt[pos]+1){
        if(dfs(nw,cnt,pos+1,(flag|(i >= 1)))){
            return true;
        }
        if(i == cnt[pos]){
            break;
        }
        if(pos == 1){
            swap(nw[1],nw[2]);
        }else if(pos == 2){
            swap(nw[0],nw[1]);
        }else if(pos == 3){
            swap(nw[0],nw[2]);
        }else if(pos == 4){
            swap(nw[0],nw[1]);
            swap(nw[1],nw[2]);
        }else{
            swap(nw[0],nw[2]);
            swap(nw[1],nw[2]);
        }
    }
    return false;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    mp[vi{0,1,2}] = 0,mp[vi{0,2,1}] = 1,mp[vi{1,0,2}] = 2;
    mp[vi{2,1,0}] = 3,mp[vi{1,2,0}] = 4,mp[vi{2,0,1}] = 5;
    int cnt[6] = {};
    rep(i,n){
        vi st = {0,1,2};
        int a;
        cin >> a;
        rep(j,a){
            int c;
            cin >> c;
            if(c){
                swap(st[1],st[2]);
            }else{
                swap(st[0],st[1]);
            }
        }
        cnt[mp[st]]++;
    }
    if(cnt[0] >= 1){
        cout << "yes\n";
        return 0;
    }
    if(cnt[1] >= 2 || cnt[2] >= 2 || cnt[3] >= 2){
        cout << "yes\n";
        return 0;
    }
    if(cnt[4] >= 3 || cnt[5] >= 3){
        cout << "yes\n";
        return 0;
    }
    if(dfs(vi{0,1,2},cnt,0,false)){
        cout << "yes\n";
    }else{
        cout << "no\n";
    }
    return 0;
}



Measured memory_bytes: 3232
N=int(input())
S=input()
a=S.count('R')
b=S.count('G')
c=S.count('B')
ans=a*b*c
for i in range(N-2):
  for j in range(i+1,N-1):
    if S[i]!=S[j]:
      if (2*j-i)<=N-1 and S[i]!=S[2*j-i]!=S[j]:
        ans-=1     
print(ans)

Measured memory_bytes: 9204
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

n = inp[0]
it = []
n.times do
  it << inp[0]
end
len = [it.shift]
it.each do |d|
  ind = nil
  if(ind = len.bsearch_index{|x|x >= d})
    if(ind - 1 < 0)
      len.unshift(d)
      next
    end
    len[ind-1] = d
  else
    len[-1] = d
  end
end
p len.size


Measured memory_bytes: 3784
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    A, B, K = [int(x) for x in input().split()]

    if A >= K:
        print(A - K, B)
    else:
        print(0, max(0, B - (K - A)))




if __name__ == '__main__':
    main()



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

using namespace std;

char s[5001];
long long dp[2][5001];

long long mod_inverse(long long a, long long m) {
    long long b = m, x = 1, y = 0;
    
    while (b) {
        long long t = a / b;
        
        a -= t * b;
        x -= t * y;
        
        swap(a, b);
        swap(x, y);
    }
    
    return (m + x % m) % m;
}

int main() {
    int n, m, mod = 1000000007, i, j;
    long long x = 1;
    
    scanf("%d", &n);
    scanf("%s", s);
    
    m = strlen(s);
    
    for (i = 0; i < m; i++) x = x * 2 % mod;
    
    dp[0][0] = 1;
    
    for (i = 0; i < n; i++) {
        for (j = 0; j <= i; j++) {
            if (dp[0][j] == 0) continue;
            
            dp[1][j + 1] += dp[0][j] * 2 % mod;
            if (dp[1][j + 1] >= mod) dp[1][j + 1] -= mod;
            
            if (j == 0) {
                dp[1][j] += dp[0][j];
                if (dp[1][j] >= mod) dp[1][j] -= mod;
            } else {
                dp[1][j - 1] += dp[0][j];
                if (dp[1][j - 1] >= mod) dp[1][j - 1] -= mod;
            }
        }
        
        for (j = 0; j <= i + 1; j++) {
            dp[0][j] = dp[1][j];
            dp[1][j] = 0;
        }
    }
    
    printf("%lld\n", dp[0][m] * mod_inverse(x, mod) % mod);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

	ll X, Y;
	cin >> X >> Y;
	if(abs(X - Y) <= 1) cout << "Brown" << endl;
	else cout << "Alice" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#define N 1001
#define V 2020
#define E 20386
#define F 0x7fffffff

#define MIN(A, B) ((A) < (B) ? (A) : (B))

struct edge {
    int u, v;
    long long w;
    int c, x;
} e[E];

const long long y[2][4] = {{-1, 1, -1, 1}, {-1, -1, 1, 1}};

long long p[2][2][N], d[V];
int h[V], m[2][N], f[V], q[V], l, t, z, n, g;
bool v[V];

inline void adde(int u, int v, long long w, int c) {
    e[z] = edge{u, v, -w, c, h[u]}; h[u] = z++;
    e[z] = edge{v, u, w, 0, h[v]}; h[v] = z++;
}

inline void push(int x) {
    q[t++] = x;
    if (t == V) t = 0;
}

inline int pop() {
    int x = q[l++];
    if (l == V) l = 0;
    return x;
}

bool spfa() {
    memset(d, 0x3f, sizeof d);
    d[0] = 0; push(0); v[0] = true;

    while (l != t) {
        int x = pop();
        v[x] = false;

        for (int i = h[x]; ~i; i = e[i].x) {
            if (e[i].c && d[e[i].v] > d[x] + e[i].w) {
                d[e[i].v] = d[x] + e[i].w; f[e[i].v] = i;
                if (!v[e[i].v]) { push(e[i].v); v[e[i].v] = true; }
            }
        }
    }

    return d[g] != 0x3f3f3f3f3f3f3f3fLL;
}

long long solve() {
    long long c = 0;

    while (spfa()) {
        int w = F;
        for (int u = g; u; u = e[f[u]].u) w = MIN(w, e[f[u]].c);

        for (int u = g; u; u = e[f[u]].u) {
            c += e[f[u]].w * w; e[f[u]].c -= w; e[f[u] ^ 1].c += w;
        }
    }

    return -c;
}

int main() {
    memset(h, -1, sizeof h);
    scanf("%d", &n); g = (n << 1) + 9;
    for (int i = 1; i <= 4; i++) adde((n << 1) + i, (n << 1) + i + 4, 0, F);

    for (int s = 0; s <= 1; s++)
        for (int i = 1; i <= n; i++)
            scanf("%lld%lld%d", &p[s][0][i], &p[s][1][i], &m[s][i]);

    for (int i = 1; i <= n; i++) {
        adde(0, i, 0, m[0][i]); adde(n + i, g, 0, m[1][i]);

        for (int j = 0; j < 4; j++) {
            adde(i, (n << 1) + j + 1, p[0][0][i] * y[0][j] + p[0][1][i] * y[1][j], F);
            adde((n << 1) + 8 - j, n + i, p[1][0][i] * y[0][j] + p[1][1][i] * y[1][j], F);
        }
    }

    printf("%lld\n", solve()); return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
typedef long long ll;

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 (b<a) { a=b; return 1; } return 0; }

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

  long long H[N];
  for(int i=0; i<N; i++)
    cin >> H[i];

  bool table[N];
  for(int i=0; i<N; i++)
    table[i] = true;
  
 
  for(int i=0; i<N-1; i++)
    {
      if(H[i]>H[i+1])
	{
	  for(int j=i; H[j]>H[j+1] & j>-1 & table[j]; j--)
	    {
	      if(table[j])
		{
		  H[j]--;
		  table[j] = false;
		}
	    }
	}      
    }

  for(int i=0; i<N-1; i++)
    {
      if(H[i]>H[i+1])
	{
	  cout << "No" << endl;

	  return 0;
      }
    }
  cout << "Yes" << endl;

 

  return 0;
}


//cout << setprecision(13);
//next_permutation(v.begin(), v.end());



Measured memory_bytes: 1152
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	abc := make([]int, 3)
	abc[0] = getNextInt(scanner)
	abc[1] = getNextInt(scanner)
	abc[2] = getNextInt(scanner)

	sort.Ints(abc)

	if abc[0]%2 == abc[1]%2 && abc[1]%2 == abc[2]%2 {
		fmt.Println((abc[2]*2 - abc[1] - abc[0]) >> 1)
		return
	}
	if abc[0]%2 == abc[1]%2 {
		abc[0]++
		abc[1]++
	} else if abc[1]%2 == abc[2]%2 {
		abc[1]++
		abc[2]++
	} else {
		abc[0]++
		abc[2]++
	}
	sort.Ints(abc)
	fmt.Println(1 + (abc[2]*2-abc[1]-abc[0])>>1)

	writer.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int a; string s; cin >> a >> s;
  cout << (a >= 3200 ? s : "red") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_V = 101;
const int INF=100000000;
int d[MAX_V][MAX_V];
int V;
void warshall_floyd(){
    for(int i = 0; i < V; i++)
        for(int j = 0; j < V; j++)
            for(int k = 0; k < V; k++)
                d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
}
int main(){
    int n,m,s,g1,g2;
    while(cin>>n>>m>>s>>g1>>g2&&!(n==0&&m==0&&s==0&&g1==0&&g2==0)){
        for(int i = 0; i < MAX_V; i++)
            for(int j = 0; j < MAX_V; j++)
                if(i==j)
                    d[i][j]=0;
                else
                    d[i][j]=INF;
        s--;g1--;g2--;
        for(int i = 0; i < m; i++){
            int b1,b2,c;
            cin>>b1>>b2>>c;
            b1--;b2--;
            d[b1][b2]=c;
        }
        V=n;
        warshall_floyd();
        int minCost=INF;
        for(int i = 0; i < n; i++)
            minCost=min(minCost,d[s][i]+d[i][g1]+d[i][g2]);
        cout<<minCost<<endl;
    }
    return 0;
}

Measured memory_bytes: 0
object Main extends App {
  var a = readInt
  var i = 0
  var sum = 0.0d
  while (i<a){
    var get = readLine
    var a = get.split(" ")(0).toDouble
    var b = get.split(" ")(1).toString
  
	if(b.equals("BTC")) {
      sum += (a * 380000.0)
    } else {
      sum += a
    }
    i+=1
  }
  println(sum)
}

Measured memory_bytes: 27196
#include<stdio.h>
int main()
{
  int n;
  scanf("%d",&n);
  n=n%100%10;
  if(n==0 || n==1 || n==6 || n==8)
    puts("pon");
  else if(n==3)
    puts("bon");
  else
    puts("hon");
  return 0;
}


Measured memory_bytes: 2088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
using Graph = vector<vector<int>>;

int main() {
	int n, ans = 1, a;
	cin >> n;
	rep(i, n) {
		cin >> a;
		if (a % 2 == 0) ans *= 2;
	}
	cout << (int)pow(3, n) - ans << endl;
}

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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

template<class T>
class segment_tree {
private:
  lli n;
  T d;
  vector<T>* v;
  T _query(lli a,lli b,lli k,lli l,lli r){
    if(r <= a || b <= l) return d;
    if(a <= l && r <= b) return this->v->at(k);
    else {
      T vl = _query(a,b,k*2+1,l,(l+r)/2);
      T vr = _query(a,b,k*2+2,(l+r)/2,r);
      return func(vl,vr);
    }
  }
public:
  segment_tree (){}
  segment_tree(lli n,T d = INT_MAX){
    this->n = 1;
    while(n > this->n) this->n <<= 1;
    v = new vector<T>(this->n*2,d);
    this->d = d;
  }
  void update(lli i,T x){
    i += n-1;
    this->v->at(i) = x;
    while(i > 0){
      i = (i-1)/2;
      this->v->at(i) = func(this->v->at(i*2+1),this->v->at(i*2+2));
    }
  }
  T query(lli a,lli b){
    return _query(a,b,0,0,n);
  }
  T func(T a,T b){
    if(a == 'A' && b == 'A') return 'B';
    if(a == 'A' && b == 'B') return 'O';
    if(a == 'A' && b == 'O') return 'A';
    if(a == 'B' && b == 'A') return 'O';
    if(a == 'B' && b == 'B') return 'A';
    if(a == 'B' && b == 'O') return 'B';
    if(a == 'O' && b == 'A') return 'A';
    if(a == 'O' && b == 'B') return 'B';
    if(a == 'O' && b == 'O') return 'O';
    return 'O';
  }
};

string s,t;
lli q;
vector<string> ans;

int main(){
  cin >> s >> t;
  cin >> q;
  segment_tree<char> sg = segment_tree<char>(s.size()+1,'O');
  segment_tree<char> tg = segment_tree<char>(t.size()+1,'O');
  for(lli i = 1;i <= s.size();i++){
    sg.update(i,s[i-1]);
  }
  for(lli i = 1;i <= t.size();i++){
    tg.update(i,t[i-1]);
  }
  for(lli i = 0;i < q;i++){
    lli a,b,c,d;
    cin >> a >> b >> c >> d;
    if(sg.query(a,b+1) == tg.query(c,d+1)) ans.push_back("YES");
    else ans.push_back("NO");
  }
  for(lli i = 0;i < q;i++){
    cout << ans[i] << endl;
  }
  return 0;

}


Measured memory_bytes: 8820
import sys

H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
a = [["."]*W for _ in range(H)]
for i in range(H):
    for j in range(1,W):
        if s[i][j-1] == "#" and s[i][j] == "#":
            a[i][j-1] = "#"
            a[i][j] = "#"

sT = list(zip(*s))
aT = [list(x) for x in zip(*a)]

for i in range(W):
    for j in range(1,H):
        if sT[i][j-1] == "#" and sT[i][j] == "#":
            aT[i][j-1] = "#"
            aT[i][j] = "#"

ans = list(zip(*aT))

for i in range(H):
    for j in range(W):
        if s[i][j] != ans[i][j]:
            print("No")
            sys.exit()
print("Yes")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args)  {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int q = sc.nextInt();

		int dp[][] = new int[n + 1][n + 1];

		for(int i = 0; i < m; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();

			dp[l][r]++;
		}

		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				dp[i][j] += dp[i][j - 1];

//				System.out.print(dp[i][j] +" ");
			}
//			System.out.println();
		}

		for(int i = 0; i < q; i++){
			int p1 = sc.nextInt();
			int p2 = sc.nextInt();

			int sum = 0;
			for(int j = p1 ; j <= p2; j++){
				sum += dp[j][p2];
			}

			System.out.println(sum);
		}
	}

}


Measured memory_bytes: 154140
#include <bits/stdc++.h>
using namespace std;
int N,l,r;
int main(){
    cin>>N;
    int ans=0;
    for(int i=0;i<N;i++){
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 764
from collections import defaultdict
Sdic = defaultdict(int)

N = int(input())
S = ['']* N
ans = 0
for i in range(N):
    Sdic[str(sorted(input()))] += 1

for i in Sdic.keys():
    ans += (Sdic[i] * (Sdic[i] - 1)) // 2

print(ans)


Measured memory_bytes: 23140
#![allow(unused_imports)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}


//
// Main
//

fn main() {
    input! {
        n: usize,
        d: usize,
    }

    let a = 2 * d + 1;
    let x = ((n as f64) / (a as f64)).ceil();
    println!("{}", x);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
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;
}
using namespace std;
int main(){ 
   int h,w;
   cin>>h>>w;
   char c[h+2][w+2];
   rep(i,h+2){
      rep(j,w+2){
         c[i][j]='0';
      }
   }
   rep(i,h){
      rep(j,w){
         cin>>c[i+1][j+1];
      }
   }
   for(int i=0;i<h+2;i++){
      for(int j=0;j<w+2;j++){
         if(c[i][j]=='0') cout<<'#';
         else cout<<c[i][j];
      }
      cout<<endl;
   }

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int i = (0);i < (n);++i)
#define rep(i,s,g) for(int i = (s);i < (g);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string str;
	cin >> str;
	str.erase(str.size()-8,8);
	cout << str << endl;
	
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;


int main() {

    int N;
    string S;
    cin >> N >> S;
    int ans = 0;

    REP(i, N-2){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C')ans++;
    }
    cout << ans << endl;
    
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256