akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	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
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()

	uf := make(unionFind, 1e5+1e5)
	uf.init()
	
	for i := 0; i < n; i++ {
		x := scanInt()-1
		y := scanInt()-1
		uf.unite(x,y+1e5)
	}

	x := map[int]int{}
	y := map[int]int{}
	for i := 0; i < 1e5; i++ {
		x[uf.find(i)]++
		y[uf.find(i+1e5)]++
	}

	ans := 0
	for i := range x {
		ans += x[i]*y[i]
	}

	fmt.Fprintln(wr, ans-n)

}

type unionFind []int

func (uf *unionFind) init() {
	for i := 0; i < len(*uf); i++ { (*uf)[i] = -1 }
}

func (uf *unionFind) find(x int) int {
	if (*uf)[x] < 0 { return x }
	(*uf)[x] = uf.find((*uf)[x])
	return (*uf)[x]
}

func (uf *unionFind) unite(x, y int) {
	x, y = uf.find(x), uf.find(y)
	if x != y {
		if (*uf)[x] > (*uf)[y] { x,y = y,x }
		(*uf)[x] += (*uf)[y]
		(*uf)[y] = x
	}
}

func (uf unionFind) size(x int) int {
	return -uf[uf.find(x)]
}


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

class SatisfactionScore {
 public:
  int d;
  vector<int> c;
  vector<vector<int>> s;
  vector<int> t;
  vector<set<int>> u;
  int v;

  SatisfactionScore(int d_)
      : d(d_), c(26), s(d_, vector<int>(26)), t(d_), u(26, {0, d_ + 1}), v(0) {}

  int InitialScore() {
    vector<int> l(26, 0);
    v = 0;
    rep(i, d) {
      v += s[i][t[i] - 1];
      l[t[i] - 1] = i + 1;
      rep(j, 26) { v -= c[j] * (i + 1 - l[j]); }
    }
    return v;
  }

  int ModifiedScore(int di, int qi) {
    int pi = t[di - 1];
    int ret = v + s[di - 1][qi - 1] - s[di - 1][pi - 1];

    for (auto i : {pi - 1, qi - 1}) {
      auto itr = u[i].upper_bound(di);
      int nd = *(itr);
      advance(itr, (i == pi - 1) ? -2 : -1);
      int pd = *(itr);

      int delta = c[i] * (di - pd) * (nd - di);
      ret += (i == pi - 1) ? -delta : delta;
    }

    return ret;
  }

  void Update(int di, int qi) {
    v = ModifiedScore(di, qi);
    u[qi - 1].insert(di);
    u[t[di - 1] - 1].erase(di);
    t[di - 1] = qi;
  }
};

int main() {
  auto t0 = chrono::steady_clock::now();
  ios::sync_with_stdio(false);
  cin.tie(0);

  int d;
  cin >> d;
  SatisfactionScore ss(d);
  rep(i, 26) cin >> ss.c[i];
  rep(i, d) rep(j, 26) cin >> ss.s[i][j];

  rep(i, d) {
    auto itr = max_element(ss.s[i].begin(), ss.s[i].end());
    ss.t[i] = distance(ss.s[i].begin(), itr) + 1;
    ss.u[ss.t[i] - 1].insert(i + 1);
  }

  int cv = ss.InitialScore();

  ll num_loops = 0;
  mt19937 mt32(123);
  double mt32_max = mt32.max();

  const double tb = 10000.0;
  const double te = 10.0;
  double t = tb;
  ll dt = 0;
  while (true) {
    int di = mt32() % d + 1;
    double best_e = 0.0;
    int qi = ss.t[di - 1];
    rep(i, 26) {
      if (ss.t[di - 1] == i + 1) continue;
      int delta = ss.ModifiedScore(di, i + 1) - ss.v;
      double e = exp(delta / t);
      if (e > best_e) {
        best_e = e;
        qi = i + 1;
      }
    }

    double rnd = mt32() / mt32_max;
    if (best_e > rnd) ss.Update(di, qi);
    t = tb + (te - tb) * min(1.0, dt / 1800.0);

    num_loops++;
    if (num_loops % 128 == 0) {
      auto t1 = chrono::steady_clock::now();
      dt = chrono::duration_cast<chrono::milliseconds>(t1 - t0).count();
      if (dt > 1950) break;
    }
  }

  rep(i, d) cout << ss.t[i] << endl;
  return 0;
}

