akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int r = in.nextInt();

			if (r < 1200) {
				out.println("ABC");
			} else if (r < 2800) {
				out.println("ARC");
			} else {
				out.println("AGC");
			}

		}
	}

	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 long nextLong() {
			return Long.parseLong(nextString());
		}

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

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

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

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

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

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

}


Measured memory_bytes: 21460
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
#define int long long
using namespace std;
#define rep(a,b,c) for(int b=a;b<c;b++)
int a[114514],b[114514],c[114514],d[114514],e[114514];
signed main(){
	int n;
	cin>>n;
	int sum=0;
	rep(0,i,n){
		cin>>a[i];
	}
	rep(0,i,n){
		cin>>b[i];
	}
	rep(0,i,n){
		cin>>c[i];
	}		
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	int *pos;
    rep(0,i,n) {
        pos=lower_bound(a, a+n, b[i]);
        d[i]=distance(a, pos);
    }
    rep(0,i,n) {
        pos=upper_bound(c,c+n,b[i]);
        e[i]=distance(pos,c+n);
    }
	rep(0,i,n){
		sum+=d[i]*e[i];
	}
	cout<<sum<<endl;
}				


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
using namespace std;

ll n;
string s, sa;

inline string rev(string ss){
    reverse(ss.begin(), ss.end());
    return ss;
}

inline void work(){
    cin >> s;                               //è¾“å…¥å­—ç¬¦ä¸²s
    n = s.size();                           //æ±‚é•¿åº¦
    if (s != rev(s)){                       //åˆ¤æ–­æ˜¯å¦æ˜¯å›žæ–‡å­—ç¬¦ä¸²
        puts("No");                         //è¾“å‡ºNo
        exit(0);                            //ç­‰åŒäºŽreturn 0
    }
    REP(i, 1, (n - 1) / 2) sa += s[i - 1];  //é¢˜æ„ä¸­çš„ç¬¬2ä¸ªå­—ç¬¦ä¸²
    if (sa != rev(sa)){                     //åˆ¤æ–­æ˜¯å¦æ˜¯å›žæ–‡å­—ç¬¦ä¸²
        puts("No");                         //è¾“å‡ºNo
        exit(0);                            //ç­‰åŒäºŽreturn 0
    }
    sa = "";                                //æ¸…ç©º
    REP(i, (n + 3) / 2, n) sa += s[i - 1];  //é¢˜æ„ä¸­çš„ç¬¬3ä¸ªå­—ç¬¦ä¸²
    if (sa != rev(sa)) puts("No");          //åˆ¤æ–­æ˜¯å¦æ˜¯å›žæ–‡å­—ç¬¦ä¸²ï¼Œå¦‚æžœä¸æ˜¯å°±è¾“å‡ºNo
    else puts("Yes");                       //å¦åˆ™è¾“å‡ºYes
}

int main(){
    work();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ll i,j,k,l,n,a,b;
    cin>>n>>a>>b;

    k=(a/n);
    l=(b/n);
    if(a%n!=0) k++;
    if((k*n>=a&&k*n<=b)||(l*n>=a&&l*n<=b)){
        cout<<"OK"<<endl;
    }
    else cout<<"NG"<<endl;
    return 0;
}

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

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n+1);
    int i, j;
    for(i = 0; i < n; i++){
        cin >> a.at(i);
    }
    a.at(n) = a.at(0) + k;
    int len = 0;
    int spare = 0;
    for(i = 0; i < n; i++){
        spare = abs(a.at(i+1) - a.at(i));
        if(spare > len){
            len = spare;
        }
    }
    cout << k-len << endl;
    return 0;
}


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

void solve() {
  // 貪欲法
  string s, t;
  cin >> s;
  cin >> t;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      for (int k = 0; k < s.size(); k++) {
        if (s[(i + k) % s.size()] == t[(j + k) % s.size()]) {
          if (k == s.size() - 1) {
            cout << "Yes" << endl;
            return;
          }
        } else {
          break;
        }
      }
    }
  }
  cout << "No" << endl;
}

int main(void) {
  solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i].fi >> a[i].se;
    sort(begin(a), end(a));
    for(auto x : a) if(x.se <= t) {cout << x.fi << endl; return 0;}
    cout << "TLE" << endl;
}

Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        for (int i = 0; i < n; i++) {
            d[i] = sc.nextInt();
            cnt[d[i]]++;
        }
        
        long ans = 1;
        if (d[0] != 0 || cnt[0] != 1) {
            System.out.println(0);
            sc.close();
            return;
        } else {
            for (int i = 1; i < n; i++) {
                for (int j = 0; j < cnt[i]; j++) {
                    ans *= cnt[i - 1];
                    ans %= 998244353;
                }
            }
        }

        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 52352
