akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#define nmax_def 110000
#define mod 2019
using namespace std;
typedef long long ll;

int main() {
	int i, j;
	int L, R;
	int ans = 10000;
	int over0;
	cin >> L >> R;
	over0 = (R / mod) - (L / mod);
	L %= mod;
	R %= mod;
	int A = min(3, over0);
	R += A * mod;
	bool can;
	for (i = 0; i < mod*3; i++)
	{
		for (j = i+1; j < mod*3; j++)
		{
			if (i >= L && j <= R)
			{
				ans = min(ans, ((i * j) % mod));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>

using namespace std;


int main() {
    string s;
    cin>>s;
    int n = s.length();
    vector<int> f(n, 0);
    map<int, int> m;
    int a = 0;
    m[0] = 0;
    for (int i=0; i<s.length(); i++) {
        int offset = s[i] - 'a';
        if (a & (1<<offset)) a &= ~(1<<offset);
        else a |= (1<<offset);
        int min_cut = INT_MAX;
        for (int j=0; j<26; j++) {
            int p_a = a ^ (1<<j);
            if (m.find(p_a) != m.end() && m[p_a] < min_cut) min_cut = m[p_a];
        }
        if (m.find(a) != m.end() && m[a] < min_cut) min_cut = m[a];
        f[i] = 1 + min_cut;
        if (m.find(a) == m.end() || m[a] > 1 + min_cut) m[a] = 1 + min_cut;
    }
    cout<<f[n-1]<<endl;
}

Measured memory_bytes: 10628
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<usize>();
    a.sort();
    a.reverse();
    let mut alice = 0;
    let mut bob = 0;
    for i in 0..n {
        if i % 2 == 0 {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }
    println!("{}", alice - bob);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]

A.sort(reverse = True)
cnt = Counter(A)

ans = 0
for a in A:
    if not cnt[a]: continue

    # aより大きい最小の2のべき乗
    p = 2 ** a.bit_length()
    if cnt[p - a]:
        if a == p - a:
            if cnt[a] >= 2:
                ans += 1
                cnt[a] -= 2
        else:
            ans += 1
            cnt[p - a] -= 1
            cnt[a] -= 1

print(ans)

Measured memory_bytes: 33212
#include <bits/stdc++.h>
#define REP(i,  n) for (int i  =  0; i < (int)(n); ++i)
#define REPR(i,  n) for (int i  =  n - 1; i >= 0; --i)
using namespace std;
#define int long long int
//------------ATCODER TEMPLATE-------------

signed main() {
  int X; cin >> X;
  if (X >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3596
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

A = itertools.permutations(range(1,N+1))
A = list(A)
A.sort()

p = 0
q = 0
for i,a in enumerate(A):
    for j in range(N):
        if a[j] != P[j]:
            break
        if j == N-1:
            p = i 

    if p != 0:
        break

for i,a in enumerate(A):
    for j in range(N):
        if a[j] != Q[j]:
            break
        if j == N-1:
            q = i 

    if q != 0:
        break

print(abs(p-q))


Measured memory_bytes: 8052
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
using graph = vector<vector<int>>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    string m;
    char tmp;
    vector <char> s;
    cin >> m;
    ll num = m.size();
    REP(i, num){
        s.push_back(m[i]);
    }
    REP(i, num){
        if(s[i] == '?') s[i] = 'D';
        cout << s[i];
    }
    return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int fact = 1;
    for(int i = 1;i<=n;i++){
    	fact *= i;
    }
    double ans = 0;
    vector<pair<int, int>> vec;
	for(int i = 0;i<n;i++){
		int t1, t2;
		cin>>t1>>t2;
		vec.pb({t1, t2});
	}
	for(int i = 0;i<n;i++){
		for(int j = i+1;j<n;j++){
			double temp = sqrt(((vec[i].fr - vec[j].fr) * (vec[i].fr - vec[j].fr)) + ((vec[i].sc - vec[j].sc) * (vec[i].sc - vec[j].sc)));
			ans += temp;
		}
	}
	int ways = n*(n-1)/2;
	ans *= fact*(n-1)/ways;
	cout<<setprecision(12)<<ans/fact<<endl;
    return 0;
}




Measured memory_bytes: 256
using System;

namespace ABC124_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array1 = Console.ReadLine().Split(' ');
            int a = int.Parse(array1[0]);
            string[] array2 = Console.ReadLine().Split(' ');
            int[] intAry = Array.ConvertAll<string, int>(array2, delegate (string value)
            {
                return int.Parse(value);
            });
            int count = 1;
            int max = 0;
            max = intAry[0];
            for(int i = 1; i < a; i++)
            {
                
                if((max <= intAry[i]) && (intAry[i - 1] <= intAry[i]))
                {
                    max = intAry[i];
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    cout << max(a+b, max(a-b, a*b)) << endl;
    return 0;
}


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

#define int long long

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

	int a;
	cin>>a;
	cout<<(a + a*a + a*a*a);
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e9;

int main(){
	int N,M;
	cin>>N>>M;
	int d[51];
	rep1(i,N)d[i]=0;
	rep(i,M){
		int x,y;
		cin>>x>>y;
		d[x]++;d[y]++;
	}
	rep1(i,N)cout<<d[i]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

auto get(i64 n) {
    std::vector<int> ret;
    while (n) {
        ret.push_back(n % 3);
        n /= 3;
    }
    while (ret.size() < 30) ret.push_back(0);
    return ret;
}

int main() {
    int q;
    std::cin >> q;

    std::vector<i64> p3 { 1 };
    while (p3.size() < 33) p3.push_back(p3.back() * 3);

    while (q--) {
        i64 a, b, c, d;
        std::cin >> a >> b >> c >> d;
        --a; --b; --c; --d;

        const auto da = get(a), db = get(b), dc = get(c), dd = get(d);
        i64 o = 0, pa = 0, pb = 0, pc = 0, pd = 0;
        for (int i = 29; i >= 0; i--) {
            pa = pa * 3 + da[i];
            pb = pb * 3 + db[i];
            pc = pc * 3 + dc[i];
            pd = pd * 3 + dd[i];
            if (db[i] == 1 && dd[i] == 1 && pb == pd && llabs(pa - pc) > 1) {
                i64 lb = 0, ld = 0;
                const i64 u = p3[i];
                for (int j = 0; j < i; j++) lb += db[j] * p3[j];
                for (int j = 0; j < i; j++) ld += dd[j] * p3[j];
                const i64 left = lb + ld + 2, right = 2 * u - lb - ld;
                o = std::min(left, right) - llabs(b - d);
                break;
            }
            if (da[i] == 1 && dc[i] == 1 && pa == pc && llabs(pb - pd) > 1) {
                i64 la = 0, lc = 0;
                const i64 u = p3[i];
                for (int j = 0; j < i; j++) la += da[j] * p3[j];
                for (int j = 0; j < i; j++) lc += dc[j] * p3[j];
                const i64 left = la + lc + 2, right = 2 * u - la - lc;
                o = std::min(left, right) - llabs(a - c);
                break;
            }
        }

        std::cout << llabs(a - c) + llabs(b - d) + o << '\n';
    }

    std::cout << std::flush;

    return 0;
}


Measured memory_bytes: 384
import java.util.Collections;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Map;

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

        Map<String, Long> m = new HashMap<>();

        for (int i=0; i<n; i++){
            String st = sc.next();
            char[] c = st.toCharArray();
            Arrays.sort(c);
            st = new String(c);
//            System.out.println(st);
            if (m.containsKey(st)){
                m.put(st, m.get(st)+1);
            }else{
                m.put(st, 1L);
            }
        }
//        System.out.println(m);

        long ans = 0;

        for (Long v: m.values()){
            ans += v*(v-1)/2;
        }
        System.out.println(ans);
    }
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((a==b&&b==5&&c==7)||(b==c&&b==5&&a==7)||(a==c&&a==5&&b==7)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>

int main(int argc, char *argv[]) {
  int x, n;
  std::cin >> x >> n;
  std::map<int, int> d;
  for (int i = 0; i < n; ++i) {
    int j;
    std::cin >> j;
    d.emplace(j, 1000);
  }
  for (int i = -2; i < 105; ++i) {
    if (d.count(i))
      continue;
    d.emplace(i, std::abs(x - i));
  }

  int min = 1000;
  int ans = -1;
  for (auto i: d) 
    if (min > i.second) {
      ans = i.first;
      min = i.second;
    }

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


Measured memory_bytes: 3232
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	A := scanInt()
	B := scanInt()
	C := scanInt()
	K := scanInt()
	for i := 0; i < K; i++ {
		if C <= B {
			C = C * 2
		} else if B <= A {
			B = B * 2
		}
	}
	if A < B && B < C {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


// --------------- BASE DEFINITIONS ---------------

var sc = bufio.NewScanner(os.Stdin)
 
func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}


Measured memory_bytes: 1808
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0;i<N;i++) cin >> X.at(i);
  
  int min_tmp = 100000000;
  for(int i=1;i<=100;i++){
    int sum_tmp = 0;
    for(int j=0;j<N;j++){
      sum_tmp += (X.at(j)-i)*(X.at(j)-i);
    }
    if(min_tmp > sum_tmp ) min_tmp = sum_tmp;
  }
  cout << min_tmp << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

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

        for(int i=0;i<n;i++)
        a[i]=sc.nextInt();
        
        
        for(int i=n-1;i>0;i--)
        System.out.print(a[i]+" ");
        
        System.out.println(a[0]);
        
    }
}


Measured memory_bytes: 26324
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    vector<int> arr = {0, 0, 0};
    string s; cin >> s;
    for(char c: s) {
        arr[c-'a'] += 1;
    }
    int m = min({arr[0], arr[1], arr[2]});
    for(int i = 0; i < 3; i++)
        arr[i] -= m;
    sort(arr.begin(), arr.end());
    if (arr[2] == 0) {
        cout << "YES" << endl;
    } else if (arr[1] == 0 && arr[2] == 1) {
        cout << "YES" << endl;
    } else if (arr[1] == 1 && arr[2] == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}




Measured memory_bytes: 512
#include<stdio.h>
#define ll long long
double p[305][305][305],e[305][305][305];
int main()
{
     ll n;
     scanf("%lld",&n);
     ll cnt[4]={0},x;
     for(int i=0;i<n;i++)
     {
          scanf("%lld",&x);
          cnt[x]++;
     }
     for(int i=0;i<=n;i++)
          for(int j=0;j<=n;j++)
               for(int k=0;k<=n;k++)
               {
                    e[i][j][k]=0;
                    p[i][j][k]=0;
               }
     p[cnt[1]][cnt[2]][cnt[3]]=1;
     for(ll c=n;c>=0;c--)
          for(ll b=n;b>=0;b--)
               for(ll a=n;a>=0;a--)
               {
                    if(a==0&&b==0&&c==0)
                    continue;
                    if(a+b+c>n)
                    continue;
                    double pw=(double)(n-(a+b+c))/n;
                    double ew=pw/(1-pw)+1;
                    e[a][b][c]+=ew*p[a][b][c];
                    if(a!=0)
                    {
                         double po=(double)a/(a+b+c);
                         p[a-1][b][c]+=p[a][b][c]*po;
                         e[a-1][b][c]+=e[a][b][c]*po;
                    }
                    if(b!=0)
                    {
                         double po=(double)b/(a+b+c);
                         p[a+1][b-1][c]+=p[a][b][c]*po;
                         e[a+1][b-1][c]+=e[a][b][c]*po;
                    }
                    if(c!=0)
                    {
                         double po=(double)c/(a+b+c);
                         p[a][b+1][c-1]+=p[a][b][c]*po;
                         e[a][b+1][c-1]+=e[a][b][c]*po;
                    }

               }
     printf("%.9lf",e[0][0][0]);


     return 0;
}

Measured memory_bytes: 440448
#include <bits/stdc++.h>
#define Int int64_t
#define pb push_back
using namespace std;
const int MAXN=500005;

Int N,M,X,Y,B,K,Z,T;
int main()
{
   cin>>N;
   vector<Int> A(N);
   for(int i=0;i<N;++i) cin>>A[i];
   sort(A.begin(),A.begin()+N);
   Int sum=A.back();int j=0;A.pop_back();
   for(int i=2;i<N;++i){
       sum+=A.back();
       j++;
       if(j==2){
           A.pop_back();
           j=0;
       }
   }
   cout<<sum<<"\n";
}

Measured memory_bytes: 4848
#include<stdio.h>

int main(){
  int a;
  scanf("%d",&a);
  if(2800>a){
    if(1200>a){
      printf("ABC\n" );
    }else{
      printf("ARC\n" );
    }
  }else{
    printf("AGC\n" );
  }
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main()
{
  int a[50];
  int count[11];
  int i,j;
  int max,min;
  int l;
  int ll,x;
  for(;;)
  {
    for(i=0;i<50;i++)
      a[i]=0;
    scanf("%d %d",&a[0],&l);
    if(a[0]==0 && l==0)
      return 0;
    for(i=1;;i++)
    {
      for(j=0;j<11;j++)
        count[j]=0;
      ll=a[i-1];
      while(ll>0)
      {
        count[ll%10]++;
        ll/=10;
      }
      min=max=0;
      for(j=0;j<11;j++)
      {
        while(count[j]>0)
        {
          min*=10;
          min+=j;
          count[j]--;
        }
      }
      ll=a[i-1];
      for(j=0;j<11;j++)
        count[j]=0;
      while(ll>0)
      {
        count[ll%10]++;
        ll/=10;
      }
      ll=l;
      for(j=10;j>0;j--)
      {
        while(count[j]>0)
        {
          max*=10;
          max+=j;
          ll--;
          count[j]--;
        }
      }
      while(ll>0)
      {
        max*=10;
        ll--;
      }
      x=0;
      for(j=0;j<i;j++)
      {
        if(a[j]==max-min)
        {
          printf("%d %d %d\n",j,max-min,i-j);
          x=4649;
          break;
        }
      }
      if(x>0)
        break;
      a[i]=max-min;
    }
  }
}


Measured memory_bytes: 2104
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<cstdint>
#include<algorithm>
#include<boost/variant.hpp>
#include<boost/range/irange.hpp>
struct update
{
	std::int64_t a, b;
};
struct output
{

};
typedef boost::variant<update, output> query;
template<class T>class binary_indexed_tree
{
	typedef T type;
	std::vector<type> ar;
	std::size_t size;
public:
	binary_indexed_tree(std::size_t size_) :ar(size_), size(size_)
	{

	}
	void add(type val, int index)
	{
		++index;
		while (index <= size)
		{
			ar[index - 1] += val;
			index += index & -index;
		}
	}
	auto get(int index)const
	{
		++index;
		type ret{};
		while (index != 0)
		{
			ret += ar[index - 1];
			index -= index & -index;
		}
		return ret;
	}
};
struct operation
{
	binary_indexed_tree<int> count;
	binary_indexed_tree<std::int64_t> sum;
	std::map<std::int64_t, int> indexes;
	std::vector<std::int64_t> values;
	std::size_t size;
	std::int64_t update_count;
	std::int64_t constant;

	operation(
		std::map<std::int64_t, int>&& _indexes,
		std::vector<std::int64_t>&& _values,
		std::size_t _size) :
		count(_size),
		sum(_size),
		indexes(std::move(_indexes)),
		values(std::move(_values)),
		size(_size),
		update_count(),
		constant()
	{

	}
	
	void operator()(update const& q)
	{
		auto a = q.a;
		auto b = q.b;
		auto i = indexes[a];
		count.add(1, i);
		sum.add(a, i);
		constant += b;
		++update_count;
	}
	void operator()(output const&)
	{
		auto j = (update_count + 1) / 2;
		auto rng = boost::irange<std::size_t>(0, size);
		auto i = *std::partition_point(rng.begin(), rng.end(), [&](std::size_t k)
			{
				auto c = count.get(k);
				return c < j;
			});
		auto v = (2 * count.get(i) - update_count) * values[i] + sum.get(size - 1) - 2 * sum.get(i) + constant;
		std::cout << values[i] << " " << v << std::endl;
	}
};

void Main()
{
	int Q;
	std::cin >> Q;
	std::vector<query> queries;
	std::set<std::int64_t> as;
	for (int i : boost::irange(0, Q))
	{
		int q;
		std::cin >> q;
		if (q == 1)
		{
			std::int64_t a, b;
			std::cin >> a >> b;
			as.emplace(a);
			queries.emplace_back(update{ a,b });
		}
		else
		{
			queries.emplace_back(output{});
		}
	}
	std::map<std::int64_t, int> indexes;
	std::vector<std::int64_t> values;
	std::size_t index = 0;
	for (auto a : as)
	{
		indexes[a] = index;
		values.emplace_back(a);
		++index;
	}
	operation op(std::move(indexes), std::move(values), index);
	for (auto const& q : queries)
	{
		boost::apply_visitor(op, q);
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 20536
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10010

bool solve(){
  int n,m,r,q;
  int rec_t[SIZE],rec_m[SIZE], rec_n[SIZE], rec_s[SIZE];
  int memo[SIZE],c[SIZE] = {};
  vector<pair<int,int> > vec[SIZE];
  
  scanf("%d%d%d",&n,&m,&r);

  if(n == 0) return false;
  
  for(int i=0;i<r;i++){
    scanf("%d%d%d%d",rec_t+i, rec_n+i, rec_m+i, rec_s+i);

    if(rec_s[i] == 1){
      if(c[rec_m[i]] == 0)
        memo[rec_m[i]] = rec_t[i];
      c[rec_m[i]]++;
    }else{
      c[rec_m[i]]--;

      if(c[rec_m[i]] == 0)
        vec[rec_m[i]].push_back({memo[rec_m[i]], rec_t[i]});
    }
  }

  scanf("%d",&q);

  for(int i=0;i<q;i++){
    int ts,te,m;
    int sum = 0;
    
    scanf("%d%d%d",&ts,&te,&m);

    for(int j=0;j<vec[m].size();j++){
      if(!(te <= vec[m][j].first || vec[m][j].second <= ts)){
        sum += min(te, vec[m][j].second) - max(ts, vec[m][j].first);
      }
    }

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

  return true;
}

int main(){

  while(solve());
  
  return 0;
}

Measured memory_bytes: 3560
import java.util.Scanner;

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

		long[][] xy = new long[n][2];
		for (int i = 0; i < n; i++) {
			xy[i][0] = sc.nextInt();
			xy[i][1] = sc.nextInt();
		}

		long answer = Long.MAX_VALUE;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int l = 0; l < n; l++) {
					for (int m = 0; m < n; m++) {
						long lx = xy[i][0];
						long hx = xy[j][0];
						long ly = xy[l][1];
						long hy = xy[m][1];
						if (lx > hx || ly > hy) continue;
						int count = 0;
						for (int o = 0; o < n; o++) {
							if (xy[o][0] >= lx && xy[o][0] <= hx
									&& xy[o][1] >= ly && xy[o][1] <= hy) {
								count++;
							}
						}
						if (count >= k) answer = Math.min(answer, (hx - lx) * (hy - ly));
					}
				}
			}
		}

		System.out.println(answer);
	}
}


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

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

    ll ans = 0, cnt = 0;
    rep(i, S.size()) if (S[i] == 'W') {
        ans += i - cnt;
        ++cnt;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;

unordered_map<char, vector<char> > G;

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

    ll N;
    cin >> N;

    string S[2];
    cin >> S[0];
    cin >> S[1];

    ll ans;
    ll i;
    if (S[0][0] == S[1][0]) {
        i = 1;
        ans = 3;
    } else {
        i = 2;
        ans = 6;
    }

    while (i < N) {
        if (S[0][i] == S[1][i]) {
            if (S[0][i - 1] == S[1][i - 1]) {
                ans *= 2;
            } else {
                ans *= 1;
            }
            i++;
        } else {
            if (S[0][i - 1] == S[1][i - 1]) {
                ans *= 2;
            } else {
                ans *= 3;
            }
            i += 2;
        }

        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}



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

int main(){
  string s;
  cin>>s;
  size_t n=s.length();
  int ans=0;
  for(int i=0;i<n/2;i++){
    if(s[i]==s[n-i-1]) ans+=0;
    else ans+=1;
  }
  cout<<ans<<endl;
}
  

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

using namespace std;

int main(){
	bool prime[1001];
	for(int i=0; i<1001; i++){
		prime[i]=true;
	}

	prime[0] = prime[1] = false;

	for(int i=2; i*i<=1000; i++){
		for(int j=2*i; j<=1000; j+=i){
			prime[j]=false;
		}
	}

	int n;
	cin >> n;

	int count[1001]={0};
	long long int res=1;

	for(int i=2; i<=n; i++){
		if(prime[i]){
			for(int j=i; j<=n; j*=i){
				count[i] += n/j;
			}
		}
	}


	for(int i=0; i<1001; i++){
		res *= (count[i]+1);
		res%=1000000007;
	}

	cout << res << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
	int N;
	cin >> N;
	int P[N];
	int ans = 0;
	//bool ok = true;
	int m = N + 1;
	for(int i = 0; i < N; ++i){
		cin >> P[i];
		m = min(m, P[i]);
		if(m == P[i]){
			++ans;
		}
	}
	cout << ans << endl;
	
		
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <math.h>
#include <limits.h>
using namespace std;

int main() {
	double n; cin >> n;
	double i, j;
	for (i = floor(sqrt(n)); i >= 1; i--) {
		j = floor(n/i);
		if (i * j == n) {
			cout << (long long)i + (long long)j - 2 << endl;
			return 0;
		}
	}
	
	return 0;
}

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

#define FOR(i, a, b) for (int (i) = (a); (i) < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cerr << #x << " " << x << endl
#define eb emplace_back
#define _ << " " <<
typedef long long ll;
typedef std::pair<int, int> ii;
#define X first
#define Y second
#define double long double
typedef double db;
using namespace std;

const int MaxN = 200100;
const int Mod = 1e9 + 7;

int N;
int a[MaxN];
ll res;

void solve() {

}

void load() {
  cin>>N;
  int last = 0;
  res = 0;
  bool bad = false;

  REP(i, N){
    scanf("%d", a + i);
    if (a[i] > i - last) {
      bad = true;
    }

    if (i == 0) continue;

    if (a[i] == a[i-1] + 1)
      res++;

    else{
      res += a[i];
      
      last = i - a[i];
    }
  }
  
  if (!bad){
  cout<<res<<endl;
  }
  else{
    cout << -1 << endl;
  }
}


int main(){
//  ios_base::sync_with_stdio(false);
  load();	
  solve();
  return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	int N, K, S;
	cin >> N >> K >> S;
	for (int i = 0; i < K; i++) {
		cout << S << " ";
	}
	for (int i = K; i < N; i++) {
		if (S == 1) {
			cout << 2 << " ";
		}
		else {
			cout << S - 1 << " ";
		}
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
        ll n,i,num,have=0,mon=1000;
        cin >> n;
        vector<ll> pr(n);
        vector<ll> di(n);
        for(i=0;i<n;++i) cin >> pr.at(i);
        for(i=0;i<n-1;++i){
                if(pr.at(i)<pr.at(i+1)&&!have){
                        num = mon/pr.at(i);
                        mon %= pr.at(i);
                        have += num;
                        di.at(i) = mon;
                        continue;
                }
                if(pr.at(i)<pr.at(i+1)&&have){
                        di.at(i) = mon;
                        continue;
                }
                if(pr.at(i)>pr.at(i+1)&&!have){
                        di.at(i) = mon;
                        continue;
                }
                if(pr.at(i)>pr.at(i+1)&&have){
                        mon += have*pr.at(i);
                        have = 0;
                        di.at(i) = mon;
                        continue;
                }
                if(pr.at(i)==pr.at(i+1)){
                        di.at(i) = mon;
                        continue;
                }
        }
        di.at(n-1) = mon + have*pr.at(n-1);
        sort(di.rbegin(),di.rend());
        cout << di.at(0) << endl;
        return 0;
}

Measured memory_bytes: 3624
import math
import sys
import collections

n = int(input())
a = list(map(int, input().split()))
ans = 0
counts = collections.Counter(a)
mod = 10**9+7


if n % 2 == 1:
    # if counts[0] is None or counts[0] != 1:
    if counts[0] != 1:
        print(0)
        sys.exit()
    for i in range(2, n-1, 2):
        if counts[i] != 2:
            print(0)
            sys.exit()
else:
    for i in range(1, n-1, 2):
        if counts[i] != 2:
            print(0)
            sys.exit()

ans = 2**(n//2)

print(ans%mod)

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

int main(){
    int *a = new int[10];
    for (int i=0;i<10;i++){
        cin >> a[i];
    }
    sort(a, a+10, greater<int>());
    for (int j=0;j<3;j++)
        cout << a[j] << endl;
    return 0;
}



Measured memory_bytes: 3148
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int n, r;
  cin >> n >> r;
  if(n>=10){
    cout << r << endl;
  }else{
    cout << ((10 - n) * 100) + r << endl;
  }

  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;


int lant[128], rant[128];

int main()
{
  int n, l;
  while(1){
    cin >> n >> l;
    if(n == 0 && l == 0) break;
    memset(lant, -1, sizeof(lant));
    memset(rant, -1, sizeof(rant));    
    int d[32];
    int res = 0, ant = 0;
    rep(i, n){
      string s; int p;
      cin >> s >> p;
      if(s == "L") lant[p] = i;
      else rant[p] = i;
    }

    rep(time, l){
      for(int i=l;i>0;i--){
	if(rant[i] != -1 && lant[i] != -1){
	  swap(rant[i], lant[i]);
	}
	if(i==l-1 && rant[i] != -1){
	  res = time;
	  ant = rant[i]; rant[i] = -1;
	  //	  cout << time << " " << ant << endl;
	  continue;
	}
	rant[i+1] = rant[i]; rant[i] = -1;
      }

      for(int i=1;i<=l;i++){
	if(i==1 && lant[i] != -1){
	  res = time;
	  ant = lant[i]; lant[i] = -1;
	  //	  cout << time << " " << ant  << endl;
	  continue;
	}
	lant[i-1] = lant[i]; lant[i] = -1;
      }
    }
    cout << res+1 << " " << ant+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
using System;

class BubbleSort {
     static void PrintArr(int[] A, int N) {
        for (int i = 0; i < N; i++) {
            Console.Write(A[i]);
            if (i != N-1)
                Console.Write(" ");
            else
                Console.Write("\n");
        }
    }

    static void BSort(int[] A, int N) {
        int c = 0;
        bool flag = true;
        int tmp;

        while (flag) {
            flag = false;
            for (int j = N-1; j > 0; j--) {
                if (A[j] < A[j-1]) {
                    tmp = A[j];
                    A[j] = A[j-1];
                    A[j-1] = tmp;

                    c++;
                    flag = true;
                }
            }
        }
        PrintArr(A, N);
        Console.WriteLine(c);
    }

    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        
        int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

        BSort(A, N);
    }
}

Measured memory_bytes: 9260
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string s,t;
void input(){
    fast_io();
    cin >> s >> t;
}

int solve(){
    string ans = (s==t.substr(0,t.length()-1)) ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3656
N, M = map(int, input().split())
ans = 1
MOD = 10 ** 9 + 7

if abs(N - M) >= 2:
	print(0)
else:
	for i in range(1, N + 1):
		ans *= (i % MOD)
		ans %= MOD
	for i in range(1, M + 1):
		ans *= (i % MOD)
		ans %= MOD
	if (N + M) % 2 == 0:
		ans *= 2

	print(ans % MOD)

Measured memory_bytes: 39280
#pragma GCC optimize("O3,no-stack-protector")
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> rgb(3);
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            rgb[0].push_back(i);
        } else if (s[i] == 'G') {
            rgb[1].push_back(i);
        } else {
            rgb[2].push_back(i);
        }
    }

    Int ans = 0;
    vector<int> t{0, 1, 2};
    do {
        for (auto e : rgb[t[0]]) {
            auto gitr = upper_bound(rgb[t[1]].begin(), rgb[t[1]].end(), e);
            for (; gitr != rgb[t[1]].end(); ++gitr) {
                auto bitr = upper_bound(rgb[t[2]].begin(), rgb[t[2]].end(), *gitr);
                while (bitr != rgb[t[2]].end()) {
                    if (*gitr - e != *bitr - *gitr) {
                        ans++;
                    }

                    ++bitr;
                }
            }

            auto gitr2 = upper_bound(rgb[t[1]].begin(), rgb[t[1]].end(), e);
            for (; gitr2 != rgb[t[1]].end(); ++gitr2) {
                auto bitr2 = upper_bound(rgb[t[2]].begin(), rgb[t[2]].end(), *gitr2);
                while (bitr2 != rgb[t[2]].end()) {
                    if (*gitr2 - e != *bitr2 - *gitr2) {
                        ans++;
                    }

                    ++bitr2;
                }
            }
        }

    } while (next_permutation(t.begin(), t.end()));

    cout << ans / 2 << '\n';

    return 0;
}


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

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

  if (a * b != ( a * b + 1 ) / 2 * 2 ) {
    cout << "Odd" << endl;
      }
  else {
    cout << "Even" << endl;
      }
}

Measured memory_bytes: 3556
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 32


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


class _UnionFind(object):
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def members_dict(self):
        pass

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = lmi()
p = lmi()
xy = llmi(M)
uf = _UnionFind(N)
for x, y in xy:
    uf.union(x - 1, y - 1)

# p[i] = i + 1 ( 1-indexed)
d = dict()
for v in range(uf.n):
    if uf.find(v) not in d:
        d[uf.find(v)] = set()
    d[uf.find(v)].add(p[v])
ans = 0
for i in range(N):
    if i + 1 in d[uf.find(i)]:
        ans += 1
print(ans)


Measured memory_bytes: 65404
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll N ; cin >> N;
  vector<pair<ll, pair<ll,ll>  > > step;
  step.pb(mp(0,mp(0,0)));
  rep(i,N){
    ll t,x,y;cin >> t >> x >> y;
    step.pb(mp(t,mp(x,y)));
  }

  rep(i,step.size()-1){
    ll time = step[i+1].first-step[i].first;
    ll moves = abs(step[i+1].second.first - step[i].second.first) + abs(step[i+1].second.second- step[i].second.second);
    time-=moves;
    if(time<0){
      cout <<"No" << endl;
      return 0;
    }
    if(time%2==1){
      cout <<"No" << endl;
      return 0;
    }
  }

  cout <<"Yes" << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 3444
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] array = new int[n];
		HashMap<Integer, Long> map = new HashMap<Integer, Long>();
		for(int i = 0; i < n; i++){
		    int a = sc.nextInt();
		    array[i] = a;
		    map.put(a, (long)map.getOrDefault(a, 0L) + 1);
		}
		
		// 計算
		long result = 0;
		//HashMap<Integer, Long> calMap = new HashMap<Integer, Long>();
		for(Integer key : map.keySet()){
		    long i = map.get(key);
		    long cnt = i*(i-1)/2;
		    result += cnt;
		}
		
		for(int i = 0; i < n; i++){
		    long t = map.get(array[i]);
		    System.out.println(result - (t-1));
		}
		
		// 出力
		//System.out.println(result);
		
	}
}


Measured memory_bytes: 108384
#include <iostream>
using namespace std;
#define ll long long

int main()
{
	string str;
	ll sum = 0;
	cin >> str;
	for (auto each : str) {
		sum = (sum + each - '0') % 9;
	}
	if (sum == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
int keta(int x) {
    int res = 0;
    while(x!=0){
        x/=10;
        res++;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        if(keta(i)%2==1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N;
    cin >> N;
    vector<int> d(N);
    REP(i, N) cin >> d[i];
    
    ll tmp = 1, ans = 0;
    for(int i = 0; i < N; i++) {
        tmp = d[i];
        for(int j = i+1; j < N; j++) {
            ans += tmp * d[j];
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n):
    s=s^a[i]
ans=[0]*n
for i in range(n):
    ans[i]=a[i]^s
print(*ans)

Measured memory_bytes: 31968
s = list(map(int, list(str(input()))))
k = int(input())
i = 0
if s.count(1) == len(s):
  print(1)
else:
  while s[i] == 1:
    i += 1
  if k <= i:
    print(1)
  else:
    print(s[i])

Measured memory_bytes: 3060
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    n, k = ZZ()
    A = ZZ()+[0]

    for _ in range(k):
        if all([A[i] >= n for i in range(n)]): break
        nA = [0] * (n+1)
        for i in range(n):
            nA[max(0, i-A[i])] += 1
            nA[min(n, i+1+A[i])] -= 1
        for i in range(1, n+1): nA[i] += nA[i-1]
        A = nA
    print(*A[:-1])

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 170700
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val H, W, D = sc.nextInt()
    val AtoIJ = new Array[(Int, Int)](H * W + 1)
    for {
      i <- 1 to H
      j <- 1 to W
    } {
      val A = sc.nextInt()
      AtoIJ(A) = (i, j)
    }
    val Q = sc.nextInt()
    val L, R = new Array[Int](Q)
    (0 until Q) foreach { i =>
      val l, r = sc.nextInt()
      L(i) = l
      R(i) = r
    }

    // H x W までの数が重複なく書かれている
    // 移動量だけ魔力を消費してマスに置かれた駒を移動させる
    // 整数Liの書かれているマスに置かれている
    // Li + nD が = Riになるまで移動を行う
    // Ai,j => (i, j) が O(1) で導出できたとして,
    // 愚直に全部計算した場合どうなる...
    // D = 1の場合, 最悪計算量 O(HWQ) ? 300 x 300 x 10^5 = 9 * 10^9
    // 最良の場合 全部 L_i = R_i で O(Q). ならしても O(HQ) とかで普通にやるとしんどそう
    // Dが固定というのがポイントそう.
    // Dが固定ということは, ある 1 <= L <= R <= H x W について
    // 共有している区間は全て同じ魔力を使用するということ
    // また, D だけスライドする
    // 先に消費魔力テーブルを用意しておく.
    // 答えは dp[R_i] - dp[L_i]
    def solve(): IndexedSeq[Long] = {
      val dp = new Array[Long](H * W + 1)
      for {
        d <- 1 to D
        i <- (d + D) to (H * W) by D
      } {
        val (x1, y1) = AtoIJ(i - D)
        val (x2, y2) = AtoIJ(i)
        dp(i) = dp(i - D) + (x2 - x1).abs.toLong + (y2 - y1).abs.toLong
      }

      (0 until Q).map(q => dp(R(q)) - dp(L(q)))
    }

    println(solve().mkString("\n"))
  }

}


Measured memory_bytes: 114260
using System;

class main{
  public static void Main(string[] args){
  double a = double.Parse(Console.ReadLine());
  
  double i = Math.Floor(a / 1.08);
  double j = Math.Ceiling(a / 1.08);
    
  if(Math.Floor(i * 1.08) == a) Console.WriteLine(i);
  else if(Math.Floor(j * 1.08) == a) Console.WriteLine(j);
  else Console.WriteLine(":(");
  }
}

Measured memory_bytes: 27632
#include<stdio.h>
#include<string.h>
#define N 1001
#define M 501

int LCSLength(char *, char *);

int main()
{
  int q, i, r[M];
  char X[N], Y[N];

  scanf("%d", &q);

  for(i = 0; i < q; i++){
    scanf("%s", X);
    scanf("%s", Y);

    r[i] = LCSLength(X, Y);
  }

  for(i = 0; i < q; i++){
    printf("%d\n", r[i]);
  }
  
  return 0;
}

int LCSLength(char *X, char *Y)
{

  int m, n, i, j;
  int c[N][N];

  m = (int)strlen(X);
  n = (int)strlen(Y);

  for(i = 1; i <= m; i++) c[i][0] = 0;
  for(j = 0; j <= n; j++) c[0][j] = 0;

  for(i = 1; i <= m; i++){
    for(j = 1; j <= n; j++){
      if(X[i-1] == Y[j-1]) c[i][j] = c[i-1][j-1] + 1;
      else if(c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
      else c[i][j] = c[i][j-1];
    }
  }

  return c[m][n];
}

Measured memory_bytes: 4524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//UnionFind tree(n);

int main(){
    ll n,m; cin>>n>>m;
    vector<ll> ans(m+1),bridge(n+1,1);
    ans[m]=n*(n-1)/2;
    vector<ll> a(m),b(m);
    rep(i,m) cin>>a[i]>>b[i];
    UnionFind tree(n+1);
    rep(i,m){
        if(!tree.same(a[m-i-1],b[m-i-1])){
            ll x=bridge[tree.par[a[m-i-1]]];
            ll y=bridge[tree.par[b[m-i-1]]];
            ll z=x+y;
            tree.unite(a[m-i-1],b[m-i-1]);
            bridge[tree.par[a[m-i-1]]]=z;
            bridge[tree.par[b[m-i-1]]]=z;
            ans[m-i-1]=ans[m-i]+x*(x-1)/2+y*(y-1)/2-z*(z-1)/2;
        }else{
            ans[m-i-1]=ans[m-i];
        }
    }
    rep(i,m) cout<<ans[i+1]<<endl;
    return 0;
}

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

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

    if (s[0] == s[1] && s[1] == s[2])
        cout << "Yes";
    else if (s[1] == s[2] && s[2] == s[3])
        cout << "Yes";
    else
        cout << "No";
    cout << endl;

    return 0;
}


Measured memory_bytes: 3584