Measured memory_bytes: 4204
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
int main() {
	// your code goes here
	long int t=1;
// 	cin>>t;
	while(t--)
	{
	   long int n;
	   cin>>n;
	   pair<long long int,long long  int> a[n];
	   for(long int i=0;i<n;i++)
	   cin>>a[i].ff>>a[i].ss;
	   sort(a,a+n);
	   long long int mint = 1e18,maxt = -1e18,aa=-1e18,bb=1e18;
	   for(long int i=0;i<n;i++)
	   {
           mint=min(mint,a[i].ff+a[i].ss);
           bb=min(bb,a[i].ff-a[i].ss);
           aa=max(aa,a[i].ff+a[i].ss);
           maxt=max(maxt,a[i].ff-a[i].ss);
	   }
	   long long int ans = max(maxt-bb,aa-mint);
	   cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 6752
MOD=10**9+7
UPPERLIMIT=3*10**5
MODMUL=[1, 1]+[0]*(UPPERLIMIT-1)
for i in range(2, UPPERLIMIT+1):
  MODMUL[i]=MODMUL[i-1]*i%MOD
MODDIV=[1]*UPPERLIMIT+[pow(MODMUL[-1], MOD-2, MOD)]
for i in range(UPPERLIMIT, 0, -1):
  MODDIV[i-1]=MODDIV[i]*i%MOD
def MODCOMB(n, r):
  if n<r or n<1:
    return 0
  else:
    return (((MODMUL[n]*MODDIV[r])%MOD)*MODDIV[n-r])%MOD

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

ans=0
k=MODCOMB(N*M-2, K-2)
for sa in range(1, N):
  ans=(ans+sa*(N-sa)*M*M*k)%MOD
    
for sa in range(1, M):
  ans=(ans+sa*(M-sa)*N*N*k)%MOD
    
print(ans)

Measured memory_bytes: 49608
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil, floor, sqrt
from copy import deepcopy
from fractions import gcd

def main():
    a,b,c,d = map(int, input().split())
    a -= 1
    num = int(c*d / gcd(c,d))
    num_a = a - int(a // c + a // d - a // num)
    num_b = b - int(b // c + b // d - b // num)
    print(num_b - num_a)

if __name__ == "__main__":
    main()

Measured memory_bytes: 5148
N, *D = map(int, open(0).read().split())
C, S, F = D[0::3], D[1::3], D[2::3]
for start in range(N):
  ans = 0
  for i in range(start, N-1):
    ans = max(S[i], (ans + F[i]-1) // F[i] * F[i])
    ans += C[i]
  print(ans)


Measured memory_bytes: 3188
import sys
from bisect import bisect_right, bisect_left
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    A_i, A_j = [], []
    for i in range(n):
        A_i.append(-A[i] - (i + 1))

    for j in range(n):
        A_j.append(A[j] - (j + 1))

    A_j.sort()

    res = 0
    for a in A_i:
        idx_1 = bisect_left(A_j, a)
        idx_2 = bisect_right(A_j, a)
        res += idx_2 - idx_1
    print(res)
    

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 33720
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;

#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define mp(x,y) make_pair(x,y)
#define sz(v) ((int)v.size())
#define rs(n) resize(n)
#define all(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define vec vector
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){
	int n;
	string a, b;
	
	cin >> n >> a >> b;
	rep(i,n){
		cout <<a[i] << b[i];
	}
}




Measured memory_bytes: 256
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <iostream>
#include <cstdio>
#include<map>
#include <iomanip>

using namespace std;
long long  combination(long long n){
    if(n>1){
        return((n*(n-1))/2);

    }else{
        return 0;
    }
}

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

    int A[N+1];
    int maps[N+1];
    int max=0;
    long long answers[N+1];
    long long combinations[N+1];
    for(int i=0;i<=N;i++){
        maps[i]=0;
        answers[i]=-1;
        combinations[i]=-1;

    }

    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]>max){
            max=A[i];
        }
        maps[A[i]]+=1;
        
    }
    long long allsum=0;
    for(int i=1;i<=max;i++){
        if(combinations[maps[i]]>0){
        }else{
            long long num=combination(maps[i]);
            combinations[maps[i]]=num;
            
        }
        
        allsum+=combinations[maps[i]];
    }
    std::cout<<std::fixed<<std::setprecision(10);

    for(int i=0;i<N;i++){
        long long ans=0;
        if(answers[A[i]]<0){
            
            ans=allsum-combinations[maps[A[i]]]+combination(maps[A[i]]-1);
            answers[A[i]]=ans;
        }else{
            ans=answers[A[i]];
        }
        cout<<ans<<endl;
    }


}



