akhauriyash/Code-Regression huggingface dataset:
import math
from decimal import Decimal, ROUND_HALF_UP


def resolve():
    a, b, C = map(int, input().split())
    x = math.radians(C)

    h = b * math.sin(x)
    S = Decimal((a * h) / 2).quantize(Decimal('0.00000001'), rounding=ROUND_HALF_UP)
    c = Decimal(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(x))).quantize(Decimal('0.00000001'),
                                                                               rounding=ROUND_HALF_UP)
    L = Decimal(a + b + c).quantize(Decimal('0.00000001'), rounding=ROUND_HALF_UP)
    print(S, L, h, sep="\n")


resolve()



Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int k,t;
  cin >> k >> t;
  int ax = 0;
  rep(i,t){
    int a;
    cin >> a;
    ax = max(ax,a);
  }

  cout << (int)max(0,2*ax-k-1) << "\n";
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
		Scanner scan = new Scanner(System.in);
		int a, b;
		String op;
		
		do {
			a = scan.nextInt();
			op = scan.next();
			b = scan.nextInt();
			
			if("?".equals(op) )break;
			
			switch(op) {
			case "+":
				System.out.println(a + b);
				break;
			case "-":
				System.out.println(a - b);
				break;
			case "*":
				System.out.println(a * b);
				break;
			case "/":
				System.out.println(a / b);
				break;
			default:
				break;
			}

		}while(true);
		
	}
}


Measured memory_bytes: 26396
#include<bits/stdc++.h>
using namespace std;
#define f(i,n) for(int i = 0;i<n;i++)
#define ll long long
int solve(int key){
	if(key>=1800 && key<=1999) return 1;
	if(key>=1600 && key<=1799) return 2;
	if(key>=1400 && key<=1599) return 3;
	if(key>=1200 && key<=1399) return 4;
	if(key>=1000 && key<=1199) return 5;
	if(key>=800 && key<=999) return 6;
	if(key>=600 && key<=799) return 7;
	if(key>=400 && key<=599) return 8;
}
int main(){
	int x;
	cin>>x;
	cout<<solve(x);	

}

Measured memory_bytes: 3632
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]+[9999999999999]*102000
for i in range(n):
    for j in range(1,k+1):
        try:
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
        except:
            break
print(dp[n-1])

