akhauriyash/Code-Regression huggingface dataset:
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <string>
#include <cstdio>
#include <chrono>
#include <random>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) x.size()
#define lowbit(x) x&(-x)
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 0x3f3f3f3f;
const int N=1e5+10;

ll r[N],g[N],v[N];

int cmp(int a,int b){
	return a>b;
}

int main() {
	IOS;
#ifdef xiaofan
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
#endif

	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	for(int i=1;i<=a;i++) cin>>r[i];
	for(int i=1;i<=b;i++) cin>>g[i];
	for(int i=1;i<=c;i++) cin>>v[i];
	sort(r+1,r+a+1,cmp);
	sort(g+1,g+b+1,cmp);
	sort(v+1,v+c+1,cmp);
	int pos1=x;
	int pos2=y;
	int pos3=1;
	r[0]=INF;
	g[0]=INF;
	while(pos3<=c){
		if(v[pos3]<r[pos1] && v[pos3]<g[pos2]) break;
		int t1=v[pos3]-r[pos1];
		int t2=v[pos3]-g[pos2];
		if(t1>t2){
			r[pos1]=v[pos3];
			pos1--;
			pos3++;
		}else{
			g[pos2]=v[pos3];
			pos2--;
			pos3++;
		}
		
	}
	ll ans=0;
	for(int i=1;i<=x;i++) ans+=r[i];

	for(int i=1;i<=y;i++) ans+=g[i];
	
	cout<<ans<<endl;
	



	return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N, H, W;
    cin >> N >> H >> W;
    int ans = 0;
    rep(i, N) {
        int A, B;
        cin >> A >> B;
        if (A >= H && B >= W) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int BubbleSort(int *A,int n,int *cnt);
int main(void){
    int n,i;
    int A[128];
    int cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&A[i]);
    BubbleSort(A,n,&cnt);
    for(i=0;i<n-1;i++)
        printf("%d ",A[i]);
    printf("%d\n",A[n-1]);
    printf("%d\n",cnt);
    return 0;
}
int BubbleSort(int *A,int n,int *cnt){
    int flag=1;
    int j;
    while(flag){
        flag=0;
        for(j=n-1;j>=1;j--){
            if(A[j]<A[j-1]){
                int temp=A[j];
                A[j]=A[j-1];
                A[j-1]=temp;
                *cnt=*cnt+1;
                flag=1;
            }
        }
    }
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    int rCnt=0, bCnt=0;
    string s;
    cin >> n >> s;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'R'){
            rCnt++;
        }else{
            bCnt++;
        }
    }
    if(rCnt>bCnt){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = 0
a = []
for i in range(n):
    a.append(int(input())-1)

count = 0
for i in range(n+10):
    count += 1
    p = a[p]
    if p == 1:
        print(count)
        break
else:
    print(-1)



Measured memory_bytes: 7084
#include<iostream>
#include<algorithm>
#include<map>
typedef long long lint;
using namespace std;

int main()
{
	int N,A;
	map<int,int> m;
	int ans=0;
	
	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> A;
		m[A]++;
	}
	
	for(auto&& itr:m)
		ans+=(itr.second%2);
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

int main(void){
  int A,B,C;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  if(A==B&&A!=C)
    printf("Yes");
  else if(A==C&&A!=B)
    printf("Yes");
  else if(B==C&&B!=A)
    printf("Yes");
  else
    printf("No");
  return 0;
}

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

int main(){
  int N;
  int d[101];
  cin >> N ;
  for (int i=0;i<N;i++){
    cin >> d[i];
  }
  set<int>kagamimochi;
  for(int i=0;i<N ;i++){
    kagamimochi.insert(d[i]);//insertで挿入
  }
  cout << kagamimochi.size() << endl;
}

Measured memory_bytes: 256
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        sum1=0
        for k in range(d):
            sum1=sum1+(x[i][k]-x[j][k])**2
        s=sum1**(1/2)
        if s.is_integer()==True:
            ans=ans+1
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

string convertString(string str,int n){
	int length = str.length();
	for(int i = 0; i < length; i++){
		int charNum = str[i] - 'A';
		charNum = (charNum + n)%26;
		str[i] = charNum + 'A';
	}
	return str;
}

int main()
{
	string s;
	int n;
	cin>>n>>s;
	cout<<convertString(s,n)<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    static boolean[] visited;

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );
	final int m = stdin.nextInt();
	final int n = stdin.nextInt();

	visited = new boolean[ m + 1 ];

	ArrayList<ArrayList<Integer> > map = new ArrayList< ArrayList<Integer> >();
	for ( int i = 0; i <= m; i++ ){
	    map.add( new ArrayList<Integer>() );
	}

	for ( int i = 0; i < n; i++ ) {
	    final int from = stdin.nextInt();
	    final int to = stdin.nextInt();
	    map.get( from ).add( to );
	}
	
	ArrayList<Integer> order = new ArrayList<Integer>();
	for ( int i = 1; i <= m; i++ ) {
	    if ( !visited[ i ] ) {
		dfs( i, order, map );
	    }
	}
	for ( int i = order.size() - 1; i >= 0; i-- ) {
	    System.out.println( order.get( i ) );
	}
    }
    
    static void dfs( int i, ArrayList<Integer> order, ArrayList< ArrayList<Integer> > map ) {
	visited[ i ] = true;
	for ( int j : map.get( i ) ) {
	    if ( !visited[ j ] ) {
		dfs( j, order, map );
	    }
	}
	order.add( i );
    }
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b,c,d; cin>>a>>b>>c>>d;
	cout<<(abs(c-a)<=d||(abs(a-b)<=d&&abs(b-c)<=d)?"Yes"s:"No"s)<<"\n"s;
}

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