Measured memory_bytes: 7296
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final Scanner sc    = new Scanner(System.in);
    static final int     MOD   = (int) 1E9 + 7;
    static final long    INF_L = (long) 4E18;
    static final int     INF   = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        int H = nint();
        int A = nint();
        System.out.println((H + A - 1) / A);
    }
    
    static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    
    static long lcm(int m, int n) {
        return (long) m * n / gcd(m, n);
    }
    
    @Deprecated
    static int nint() {
        return sc.nextInt();
    }

    @Deprecated
    static int[] nints(int N) {
        return nints(N, 0, 0);
    }

    @Deprecated
    private static int[] nints(int N, int padL, int padR) {
        int[] a = new int[padL + N + padR];
        for (int i = 0; i < N; i++)
            a[padL + i] = nint();
        return a;
    }

    static long nlong() {
        return sc.nextLong();
    }

    static long[] nlongs(int N) {
        return nlongs(N, 0, 0);
    }

    static long[] nlongs(int N, int padL, int padR) {
        long[] a = new long[padL + N + padR];
        for (int i = 0; i < N; i++)
            a[padL + i] = nlong();
        return a;
    }

    static double ndouble() {
        return sc.nextDouble();
    }

    static double[] ndoubles(int N) {
        return ndoubles(N, 0, 0);
    }

    static double[] ndoubles(int N, int padL, int padR) {
        double[] d = new double[N + padL + padR];
        for (int i = 0; i < N; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    static String nstr() {
        return sc.next();
    }

    static char[] nchars() {
        return sc.next().toCharArray();
    }

    static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    static char[][] nchars2(int H, int W) {
        return nchars2(H, W, 0, 0);
    }

    static char[][] nchars2(int H, int W, int padLU, int padRD) {
        char[][] a2 = new char[H + padLU + padRD][W + padLU + padRD];
        for (int i = 0; i < H; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, W);
        return a2;
    }

    static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }

    static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }

    static long abs(long a) {
        return Math.abs(a);
    }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/28  Problem: ABC 107 B / Link: http://abc107.contest.atcoder.jp/tasks/abc107_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL H, W; cin >> H >> W;
	vector<string> a(H);
	for (int i = 0; i < H; ++i) {
		cin >> a[i];
	}
	VI pr(H, 1), pc(W,1);
	FOR(i, 0, H) {
		bool allwhite = 1;
		FOR(j, 0, W) {
			allwhite &= a[i][j] == '.';
		}
		pr[i] = !allwhite;
	}
	FOR(j, 0, W) {
		bool allwhite = 1;
		FOR(i, 0, H) {
			allwhite &= a[i][j] == '.';
		}
		pc[j] = !allwhite;
	}
	FOR(i, 0, H) {
		int prc = 0;
		FOR(j, 0, W) {
			if (pr[i] && pc[j]) {
				cout << a[i][j];
				prc++;
			}
		}
		if (prc) {
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    fast_io

    ll n, mean=0;
    cin>>n;
    vector<ll> A(n);
    rep(i,n) cin>>A[i];
    
    ll li=1, ri=n-1;
    ll l=A[0], r=0;
    while(li<=ri){
        if(l>r){
            r+=A[ri];
            ri--;
        }
        else if(l<=r){
            l+=A[li];
            li++;
        }
        //cout<<l<<" "<<r<<endl;
    }
    cout<<abs(r-l)<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<queue>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;

struct Graph {
	int frm, to, w;	
};
bool operator<(const Graph&g1, const Graph &g2) {return (g1.w<g2.w);}

struct node {
	int parent;
	int group;
	int x, y;
	node() {}
};
node N[10001];
map<int, int> M;

int find(int v) {
	int ret;
	if(N[v].parent==-1) {
		N[v].parent = v;
		return v;
	}
	if(v==N[v].parent) return v;
	ret = find(N[v].parent);
	N[v].parent = ret;
	return ret;
}

void union_node(int src, int dst) {
	N[find(src)].parent = find(dst);
}

void update(int n) {
	for(int i=1; i<=n; ++i) {
		find(i);
	}
}

bool check(int n) {
	M.clear();
	update(n);
	for(int i=1; i<=n; ++i) {
		if(!M.count(N[i].group)) {
			M[N[i].group] = N[i].parent;
		}else {
			if(N[i].parent!=M[N[i].group]) {
				return false;
			}
		}
	}
	return true;
}

int main() {
	int n, m, xx, yy;
	double ans=0.0;
	priority_queue<Graph> q;
	Graph g;
	cin >> n >> m;
	for(int i=1; i<=n; ++i) {
		cin >> N[i].x >> N[i].y;
		N[i].parent = i;
	}
	for(int i=0; i<m; ++i) {
		cin >> g.frm >> g.to;
		xx = N[g.to].x-N[g.frm].x;
		yy = N[g.to].y-N[g.frm].y;
		g.w = xx*xx+yy*yy;
		q.push(g);
		union_node(g.frm, g.to);
	}
	update(n);
	for(int i=1; i<=n; ++i) {
		N[i].group = N[i].parent;
		N[i].parent = -1;
	}
	while(!q.empty()) {
		g = q.top(); q.pop();
		if(find(g.frm)!=find(g.to)) union_node(g.frm, g.to);
		else ans += sqrt((double)g.w);
		if(check(n)) break;
	}
	while(!q.empty()) {
		g = q.top(); q.pop();
		ans += sqrt((double)g.w);
	}
	printf("%lf\n", ans);
}

Measured memory_bytes: 1804
#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++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<double> p(n,0);
    rep(i,n) cin>>p[i];
    vector<double> ans(n,0);
    rep(i,n){
        if(i==0) ans[i]=(p[i]+1)/2;
        else ans[i]+=ans[i-1]+(p[i]+1)/2;
    }
    //rep(i,n) cout<<ans[i]<<" ";
    //cout<<endl;
    double max=0;
    rep(i,n-k+1){
        if(i==0){
            max=ans[k-1];
        }
        else{
            //cout<<i<<" "<<ans[i+k-1]<<" "<<ans[i-1]<<endl;

            if(max<ans[i+k-1]-ans[i-1]) max=ans[i+k-1]-ans[i-1];
        }
    }
    printf("%.10f\n",max);
    return 0;
}

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

int main(){
  string N;
  cin >> N;
  if(N[0]==N[1]&&N[1]==N[2]){
    cout << "Yes" << endl;}
    else if(N[1]==N[2]&&N[2]==N[3]){
      cout << "Yes" << endl;}
    else {cout << "No" << endl;}
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int n;
    cin>>n;
    for(;;)
    {
        int flag=0;
        for(long long int i=2;i*i<=n;i++)
        {if(n%i==0){flag++;break;}}
        if(flag)
        n++;
        else
        {cout<<n;return;}
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  string S;
  int ans =0;
  cin >> S;
  
  if(S == "AAA"){
    ans ++;
  }else if(S == "BBB"){
    ans ++;
  }
  if(ans == 0){
    cout << "Yes"<<endl;
  }else if(ans > 0){
    cout <<"No" <<endl;
  }
}


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

#define ll long long
#define rep(i,n) for(int i = 0;i < (n); i++)

int main() {
	int n, m;
	int s, c;
	int ans = 0;
	cin >> n >> m;
	vector<int> a(3);
	a[0] = a[1] = a[2] = 10;
	rep(i, m) {
		cin >> s >> c;
		if (a[s - 1] != 10 && a[s - 1] != c) {
			cout << -1 << endl;
			return 0;
		}
		else {
			a[s - 1] = c;
		}
	}
	if (a[0] == 0 && n != 1) {
		cout << -1 << endl;
		return 0;
	}
	else {
		if (a[0] == 10) {
			if (n == 1)a[0] = 0;
			else a[0] = 1;
		}
		for (int i = 1; i<n; i++) {
			if (a[i] == 10)a[i] = 0;
		}
		rep(i, n) {
			ans += a[i] * pow(10, n - i - 1);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3832
#include<cstdio>
#include<cmath>
#define mid ((left+right)>>1)
#define lson rt<<1,left,mid
#define rson rt<<1|1,mid+1,right
#define INF 2147483647

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

int n,q;
int node[100000<<2];

void init(int n_)
{
    for(int i=0;i<=(n_<<2);i++) node[i]=INF;
}

void pushup(int rt)
{
    node[rt]=min(node[rt<<1|1],node[rt<<1]);
}

void update1(int rt,int left,int right,int target,int value)
{
    if(left==right){
        node[rt]=value;
        return ;
    }
    if(target<=mid) update1(lson,target,value);
    else if(target>mid) update1(rson,target,value);
    pushup(rt);
}

void update2(int target,int value)
{
    int v = target + n;
    node[v] =value;
    v /= 2;
    while (v > 0) {
        node[v] = min(node[2 * v], node[2 * v + 1]);
        v /= 2;
    }
}

int query(int rt,int left,int right,int L,int R)
{
    //printf("%d %d %d %d %d\n",rt,left,right,L,R);
    if(left==L&&R==right) return node[rt];
    if(R<left&&right<L) return INF;
    if(mid>=R) query(lson,L,R);
    else if(mid<L) query(rson,L,R);
    else return min(query(lson,L,mid),query(rson,mid+1,R));
}

int main()
{
    init(100000);
    while(~scanf("%d%d",&n,&q))
    {
        for(int i=0;i<q;i++)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            if(a==1) printf("%d\n",query(1,1,n,b+1,c+1));
            else update1(1,1,n,b+1,c);
        }
    }
    return 0;
}
/*

3 7
0 0 1
0 1 2
0 2 3
1 0 0
1 0 2
1 1 2
1 0 1

*/

Measured memory_bytes: 2588
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void) {
    int x, n;
    cin>>x>>n;
    vector<bool> d(400);

    int ret = 1000;
    int num = -1;
    for(int i = 0 ; i < 400 ; i ++)d[i] = true;
    for(int i = 0 ; i < n; i ++) {
        int f;
        cin>>f;
        d[f + 200] = false;
    }

    for(int i = 0 ; i < 400 ; i ++) {
        if (d[i] == false) continue;
        if (abs(i - 200 - x) < ret) {
            ret = abs(i - 200 - x);
            num = i - 200;
        }
    }
    
    cout<<num<<endl;
}

Measured memory_bytes: 3192
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		for (int i = 0; i < n; i++)
		{
			int b = 0;
			int c = 0;
			for (int j = 0; j < 10; j++)
			{
				int ball = sc.nextInt();
				if (ball < b && ball < c)
				{
					System.out.println("NO");
					sc.nextLine();
					break;
				}
				
				if (c <= b && b < ball)
				{
					b = ball;
				}
				else
				{
					c = ball;
				}

				if (j == 9)
				{
					System.out.println("YES");
				}
			}
		}
	}
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if (a + b == 15){
        cout << '+' <<endl;
    }

    else if (a * b == 15){
        cout << '*' <<endl;
    }

    else {
        cout << 'x' <<endl;
    }


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String o = scan.next();
		String e = scan.next();

		int l = 0;
		if(o.length()>=e.length()) {
			l = e.length();
		}else {
			l=o.length();
		}

		for(int i=0;i<l;i++) {
			System.out.print(o.charAt(i));
			System.out.print(e.charAt(i));
		}

		if(o.length()-e.length()==1) {
			System.out.println(o.charAt(o.length()-1));
		}
	}

}