fun main(args: Array<String>) {
    val n = readLine()?: return
    val aList = readLine()
        ?.split(" ")
        ?.map { it.toLong() }
        ?.groupBy { it }
        ?.mapValues { it.value.size }
        ?.filter { it.value >= 2 }
        ?.toList()
        ?.sortedByDescending { it.first }
        ?.take(2)
        ?: listOf()

    if (aList.isEmpty() || aList.map { it.second }.sum() < 4) {
        println(0)
        return
    }

    if (aList[0].second >= 4) {
        println(aList[0].first * aList[0].first)
        return
    }

    println(aList[0].first * aList[1].first)
}

Measured memory_bytes: 84368
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    string s, t;
    int cnt = 0;
    cin >> s >> t;
    for(int i=0; i<s.size(); i++){
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int gcd(int x, int y){
    return y?gcd(y,x%y):x;
}

int lcm(int x, int y){
    return x/gcd(x,y)*y;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    sort(ALL(v));
    if(v[n-1]<k) cout << "IMPOSSIBLE" << endl;
    else {
        int num = v[0];
        rep(i,n) {
            num = gcd(num,v[i]);
        }
        if(num!=1) {
            if(k%num) cout << "IMPOSSIBLE" << endl;
            else cout << "POSSIBLE" << endl;
        }
        else cout << "POSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

vector<pair<ll, bool>>slot;//first:cost second:flag
ll w, h;
ll p[123456];
ll q[123456];

int main()
{
	scanf("%lld %lld", &w, &h);
	for (int i = 0; i < w; ++i)
	{
		scanf("%lld", p + i);
		slot.emplace_back(p[i], true);
	}
	for (int j = 0; j < h; ++j)
	{
		scanf("%lld", q + j);
		slot.emplace_back(q[j], false);
	}
	sort(slot.begin(), slot.end());
	ll pnum = w + 1;
	ll qnum = h + 1;
	ll ans = 0;
	for (auto sl : slot)
	{
		ans += sl.first * (sl.second ? qnum : pnum);
		if (sl.second)
		{
			--pnum;
		}
		else
		{
			--qnum;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5616
#include <stdio.h>

typedef struct  {
    int f[6];
} dice;

dice op_s(dice d) {
    dice tmp;
    tmp.f[0] = d.f[4];
    tmp.f[1] = d.f[0];
    tmp.f[2] = d.f[2];
    tmp.f[3] = d.f[3];
    tmp.f[4] = d.f[5];
    tmp.f[5] = d.f[1];
    return tmp;
}

dice op_n(dice d) {
    dice tmp;
    tmp.f[0] = d.f[1];
    tmp.f[1] = d.f[5];
    tmp.f[2] = d.f[2];
    tmp.f[3] = d.f[3];
    tmp.f[4] = d.f[0];
    tmp.f[5] = d.f[4];
    return tmp;
}

dice op_w(dice d) {
    dice tmp;
    tmp.f[0] = d.f[0];
    tmp.f[1] = d.f[2];
    tmp.f[2] = d.f[4];
    tmp.f[3] = d.f[1];
    tmp.f[4] = d.f[3];
    tmp.f[5] = d.f[5];
    return tmp;
}

dice op_e(dice d) {
    dice tmp;
    tmp.f[0] = d.f[0];
    tmp.f[1] = d.f[3];
    tmp.f[2] = d.f[1];
    tmp.f[3] = d.f[4];
    tmp.f[4] = d.f[2];
    tmp.f[5] = d.f[5];
    return tmp;
}

int func(dice *d1, dice *d2)
{
    int i;
    if(d1->f[0] == d2->f[0] && d1->f[5] == d2->f[5]) {
        for(i = 0; i < 4; i++) {
            *d2 = op_e(*d2);
            if(d1->f[1] == d2->f[1] && d1->f[2] == d2->f[2] && d1->f[3] == d2->f[3] && d1->f[4] == d1->f[4]) {
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    dice d1;
    dice d2;
    int i;
    int j;

    for(i = 0; i < 6; i++) {
        scanf("%d", &(d1.f[i]));
    }
    for(i = 0; i < 6; i++) {
        scanf("%d", &(d2.f[i]));
    }

    // top 0
    if(func(&d1, &d2) == 1) {
        printf("Yes\n");
        return 0;
    }
    // top 1
    d2 = op_n(d2);
    if(func(&d1, &d2) == 1) {
        printf("Yes\n");
        return 0;
    }
    // top 2
    d2 = op_w(d2);
    d2 = op_n(d2);
    if(func(&d1, &d2) == 1) {
        printf("Yes\n");
        return 0;
    }
    // top 3
    d2 = op_n(d2);
    d2 = op_n(d2);
    if(func(&d1, &d2) == 1) {
        printf("Yes\n");
        return 0;
    }
    // top 4
    d2 = op_s(d2);
    if(func(&d1, &d2) == 1) {
        printf("Yes\n");
        return 0;
    }
    // top 5
    d2 = op_e(d2);
    d2 = op_n(d2);
    if(func(&d1, &d2) == 1) {
        printf("Yes\n");
        return 0;
    }


    printf("No\n");
    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
template<typename capacity_t> class MaxFlow{
    struct edge { int to; capacity_t cap; int rev; };
    int v;
    vector<vector<edge>> G;
    vector<int> itr, level;

    //@brief cap>0の辺からなるGの部分グラフでsからの深さをbfsで調べlevelに格納する。届かないところは-1。
    void bfs(int s){
        level.assign(v,-1);
        queue<int> q;
        level[s]=0;
        q.push(s);
        while(!q.empty()){
            int v=q.front();
            q.pop();
            for(auto &e: G[v]){
                if(e.cap>0 && level[e.to]<0){
                    level[e.to]=level[v]+1;
                    q.push(e.to);
                }
            }
        }
    }
    //@brief v時点の流量がfで、tまで行くときの流量
    capacity_t dfs(int v, int t, capacity_t f) {
        if(v==t)return f;
        for(int& i=itr[v]; i<(int)G[v].size();++i){
            edge& e=G[v][i];
            if(e.cap>0 && level[v]<level[e.to]){
                capacity_t d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }
public:
    MaxFlow(int v):v(v){G.assign(v,vector<edge>());}
    void add_edge(int from, int to, capacity_t cap){
        assert(cap>=0);
        G[from].push_back((edge){to,cap,(int)G[to].size()});
        G[to].push_back((edge){from,0,(int)G[from].size()-1});
    }
    //@brief sからtへの最大流を求める
    capacity_t run(int s,int t){
        capacity_t ret=0, f;
        while(bfs(s), level[t]>=0){
            itr.assign(v,0);
            while((f=dfs(s,t,numeric_limits<capacity_t>::max()))>0) ret+=f;
        }
        return ret;
    }
};
/**
 * グラフの頂点を(白,黒)の2値に分類するタスクで
 * 「頂点iが白、頂点jが黒なら罰金k円」の形で与えられた罰金を最小化する問題
 *  -> 最小カット = 最大流
 * 
 * 今回は、白<=>割られた、黒<=>割られていない、の2値分類
 * - iが割られるならc*iも割られる <=> i->c*i に罰金 INF 円
 * - iが割られるなら a[i]<=0 円もらえる <=> 0->i に罰金 -a[i] 円
 * - iが割られるなら a[i]>0 円もらえる <=> iが割られないなら罰金 a[i] 円 <=> i->n+1 に罰金 a[i] 円
 * と定義したグラフの最小カット = 最大流が答え
 */
int main(){
    int n;
    cin >> n;
    MaxFlow<ll> flow(n+2);
    ll ans=0;
    rep(i,1,1+n){
        ll a;
        cin >> a;
        if(a<=0)flow.add_edge(0,i,-a);
        else{
            flow.add_edge(i,n+1,a);
            ans+=a;
        }
    }
    rep(i,1,1+n){
        for(int j=2;i*j<=n;++j){
            flow.add_edge(i,i*j,numeric_limits<ll>::max());
        }
    }
    cout << ans-flow.run(0,n+1) << endl;
    return 0;
}

Measured memory_bytes: 256
module Main where


main :: IO ()
main = do
        a      <- getLine
        let char6 = last a
        let char5 = last (init a)
        let char4 = last (init (init a)) 
        let char3 = last (init (init (init a))) 
        putStrLn (if ( char3 == char4 && char5 == char6) then "Yes" else "No")



Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n, k; cin >> n >> k;
	if (n >= 10) {
		cout << k << '\n';
	}
	else {
		cout << k + (100 * (10 - n)) << '\n';
	}





}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long m=1e9+7;
long long fact[1000001],inv[1000001];

long long modRecursive(long long a,long long b,long long c)
{
	if(b == 0) return 1;
	if(b%2 ==0) return modRecursive((a*a)%c,b/2,c);
	else return ((a%c)*(modRecursive((a*a)%c,b/2,c)))%c;
}

int main()
{
	long long a,b;
	cin>>a>>b;
	if((a+b)%2==0) cout<<(a+b)/2<<endl;
	else cout<<"IMPOSSIBLE\n";
    return 0;
}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll a,b;

int main(){
    ll ans;
    cin >> a >>b;
    if(a >= 13) ans = b;
    else if(a >= 6) ans = b/2;
    else ans = 0;

    cout << ans << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int main()
{
	FAST_IO ;
	string s;
	cin >> s;
	ll i,j,k;
	j = 0;
	f(i,0,s.size())
		if(s[i]=='R')
			j++ ;
	if(!j || j==3 || j==1)
	{
		cout << j endl ;
		return 0 ;
	}
	if(s[0]==s[2] && s[0]=='R')
		cout << j-1 endl ;
	else
		cout << j endl ;
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int b[3][3];
  rep(i,3){
    rep(j,3){
      cin >> b[i][j];
    }
  }
  int N; cin >> N;
  vector<int> A(N); rep(i,N) cin >> A[i];
  rep(i,N){
    rep(y,3){
      rep(x,3){
        if(b[y][x] == A[i]){
          b[y][x] = 0;
        }
      }
    }
  }
  bool bingo = false;
  rep(i,3){
    if(b[i][0]+b[i][1]+b[i][2]==0) bingo = true;
    if(b[0][i]+b[1][i]+b[2][i]==0) bingo = true;
  }
  if(b[0][0]+b[1][1]+b[2][2]==0) bingo = true;
  if(b[0][2]+b[1][1]+b[2][0]==0) bingo = true;
  cout << (bingo?"Yes":"No") << endl;
  return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int l = s.size();
    int have = 0;
    for (int i = 0; i < l; i++)
    {
        int c = 0;
        if (s[i] == 'R')
        {
            c++;
            for (int j = i+1; j < l; j++)
            {
                if (s[j] == 'R')
                {
                    c++;
                }
                else
                {
                    break;
                }
            }
        }
        have = max(have,c);
    }
    cout << have << "\n";

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
set<int> obstacles[200010];
int r, c, n;
int main()
{
	scanf("%d%d%d", &r, &c, &n);
	int ans = r+1;
	for (int i = 0; i < n; i++)
	{
		int a, b;
		scanf("%d%d", &b, &a);
		obstacles[a].insert(b);
	}
	int a = 1;
	for (int b = 1; b <= c; b++)
	{
		auto it = obstacles[b].upper_bound(a);
		if (it != obstacles[b].end()) ans = min(ans, *it);
		a++;
		while (1)
		{
			if (obstacles[b+1].find(a) != obstacles[b+1].end()) a++;
			else break;
		}
		
	}
	printf("%d\n", ans-1);
}

Measured memory_bytes: 18944
def check(a, b):
    for j in range(len(a)):
        if b[j] == a[j] or a[j] == '?':
            continue
        else:
            return False
    return True

ans_list = []
s_prime = input()
t = input()
for i in range(len(s_prime) - len(t) + 1):
    if check(s_prime[i:i+len(t)], t):
        s = s_prime[:i] + t + s_prime[i+len(t):]
        ans = s.replace('?', 'a')
        ans_list.append(ans)
ans_list.sort()
if len(ans_list) > 0:
    print(ans_list[0])
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
from bisect import bisect_right

N, M = map(int, input().split())

Ps, Ys, vals = [], [], {}
for i in range(M):
  P, Y = map(int, input().split())
  Ps.append(P)
  Ys.append(Y)

  if P not in vals:
    vals[P] = []
  vals[P].append(Y)

for P in vals:
  vals[P].sort()

for i in range(M):
  pref = str(Ps[i]).zfill(6)
  city = str(bisect_right(vals[Ps[i]], Ys[i])).zfill(6)
  print(pref + city)

Measured memory_bytes: 30424
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/

int main(){
    boost;
    int TESTS=1;
   // cin>>TESTS;
    while(TESTS--){
       
      int n;
      cin>>n;
      vi v(n);
      for(int i=0;i<n;i++)cin>>v[i];
      int mi=v[0];
       int ans=0;
      for(int i=0;i<n;i++){
      if(v[i]<=mi){
        ans++;
        mi=v[i];
      }
     }
    cout<<ans<<endl;
    }
}











Measured memory_bytes: 3956
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t H,W;
char map[400][410];
bool passed[400][400];
std::pair<int64_t, int64_t> func(int i, int j)
{
	assert(passed[i][j] == false);
	passed[i][j] = true;

	std::pair<int64_t, int64_t> res;
	if (map[i][j] == '#') {
		res.first += 1;
	}
	else {
		res.second += 1;
	}
	const int diff[] = { -1,0,1,0,-1 };
	for (size_t d = 0; d < 4; d++)
	{
		int ni = diff[d] + i;
		int nj = diff[d+1] + j;
		if (0 <= ni && ni < H && 0 <= nj && nj < W && passed[ni][nj] == false && map[ni][nj] != map[i][j]) {
			auto t =func(ni, nj);
			res.first += t.first;
			res.second += t.second;
		}
	}
	return res;
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> H>>W;
	for (size_t i = 0; i < H; i++)
	{
		in >> map[i];
	}
	
	int64_t res = 0;
	for (size_t i = 0; i < H; i++)
	{
		for (size_t j = 0; j < W; j++)
		{
			if (passed[i][j] == false)
			{
				auto tmp = func(i, j);
				res += tmp.first * tmp.second;
			}
		}
	}
	out << res << endl;

	return 0;
}
#endif


Measured memory_bytes: 18048
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<=n;i++)
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;


/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;    
    }
    return sum;
}
/// 最大公約数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }

long long oddsolve(long long a){
    return(a+1)/2 % 2;
}
long long solve(long long a){
    if(a % 2 == 1)return oddsolve(a);
    else return (a+1)^oddsolve(a+1);
}
int main(){
    long long A,B;
    cin >> A >> B;
    cout << (solve(B) ^ solve(A-1)) <<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

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

    sort(d,d+N, greater<int>());
    int max = 1000000;
    int ct = 0;
    for(int i=0; i<N; i++){
        if (d[i]<max){
            ct++;
            max = d[i];
        }    
    }
    cout << ct << endl;

}

Measured memory_bytes: 256
a,b=map(int,input().split())
s=str(input())
slist=list(s)
temp=slist.count("-")
if temp==1 and slist[a]=="-":
  s=s.replace("-","")
  if s.isdecimal()==True:
    print("Yes")
  else:
    print("No")
else:
  print("No")


Measured memory_bytes: 3060
from sys import exit
s=input()
x,y=map(int,input().split())

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s=groupby(s)
ab=[[],[]]
turn=True
#初めまっすぐの場合
if s[0][0]=="F":
    x-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        ab[not turn].append(i[1])
    elif i[1]%2==1:
        turn=not turn
ab[0].sort(reverse=True)
ab[1].sort(reverse=True)
for i in ab[0]:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in ab[1]:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")

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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> nums(N+1, 0);
    for(int i=0; i<N; i++){
        cin >> A[i];
        nums[A[i]]++;
    }

    ll sum = 0;
    for(int i=1; i<=N; i++){
        sum += nums[i]*(nums[i]-1)/2;
    }

    for(int i=0; i<N; i++){
        cout << sum - nums[A[i]]*(nums[A[i]]-1)/2 + (nums[A[i]]-1)*(nums[A[i]]-2)/2 << endl;
    }

    return 0;
}

Measured memory_bytes: 5760
mymin :: Int -> Int -> Int
mymin r l
    | r<l = r
    | otherwise = l

main :: IO ()
main = do
    input <- getContents --ここ間違ってた
    let [a, b, c, d, e, f] = map read $ words input
    putStrLn $ show $ a + b + c + d + e + f - (mymin (mymin a b) (mymin c d)) - (mymin e f)


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

#define fi first
#define se second
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 2e5 + 5;

#define lc ((x)<<1)
#define rc ((x)<<1|1)
LL mn[MAXN<<2],tag[MAXN<<2];
LL mn1[MAXN<<2],mn2[MAXN<<2];

inline void pushup(int x){
    mn[x] = std::min(mn[lc],mn[rc]);
    mn1[x] = std::min(mn1[lc],mn1[rc]);
    mn2[x] = std::min(mn2[lc],mn2[rc]);
}

inline void cover(int x,LL d){
    mn[x] += d;mn1[x] += d;mn2[x] += d;tag[x] += d;
}

inline void pushdown(int x){
    if(tag[x]){
        cover(lc,tag[x]);
        cover(rc,tag[x]);
        tag[x] = 0;
    }
}

inline void update(int x,int l,int r,int p,LL d){
    if(l == r){
        mn[x] = std::min(mn[x],d);
        mn1[x] = std::min(mn1[x],d+l);
        mn2[x] = std::min(mn2[x],d-l);
        return;
    }
    pushdown(x);
    int mid = (l + r) >> 1;
    if(p <= mid) update(lc,l,mid,p,d);
    else update(rc,mid+1,r,p,d);
    pushup(x);
}

inline void modify(int x,int l,int r,int L,int R,LL d){
    if(l == L && r == R) {cover(x,d);return;}
    int mid = (l + r) >> 1;pushdown(x);
    if(R <= mid) modify(lc,l,mid,L,R,d);
    else if(L > mid) modify(rc,mid+1,r,L,R,d);
    else modify(lc,l,mid,L,mid,d),modify(rc,mid+1,r,mid+1,R,d);
    pushup(x);
}

inline void build(int x,int l,int r){
    tag[x] = 0;
    if(l == r){
        mn[x] = 0;mn1[x] = l;mn2[x] = -l;return;
    }
    int mid = (l + r) >> 1;
    build(lc,l,mid);build(rc,mid+1,r);
    pushup(x);
}

inline LL query1(int x,int l,int r,int L,int R){
    if(L > R) return 1e18;
    if(l == L && r == R) return mn1[x];
    int mid = (l + r) >> 1;pushdown(x);
    if(R <= mid) return query1(lc,l,mid,L,R);
    if(L > mid) return query1(rc,mid+1,r,L,R);
    return std::min(query1(lc,l,mid,L,mid),query1(rc,mid+1,r,mid+1,R));
}

inline LL query2(int x,int l,int r,int L,int R){
    if(L > R) return 1e18;
    if(l == L && r == R) return mn2[x];
    int mid = (l + r) >> 1;pushdown(x);
    if(R <= mid) return query2(lc,l,mid,L,R);
    if(L > mid) return query2(rc,mid+1,r,L,R);
    return std::min(query2(lc,l,mid,L,mid),query2(rc,mid+1,r,mid+1,R));
}

int n,q,A,B;
int x[MAXN];

int main(){
    scanf("%d%d%d%d",&n,&q,&A,&B);
    FOR(i,1,q) scanf("%d",x+i);
    build(1,1,n);
    FOR(i,1,n) modify(1,1,n,i,i,std::min(std::abs(A-x[1])+std::abs(B-i),std::abs(B-x[1])+std::abs(A-i)));
    FOR(i,2,q){
        LL t = std::min(query1(1,1,n,x[i]+1,n)-x[i],query2(1,1,n,1,x[i])+x[i]);
        modify(1,1,n,1,n,std::abs(x[i]-x[i-1]));
        update(1,1,n,x[i-1],t);
    }
    printf("%lld\n",mn[1]);
    return 0;
}
/*
f[i][j] 表示处理了前 i 个操作 棋子分别在 x[i] 和 j 上
将 x[i-1] 移动到 x[i] 上
f[i][j] = f[i-1][j]+|x[i]-x[i-1]|
将 j 移动到 x[i] 上
f[i][x[i-1]] = min{ f[i-1][j]+|j-x[i]| }

线段树基本操作
*/


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

namespace atcoder_ensyuu_165_a
{
    class Program
    {
        private static void Main(string[] args)
        {

            int multiple = int.Parse(Console.ReadLine());
            int [] score = GetConsole();

            if (multiple < 1 || multiple > 1000)
            {
                Console.WriteLine("error");
                return;
            }

            if(score[0] < 1 || score[0] > score[1] || score[1] > 1000)
            {
                Console.WriteLine("error");
                return;
            }

            if ((score[1] - score[0]) >= (score[1] % multiple))
            {
                Console.WriteLine("OK");
            }
            else
            {
                Console.WriteLine("NG");
            }
        }

        private static int[] GetConsole()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
    }
}


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

ifstream in ("test.in" );
ofstream out("test.out");

const int DIM = 1e5 + 5;

pair<int, int> arr[DIM];
multiset<int> mst1, mst2;

long long ans1[DIM], ans2[DIM];

inline bool cmp(pair<int, int> p1, pair<int, int> p2)
{
    return 0LL + p1.second - p1.first <
           0LL + p2.second - p2.first;
}

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int x, y, z;
    cin >> x >> y >> z;
    
    long long aux = 0, val = 0;
    for (int i = 1; i <= x+y+z; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        
        val += c;
        arr[i] = make_pair(a - c, b - c);
    }
    
    sort(arr + 1, arr + x+y+z + 1, cmp);
    
    mst1.clear(); mst2.clear(); aux = 0;
    for (int i = 1; i <= x; ++i) {
        mst2.insert(arr[i].first);
        aux += arr[i].first;
    }
    
    ans1[x] += aux;
    for (int i = x+1; i <= x+z; ++i) {
        mst1.insert(arr[i].first);
        
        if (*mst1.rbegin() > *mst2.begin()) {
            int a = *mst1.rbegin(), b = *mst2.begin();
            mst1.erase(prev(mst1.end())); mst2.erase(mst2.begin());
            
            aux += a - b;
            mst1.insert(b);
            mst2.insert(a);
        }
        
        ans1[i] += aux;
    }
    
    mst1.clear(); mst2.clear(); aux = 0;
    for (int i = x+y+z; i > x+z; --i) {
        mst2.insert(arr[i].second);
        aux += arr[i].second;
    }
    
    ans2[x+z+1] += aux;
    for (int i = x+z; i > x; --i) {
        mst1.insert(arr[i].second);
        
        if (*mst1.rbegin() > *mst2.begin()) {
            int a = *mst1.rbegin(), b = *mst2.begin();
            mst1.erase(prev(mst1.end())); mst2.erase(mst2.begin());
            
            aux += a - b;
            mst1.insert(b);
            mst2.insert(a);
        }
        
        ans2[i] += aux;
    }
    
    long long sol = 0;
    for (int i = x; i <= x+z; ++i)
        sol = max(sol, val + ans1[i] + ans2[i + 1]);
    
    cout << sol;
    return 0;
}

Measured memory_bytes: 6528
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] usa = new int[N+1];
		for (int i = 1; i < N+1; i++) {
			usa[i] = sc.nextInt();
		}
		int count = 0;
		for (int i = 1; i < N+1; i++) {
			if (i == usa[usa[i]]) {
				count++;
			}
		}
		System.out.println(count/2);
	}
}

Measured memory_bytes: 48804
N , K = map(int, input().split())
sushi = [list(map(int, input().split())) for i in range(N)]
top = [-10**10]*(N+1)
sub = [0]
cnt = 0
for t, d in sushi:
    if top[t] < d:
        sub.append(top[t])
        top[t] = d
    else:
        sub.append(d)
top.sort(reverse = True)
sub.sort(reverse = True)
top_dp = [0] *(N+1)
sub_dp = [0] * (N+2)
top_dp[1] = top[0]
sub_dp[1] = sub[0]
for i in range(1, N):
    top_dp[i+1] = top_dp[i] + top[i]
for i in range(1, len(sub)):
    sub_dp[i+1] = sub_dp[i] + sub[i]
dp = [0] * (K+1)
for i in range(1, K+1):
    dp[i] = top_dp[i] + sub_dp[K-i] + i*i
print(max(dp))

Measured memory_bytes: 69848
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

string dp[10010];

int main() {
    ll N, M;
    cin >> N >> M;
    bool num[10];
    fill(num, num + 10, false);
    ll mnum[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    string digit[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
    ll A[M];
    REP(i, 0, M) {
        cin >> A[i];
        num[A[i]] = true;
    }
    ll numbo[9];
    fill(numbo, numbo + 9, 0);
    REP(i, 0, 10) {
        if (num[i]) {
            numbo[mnum[i - 1]] = i;
        }
    }
    // REP(i, 0, 9) {
    //     cout << numbo[i] << " ";
    // }
    fill(dp, dp + 10010, "");
    REP(i, 0, N) {
        if (i == 0 || dp[i] != "") {
            REP(j, 2, 8) {
                if (numbo[j] > 0) {
                    string tmp = dp[i] + digit[numbo[j]];
                    sort(tmp.begin(), tmp.end());
                    reverse(tmp.begin(), tmp.end());
                    if (dp[i + j].size() < tmp.size()) {
                        dp[i + j] = tmp;
                    } else if (dp[i + j].size() == tmp.size()) {
                        dp[i + j] = max(dp[i + j], tmp);
                    }
                }
            }
        }
    }
    string ans = dp[N];
    cout << ans << endl;
}


Measured memory_bytes: 26880
N,D=map(int,input().split())
X=[list(map(int,input().split())) for x in range(N)]
l=[]
for i in range(N):
    for j in range(i+1,N):
        s=0
        for k in range(D):
            s+=(X[i][k]-X[j][k])**2
        s=s**0.5
        if s-(s//1)==0:
            l.append(s)
print(len(l))

Measured memory_bytes: 9456
import sys


class AlgSegmentTreeMin:
    def __init__(self, n, default_value):
        self.Nelem = n
        self.default_value = default_value
        self.size = 1 << (n.bit_length())
        self.data = [default_value] * (2 * self.size)

    def update(self, i, x):
        i += self.size
        self.data[i] = x
        i >>= 1
        while i:
            x = self.data[i + i]
            y = self.data[i + i + 1]
            self.data[i] = min(x, y)
            i >>= 1

    def get_value(self, left, right):
        left += self.size
        right += self.size + 1
        x = self.default_value
        while left < right:
            if left & 1:
                y = self.data[left]
                x = min(x, y)
                left += 1
            if right & 1:
                right -= 1
                y = self.data[right]
                x = min(x, y)
            left >>= 1
            right >>= 1
        return x


def solve():
    input = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().split()))
    stree = AlgSegmentTreeMin(n, 10 ** 15)
    lrc = [list(map(int, input().split())) for _ in range(m)]
    lrc.sort()
    stree.update(0, 0)
    for l, r, c in lrc:
        l -= 1
        r -= 1
        tm = stree.get_value(l, r)
        now = stree.get_value(r, r)
        tm = tm + c if tm + c < now else now
        stree.update(r, tm)
    mt = stree.get_value(n-1, n)
    print(mt if mt != stree.default_value else -1)


if __name__ == '__main__':
    solve()


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

using ld = long double;
using ll = int64_t;
using Str = std::string;
template <class T> using Vec = std::vector<T>;
template <class K, class V> using UM = std::unordered_map<K, V>;

namespace io {

    template <class ...As> auto &read(As &...as)
    { return (std::cin >> ... >> as); }

} // namespace io

#define PB push_back

#define A(xs) xs.begin(), xs.end()
#define R(...) __VA_ARGS__; io::read(__VA_ARGS__)
#define FOR(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    int R(n, k);
    Vec<int> v(n);
    for (int& x : v) cin >> x;
    FOR(i, k) {
        Vec<int> nv(n);
        Vec<pair<int, bool>> segs;
        FOR(j, n) {
            int beg = max(0, j - v[j]);
            int end = min(n, j + v[j] + 1);
            segs.emplace_back(beg, true);
            segs.emplace_back(end, false);
        }
        sort(A(segs));
        int ind = 0;
        int cnt = 0;
        FOR(j, n) {
            while (ind < segs.size() && segs[ind].first == j) {
                if (segs[ind].second)
                    ++cnt;
                else
                    --cnt;
                ++ind;
            }
            nv[j] = cnt;
        }
        v = nv;
        if (nv == Vec<int>(n, n))
            break;
    }
    for (int x : v) cout << x << ' ';
    return 0;
}


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

int f(long long a,long long b){
  return max(log10(a),log10(b))+1;
}

int main(){
  long long n;
  cin>>n;
  int ans=log10(n)+1;
  for(int i=1;i<=sqrt(n);++i){
    if(n%i==0)ans=min(ans,f(i,n/i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b,h;
	scanf("%lld%lld%lld",&a,&b,&h);
	printf("%lld",(a+b)*h/2);
}

Measured memory_bytes: 128
#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>;
const double PI = acos(-1);

int main(){
  int n;
  cin >>n;
  vector<int> a(n);
  vector<int> b(n);

  a[0]=0;
  b[0]=0;
  for (int i=1;i<n;++i){
    cin >>a[i];
    b[a[i]-1]++;
  } 
  rep (i,n){
    cout <<b[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
	if(fopen("input.txt", "r"))
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	ios::sync_with_stdio(0),cin.tie(0);
	int n,k,sum=0;
	cin >> n >> k;
	int h[n];
	for(int i=0;i<n;i++)
		cin >> h[i];
	sort(h,h+n);
	for(int i=0;i<n-k;i++)
		sum+=h[i];
	cout << sum;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] dp = new long[n];
		long[] h = new long[n];
		for(int i = 0; i < n ; i++) {
			h[i] = sc.nextLong();
		}
		for(int i = 0 ; i < n ; i ++) {
			if(i == 0) {
				dp[i] = 0;
			}
			else if(i == 1) {
				dp[i] = Math.abs(h[i] - h[i - 1]);
			}
			else {
				dp[i] = Math.min(dp[i - 2] + Math.abs(h[i] - h[i - 2]), dp[i - 1] + Math.abs(h[i] - h[i - 1]));
			}
		}

		System.out.println(dp[n - 1]);

	}


}



Measured memory_bytes: 61512
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;
const int INF = 1<<29;

bool nw1[200009];
bool nw2[200009];

signed main(){
    ll n,k,c;
    string s;
    cin>>n>>k>>c;
    cin>>s;
    ll tp=mod;
    ll n1[200009];
    ll n2[200009];
    ll nc1[200009];
    ll nc2[200009];
    ll ct=0;
    rep(i,n){
        if(tp>=c && s[i]=='o'){
            ct++;
            tp=0;
            nw1[i]=true;
        }else tp++;
        n1[i]=ct;
    }
    ct=0,tp=mod;
    rep(i,n){
        if(tp>=c && s[n-1-i]=='o'){
            ct++;
            tp=0;
            nw2[n-1-i]=true;
        }else tp++;
        n2[n-1-i]=ct;
    }
    ll wk =0;
    vector<ll> ans;
    c++;
    rep(i,n){
        wk = n1[i]+n2[i];
        if(wk==k+1 && nw1[i]==true && nw2[i]==true) ans.push_back(i+1);
        // cout<<" "<<wk<<endl;
    }
    ll sz1 = ans.size();
    rep(i,sz1){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 6900
#include <string>
#include <iostream>
#include <vector>

using namespace std;
int main() {
    string s;
    int X,Y;
    cin >> s;
    cin >> X >> Y;
    vector<int> x, y;
    int count = 0;
    bool isX = true;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'F') {
            count++;
        } else {
            if (isX) {
                x.push_back(count);
                //cout << "x" << count << endl;
            } else {
                y.push_back(count);
                //cout << "y" << count << endl;
            }
            count = 0;
            isX = !isX;
        }
    }
    if (isX) {
        x.push_back(count);
        //cout << "x" << count << endl;
    } else {
        y.push_back(count);
        //cout << "y" << count << endl;
    }


    vector<vector<bool>> dpx(x.size() + 1, vector<bool>(20000, false));
    vector<vector<bool>> dpy(y.size() + 1, vector<bool>(20000, false));
    int zero = 10000;
    dpx[1][zero + x[0]] = true;
    dpy[0][zero] = true;

    //printf("x:%d回目に%dに到達\n", 1, zero + x[0] - zero);
    for (int i = 1; i < x.size(); i++) {
        for (int j = 0; j < 20000; j++) {
            if (dpx[i][j]) {
                dpx[i + 1][j + x[i]] = true;
                dpx[i + 1][j - x[i]] = true;
                //printf("x:%d回目に%dに到達\n", i + 1, j + x[i] - zero);
                //printf("x:%d回目に%dに到達\n", i + 1, j - x[i] - zero);
            }
        }
    }

    for (int i = 0; i < y.size(); i++) {
        for (int j = 0; j < 20000; j++) {
            if (dpy[i][j]) {
                dpy[i + 1][j + y[i]] = true;
                dpy[i + 1][j - y[i]] = true;
                //printf("y:%d回目に%dに到達\n", i + 1, j + y[i] - zero);
                //printf("y:%d回目に%dに到達\n", i + 1, j - y[i] - zero);
            }
        }
    }

    //printf("(x.size,X)=(%d,%d):dpx[x.size()][zero+X] = %b\n", x.size(),X,dpx[x.size()][zero+X]);
    //printf("(x.size,X)=(%d,%d):dpy[y.size()][zero+Y] = %b\n", y.size(),Y,dpy[y.size()][zero+Y]);

    if(dpx[x.size()][zero+X] && dpy[y.size()][zero+Y]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 23088