const int P = 1e9 + 7;
int bm[103][103];

int poww(long long a , int b){int tms = 1; while(b){if(b & 1) tms = tms * a % P; a = a * a % P; b >>= 1;} return tms;}
int calc(int a , int b , int A , int B){return (1ll * poww(a , B / b) * b + 1ll * poww(b , A / a) * a - 1ll * a * b + P) % P;}

int main(){
	int a , b , c , A , B , C;
	for(int i = 0 ; i <= 100 ; ++i){bm[i][0] = 1; for(int j = 1 ; j <= i ; ++j) bm[i][j] = (bm[i - 1][j] + bm[i - 1][j - 1]) % P;}
	cin >> a >> b >> c >> A >> B >> C;
	if(A % a || B % b || C % c){puts("0"); return 0;}
	int sum = a * b * c;
	sum = (sum + 1ll * c * poww(calc(a , b , A , B) , C / c)) % P;
	sum = (sum + 1ll * b * poww(calc(a , c , A , C) , B / b)) % P;
	sum = (sum + 1ll * a * poww(calc(b , c , B , C) , A / a)) % P;
	sum = (sum - 1ll * a * b * poww(c , A / a * B / b) % P + P) % P;
	sum = (sum - 1ll * b * c * poww(a , B / b * C / c) % P + P) % P;
	sum = (sum - 1ll * a * c * poww(b , A / a * C / c) % P + P) % P;
	for(int q = 1 ; q < B / b ; ++q){
		static int arr[103];
		for(int k = A / a - 1 ; k ; --k){
			arr[k] = 1ll * bm[B / b][q] * bm[A / a][k] % P * poww(poww(c , A / a - k) - 1 , B / b - q) % P;
				for(int l = k + 1 ; l < A / a ; ++l)
				arr[k] = (arr[k] - 1ll * arr[l] * bm[l][k] + P) % P;
			sum = (sum + 1ll * arr[k] * (poww(poww(b , k) + poww(a , q) - 1 , C / c) - poww(poww(b , k) , C / c) - poww(poww(a , q) , C / c) + 1) % P * a * b * c % P + P) % P;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    int cnt_w = 0, cnt_r = 0;
    for (size_t i = 0; i < s.length(); i++)
    {
        if (s[i] == 'W')
            cnt_w++;
        else
            cnt_r++;
    }
    int ans = 0;
    for (int i = 0; i < cnt_r; i++)
    {
        if (s[i] == 'W')
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3700
from bisect import bisect_left
n=int(input())
A=[int(input()) for _ in range(n)]

DP=[A[0]]
for i in range(1,n):
    num=A[i]
    if DP[-1]<num:
        DP.append(num)
    else:
        index=bisect_left(DP,num)
        DP[index]=num
print(len(DP))


Measured memory_bytes: 10352
/*
Author : N_o_o_B
Created : April 15 2020 14:22:18 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    ll n,k;
    cin >> n >> k;
    ll ans = (ll)n*n;
    if(k==0) {
        cout << ans << endl;
        return 0;
    }
    rep(b,k+1,n){
        ll cur = 0;
        cur += n/b*k;
        cur += min(n%b+1,k);
        cur--;
        ans -= cur;
    }
    ans -= k*n;
    cout << ans << endl;

    time_taken();
    return 0;
}

/*
    1 2 3 4 5

*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
#define pii pair<int,int>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define inf 1e9
void solve(){
	ll a,b,k;
	cin>>a>>b>>k;
	if(k>a){
		cout<<0<<" ";
		k-=a;
	} else{
		cout<<a-k<<" "<<b<<endl;
		return;
	}
	if(k>b){
		cout<<0<<endl;
		return;
	} else{
		cout<<b-k<<endl;
		return;
	}
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
typedef long long ll;
const int MAX_N=100,INF=1e8;
int N,T;

int main(){
	cin>>N>>T;
	int ans=INF;
	REP(i,N){
		int c,t;
		cin>>c>>t;
		if (t<=T){
			ans=min(ans,c);
		}
	}
	if (ans==INF){
		cout<<"TLE"<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return float64(i)
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

type pair struct {
	s int
	c int
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := readInt(), readInt()

	pairs := make(map[int]int, 0)
	for i := 0; i < m; i++ {
		s := readInt()
		c := readInt()
		s--
		if _, ok := pairs[s]; ok {
			if pairs[s] != c {
				fmt.Println("-1")
				return
			}
		}
		pairs[s] = c
	}
	if n == 1 && pairs[0] == 0 {
		fmt.Println(0)
		return
	}
	for i := 1; i <= 999; i++ {
		ok := true
		keta := 0
		k := i
		r := make([]int, 0)
		for k > 0 {
			r = append(r, k%10)
			k /= 10
			keta++
		}
		if keta != n {
			ok = false
			continue
		}
		Reverse(r)
		for k, v := range r {
			if _, exist := pairs[k]; !exist {
				continue
			}
			if pairs[k] != v {
				ok = false
				break
			}
		}
		if ok {
			fmt.Println(i)
			return
		}
	}
	fmt.Println("-1")
}

func Reverse(a []int) []int {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}


Measured memory_bytes: 640
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
        int H = stdIn.nextInt();
	int W = stdIn.nextInt();
	int h = stdIn.nextInt();
	int w = stdIn.nextInt();
	System.out.println((H-h)*(W-w));
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define setNil(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
#define setNegINF(x) memset((x),192,sizeof(x)) //NegINF=-INF-1
#define setNeg1(x) memset((x),255,sizeof(x))
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<int,ll> pii;
int n,m,res;
vector<pii> g[100005];
pii p[100005];
bool vis[100005];
void dfs(int x){
	vis[x]=1;
	for(int i=0;i<g[x].size();i++){
		int u=g[x][i].X;
		if(vis[u]){
			if(p[x].X+p[u].X==0){
				if(p[x].Y+p[u].Y!=g[x][i].Y){
					cout<<"0\n";
					exit(0);
				}
			}
			else{
				ll diff=g[x][i].Y-(p[x].Y+p[u].Y);
				if(p[x].X<0)diff=-diff;
				if(diff<2 || diff&1 || (res && (diff>>1)!=res)){
					cout<<"0\n";
					exit(0);
				}
				else res=diff>>1;
			}
		}
		else{
			p[u]=pii(-p[x].X,g[x][i].Y-p[x].Y);
			dfs(u);
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		ll c;
		cin>>u>>v>>c;
		g[u].push_back(pii(v,c));
		g[v].push_back(pii(u,c));
	}
	p[1]=pii(1,0);
	dfs(1);
	if(!res){
		ll lb=2e9,ub=0;
		for(int i=1;i<=n;i++){
			if(p[i].X<1)lb=min(lb,p[i].Y-1);
			else ub=max(ub,1-p[i].Y);
		}
		cout<<max(0ll,lb-ub+1)<<endl;
	}
	else{
		for(int i=1;i<=n;i++){
			if(p[i].X*res+p[i].Y<=0){
				cout<<"0\n";
				return 0;
			}
		}
		cout<<"1\n";
	}
	return 0;
}

Measured memory_bytes: 14208
n=int(input())
list=[[0]*n]
list=input().split()
for i in range(n):
  list[i]=int(list[i])

yen=1000
stock=0
keikou=0
for i in range(1,n):
  if list[i]-list[i-1]<=0:
    keikou+=1
if keikou!=n-1:
  for t in range(1,n):
    if list[t]-list[t-1]>=0:
      stock+=int(yen/list[t-1])
      yen-=list[t-1]*int(yen/list[t-1])
      yen+=list[t]*stock
      stock=0
print(yen)

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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template<typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

VI primes(ll val) {
    VI v;
    ll i = 2;
    while(i * i <= val) {
        if(val % i == 0) v.pb(i);
        while(val % i == 0) val /= i;
        i++;
    }
    if(val != 1) v.pb(val);
    return v;
}

int main() {
    ll A, B;
    cin >> A >> B;
    VI a = primes(A), b = primes(B);

    sort(all(a)); sort(all(b));
    DU(a) DU(b)
    int ia = 0, ib = 0;
    int ans = 1;
    while(ia < a.size() && ib < b.size()) {
        if(a[ia] == b[ib]) {
            ans++;
            ia++; ib++;
        } else if (a[ia] < b[ib]) {
            ia++;
        } else {
            ib++;
        }
    }
    out(ans);
    return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn main() {
    let stdin = std::io::stdin();
    let mut reader = std::io::BufReader::new(stdin.lock());

    let mut v: Vec<Vec<i32>> = Vec::new();

    for _ in 0..3 {
        let mut s = String::new();
        let _ = reader.read_line(&mut s);
        let mut tmp = s.split_whitespace().map(|x| x.parse().unwrap()).collect();
        v.push(tmp);
    }

    let mut ans = false;

    let x_max = v[1].iter().max().unwrap();
    let y_min = v[2].iter().min().unwrap();

    let x = v[0][2];
    let y = v[0][3];

    for z in x_max + 1..y_min + 1 {
        if x < z && z <= y {
            ans = true;
            break;
        }
    }

    println!("{}", if ans { "No War" } else { "War" });
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

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

    bool exists = false;
    for (int i = 1; i <= 3; ++i) {
        int tmp = a * b * i;
        if (tmp % 2 == 1) {
            exists = true;
            break;
        }
    }
    if (exists)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>

using namespace std;

int N,M,Q; vector<vector<int>> sum;
int makesumtable(vector<int> L, vector<int> R){
  sum = vector<vector<int>> (N + 1, vector<int>(N+1,0));
  for(int i = 0; i < M; i++){
    sum[L[i]][R[i]]++;}
  
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= N; j++){
      sum[i][j] = sum[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];}}}
    
int getsumtable(int p, int q){
  int ans = sum[q][q] - sum[p-1][q] - sum[q][p-1] + sum[p-1][p-1]; 
  return ans;}
              

int main(){
 cin >> N >> M >> Q;
  vector<int> L(M); vector<int> R(M);
  for(int i = 0; i < M ; i++){
    cin >> L[i] >> R[i];}
  
  vector<int> p(Q); vector<int> q(Q);
  for(int i = 0; i < Q; i++){ cin >> p[i] >> q[i];}
  
  makesumtable(L,R);
  
  for(int i = 0; i < Q; i++){
    cout << getsumtable(p[i],q[i]) << endl;}
  
  return 0;}
 

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

int main(void){
    int N; cin >> N;
    int C[N],S[N],F[N];
    for (int i = 0; i < N-1; i++)
    {
        cin >> C[i+1] >> S[i+1] >> F[i+1];
    }

    int ans;
    for (int i = 1; i < N; i++)
    {
        ans = 0;
        ans += S[i]+C[i];
        for (int j = i+1; j < N; j++)
        {
            ans = max(ans,S[j]);
            ans += (F[j]-(ans - S[j])%F[j])%F[j];
            ans += C[j];
        }
        cout << ans << endl;
    }
    cout << 0 << endl;
}

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

h=list(map(int,input().split()))
l=[0]*n
for j in range(m):
    a,b=map(int,input().split())
    l[a-1]=max(l[a-1],h[b-1])
    l[b-1]=max(l[b-1],h[a-1])

ans=0
for i in range(n):
    if h[i]>l[i]:
        ans+=1

print(ans)        

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

int main()
{
  int A, B;
  cin >> A >> B;
  
  cout << A * B << endl;
}

Measured memory_bytes: 3628
def tri(x1, y1, x2, y2, x3, y3):
    return abs((x2-x1)*(y3-y1) - (y2-y1)*(x3-x1)) / 2
 
while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
    except:
        break
    abc = tri(x1, y1, x2, y2, x3, y3)
    abp = tri(x1, y1, x2, y2, xp, yp)
    acp = tri(x1, y1, x3, y3, xp, yp)
    bcp = tri(x2, y2, x3, y3, xp, yp)
    x, y = int(abc*pow(10, 5)), int((abp+acp+bcp)*pow(10, 5))
    print("YES" if x >= y else "NO")
   


Measured memory_bytes: 5588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc106_d
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, m, q;
            int l, r;
            string[] nums;
            int[,] sum = new int[501, 501];

            nums = Console.ReadLine().Split(' ');
            n = int.Parse(nums[0]);
            m = int.Parse(nums[1]);
            q = int.Parse(nums[2]);

            for(int i = 0; i < m; ++i)
            {
                nums = Console.ReadLine().Split(' ');
                l = int.Parse(nums[0]);
                r = int.Parse(nums[1]);

                ++sum[l, r];
            }

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

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

            for(int i = 0; i < q; ++i)
            {
                nums = Console.ReadLine().Split(' ');
                l = int.Parse(nums[0]);
                r = int.Parse(nums[1]);

                Console.WriteLine(sum[r, r] - sum[r, l - 1] - sum[l - 1, r] + sum[l - 1, l - 1]);
            }            
        }
    }
}


Measured memory_bytes: 16664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n+2); rep(i, n) cin >> A[i+1];
  ll sum = 0;
  rep(i, n+1) sum += abs(A[i+1]-A[i]);
  rep(i, n) {
    cout << sum - abs(A[i+1]-A[i]) - abs(A[i+2]-A[i+1]) + abs(A[i+2]-A[i]) << "\n";
  }
  return 0;
}


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

using namespace std;

int main()
{
	string s;
	cin>>s;
	int count=0,mx=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='R')
			count++;

		else
		{
			mx=max(mx,count);
			count=0;
		}
	}

	cout<<max(mx,count);
	return 0;
}

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

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

int main(){
	int n;
	cin>>n;
	vector<string>s(n);
	map<string,int>mp;
	for(int i=0;i<n;i++){
		cin>>s[i];
		mp[s[i]]++;
	}
	int m;
	cin>>m;
	vector<string>t(m);
	for(int i=0;i<m;i++){
		cin>>t[i];
		mp[t[i]]--;
	}
	int ans=0;
	for(auto itr=mp.begin();itr!=mp.end();itr++){
		if(itr->second>ans)ans=itr->second;
	}
	cout<<ans<<endl;
	return 0;	
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

long long int F[200][10];
long long int P[200][11];

int main(){
	
	int N;
	cin >> N;
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 10; j++){
			cin >> F[i][j];
		}
	}
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 11; j++){
			cin >> P[i][j];
		}
	}
	
	long long int ans = -1000000000000000LL;
	
	for(int n = 1; n < 1024; n++){
		int hoge = n;
		int a[10];
		for(int i = 0; i < 10; i++){
			a[i] = hoge % 2;
			hoge /= 2;
		}
		long long int cur = 0;
		for(int i = 0; i < N; i++){
			int num = 0;
			for(int j = 0; j < 10; j++){
				if(a[j] == 1 && F[i][j] == 1){
					num++;
				}
			}
			cur += P[i][num];
		}
		ans = max(ans, cur);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int gcd(int a,int b){
	while(a){
		b%=a;int c=a;a=b;b=c;
	}
	return b;
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
char str[10][11000];
int len[10];
int sz[10];
int com[10][11000];
int ret[11000];
int main(){
	int T;scanf("%d",&T);
	while(T--){
		int a;scanf("%d",&a);
		for(int i=0;i<a;i++)scanf("%s",str[i]);
		for(int i=0;i<a;i++)len[i]=strlen(str[i])/2;
		for(int i=0;i<a;i++){
			int v=0;
			for(int j=1;j<=len[i];j++){
				if(len[i]%j)continue;
				bool ok=true;
				for(int k=0;k<len[i];k++){
					if(k%j&&(str[i][k*2]!='0'||str[i][k*2+1]!='0')){ok=false;break;}
				}
				if(ok)v=j;
			}
			sz[i]=len[i]/v;
			for(int j=0;j<len[i]/v;j++){
				com[i][j]=(str[i][v*j*2]-'0')*16+(str[i][v*j*2+1]-'0');
			}
		}
		int now=1;
		for(int i=0;i<a;i++){
			now=lcm(now,sz[i]);
			if(now>1024)break;
		}
		if(now>1024){
			printf("Too complex.\n");
		}else{
			for(int i=0;i<now;i++)ret[i]=0;
			for(int i=0;i<a;i++){
				for(int j=0;j<sz[i];j++)ret[now/sz[i]*j]+=com[i][j];
			}
			for(int i=0;i<now;i++)printf("%02X",ret[i]);
			printf("\n");
		}
	}
}

Measured memory_bytes: 1172
package main

import (
  "fmt"
)

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

  baseNum := k
  tmpNum := n
  conversionNum := "" // 変換後の値格納用　11進以上はアルファベットのため、文字列で扱う必要がある

  for digitNum := 1;; {
      remainder := tmpNum%baseNum
      if remainder >= 10 {
          conversionNum = string('A' + (remainder-10)) + conversionNum
      } else {
          conversionNum = string('0' + remainder) + conversionNum
      }
      tmpNum = tmpNum/baseNum
      if tmpNum == 0 {
          break
      }
      digitNum *= 10
  }
  fmt.Println(len(conversionNum))
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int h, a, ans = 0;

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> h >> a;
	ans = h / a;
	if( h % a )
	{
		++ans;
	}
	cout << ans << "\n";	
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] a = new int[m];
            int[] b = new int[m];
            int[] c = new int[m];
            for (int i = 0; i < m; i++) {
                a[i] = in.nextInt() - 1;
                b[i] = in.nextInt() - 1;
                c[i] = -in.nextInt();
            }

            long[] dist = new long[n];
            Arrays.fill(dist, Long.MAX_VALUE / 3);
            dist[0] = 0;

            for (int i = 0; i < n - 1; i++) {
                for (int j = 0; j < m; j++) {
                    if (dist[a[j]] == Long.MAX_VALUE / 3) continue;

                    if (dist[b[j]] > dist[a[j]] + c[j]) {
                        dist[b[j]] = dist[a[j]] + c[j];
                    }
                }
            }

            boolean[] canFromLoop = new boolean[n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (dist[a[j]] == Long.MAX_VALUE / 3) continue;

                    if (dist[b[j]] > dist[a[j]] + c[j]) {
                        canFromLoop[a[j]] = true;
                    }

                    if (canFromLoop[a[j]]) {
                        canFromLoop[b[j]] = true;
                    }
                }
            }

            out.println(canFromLoop[n - 1] ? "inf" : -dist[n - 1]);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

vector<int> X = {1,0,-1,0}, Y = {0,1,0,-1};
int inf = 1001001001;

int main(){
  int H,W,K,x1,y1,x2,y2;
  cin >> H >> W >> K >> x1 >> y1 >> x2 >> y2;
  vector<vector<bool>> C(H+2,vector<bool>(W+2,false));
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      char c;
      cin >> c;
      if(c=='.') C[i][j] = true;
    }
  }
  
  vector<vector<vector<pair<int,int>>>> dp(H+2,vector<vector<pair<int,int>>>(W+2,vector<pair<int,int>>(4,make_pair(inf,-1))));
  queue<pair<pair<int,int>,int>> Q;
  for(int i=0;i<=3;i++){
    Q.push(make_pair(make_pair(x1,y1),i));
    dp[x1][y1][i] = make_pair(0,K);
  }
  
  while(!Q.empty()){
    pair<int,int> u = Q.front().first;
    int r = Q.front().second, ux = u.first, uy = u.second;
    Q.pop();
    for(int s=0;s<=3;s++){
      int vx = ux+X[s], vy = uy+Y[s];
      if(!C[vx][vy]) continue;
      if(r==s && dp[ux][uy][r].second<K){
        if(dp[vx][vy][s]>make_pair(dp[ux][uy][r].first,dp[ux][uy][r].second+1)){
          dp[vx][vy][s] = make_pair(dp[ux][uy][r].first,dp[ux][uy][r].second+1);
          Q.push(make_pair(make_pair(vx,vy),s));
        }
      }
      else{
        if(dp[vx][vy][s]>make_pair(dp[ux][uy][r].first+1,1)){
          dp[vx][vy][s] = make_pair(dp[ux][uy][r].first+1,1);
          Q.push(make_pair(make_pair(vx,vy),s));
        }
      }
    }
  }
  
  int ans = inf;
  for(int i=0;i<=3;i++) ans = min(ans,dp[x2][y2][i].first);
  if(ans==inf) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 284912
import java.awt.*;
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        String s=sc.next();
        int n=s.length();
        boolean l=isPal(s.substring(0,(n-1)/2));
        boolean r=isPal(s.substring(((n+3)/2)-1));
        if (isPal(s) && l & r) System.out.println("Yes");
        else System.out.println("No");
    }
    static boolean isPal(String s){
        if (s.length()==1)return true;
        int l=0,r=s.length()-1;
        while (l<=r){
            if (s.charAt(l)!=s.charAt(r))return false;
            l++;
            r--;
        }
        return true;
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 22484
#include<iostream>
using namespace std;
int main()
{
  int M,D,p_days=0,d1,d10;
  cin>>M>>D;
  for(int i=1;i<=M;i++)
  {
    for(int j=10;j<=D;j++)
    { 
      d1=j%10;
      d10=j/10;
      if(d1>=2 && d10>=2)
      {
        if((d1*d10)==i)
          p_days++;
      }
    }
  }
  cout<<p_days;
 return 0;
}

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

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d|| (abs(a - b) <= d && abs(b - c) <= d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        long x = Long.parseLong(sc.next());

        for (int i = 0; i < 10; i++) {
            x = r * x - d;
            System.out.println(x);
        }
    }
}


Measured memory_bytes: 21332
n,m,c=map(int,input().split())  
b =list(map(int, input().split()))
cnt = 0
for i in range(n):
    s = 0
    a =list(map(int, input().split()))
    for j in range(m):
        s += a[j]*b[j]
    if s +c > 0:
        cnt +=1
print(cnt)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    // printf("%d %d \n", 'a', 'A');
    // printf("%d %d \n", 'z', 'Z');

    pair<int, int> capitalRange, smallRange;
    capitalRange = make_pair('A', 'Z');
    smallRange = make_pair('a', 'z');
    char in;
    while (in = getc(stdin))
    {
        if (capitalRange.first <= in && in <= capitalRange.second)
            printf("%c", in + (smallRange.first - capitalRange.first));
        else if(smallRange.first <= in && in <= smallRange.second)
            printf("%c", in - (smallRange.first - capitalRange.first));
        else
            cout << in;

        if(in == '\n')
            break;
    }

    return 0;
}


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

struct UnionFind{
	vector<int> d;
	UnionFind(int n=0): d(n,-1) {}
	int find(int x){
		if(d[x]<0) return x;
		return d[x]=find(d[x]);
	}
	bool unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return false;
		if(d[x]>d[y]) swap(x,y);

		d[x]+=d[y];
		d[y]=x;
		return true;
	}
	bool same(int x,int y){return find(x)==find(y);}
	int size(int x){return -d[find(x)];}
};

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

	int N,M;
	int i,k;
	int ans=0;
	int ctr=0;

	cin >> N >> M;

	UnionFind uni(N);
	rep(i,M){
		int x,y;
		cin >> x >> y;
		x--;y--;
		uni.unite(x,y);
	}

	rep(i,N) ans=max(ans,uni.size(i));
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  string n;cin>>n;
  cout << ((n[2]==n[1])&&(n[3]==n[2]||n[1]==n[0])?"Yes":"No") << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	mp := map[int]bool{}
	for i := 0; i < N; i++ {
		A := sc.NextInt()
		if _, ok := mp[A]; ok {
			delete(mp, A)
		} else {
			mp[A] = true
		}
	}
	fmt.Println(len(mp))

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

using namespace std;

int main () {
  string s;
  cin >> s;
  int n = (int)s.size();
  long long b_cnt = 0;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'W') ans += b_cnt;
    else b_cnt++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    ll ans = 0;

    ll sum = a.back();
    // for (ll i = 1; i < n; i++)
    // {
    //     sum += a[i];
    //     sum %= 1000000007;
    // }

    for (ll i = n - 2; i >= 0; i--)
    {
        ll temp = sum * a[i] % 1000000007;
        ans += temp;
        ans %= 1000000007;
        sum += a[i];
        sum %= 1000000007;
    }

    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N;
ll H[100010];

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

    for (int i = N-2; i >= 0; --i) {
        if (H[i] <= H[i+1]) {
            continue;
        } else if (H[i] == H[i+1] + 1) {
            H[i]--;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <stack>
using namespace std;

typedef pair<int, int> pii;
vector<pii> v[100001];
int h[100001];
bool used[100001];
int x[100001];

bool dfs(int p)
{
  used[p] = true;
  for(auto u : v[p]){
    if(used[u.first]){
      if(x[p] + u.second != x[u.first]) return false;
    } else {
      x[u.first] = x[p] + u.second;
      if(!dfs(u.first)) return false;
    }
  }
  return true;
}

int main()
{
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int l, r, d;
    cin >> l >> r >> d;
    v[l].push_back(make_pair(r, d));
    h[r]++;
  }

  stack<int> st;
  for(int i = 1; i <= n; i++)
    if(h[i] == 0)
      st.push(i);

  vector<int> ans;
  while(st.size()){
    int i = st.top();
    st.pop();
    ans.push_back(i);
    for(auto u : v[i]){
      h[u.first]--;
      if(h[u.first] == 0) st.push(u.first);
    }
  }

  if(ans.size() != n){
    cout << "No" << endl;
    return 0;
  }

  for(int i = 0; i < n; i++){
    if(!used[ans[i]]){
      if(!dfs(ans[i])){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 10232
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
char a[Max];
int main()
{
    scanf("%s",a);
    int len = strlen(a);
    int ans1=0,ans2=0;
    int now=0;
    for(int i=0;i<len;i++){
        if((a[i]-'0')!=now)
            ans1++;
        now=now==1?0:1;
    }
    now=1;
    for(int i=0;i<len;i++){
        if((a[i]-'0')!=now)
            ans2++;
        now=now==1?0:1;
    }
   // printf("%d %d\n",ans1,ans2);
    printf("%d\n",min(ans1,ans2));
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
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;
#define fin(ans) cout << (ans) << '\n'
//x+1 = rx - D
int main()
{
    int N,M;
    int flag[101000] = {0};
    int L,R;
    int cnt = 0;
    cin >> N >> M;
    REP(i,M){
        cin >> L >> R;
        if (i == 0)
        {
            REPD(j,L,R+1){
                flag[j] = 1;
            }
        }
        else
        {
            REPD(j,1,L) flag[j] = 0;
            REPD(j,R+1,N+1) flag[j] = 0;
        }
    }
    REPD(i,1,N+1){
        //fin(flag[i]);
        cnt += flag[i];
    }
    fin(cnt);
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#define mp make_pair
#define F first
#define S second
using namespace std;

typedef long long int ll;

const ll maxN = 1e7;
const ll INF = 1e17;

ll xs[] = {-1, 1, 0, 0};
ll ys[] = {0, 0, -1, 1};

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll a[5];
	for(ll i=0; i<5; i++)
		cin >> a[i];
	string st = "01234";
	ll mn = INF;
	do{
		ll cur = 0;
		for(ll i=0; i<4; i++){
			cur += a[st[i]-'0'];
			if(cur%10 != 0)
				cur += 10-(cur%10);
		}
		mn = min(mn, cur + a[st[4]-'0']);
	}while(next_permutation(begin(st), end(st)));
	cout << mn;
	return 0;
}

Measured memory_bytes: 3540
import std.stdio;
import std.string;
import std.array;
import std.algorithm;
import std.conv;

void main() {
	auto n = readln.chomp.to!int;
	auto a = readln.chomp.split(' ').map!(to!int).array;

	auto counts = new int[n];
	foreach (e;a) {
		++counts[e - 1];
	}

	foreach (e;counts) {
		writeln(e);
	}
}


Measured memory_bytes: 11644
#include <iostream>
#include <vector>

using namespace std;

const int NMAX = 1000;

int N, f;
int ord[NMAX + 5][NMAX + 5];
int m[NMAX + 5][NMAX + 5];

vector < int > g[NMAX * NMAX + 5];
vector < int > w;

int ind[NMAX * NMAX + 5];

int main()
{
    cin >> N;

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

            if(!m[min(i, ord[i][j])][max(i, ord[i][j])])
                m[min(i, ord[i][j])][max(i, ord[i][j])] = ++f;
        }

        for(int j = 2; j < N; j++)
        {
            ///trasam muchie de la i, ord[i][j - 1] la i, ord[i][j]
            g[m[min(i, ord[i][j - 1])][max(i, ord[i][j - 1])]].push_back(m[min(i, ord[i][j])][max(i, ord[i][j])]);
            ind[m[min(i, ord[i][j])][max(i, ord[i][j])]]++;
        }
    }

    for(int i = 1; i <= f; i++)
        if(!ind[i])
            w.push_back(i);

    int days = 0, processed = 0;

    while(!w.empty())
    {
        days++;
        processed += w.size();

        vector <int> w2;

        for(auto it : w)
        {
            for(auto it2 : g[it])
            {
                ind[it2]--;
                if(ind[it2] == 0)
                    w2.push_back(it2);
            }
        }

        w = w2;
    }

    if(processed == f)
        cout << days << '\n';
    else
        cout << -1 << '\n';

    return 0;
}


Measured memory_bytes: 50944
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int cnt = 1;
    rep(i,n){
        if(a[i] == cnt) ++cnt;
    }
    sort(all(a));
    if(!binary_search(all(a),1)) cout << -1 << '\n';
    else cout << n - cnt + 1 << '\n';
	return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <tuple>
#include <functional>
#include <limits>
#include <utility>
#include <string>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    vector<int> stack;

    unordered_map<string, function<int(int, int)>> operations
    {
        { "+", plus<int>() }, { "-", minus<int>() }, { "*", multiplies<int>() }
    };

    string symbol;
    while(cin >> symbol)
    {
        auto it(operations.find(symbol));

        if(it != end(operations))
        {
            int x(stack.back());
            stack.pop_back();

            int y(stack.back());
            stack.pop_back();

            stack.push_back(it->second(y, x));
        }
        else
        {
            stack.push_back(stoi(symbol));
        }
    }

    cout << stack.back() << endl;

    return 0;
}

Measured memory_bytes: 3184