Measured memory_bytes: 21716
//Minesweeper.cpp (B)
#include <iostream>
using namespace std;

int main(){
  int H, W;
  char S[60];
  int M[60][60] = {0};
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    cin >> S;
    for(int j = 0; j < W; j++){
      if(S[j] == '#'){
        for(int k = i; k < i+3; k++){
          for(int l = j; l < j+3; l++){
            if(M[k][l]!=10) ++M[k][l];
          }
        }
        M[i+1][j+1] = 10;
       }
    }
  }
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W-1; j++){
      if(M[i+1][j+1] == 10) printf("#");
      else printf("%d",M[i+1][j+1]);
    }
    if(M[i+1][W] == 10) printf("#\n");
    else printf("%d\n",M[i+1][W]);
  }


}


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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;





int main(){
    int n, m, x; cin>>n >>m >>x;
    int c[n], a[n][m];
    ll ans=0;
    rep(i,n){
        cin>>c[i];
        rep(j,m) cin>>a[i][j];
    ans+=c[i];
    }
    ans++;
    int fal=ans;
    int all= 1<<n;
    for(int mask=0; mask<all; mask++){
        vector<int> level(m);
        ll now=0;
        for(int i = 0; i < n; i++){
            if((mask>>i)&1){
                now+=c[i];
                for(int j=0; j<m; j++) level[j]+= a[i][j];
            }
            
        }
        bool ok = true;
        rep(j,m) if(level[j]<x) ok=false;
        if(ok) ans = min(ans,now);
    }
    if(fal==ans) cout<<-1<<endl;
    else cout<<ans<<endl;   
}