Measured memory_bytes: 52448
import           Control.Exception (assert)
import           Data.List         (foldl1')

main :: IO ()
main = do
  n <- readLn
  as <- map read . words <$> getLine
  assert (length as == n) $
    print $ solve' as

solve :: [Int] -> Int
solve = maximum . map (foldl1' gcd) . removeOne

removeOne :: [a] -> [[a]]
removeOne []       = []
removeOne (x : xs) = xs : map (x:) (removeOne xs)

solve' :: [Int] -> Int
solve' as =
  let
    ls = scanl1 gcd $ init as
    rs = scanr1 gcd $ tail as
  in
    maximum $ [last ls, head rs] ++ zipWith gcd (init ls) (tail rs)


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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = INF, tmp;
int N, P;
vi X;

void solve(){
    for(int p = 0; p <= 100; ++p){
        tmp = 0;
        rep(i, X.size()){
            tmp += (X[i]-p)*(X[i]-p);
        }
        ans = min(tmp, ans);
    }

    cout << ans << endl;
}

int main(){
    cin >> N;
    X.resize(N);

    rep(i, N) cin >> X[i];

    sort(X.begin(), X.end());

    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
LL mod=1000000007;
LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


struct edge {int to;int cost;};
const int M_N=300;
int L;
vector<edge> G[M_N+1];
P d[M_N+1][M_N+1];

struct Dijkstra{

    void dijkstra(int s){
        priority_queue<pair<P,int> ,vector<pair<P,int>>,greater<pair<P,int>>> que;
        que.push({{0,-L},s});
        while(!que.empty()){
            pair<P,int> p=que.top();que.pop();
            int v=p.second;
            int t=-p.first.second;
            int l=p.first.first;
            if(d[s][v].first<l) continue;
            else if(d[s][v].first==l&&d[s][v].second>t) continue;
            for(int i=0;i<G[v].size();i++){
                edge e=G[v][i];
                if(e.cost>t){
                    if(d[s][e.to].fs>l+1||(d[s][e.to].fs==l+1&&d[s][e.to].sc<L-e.cost)){
                        d[s][e.to] = mp(l+1,L-e.cost);
                        que.push({{l+1,-(L-e.cost)},e.to});
                    }
                }
                else{
                    if(d[s][e.to].fs>l||(d[s][e.to].fs==l&&d[s][e.to].sc<t-e.cost)){
                        d[s][e.to] = mp(l,t-e.cost);
                        que.push({{l,-(t-e.cost)},e.to});
                    }
                }
            }
        }
    }

};




int main(){
    int n,m;cin >> n >> m >> L;
    for (int i = 0; i < m; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        int c;cin >> c;
        if(c>L) continue;
        G[x].pb({y,c});
        G[y].pb({x,c});
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            d[i][j] = mp(INF,INF);
        }
    }
    Dijkstra Ds[n];
    for (int i = 0; i < n; i++) {
        Ds[i].dijkstra(i);
    }
    int q;cin >> q;
    for (int i = 0; i < q; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        int ans = d[x][y].fs;
        if(ans == INF) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2984
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int x = new Scanner(System.in).nextInt();
        if(x == 7 || x == 5 || x == 3){
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }

    }
}

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

using namespace std;

int main() {
    map<int, int> occ;
    for (int i = 0, entry; i < 3 && cin >> entry; i++)
        occ[entry]++;
    if (occ.size() == 2 && (occ[7] == 1 && occ[5] == 2)) {
        cout << "YES";
    } else
        cout << "NO";
    return 0;
}


Measured memory_bytes: 3524
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

const int MOD = 1e9 + 7;

void solve() {
    int n, k, ans = 1;
    cin >> n >> k;
    vector <int> a(n);
    bool mns = 1;
    loop(i, n) {
        cin >> a[i];
        if (a[i] > 0)
            mns = 0;
    }
    sort(all(a), [](int a, int b) {return abs(a) > abs(b); });
    if (mns || n == k)
        for (int i = (k & 1 ? n - 1 : 0); (k & 1 ? i >= n - k : i < k); (k & 1 ? --i : ++i))
            ans = ans * (a[i] + MOD) % MOD;
    else {
        int cnt = 0;
        loop(i, k)
            if (a[i] < 0)
                ++cnt;
        if (cnt & 1) {
            int lst_pls = -1, lst_mns = -1, fst_pls = -1, fst_mns = -1;
            for (int i = k - 1; i >= 0; --i) {
                if (lst_pls == -1 && a[i] >= 0)
                    lst_pls = i;
                if (lst_mns == -1 && a[i] < 0)
                    lst_mns = i;
            }
            for (int i = k; i < n; ++i) {
                if (fst_pls == -1 && a[i] >= 0)
                    fst_pls = i;
                if (fst_mns == -1 && a[i] < 0)
                    fst_mns = i;
            }
            bool flag;
            if (fst_pls == -1 || lst_mns == -1)
                flag = 0;
            else if (fst_mns == -1 || lst_pls == -1)
                flag = 1;
            else
                flag = a[fst_pls] * a[lst_pls] > a[fst_mns] * a[lst_mns];
            loop(i, k) {
                if ((!flag && i == lst_pls) || (flag && i == lst_mns))
                    continue;
                ans = ans * abs(a[i]) % MOD;
            }
            ans = ans * abs(flag ? a[fst_pls] : a[fst_mns]) % MOD;
        }
        else
            loop(i, k)
                ans = ans * abs(a[i]) % MOD;
    }
    cout << ans;

}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


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

int main() {
  int a, b, c, x;
  int ans = 0;
  cin >> a >> b >> c >> x;
  
  for(int i = a; i > -1; i--) {
    for(int s = b; s > -1; s--) {
      for(int j = c; j > -1; j--) {
        if(x == (500 * i) + (100 * s) + (50 * j)) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = (ans * x) % 13;
        x = (x * x) % 13;
        y >>= 1;
    }
    return ans;
}

int main(void)
{
    string s;

    static ll dp[100010][13];

    cin >> s;

    dp[0][0] = 1;

    for (int i = 0; i <= s.size(); i++)
    {
        int c;

        if (s[i] == '?')
        {
            c = -1;
        }
        else
        {
            c = s[i] - '0';
        }

        for (int j = 0; j < 10; j++)
        {
            if (c == -1 || c == j)
            {
                for (int k = 0; k < 13; k++)
                {
                    dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
                }
            }
        }

        for (int j = 0; j < 13; j++)
        {
            dp[i + 1][j] %= MOD;
        }
    }

    cout << dp[s.size()][5] << endl;
}

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

typedef long long i64;
typedef pair<int, int> ii;
typedef pair<i64, i64> ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(a, x) memset(a, x, sizeof(a))
#define len(x) (x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 1e9;
const int maxn = 2e5+5;
const int mod = 1e9+7;

i64 k, cur, ans, ct;
bool ok;

int main() {
    fastIO();
    cin >> k;
    if (k % 2 == 0) {
    	cout << "-1\n"; return 0;
    }
    cur = 7;
    ans = 1;
    while (true) {
    	ct++;
    	if (ct == 2000000LL) {
    		break;
    	}
    	if (cur % k == 0) {
    		ok = true; break;
    	}
    	ans++;
    	cur = (cur * 10LL % k + 7LL) % k;
    }
    if (!ok) cout << "-1\n";
    else cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define Would
#define you
#define please

int main() {

	int K;
	cin >> K;

	cout << (K / 2) * ((K / 2) + K % 2) << "\n";
	Would you please return 0;
}

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

int main() {
	int N, X;

	cin >> N >> X;
	vector<int> L( N );
	for( int i = 0; i < N; i++ ) {
		cin >> L[i];
	}

	int ans = 1;
	int D = 0;
	for( int i = 0; i < N; i++ ) {
		D = D + L[i];
		if( D <= X ) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

const int N=1e6+5;

int n,m,q,mod,s,t,r,u[N],v[N],c[N],g,fa[N];
bool can[2][N];

int Id(int x,int y,int z) {return (x-1)*6+y*3+z;}
int get(int x) {return fa[x]==x?x:fa[x]=get(fa[x]);}

void link(int x,int y) {
	x=get(x);y=get(y);
	if (x==y) return;
	fa[x]=y;
}

int main() {
	scanf("%d%d%d%d",&n,&m,&q,&mod);
	fo(i,1,m) {
		scanf("%d%d%d",&u[i],&v[i],&c[i]);
		g=__gcd(g,abs(c[i]-c[1]));
	}
	if (!g) g=mod;mod=__gcd(mod,3*g);int z=c[1]%g;
	fo(i,0,6*n) fa[i]=i;
	fo(i,1,m) {
		int w=(c[i]-z)/g;
		fo(p,0,1)
			fo(q,0,2) {
				link(Id(u[i],p,q),Id(v[i],1-p,(2*q+w)%3));
				link(Id(v[i],p,q),Id(u[i],1-p,(2*q+w)%3));
			}
	}
	for(int i=0,j=z;i<mod<<1;i++,(j<<=1)%=mod) can[i&1][j]=1;
	for(;q;q--) {
		scanf("%d%d%d",&s,&t,&r);
		int ret=0;
		fo(p,0,1) fo(q,0,2) if (get(Id(t,0,0))==get(Id(s,p,q))) ret|=can[p][(r+z+(3-q)*g)%mod];
		puts(ret?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 10624
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        long ans = 0;
        for (int i = 0; i < n - 1; i++) {
            ans += a[i] / 2;
            a[i] %= 2;
            if (a[i] != 0 && a[i + 1] != 0) {
                long min = Math.min(a[i], a[i + 1]);
                ans += min;
                a[i] -= min;
                a[i + 1] -= min;
            }
        }

        ans += a[n - 1] / 2;

        System.out.println(ans);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 63236
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef pair<int,int>pii;
vector<int> v[100010];
int main(){
    
    int N, T,min_min=1000000;
    cin >> N >> T;
    
    
    
    for(int i=0;i<N;i++){
        int a,b;
        cin >> a >> b;
        if(T>=b){
            min_min = min(min_min,a);
        }
    }
    if(min_min==1000000)    cout << "TLE" << endl;

    else cout << min_min << endl;


}


Measured memory_bytes: 2560
// ABC 086 C
#include<bits/stdc++.h>
 
using namespace std;
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

bool func(int t,int x,int y,int pt,int px,int py){
  int dt,dx,dy;
  dt = t-pt;
  dx = x-px;
  dy = y-py;
  if(abs(dx)+abs(dy)>dt||dt%2!=abs(dx+dy)%2) return false;
  return true;
}

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int n;
  int t,x,y;
  int pt=0,px=0,py=0;
  str ans;
  cin >> n;
  REP(i,n){
    cin >> t >> x >> y;
    if(!func(t,x,y,pt,px,py)){  
      ans = "No";
      break;
    } 
    pt=t;px=x;py=y;
  }
  if(ans=="")ans="Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <algorithm>

using namespace std;

#define all(c) (c).begin(), (c).end()

bool solve(string& s){
    s.erase(remove_if(all(s), [](char c){return string("()[]").find(c) == string::npos;}), s.end());
    stack<char> st;
    for(auto c: s){
        if(c == '(' || c == '[')st.push(c);
        else if(st.empty() || st.top() != (c == ')'? '(': '['))return false;
        else st.pop();
    }
    return st.empty();
}

int main(){
    for(string s; getline(cin, s) && s != "."; cout << (solve(s)? "yes\n": "no\n"));
    return 0;
}

Measured memory_bytes: 1180
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define p 1000000007

vector<vector<ll>> multiply(vector<vector<ll>> &mat1,vector<vector<ll>> &mat2,ll n)
{
    vector<vector<ll>> mat(n+1,vector<ll>(n+1));  
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            ll ans=0;
            for(ll k=1;k<=n;k++)
            {
                ans=(ans%p+(mat1[i][k]%p*mat2[k][j]%p)%p)%p;
            }
            mat[i][j]=ans;
        }
    }
    return mat;
}

vector<vector<ll>> power(ll n,ll k,vector<vector<ll>> &v)
{
    if(k==1)
    {
        return v;
    }
    else
    {
        vector<vector<ll>> res=power(n,k/2,v);
        if(k&1)
        {
            // agr power odd hai tu in that case
            vector<vector<ll>> mat1=multiply(res,res,n);
            return multiply(mat1,v,n);
        }
        else
        {
            return multiply(res,res,n); // ye jo function hai vo two matrxi ko lega and uske product
            // ko eik matrix mei store krke return kr dega..
        }
    }
}

ll solve(ll n,ll k,vector<vector<ll>> &v)
{
    vector<vector<ll>> arr=power(n,k,v);  // ye function v ki power k ko return kr dega...
    ll ans=0;
    // arr matrix ke saare element ka sum nikal lo vo answer hoga..
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            ans=(ans%p+arr[i][j]%p)%p;
        }
    }
    return ans;
}

int main()
{
    ll n,k;
    cin>>n>>k;
    
    vector<vector<ll>> v(n+1,vector<ll>(n+1));
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cin>>v[i][j];
        }
    }
    cout<<solve(n,k,v);
    return 0;
}


Measured memory_bytes: 3728
open System

let getIntLine() = Console.ReadLine().Split(' ') |> Array.map Int32.Parse

let getMaxMin (l: 'a list): int*int =
    let mutable lMax, rMin = 0, Int32.MaxValue
    for _ in l do
        let [|l; r |] = getIntLine()
        if l > lMax then lMax <- l
        if r < rMin then rMin <- r
    lMax, rMin

[<EntryPoint>]
let main _ =
    let [| n; m |] = getIntLine()
    let lMax, rMin = getMaxMin [ 1..m ]
    let res =
        if lMax <= rMin && lMax <= n then
            (min rMin n) - lMax + 1
        else
            0
    printfn "%d" res

    0


Measured memory_bytes: 21424
#include <cstdio>
#include <vector>
#include <cstring>
#define PB push_back
using namespace std;
typedef vector<int> VI;
const int N=1010,M=200010;
int n,m;
int edge[M][2];
VI e[N];
void readData(){
	scanf("%d%d",&n,&m);
	int u,v;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		edge[i][0]=u; edge[i][1]=v;
		e[u].PB(v);
	}
}
int reach[2][N][N];
void dfs(int u,int x,int id,int *arr){
	if(arr[u]!=-1)
		return;
	arr[u]=id;
	for(int i=0,sz=e[u].size();i<sz;i++)
		if(e[u][i]!=x)
			dfs(e[u][i],x,id,arr);
}
void calcReach(){
	memset(reach,-1,sizeof reach);
	for(int u=1;u<=n;u++){
		int sz=e[u].size();
		for(int i=0;i<sz;i++)
			dfs(e[u][i],u,i,reach[0][u]);
		for(int i=sz-1;i>=0;i--)
			dfs(e[u][i],u,i,reach[1][u]);
	}
}
void answer(){
	for(int i=1;i<=m;i++){
		int u=edge[i][0],v=edge[i][1];
		if((reach[0][v][u]!=-1)^(e[u][reach[0][u][v]]!=v||e[u][reach[1][u][v]]!=v))
			puts("diff");
		else
			puts("same");
	}
}
int main(){
	readData();
	calcReach();
	answer();
	return 0;
}


Measured memory_bytes: 12288
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;

  vector<int>slime(N,0);
  for(int i=0;i<N;i++){
    cin >> slime[i];
  }

  int ans = 0;
  int same = 0;

  for(int i=0;i<N - 1;i++){
    if(slime[i] == slime[i + 1])
      same++;
    else{
      ans += (same + 1) / 2;
      same = 0;
    }
  }

  ans += (same + 1) / 2;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <climits>

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

using namespace std;

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

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

#define Max 110
#define VMax 100100
ll N, W;
ll w[Max];
int v[Max];
ll dp[Max][VMax];

int main(int argc, const char * argv[]) {
    N = inputValue();
    W = inputValue();
    rep(i, N) {
        w[i] = inputValue();
        v[i] = inputValue();
    }

    rep(i, Max) rep(j, VMax) dp[i][j] = 1LL<<60;

    dp[0][0] = 0;

    rep(i, N) {
        rep(vv, VMax) {
            if (vv - v[i] >= 0) {
                chmin(dp[i+1][vv], dp[i][vv-v[i]] + w[i]);
            }
            chmin(dp[i+1][vv], dp[i][vv]);
        }
    }

    int ans = 0;
    rep(i, VMax) {
        if (dp[N][i] <= W) {
            ans = i;
        }
    }

    output(ans);

    return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  long double w, h, x, y;
  cin >> w >> h >> x >> y;
  int wayCount = 0;
  if (w / 2 == x && h / 2 == y) wayCount = 1;
  cout << w * h / 2 << " " << wayCount << endl;
}


Measured memory_bytes: 256
n = int(input())
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][n-1])

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
const int inf = 1 << 29;

int n, m, s, g1, g2;
vector<vector<int> > cost;

int solve(){
    rep(k, n)rep(i, n)rep(j, n){
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
    }
    int res = inf;
    rep(i, n)res = min(res, cost[s-1][i] + cost[i][g1-1] + cost[i][g2-1]);
    return res;
}

int main(){
    while(cin >> n >> m >> s >> g1 >> g2, n|m|s|g1|g2){
        cost.assign(n, vector<int>(n, inf));
        rep(i, n)cost[i][i] = 0;
        rep(i, m){
            int b1, b2, c;
            cin >> b1 >> b2 >> c;
            cost[b1-1][b2-1] = c;
        }
        cout << solve() << '\n';
    }
    return 0;
}

Measured memory_bytes: 1260
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
int k,x;
int main()
{
	cin>>k>>x;
	if(k*500>=x) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
# python 3.8.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def lcm(a,b):return (a*b) // gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N = iin()
s = set()
for _ in range(N):
    s.add(input())
print(len(s))

Measured memory_bytes: 32696
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <math.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;
 
vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
ll gcd(ll a, ll b)
{
   if (b == 0)
   {
       return a;
   }
    return gcd(b, a%b);
}
void dfs(int now, ll d) {
  visited[now] = true;
  dist[now] = d;
  for (auto p : to[now]) {
    if (visited[p.first]) continue;
    dfs(p.first, d + p.second);
  }
}
vector<int>ans(10005,0);
void f(ll n){
    for (ll x = 1; x*x<n;x++){
        for (ll y = 1; y*y<n;y++){
            for (ll z = 1; z*z<n;z++){
                ll v = (x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
                if(v<10005) ans[v]++;
            }
        }
    }
}
int find(ll k) {
    ll tag = 7777777;
    int cnt = 0;
    cout << tag%k << endl;
    while (tag%k) {
        cnt++;
        tag/=10;
        cout << tag << endl;
        
    }
    return cnt;
}
 
int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    int k = 0;
    rep(i,0,n) {
        cin >> p[i];
    }
    rep(i,0,n) {
        if(p[i] != i+1) k++;
    }
    if(k<=2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

const ll MAX = 1e6 + 1;
const ll MOD = 998244353;
vector<ll> fac(MAX);
vector<ll> finv(MAX);
vector<ll> inv(MAX);

// COMinit()を忘れないように！
void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(ll i = 2; i < MAX; i++){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

ll nCr(ll n, ll r){
  if(n < r) return 0;
  if(n < 0 || r < 0) return 0;
  return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD;
}

ll fastpow(ll a, ll n){  // a^n mod MOD
  if(n==0) return 1;
  if(n%2==0){
    ll t = fastpow(a, n/2) % MOD;
    return t*t % MOD;
  }
  return a * fastpow(a, n-1) % MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M, K; cin >> N >> M >> K;
  COMinit();
  ll ans = 0;
  REPLL(i, K+1){
    ans += ((M * fastpow(M-1, N-i-1))%MOD * nCr(N-1, i))%MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 26544
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc = 1; 
    //cin >> tc;
    while(tc--){
        string s; cin >> s; 
        int n = s.size();
        int MOD = 2019;
        int ans = 0;
        map<int,int> mp;
        mp[0] = 1;
        int rem = 0, mul = 1;
        for(int i = n-1; i >= 0; i--)
        {
            int x = s[i] - '0';
            rem = ((mul*x) % MOD + rem) % MOD;
            ans += mp[rem];
            mul  = (mul*10) % MOD;
            mp[rem]++;
        }
        cout << ans;
    }    
}

Measured memory_bytes: 3776
N=int(input())
S=input()
if N%2!=0:
  print("No")
if N%2==0:
  check = True
  for i in range(N//2):
    if S[i]!=S[i+N//2]:
      check = False
  if(check):
    print("Yes")
  else:
    print("No")

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

int main(){
  int H,W; cin >> H >> W;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      string str; cin >> str;
      if(str=="snuke"){
        cout << (char)('A'+j) << i+1 << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    visited_list = [-1] * n  # 何ワープ目で訪れたか
    visited_list[0] = 0
    path_list = [1]
    city, loop, non_loop = 1, 0, 0  # 今いる街、何ワープでループするか、最初にループするまでのワープ数

    for i in range(1, n + 1):
        city = a_list[city - 1]
        path_list.append(city)
        if visited_list[city - 1] != -1:
            loop = i - visited_list[city - 1]
            non_loop = visited_list[city - 1]
            break
        else:
            visited_list[city - 1] = i

    city = 1
    if k <= non_loop:
        city = path_list[k]
    else:
        city = path_list[non_loop + (k - non_loop) % loop]

    print(city)


if __name__ == "__main__":
    main()


Measured memory_bytes: 102552
from collections import deque
n=int(input())
graph=[[] for i in range(n)]#0-indexed
edges=[tuple(map(int,input().split())) for i in range(n-1)]#1-indexed
edge_color={(edges[i][0]-1,edges[i][1]-1):0 for i in range(n-1)}#0-indexed
vertex=[0 for i in range(n)]
for i in edges:
  a,b=i[0],i[1]
  a-=1;b-=1
  graph[a].append(b)
  graph[b].append(a)
color=0;most_connected=0
for i in range(n):
  if len(graph[i])>color:
    color=len(graph[i])
    most_connected=i
visited=[False]*n
bfs=deque([most_connected])
while bfs:
  v=bfs.popleft()
  visited[v]=True
  for i in graph[v]:
    if visited[i]:continue
    I,V=i,v
    if i<v:
      I,V=v,i
    
    edge_color[(V,I)]=vertex[v]%color+1
    vertex[V],vertex[I]=edge_color[(V,I)],edge_color[(V,I)] 
    bfs.append(i)
print(color)
for i in edges:
  print(edge_color[(i[0]-1,i[1]-1)])


Measured memory_bytes: 56328
#include <cstdio>
#include <iostream>
using namespace std;
#define CENTINEL 2000000000
#define MAX 200000
typedef long long int llong;
int n,A[200000];
int L[MAX/2+2],R[MAX/2+2];
llong merge(int A[],int left,int mid,int right){
  int na=mid-left;
  int nb=right-mid;
  llong sum=0;
  for(int i=0;i<na;i++)L[i]=A[left+i];
  for(int i=0;i<nb;i++)R[i]=A[mid+i];
  L[na]=R[nb]=CENTINEL;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    if(L[i]<=R[j])A[k]=L[i++];
    else {A[k]=R[j++];sum+=na-i;}
  }
  return sum;
}
llong mergesort(int A[],int left,int right){
  llong v1,v2,v3;
  if(left+1<right){
    int mid=(left+right)/2;
    v1=mergesort(A,left,mid);
    v2=mergesort(A,mid,right);
    v3=merge(A,left,mid,right);
    return v1+v2+v3;
  } else return 0;
}
int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++)scanf("%d",&A[i]);
  llong cnt;
  cnt=mergesort(A,0,n);
  printf("%lld\n",cnt);
  return 0;
}

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

const int MOD = 998244353;
const int KEY = 61;

int ADD(int x, int y) {
  int res = (x + y);
  if (res < 0) res += MOD;
  if (res >= MOD) res -= MOD;
  return res;
}

int MUL(int x, int y) {
  int res = 1ll * x * y % MOD;
  if (res < 0) res += MOD;
  return res;
}

int power(int n, int x) {
  if (x == 0) {
    return 1;
  }
  int res = power(n, x / 2);
  res = MUL(res, res);
  if (x & 1) {
    res = MUL(res, n);
  }
  return res;
}

int inverse(int n) {
  return power(n, MOD - 2);
}

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

  string s;
  cin >> s;
  int n = s.size();

  // the number of elements is either 1, 2, or n (if all characters are the same)
  // if prefix(n - 1) is periodic, and suffix(n - 1) is periiodic, then all characters are the same


  vector<int> Hash(n); // string hashing
  for (int i = 0; i < s.size(); i++) {
    if (i > 0) Hash[i] = Hash[i - 1];
    Hash[i] = ADD(Hash[i], MUL((s[i] - 'a' + 1), power(KEY, i)));
  }

  vector<int> inv(n); // inverse of power(KEY, i)

  for (int i = 0; i < n; i++) {
    inv[i] = inverse(power(KEY, i));
  }

  auto GetHash = [&Hash, &inv](int i, int j) {
    int seg = Hash[j];
    if (i > 0) {
      seg = ADD(seg, -Hash[i - 1]);
    }
    seg = MUL(seg, inv[i]);
    return seg;
  };

  vector<int> goodPrefix(n, 1); // the prefix i of string s is good (there is no period)
  vector<int> goodSuffix(n, 1); // the suffix i of string s is good (there is no period)

  for (int d = 1; d <= n; d++) {
    int Key = GetHash(0, d - 1);
    for (int i = d; i + d - 1 < n; i += d) {
      if (GetHash(i, i + d - 1) != Key) {
        break;
      }
      goodPrefix[i + d - 1] = 0;
    }
  }

  for (int d = 1; d <= n; d++) {
    int Key = GetHash(n - d, n - 1);
    for (int i = n - d - 1; i - d + 1 >= 0; i -= d) {
      if (GetHash(i - d + 1, i) != Key) {
        break;
      }
      goodSuffix[i - d + 1] = 0;
    }
  }

  if (goodPrefix[n - 1]) { // length n is good
    cout << 1 << "\n";
    cout << 1 << "\n";
    return 0;
  }

  int cnt = 0; // count number of 2-element goods
  for (int i = 0; i + 1 < n; i++) {
    if (goodPrefix[i] && goodSuffix[i + 1]) {
      cnt++;
    }
  }
  if (cnt > 0) {
    cout << 2 << "\n";
    cout << cnt << "\n";
    return 0;
  }

  // all elements are the same, only 1 possibility

  cout << n << "\n";
  cout << 1 << "\n";
  return 0;
}


Measured memory_bytes: 8732
'use strict';
// d
class Main {
  solve() {
    const nums = input.nextIntArr();
    const table = input.nextIntRange(nums[1]);
    const uf = new UnionFind(nums[0]);
    table.reverse();
    let remain = nums[0] * (nums[0] - 1) / 2;
    const result = [];
    result.push(remain);
    const counts = [...Array(nums[0])].map((e) => 1);

    for (const node of table) {
      const n = node.map(e=>e-1);
      remain -= (uf.same(...n) ? 0 : (uf.size(n[0]) * uf.size(n[1])));
      uf.unite(...n);
      result.push(remain);
    }
    console.log(result.reverse().slice(1).join('\n'));
  }
}

class Input {
  constructor() {
    this.cursor = 0;
    this.inputAll();
  }

  inputAll() {
    this.data = (require("fs").readFileSync("/dev/stdin", "utf8")).split('\n');
    return this.data;
  }

  nextLine(n) {
    if (n) {
      const ret = this.data.slice(this.cursor, this.cursor + n);
      this.cursor += n;
      return ret;
    }
    return this.data[this.cursor++];
  }

  nextStrArr() {
    return this.nextLine().split(' ');
  }

  nextIntArr() {
    return this.nextStrArr().map((e) => parseInt(e));
  }

  nextStrRange(n) {
    return this.nextLine(n).map((line) => line.split(' '));
  }

  nextIntRange(n) {
    return this.nextLine(n).map((line) => line.split(' ').map((e) => parseInt(e)));
  }
}

class UnionFind {
  constructor(n) {
    this.ref = [];
    this.count = [];
    for (let i = 0;i < n; ++i) {
      this.ref[i] = i;
      this.count[i] = 1;
    }
  }

  root(x) {
    if (this.ref[x] == x) return x;
    return this.ref[x] = this.root(this.ref[x]);
  }

  size(x) {
    return this.count[this.root(x)];
  }

  unite(x, y) { // xとyの木を併合
    const rx = this.root(x);
    const ry = this.root(y);
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    this.ref[Math.max(rx,ry)] = Math.min(rx,ry); //xとyの根が同じでない(=同じ木にない)時, rx,ryの小さい方を根とする
    this.count[Math.min(rx,ry)] = this.count[rx] + this.count[ry]; 
  }

  same(x, y) { // 2つのデータx, yが属する木が同じならtrueを返す
    const rx = this.root(x);
    const ry = this.root(y);
    return rx == ry;
  } 
}

const input = new Input();
(new Main()).solve();


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

template <typename Monoid, typename OperatorMonoid = Monoid> struct LazySegmentTree {
  using F = function<Monoid(Monoid, Monoid)>;
  using G = function<Monoid(Monoid, OperatorMonoid)>;
  using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
  using P = function<OperatorMonoid(OperatorMonoid, int)>;

  size_t sz;
  vector<Monoid> data;
  vector<OperatorMonoid> lazy;
  const F f;
  const G g;
  const H h;
  const P p;
  const Monoid M1;
  const OperatorMonoid OM0;

  LazySegmentTree(size_t n, const F f, const G g, const H h, const P p, const Monoid &M1, const OperatorMonoid &OM0) : sz(1 << (32 - __builtin_clz(n - 1))), f(f), g(g), h(h), p(p), M1(M1), OM0(OM0) {
    data.assign(2 * sz, M1);
    lazy.assign(2 * sz, OM0);
  }

  void set(int k, const Monoid &x) {
    data[k + sz] = x;
  }

  void build() {
    for (int k = sz - 1; k; --k) {
      data[k] = f(data[2 * k], data[2 * k + 1]);
    }
  }

  void propagate(int k, int length) {
    if (lazy[k] != OM0) {
      if (k < sz) {
        lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
        lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      }

      data[k] = g(data[k], p(lazy[k], length));
      lazy[k] = OM0;
    }
  }

  Monoid update(int a, int b, const OperatorMonoid &x) {
    return update(a, b, x, 1, 0, sz);
  }

  Monoid update(int a, int b, const OperatorMonoid &x, int k, int l, int r) {
    propagate(k, r - l);

    if (r <= a || b <= l) {
      return data[k];
    } else if (a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      propagate(k, r - l);
      return data[k];
    } else {
      return data[k] = f(update(a, b, x, 2 * k, l, (l + r) >> 1), update(a, b, x, 2 * k + 1, (l + r) >> 1, r));
    }
  }

  Monoid query(int a, int b) {
    return query(a, b, 1, 0, sz);
  }

  Monoid query(int a, int b, int k, int l, int r) {
    propagate(k, r - l);

    if (r <= a || b <= l) {
      return M1;
    } else if (a <= l && r <= b) {
      return data[k];
    } else {
      return f(query(a, b, 2 * k, l, (r + l) >> 1), query(a, b, 2 * k + 1, (r + l) >> 1, r));
    }
  }
};

// https://onlinejudge.u-aizu.ac.jp/#/courses/library/3/DSL/2/DSL_2_F
int main() {
  int n, q;
  cin >> n >> q;

  auto f = [](int64_t a, int64_t b) { return min(a, b); };
  auto g = [](int64_t a, int64_t b) { return b < 0 ? a : b; };
  auto p = [](int64_t a, int b) { return a; };
  LazySegmentTree<int64_t> seg(n, f, g, g, p, (1ll << 31) - 1, -1);
  while (q--) {
    int type;
    cin >> type;

    if (type) {
      int s, t;
      cin >> s >> t;

      cout << seg.query(s, t + 1) << endl;
    } else {
      int s, t, x;
      cin >> s >> t >> x;

      seg.update(s, t + 1, x);
    }
  }
}



Measured memory_bytes: 7032
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();

		StringBuilder answer = new StringBuilder();

		for (int i = 0; i < line.length(); i++) {
			String s = line.substring(i, i + 1);
			char cs = line.charAt(i);
			if (Character.isUpperCase(cs)) {
				answer.append(s.toLowerCase());
			} else {
				answer.append(s.toUpperCase());
			}

		}

		System.out.println(answer);

	}
}

Measured memory_bytes: 26656
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
ans="No"
for i in range(n-m+1):
  for j in range(n-m+1):
    if [line[j:j+m] for line in a[i:i+m]]==b:
      ans="Yes"
      break
  if ans=="Yes":
    break
print(ans)

Measured memory_bytes: 67424
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0, x = 0, y = 0, z = 0,n=0,m=0, maxy = 0, mini = 9999, counter = 0, s = 0, endp = 0, checker = 0;
long long int one = 0, two = 0, four = 0;
std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[100001],sec[100001],pointx[100001],pointy[100001];
long long int iremono2[100001],check[100001];
std::vector<long long int>kinds{}, ans{}, kaku{};
char moji, moji2;
bool okada = false, okada2 = false;
std::string output, output2, input,input2;
char rev[100001];
unsigned long long int kakunou2[101][101] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}
int main()
{
	okada = true;
	cin >> a >> b >> input;
	rep(i, a) {
		if (input[i] =='-'){
			okada = false;
		}
}
	if (input[a] != '-') {
		okada = false;
	}
	for (int i = a + 1; i < a+b+1;i++) {
		if ( input[i] =='-') {
			okada = false;
		}
	}
	if (input.size() != a + b + 1) {
		okada = false;
	}
	if (okada) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int total = 0;
        for (int i = 1; i <= n; i++) {
            int cand = sumByDigit(i);
            if (cand >= a && cand <= b) {
                total += i;
            }
        }

        System.out.println(total);
    }

    static int sumByDigit(int n) {
        int total = 0;
        while (n > 0) {
            total += n % 10;
            n /= 10;
        }
        return total;
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N;
  cin >> N;
  vector<int> L(N);
  REP(i, N) {
    cin >> L[i];
  }
  int m = 0, s = 0;
  REP(i, N) {
    m = max(m, L[i]);
    s += L[i];
  }
  if ((s - m) > m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
const val P = 1000000007L

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val list = mutableListOf<Pair<IntRange, Int>>()
    val r = Math.floor(Math.sqrt(n.toDouble())).toInt()
    for (i in 1..r) {
        list.add(Pair(i..i, n / i))
    }
    for (i in r downTo 1) {
        val l = Math.max(n / (i + 1) + 1, r + 1)
        val u = n / i
        if (l <= u) {
            list.add(Pair(l..u, i))
        }
    }
    // println(list)
    // println(list.size)
    val size = list.size
    val dp = Array(k, { LongArray(size) })
    for (i in 0 until size) {
        dp[0][i] = (list[i].first.last - list[i].first.first + 1).toLong()
    }
    var counter = 0L
    for (t in 1 until k) {
        val sum = LongArray(size)
        sum[0] = dp[t - 1][0]
        for (i in 1 until size) {
            sum[i] = sum[i - 1] + dp[t - 1][i]
        }


        dp[t][size - 1] = sum[0] * (list[size - 1].first.last - list[size - 1].first.first + 1)
        dp[t][size - 1] %= P
        for (i in size - 2 downTo 0) {
            dp[t][i] = sum[size - 1 - i]  * (list[i].first.last - list[i].first.first + 1)
            dp[t][i] %= P
//            val nextMax = list[i].second
//            for (j in 0 until size) {
//                counter++
//                if (list[j].first.last <= nextMax) {
//                    dp[t + 1][j] += dp[t][i] * (list[j].first.last - list[j].first.first + 1)
//                    dp[t + 1][j] %= P
//                } else if (list[j].first.first <= nextMax) {
//                    dp[t + 1][j] += dp[t][i] * (nextMax - list[j].first.first + 1)
//                    dp[t + 1][j] %= P
//                } else {
//                    break
//                }
//            }
        }
    }
    // println("counter: $counter")
//    println(dp[0].asList())
//    println(dp[k - 1].asList())
    var ans = 0L
    for (i in 0 until size) {
        ans += dp[k - 1][i]
        ans %= P
    }
    println(ans)
}

Measured memory_bytes: 126408
#include <stdio.h>
#include <math.h>

int main(void) {
	int n, i;
	double a[1000], b[1000], c[1000];
	double buf;

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%lf %lf %lf", &a[i], &b[i], &c[i]);
		if (a[i] <= c[i] && b[i] <= c[i]){
			buf = (a[i] * a[i]) + (b[i] * b[i]);
			if ((c[i]*c[i]) == buf){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
		else if (a[i] <= b[i] && b[i] >= c[i]){
			buf = ((a[i] * a[i]) +(c[i] * c[i]));
			if ((b[i]*b[i]) == buf){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
		else if (a[i] >= b[i] && a[i] >= c[i]){
			buf = ((b[i] * b[i]) + (c[i] * c[i]));
			if ((a[i]*a[i]) == buf){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 640