Measured memory_bytes: 3592
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 999999999

int main() {
	string s;
	cin >> s;
	bool flag1 = 0, flag2 = 0;
	REP(i, s.length()) {
		if (s[i] == 'C')flag1 = 1;
		if(flag1)if (s[i] == 'F')flag2 = 1;
	}
	if (flag1&&flag2)cout << "Yes" << endl;
	else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s, t;
    cin  >> s >> t;
    map<char, char> mp, rmp;
    bool flag = true;
    rep(i, 0, s.size()) {
        if (mp.count(s[i])) {
            if (mp[s[i]] != t[i]) {
                flag = false;
            }
        } else {
            mp[s[i]] = t[i];
        }
        if (rmp.count(t[i])) {
            if (rmp[t[i]] != s[i]) {
                flag = false;
            }
        } else {
            rmp[t[i]] = s[i];
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int div=0;
  for(int i=0;i<N-1;i++){
    if(S[i]!=S[i+1]){
      div++;
    }
  }
  cout << div+1;
}


Measured memory_bytes: 512
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
L = l()
L.sort()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        if L[i] != L[j]:
            num = L[i]+L[j]
            for k in range(j,N):
                if L[j] != L[k] and num > L[k]:
                    ans += 1
print(ans)

Measured memory_bytes: 72856
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main(void) {
    int N;
    vector<int> a(200010,0), b(200010,0);
    cin >> N;
    for (int i=0;i<N;i++) {
        cin >> a[i];
        b[a[i]] = i;
    }

    set<int> S;
    S.insert(-1);
    S.insert(N);
    long long ans = 0LL;
    for (int i=1;i<=N;i++) {
        auto itr = S.lower_bound(b[i]);
        long long r = *itr - b[i];
        long long l = b[i] - *(--itr);
        ans += i * l * r;
        S.insert(b[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	cout << a << ' ' << b << ' ' << 3*c-a-b << endl;
	cout << 4*c-b-2*a << ' ' << c << ' ' << 2*a+b-2*c << endl;
	cout << a+b-c << ' ' << 2*c-b << ' ' << 2*c-a << endl;
	return 0; 
}

Measured memory_bytes: 256
N = int(input())
a = [0]*N
cnt = 0
dic = {}
for i in range(N):
	a[i] = int(input())
	dic[a[i]] = i

ans = 1
cnt = 1
for num in range(1,N):
	if dic[num] < dic[num+1]:
		cnt += 1
	else:
		ans = max(cnt,ans)
		cnt = 1


ans = max(cnt,ans)
print(N-ans)




Measured memory_bytes: 34144
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

int main() {
  int a[3];
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  sort(a, a + 3);
  if (a[0] == a[1] && a[1] == a[2]) {
    cout << 1 << endl;
  } else if (a[0] == a[1] || a[1] == a[2] || a[0] == a[2]) {
    cout << 2 << endl;
  } else {
    cout << 3 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
// Problem F : Controlled Tournament

#include <iostream>
#include <cstring>

using namespace std;

static int mem[16][1<<16][5];
int vs[16][16];
int lg[16] = {1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};

// ツ講ツ評ツスツδ可イツドツつサツづ個づ慊づ慊づ個δδつ可サツ探ツ催オ
int search(int win, int lose, int cnt, int n){
	if(cnt < 0) return 0;
	if(~mem[win][lose][cnt]) return mem[win][lose][cnt];
	if(!lose) return mem[win][lose][cnt] = 1;
	int res = 0, loseBit = 0;
	for(int t=lose;t;t&=(t-1)) loseBit++;
	if(lg[loseBit] > cnt) return mem[win][lose][cnt] = 0;
	for(int i=0;i<n;i++){
		if(!(lose&(1<<i))) continue;
		if(!vs[win][i]) continue;
		int mask = lose^(1<<i);
		int b = mask;
		do{
			res += search(win, b, cnt-1, n) * search(i, mask^b, cnt-1, n);
			b = (b-1)&mask;
		} while (b != mask);
	}
	return mem[win][lose][cnt] = res;
}

int main(){
	int n, m;
	while(cin >> n >> m, n){
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cin >> vs[i][j];
		memset(mem,-1,sizeof(mem));
		cout << search(m-1, (((1<<n)-1)^(1<<(m-1))), lg[n-1], n) << endl;
	}
}

Measured memory_bytes: 20000
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <climits>
#include <bitset>
#include <cassert>

using namespace std;

const int SIZE = 1 << 17;

int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0,sign = 1;
    char ch = Advance();
    while (!isdigit(ch) && ch != '-')
        ch = Advance();
    if (ch == '-') {
        ch = Advance();
        sign = -1;
    }
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer * sign;
}

char ReadCh() {
    char ch = Advance();
    while (!isalpha(ch))
        ch = Advance();
    return ch;
}

int v[20];

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    long long n;
    int d = 0;
    scanf("%lld", &n);
    while (n) {
        d++;
        v[d] = n % 10;
        n /= 10;
    }
    int answer = 0, sum = 0;
    for (int i = d; i >= 1; i--) {
        if (v[i] == 0)
            continue;
        answer = max(answer, sum + v[i] - 1 + 9 * (i - 1));
        sum += v[i];
    }
    answer = max(answer, sum);
    printf("%d\n", answer);
    return 0;
}


Measured memory_bytes: 128
import math
n , d = map(int, input().split())

x = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
sum_tmp = 0

for i in range(n):
    for j in range(i+1, n):
        for h in range(d):
            sum_tmp += (x[i][h] - x[j][h]) ** 2
        if math.sqrt(sum_tmp).is_integer():
            cnt += 1
        sum_tmp = 0

print(cnt)


Measured memory_bytes: 9192
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <bitset>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)
#define RPA(i,s,e) for(int i=s; i<=e; i++)
#define RPD(i,s,e) for(int i=s; i>=e; i--)
#define PB(a) push_back(a)
#define MP(i,s) make_pair(i,s)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(), (a).end()
#define PRT(a) cout << (a) << endl
#define PRT2(a,b) cout << (a) << " " << (b) << endl
#define PRT3(a,b,c) cout << (a) << " " << (b) << " " << (c) << endl

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> P;


void coding() {
	vector<int> v(5);
	for(int i=0; i<5; i++) {
		cin>>v[i];
	}
	sort(ALL(v), greater<int>());
	for(int i=0; i<5; i++) {
		printf("%d%c", v[i], i==4 ? '\n' : ' ');
	}
}

// #define _LOCAL_TEST

int main() {
#ifdef _LOCAL_TEST
	clock_t startTime = clock();
	freopen("a.in", "r", stdin);
#endif

	coding();

#ifdef _LOCAL_TEST
	clock_t elapsedTime = clock() - startTime;
	cout << endl;
	cout << (elapsedTime / 1000.0) << " sec elapsed." << endl;
	cout << "This is local test" << endl;
	cout << "Do not forget to comment out _LOCAL_TEST" << endl << endl;
#endif
}

Measured memory_bytes: 1188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		String S = sc.next();
		int[] dp = new int[n];
		for(int i=1;i<n;i++) {
			dp[i]=dp[i-1];
			if(S.substring(i-1, i+1).equals("AC")) {
				dp[i]++;
			}
		}
		for(int i=0;i<q;i++) {
			int L = Integer.parseInt(sc.next())-1;
			int R = Integer.parseInt(sc.next())-1;
			System.out.println((dp[R]-dp[L]));
		}
		sc.close();
	}
}


Measured memory_bytes: 49096
N = int(input())
A = list(map(int, input().split()))

D = {}
for a in A:
    if a not in D:
        D[a] = 1
    else:
        D[a] += 1

for i in range(1,N+1):
    if i in D:
        print(D[i])
    else:
        print(0)


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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
   su;
   int n,w=0,ans;
   string s;
   cin>>n>>s;
   lo(i,0,n)
   {
     if(s[i]=='W')
      w++;
   }
   ans=w;
   for(int i=n-1;i>=n-w;i--)
   {
     if(s[i]=='W')
      ans--;
   }
   cout<<ans<<nl;
   return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>


using namespace std;

int main()
{
    //vector<int>v1;
    int sum=0,h,n,x;
    bool f = true;
    cin>>h>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>x;
        sum= sum+x;
        arr[i] = x;
    }


    sort(arr,arr+n);

    for(int i =0; i<n-1 ; i++){
        if(arr[i] == arr[i+1]){
            f = false;
            break;
        }
    }

    if( sum >=h ){
        cout<<"Yes";
    }else{
        cout<<"No";
    }

    return 0;
}


Measured memory_bytes: 760
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define eps 0.000000001
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int a[105];
map<int,int> mp;
int main(){
	int x,n;cin>>x>>n;
	rep(i,1,n){
		cin>>a[i];
		mp[a[i]]=1;
	}
	int minn=INF;
	int pos=INF;
	rep(i,-200,200){
		if(!mp[i]){
			if(abs(x-i)<minn){
				minn= abs(x-i);
				pos=i;
			}
		}
	}
	cout<<pos<<endl;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

inline void chmax(ll &x, ll y) {
	if (x < y) x = y;
}

ll calc(ll N, int p, int q, int r, int s, int t, int u) {
	vector<ll> dp(N + 1, -1);
	for (int i = 0; i <= N; ++i) dp[i] = i;

	dp[0] = 0;
	for (int i = 1; i <= N; ++i) {
		if (i >= p && dp[i-p] >= 0) {
			chmax(dp[i], dp[i-p] + s); 
		}
		if (i >= q && dp[i-q] >= 0) {
			chmax(dp[i], dp[i-q] + t); 
		}	
		if (i >= r && dp[i-r] >= 0) {
			chmax(dp[i], dp[i-r] + u); 
		}	
	}
	return *max_element(dp.begin(), dp.begin() + N + 1);	
}

int main() {
	int N; cin >> N;
	int p, q, r, s, t, u;
	cin >> p >> q >> r >> s >> t >> u;

	ll res1 = calc(N, p, q, r, s, t, u);
	ll res2 = calc(res1, s, t, u, p, q, r);

	cout << res2 << endl;
	
	return 0;
}

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

using namespace std;

int main()
{
	string key[2] = {"JOI","IOI"};
	string in;
	string::size_type now;
	int count[2];
	char step[10001];


	while(scanf("%s",step) != EOF){
		in.clear();
		in.append(step);
		for(int i = 0; i < 2; i++){
			now = 0;
			count[i] = 0;
			while(in.find(key[i],now) < in.length()){
				now = in.find(key[i],now) + 1;
				count[i]++;
			}
			printf("%d\n",count[i]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    vector<int> perm(n);
    iota(all(perm), 0);

    double sum = 0;
    int cnt = 0;
    do {
        cnt++;
        rep(i, n-1) {
            sum += hypot(x[perm[i]] - x[perm[i+1]], y[perm[i]] - y[perm[i+1]]);
        }
    } while (next_permutation(all(perm)));
    sum /= cnt;
    cout << fixed << setprecision(15) << sum << endl;
}


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

using namespace std;
typedef long long ll;

int main()
{
  int R, C, K;
  cin >> R >> C >> K;

  vector<vector<vector<ll>>> A(R, vector<vector<ll>>(C, vector<ll>(4, -1)));

  vector<vector<ll>> Vs(R, vector<ll>(C, 0));

  for (int i = 0; i < K; i++)
  {

    int r, c, v;
    cin >> r >> c >> v;

    Vs[r - 1][c - 1] = v;
  }

  if (Vs[0][0] == 0)
  {
    A[0][0][0] = 0;
  }
  else
  {
    A[0][0][0] = 0;

    A[0][0][1] = Vs[0][0];
  }

  if (C > 1)
  {
    for (int i = 0; i < (C - 1); i++)
    {

      A[0][i + 1][0] = 0;

      for (int k = 1; k < 4; k++)
      {

        if (Vs[0][i + 1] > 0 && A[0][i][k - 1] != -1)
        {

          A[0][i + 1][k] = max(A[0][i][k - 1] + Vs[0][i + 1], A[0][i][k]);
        }
        else
        {

          A[0][i + 1][k] = A[0][i][k];
        }
      }
    }
  }

  if (R > 1)
  {
    for (int j = 0; j < (R - 1); j++)
    {

      ll art0 = max(A[j][0][0], A[j][0][1]);
      if (Vs[j+1][0] == 0)
      {
        A[j + 1][0][0] = art0;
      }
      else
      {

        A[j + 1][0][1] = art0 + Vs[j + 1][0];
        A[j + 1][0][0] = art0;
      }

      if (C > 1)
      {

        for (int i = 0; i < (C - 1); i++)
        {

          ll art = max(A[j][i + 1][0], A[j][i + 1][1]);
          art = max(A[j][i + 1][2], art);
          art = max(A[j][i + 1][3], art);

          A[j + 1][i + 1][0] = max(A[j + 1][i][0], art);

          for (int k = 1; k < 4; k++)
          {

            if (Vs[j + 1][i + 1] > 0 && A[j + 1][i][k - 1] != -1)
            {

              A[j + 1][i + 1][k] = max(A[j + 1][i][k - 1] + Vs[j + 1][i + 1], A[j + 1][i][k]);

              if (k == 1)
              {

                A[j + 1][i + 1][k] = max(art + Vs[j + 1][i + 1], A[j + 1][i + 1][k]);
              }
            }
            else
            {

              A[j + 1][i + 1][k] = A[j + 1][i][k];
            }
          }
        }
      }
    }
  }

  ll ans = max(A[R - 1][C - 1][0], A[R - 1][C - 1][1]);
  ans = max(A[R - 1][C - 1][2], ans);
  ans = max(A[R - 1][C - 1][3], ans);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 706352
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


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

	int n;
	cin >> n;
	vector<int> ans(26, INF);
	rep(_, n) {
		string s;
		cin >> s;
		vector<int> cnt(26);
		for (char c : s) cnt[c - 'a']++;
		rep(i, 26) chmin(ans[i], cnt[i]);
	}
	rep(i, 26) {
		rep(_, ans[i]) {
			char c = 'a' + i;
			cout << c;
		}
	}
	cout << endl;
}

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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  map<int,int>mp;
  mp[A]++;
  mp[B]++;
  mp[C]++;
  for(map<int,int>::iterator itr = mp.begin(); itr != mp.end() ; ++itr ){
    if(itr->second == 1){
      cout << itr->first << endl;
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;


int timesum[1001];
int entry[1001];
int main(void) {
    // cin.tie(0); ios::sync_with_stdio(false);
    int n;
    while(cin >> n,n){
        vector<int> M(n),D(n),h(n),m(n);
        vector<string> e(n);
        vector<int> p(n);
        char c;
        for(int i = 0; i < n;i++){
            cin >> M[i] >> c >> D[i] >> h[i] >> c >> m[i] >> e[i] >> p[i];
        }
        fill(timesum,timesum+1001,0);
        fill(entry,entry+1001,-1);
        
        for(int i = 0; i < n;i++){
            
            if(e[i] == "I"){
                entry[p[i]] = h[i] * 60 + m[i];
            }else{
                int time = h[i] * 60 + m[i];
                
                if(p[i] == 0){
                    for(int j = 1; j <= 1000; j++){
                        if(entry[j] == -1) continue;
                        timesum[j] += time-max(entry[0],entry[j]);
                    }
                    
                }else{
                    if(entry[0] != -1 && entry[p[i]] != -1){
                        timesum[p[i]] += time - max(entry[0],entry[p[i]]);
                    }
                }
                entry[p[i]] = -1;
            }
        }
        cout << *max_element(timesum, timesum+101) << endl;
    }
    return 0;
}



Measured memory_bytes: 3208
def solve(s):
    weekday = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']

    ans = len(weekday) - (weekday.index(s) + 1)
    return ans if ans != 0 else 7


S = input()

print(solve(S))


Measured memory_bytes: 38384
#include <cstdio>
#include <vector>
#include <cstdlib>
#define N 100005
int n, m, l, r, d, v[N], w[N];
std::vector<int> g[N], h[N];

void f(int p, int q) {
	if(v[p]) {
		if(q != w[p]) {puts("No"); exit(0);}
		return;
	}
	v[p] = 1;
	w[p] = q;
	for(int i=0; i<g[p].size(); i++) {
		f(g[p][i], q + h[p][i]);
	}
}

int main() {
	scanf("%d%d", &n, &m);
	while(m--) {
		scanf("%d%d%d", &l, &r, &d);
		g[l].push_back(r);
		g[r].push_back(l);
		h[l].push_back(d);
		h[r].push_back(-d);
	}
	for(int i=1; i<=n; i++) {
		if(!v[i]) f(i, 0);
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 16768
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<functional>
#include<string>
using namespace std;

int main(){
	string str;
	int ans=0;
	while(cin>>str){
		for(int i=0;i<str.length();i++){
			int num=0;
			for(;i<str.length() && isdigit(str[i]);i++){
				num = num*10+str[i]-'0';
			}
			ans+=num;
		}
	}
	printf("%d\n",ans);
    return 0;
}

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

int main() {
	int n, k; cin>>n>>k;
	int arr[n];
	long long int dp[n];
	for(int i=0; i<n; i++){ 
	    cin>>arr[i];
	    dp[i]=1000000000;
	}
	
	
	dp[0]=0;
	for(int i=1; i<=k and i<n ; i++){
	    dp[i]=abs(arr[i]-arr[0]);
	}
	
	for(int i=k+1; i<n; i++){
	    for(int j=1; j<=k; j++){
	        long long int a=dp[i-j]+abs(arr[i]-arr[i-j]);
	        dp[i]=min(a, dp[i]);
	    }
	}
	
    cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1408