akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	int n, q;
	cin >> n;

	vector<long> a(n);

	for(int i = 0; i < n; i++)
		cin >> a[i];

	cin >> q;

	for (int i = 0; i < q; i++) {
		int c, b, e;
		cin >> c >> b >> e;

		vector<long>::iterator ib = a.begin(), ie = a.begin();
		ib += b;
		ie += e;

		if (c == 0)
			cout << *min_element(ib, ie) << endl;
		else if (c == 1)
			cout << *max_element(ib, ie) << endl;
	}

	return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
int main()
{
	int n,m,p[1000];
	int i,j,x,a;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	x=0;
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(p[i]>p[j]){
				x=p[i];
				p[i]=p[j];
				p[j]=x;
			}
		}
	}
	a=0;
	for(i=0;i<m;i++){
		a+=p[i];
	}
	printf("%d\n",a);
	return 0;
}


Measured memory_bytes: 1708
import java.util.Scanner;

public class Main{
  public static void main (String[] args){
    Scanner stdIn = new Scanner(System.in);
    String a = stdIn.next();
      if (a.equals("ABC")){
        System.out.println("ARC");
      }
         else if (a.equals("ARC")){
           System.out.println("ABC");
         }
  }
}
    
    

Measured memory_bytes: 35432
import math
def main():
    n = int(input())
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    city = [0] * 6
    city[0] = n
    ans = 0
    ans = math.ceil(n / min(a,b,c,d,e) + 4)
    print(ans)

def isFinished(city, n):
    if city[-1] == n:return True
    return False

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2019-12-15 22:57:23
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    string ans = "Good";
    for (int i = 0; i < 3; i++) {
        if (S[i] == S[i+1]) {
            ans = "Bad";
        }
    }

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


Measured memory_bytes: 384
#include <cstdio>
int main() {
    int x, y, i;
    for(i = 1;; ++i) {
        scanf("%d%d\n", &x, &y);
        if(x == 0 && y == 0) {
            break;
        }
        else {
            if(x >= y) {
                printf("%d %d\n", y, x);
            }
            else if(x <= y) {
                printf("%d %d\n", x, y);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2672
#include<cstdio>
using namespace std;
int main(void)
{
	int flg,i,a,b;
	char s[12];
	scanf("%d %d",&a,&b);
	scanf("%s",s);
	flg=1;
	for(i=0;i<a;i++)	{
		if(s[i]<'0' || s[i]>'9')	flg=0;
	}
	if(s[a]!='-')	flg=0;
	for(i=a+1;i<a+b+1;i++)	{
		if(s[i]<'0' || s[i]>'9')	flg=0;
	}
	if(flg==1)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [s, t] = stdin.split('\n')

const ans = () => {
  const sd = s.split('').sort().join('')
  const td = t.split('').sort().reverse().join('')

  console.log(sd < td ? 'Yes' : 'No')
}

ans()


Measured memory_bytes: 9420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
int A[100010];
ll L[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    if (i == 0) L[i] = A[i] % M;
    else L[i] = (L[i - 1] + A[i]) % M;
  }
  map<int, int> mp;
  mp[0]++;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (mp[L[i]]) ans += mp[L[i]];
    mp[L[i]]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) x.begin(),x.end()
using namespace std;


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

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

Measured memory_bytes: 3596
import java.util.*

val sc = Scanner(System.`in`)
val N = sc.nextInt()

fun main(args: Array<String>) {
    println(if (judge(N)) "Yes" else "No")
}

fun judge(n: Int): Boolean {
    val cake = 4
    val doughnut = 7

    for (c in 0..n / cake) {
        for (d in 0..n / doughnut) {
            if (c * cake + d * doughnut == n) {
                return true
            }
        }
    }
    return false
}


Measured memory_bytes: 31388
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    cout << string(dy, 'U');
    cout << string(dx, 'R');
    cout << string(dy, 'D');
    cout << string(dx + 1, 'L');
    
    cout << string(dy + 1, 'U');
    cout << string(dx + 1, 'R');
    cout << string(1, 'D');
    cout << string(1, 'R');    
    cout << string(dy + 1, 'D');
    cout << string(dx + 1, 'L');
    cout << string(1, 'U') << endl;    

    return 0;
}


Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/11/ALDS1_11_C
# 実家のような安心感
# 与えられるノード番号についてはすべて0based indexに治す

from collections import deque

# データの入力
N = int(input())
DG = {}
for i in range(N):
    tmp = input().split()
    if int(tmp[1]) != 0:
        DG[i] = [int(x)-1 for x in tmp[2:]]
    else:
        DG[i] = []


result = {}
is_visited = {key: False for key in range(N)}
# bfs
# 初期queue
que = deque([(0, 0)])  # 必要なものはnodeidと原点からの距離
while que:
    nodeid, cost = que.popleft()  # 先入れ先出し
    result[nodeid] = cost
    is_visited[nodeid] = True  # この文は最初の1for目しか意味ないんだけどなんかうまい方法ないのか
    for nextnode in DG[nodeid]:
        if is_visited[nextnode]:
            pass
        else:  # 未訪問のものについては探索候補に入れる
            que.append((nextnode, cost + 1))
            is_visited[nextnode] = True  # 探索候補に入れた瞬間に訪問管理しないと重複を生じる場合がある

for i in range(N):
    if is_visited[i]:
        print(i + 1, result[i])
    else:
        print(i+1, -1)



Measured memory_bytes: 6036
N = int(input())
x1 = input()
x2 = input()
for i in range(N):
    arr1 = list(map(int, x1.split()))
for i in range(N):
    arr2 = list(map(int, x2.split()))
sumarr2 = 0
for i in range(N):
    sumarr2 += arr2[i]
sum = arr1[0] + sumarr2
for i in range(1, N):
    temp = 0
    for j in range(i):
        temp += arr1[j]
        temp -= arr2[j]
    temp = temp + arr2[j] + sumarr2
    if temp > sum:
        sum = temp
print(sum)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String x;
		x = in.nextLine();
	    String[] myName = x.split(" ");
	    for (int i = 0; i < myName.length; i++) {
	        String s = myName[i];
	        System.out.print(s.charAt(0));
	    }
	}

}

Measured memory_bytes: 27024
/*
  Contest 096
  A - Day of Takahashi
  Rakesh Kumar --> 23/09/2020
 */

#include <bits/stdc++.h>

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

    int m = 0, d = 0;
    std::cin >> m >> d;
    int r = m;
    if (d < m)
        --r;
    std::cout << r << std::endl;

    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
using namespace std;
int mi(int a,int b)
{
	if(a<b) return a;
	else return b;
}
int main()
{
  int l,r;
  cin>>l>>r;
  if(r-l+1 >=2019- l%2019) cout<<"0";
  else 
  {
  int a=l%2019,b=r%2019;
  int m=2018;
  for(int i=a;i<b;i++)
  {
  for(int j=i+1;j<=b;j++)
  {
  	
  	m=mi(m,((i*j)%2019));
  }	
  }
  cout<<m;
  }
  
}
//1999999262 1999999281


Measured memory_bytes: 256
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	while (n > 0) {
		++ans;
		n /= k;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
k, n = map(int, input().split())
A = list(map(int, input().split()))
dmax = 0

for i in range(n-1):
    d = A[i+1]-A[i]
    if d > dmax:
        dmax = d
dmax = max(k-A[-1]+A[0], dmax)

print(k-dmax)


Measured memory_bytes: 26060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int x = Integer.parseInt(chr[0]);
			int y = Integer.parseInt(chr[1]);
			 System.out.println(x+y/2);
		}
	}
}

Measured memory_bytes: 25348
#include <bits/stdc++.h>
using namespace std;
const double PI=3.14159265358979323846;

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  h += m / 60;
  h *= 30;
  m *= 6;
  double rad = (h - m) * PI / 180;
  double c = sqrt(a * a + b * b - 2 * a * b * cos(rad));
  printf("%.10f\n", c);
  return 0;
}

Measured memory_bytes: 4228
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import           Data.Char


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las



main = do
    (n, k) <- readTuple2
    hs <- readInts
    print $ sum $ drop k $ sortOn negate hs




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

using namespace std;

int main() {
    int H, W, N;   cin >> H >> W;
    cin >> N;
    vector<int> color;
    for (int i = 0; i < N; i++) {
        int a;  cin >> a;
        while (a-- > 0)
            color.push_back(i+1);
    }
    
    vector<vector<int> > ans(H, vector<int>(W));

    int k = 0;
    for (int i = 0; i < H; i++) {
        if (i % 2 == 0) {
            for (int j = 0; j < W; j++)
                ans[i][j] = color[k++];
        }
        else {
            for (int j = W-1; j >= 0; j--)
                ans[i][j] = color[k++];
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++)
            cout << ans[i][j] << " ";
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i, n)         for(int i=0; i<n; i++)
#define fo(i, k, n)     for(int i=k; i<n; i++)
#define forr(i, a, b)   for(int i=a; i<=b; i++)
#define rf(i,n)         for(int i=n;i>=0;i--)
typedef unsigned long long ull;
typedef pair<int ,int> pr;
#define MAX 100005
#define INF 1000000009
#define   sq(n)         (n*n)
#define p(n) cout<<n<<endl
#define pb push_back
#define py cout<<"YES"<<endl;
#define pn cout<<"NO"<<endl;
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
ll lcm ( ll a, ll b )
{
    return ( a / __gcd ( a, b ) ) * b;
}
int main()
{
    __FastIO;

     int n;
     cin>>n;
     int ac=0,tle=0,re=0,wa=0;
     for(int i=0;i<n;i++)
     {
        string s;
         cin>>s;
         if(s=="AC")
         {
             ac++;
         }
         else if(s=="WA")
         {
             wa++;
         }
         else if(s=="TLE")
         {
             tle++;
         }
         else if(s=="RE")
         {
             re++;
         }
     }
     cout<<"AC "<<"x "<<ac<<endl;
     cout<<"WA "<<"x "<<wa<<endl;
     cout<<"TLE "<<"x "<<tle<<endl;
     cout<<"RE "<<"x "<<re<<endl;

    return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    multiset<int> se;
    for (int i = N-1; i >= 0; --i) {
        auto iter = se.upper_bound(A[i]);
        if(iter != se.end()) se.erase(iter);
        se.insert(A[i]);
    }
    cout << se.size();
    return 0;
}

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

using namespace std;

int main()
{
    int n, m;
    cin >> n;
    int t[n];
    for (int i=0; i<n; i++) cin >> t[i];
    cin >> m;
    int p[m];
    int x[m];
    for (int i=0; i<m; i++) cin >> p[i] >> x[i];
    for (int i=0; i<m; i++) {
        int res = 0;
        for (int j=0; j<n; j++) {
            if (j == p[i]-1) {
                res += x[i];
            }
            else res += t[j];
        }
        cout << res << '\n';
    }
    
    return 0;
}

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

int main() {
    int a, b, c, x, pair = 0;
    int k = 0;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    while (k * 500 <= x && k <= a) {
        for (int i = 0; i <= b; i++) {
            for (int j = 0; j <= c; j++) {
                if (500 * k + 100 * i + 50 * j == x) pair++;
            }
        }
        k++;
    }
    cout << pair;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi x(n), y(n), p(n);
    rep(i, n) cin >> x[i] >> y[i] >> p[i];

    const ll ez = INT64_MAX>>1;
    vector<ll> test(1<<n, ez);
    rep(i, 1<<n) {
        rep(j, n) if(i>>j&1) rep(k, 2) {
            ll res = 0;
            rep(l, n) if(i>>l&1) {
                if(k) {
                    res += ll(p[l]) * min({abs(x[l]), abs(y[l]), abs(x[l]-x[j])});
                } else {
                    res += ll(p[l]) * min({abs(x[l]), abs(y[l]), abs(y[l]-y[j])});
                }
            }
            chmin(test[i], res);
        }
    }

    vector<vector<ll> > ans(1<<n, vector<ll>(n+1, ez));
    rep(i, 1<<n) {
        ans[i][0] = 0;
        rep(j, n) if(i>>j&1) {
            ans[i][0] += ll(p[j]) * min(abs(x[j]), abs(y[j]));
        }
        for(int j = (i-1)&i; j >= 0; j--) {
            j &= i;
            int k = i-j;
            for(int l = 1; l <= n; l++) {
                chmin(ans[i][l], ans[j][l-1] + test[k]);
            }
        }
    }

    rep(i, n+1) cout << ans[(1<<n)-1][i] << '\n';
}

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

int main(){
  int x; cin>>x;
  if (x>=30) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3632
use strict;
use warnings;

chomp(my $hw = <>);
my ($h, $w) = split(" ", $hw);

if ($h == 1 || $w == 1){
  print "1\n";
} elsif ($h%2==0) {
  print $h/2 * $w, "\n";
} elsif ($w%2==0) {
  print $h * $w/2, "\n";
} else {
  print int($h/2) * $w + int($w/2)+1, "\n";
}

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

string expr;
int p,s,l;
char ans;

int parseInt()
{
	int ret=0;
	while(p<expr.size())
	{
		if(!isdigit(expr[p])) break;
		ret*=10;
		ret+=expr[p]-'0';
		p++;
	}
	
	return ret;
}

string parseStr()
{
	string ret;
	while(p<expr.size())
	{
		if(!isupper(expr[p])) break;
		ret+=expr[p];
		p++;
	}
	
	return ret;
}

bool parse()
{
	int lp=parseInt(), tp=p;
	string str;
	if(expr[p]=='(')
	{
		while(lp--)
		{
			p=tp;
			p++;
			if(parse()) return true;
		}
		p++;
	}
	else
	{
		if(lp==0) lp++;
		str=parseStr();
		
		for(int i=0; i<lp; i++) 
		{
			if(s+str.size() > l)
			{
				int ex=l-s;
				ans=str[ex];
				return true;
			}
			s+=str.size();
		}
	}

	if(p<expr.size() && expr[p]!=')') return parse();
	return false;
}

int main()
{
	while(cin >> expr >> l, (expr!="0"||l))
	{
		p=0; s=0; ans='0';
		
		parse();
		printf("%c\n", ans);
	}
}

Measured memory_bytes: 932
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

vector<int> pf(int n) {
    vector<int> primes;
    if (n%2 == 0) {
        primes.push_back(2);
        while (n%2 == 0) n /= 2;
    }
    for (int i=3; i*i<=n; i+=2) {
        if (n%i) continue;
        primes.push_back(i);
        while (n%i == 0) n /= i;
    }
    if (n != 1) primes.push_back(n);

    return primes;
}

int main() {
    const int MAX_N = 1e6;
    vector<int> sieve(MAX_N+1);
    iota(sieve.begin(), sieve.end(), 0);
    for (int64 i=2; i<=MAX_N; i++) {
        if (i != sieve[i]) continue;
        for (int64 j=i*i; j<=MAX_N; j+=i)
            sieve[j] = i;
    }

    int n;
    cin >> n;
    int all_gcd;
    bool pc = true;
    unordered_map<int, bool> check;
    set<int> st;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        all_gcd = (i==0)? a : gcd(all_gcd, a);

        if (!pc) continue;
        st.clear();
        while (a != 1) {
            st.insert(sieve[a]);
            a /= sieve[a];
        }
        for (auto i : st) {
            if (check[i]) pc = false;
            check[i] = true;
        }
    }

    if (pc)
        cout << "pairwise coprime" << endl;
    else if (all_gcd == 1)
        cout << "setwise coprime" << endl;
    else
        cout << "not coprime" << endl;
}


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

int main(){
  int i,N,count=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    int n,j,l=0;
    scanf("%d",&n);
    if(n==1||n==2){
      count++;
      continue;
    }
    if(n%2==0){
      continue;
    }
    for(j=3;j<=sqrt(n);j+=2){
      if(n%j==0){
        l+=1;
        break;
      }
    }
    if(l!=1){
      count++;
    }
    l=0;
  }
  printf("%d\n",count);
  return 0;
}

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

using namespace std;
using ll = long long int;

template <typename T>
struct SegmentTree {
    using F = function<T(T, T)>;

    const T e;
    const F f;
    size_t sz;
    vector<T> tree;

    SegmentTree(size_t n, const F &f, const T &e = 0) : f(f), e(e) {
        sz = 1;
        while(sz < n) sz <<= 1;
        tree.assign(2*sz, e);
    }

    void set(typename vector<T>::iterator begin, typename vector<T>::iterator end) {
        copy(begin, end, tree.begin() + sz);
        for(size_t k=sz-1; k>0; k--)
            tree[k] = f(tree[2*k+0], tree[2*k+1]);
    }

    void update(size_t k, const T &x) {
        k += sz;
        tree[k] = x;
        while(k >>= 1)
            tree[k] = f(tree[2*k+0], tree[2*k+1]);
    }

    T query(size_t a, size_t b) const {
        T l = e, r = e;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) l = f(l, tree[a++]);
            if(b & 1) r = f(tree[--b], r);
        }
        return f(l, r);
    }

    T operator[](const size_t k) const {
        return tree[sz + k];
    }
};

/*
   SegmentTree<long> st(n, [&](long a, long b){return min(a, b);}, 1e9);
   st.set(a.begin(), a.end());
  
   [&](F a, F b) -> F { return {b.first * a.first % MOD, (b.first * a.second + b.second) % MOD};
 */

int main(void) {
    ll n;
    cin >> n;

    string s;
    cin >> s;

    vector<SegmentTree<long>> sts(26, SegmentTree<long>(n, [&](long a, long b){return max(a, b);}, 0));
    for(ll i=0; i<n; i++) {
        ll c = s[i] - 'a';
        sts[c].update(i, 1);
    }

    ll q;
    cin >> q;
    while(q--) {
        ll t;
        cin >> t;
        if(t == 1) {
            ll i;
            cin >> i;
            i--;
            string c;
            cin >> c;
            sts[s[i]-'a'].update(i, 0);
            s[i] = c[0];
            sts[s[i]-'a'].update(i, 1);
        } else {
            ll l, r;
            cin >> l >> r;
            l--;

            ll res = 0;
            for(ll i=0; i<26; i++)
                res += sts[i].query(l, r);
            cout << res << endl;
        }
    }
}


Measured memory_bytes: 222212
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>


using namespace std;

typedef long long ll;
#define INF 0x3f3f3f3f
#define ESP 1e-8;
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
const double PI = acos(-1.0);

#define P 1000000007
#define N 100005
bool isprime[N] = {0};
int prime[N], pcnt;

int n, m, k[N], kcnt;

void Euler(){
    int i, j;
    memset(isprime, 1, sizeof(isprime));
    pcnt = 0;
    for(i = 2; i < N; i++){
        if(isprime[i])
            prime[pcnt++] = i;
        for(j = 0; j < pcnt && prime[j] * i < N; j++){
            isprime[prime[j]*i] = 0;
            if(i%prime[j] == 0)
                break;
        }
    }
}

void Inv(ll a, ll b, ll &x, ll &y)  // x 是 a 关于 b 的乘法逆元
{
    if(0 == b){
        x = 1, y = 0;
        return ;
    }
    Inv(b, a%b, x, y);
    ll flag = x;
    x = y;
    y = flag - a/b * y;
}

ll C(ll n, ll m){
    if(n==0 || m>n)
        return 1;
    ll i, ret=1;
    if(m > n/2)
        m = n-m;
    for(i = n; i >= n-m+1; i--)
        ret = ret*i%P;
    ll t1, t2;
    for(i = m; i > 1; i--){
        Inv(i, P, t1, t2);
        ret = ((ret*t1%P>0)?(ret*t1%P):(ret*t1%P+P));
    }
    return ret;
}

int main(){
    Euler();
    int i, j;
    ll ans;
    while(scanf("%d%d", &n, &m)!=EOF){
        kcnt = 0;
        i = 0;
        while(m>1 && i<pcnt){
            if(m%prime[i]==0){
                ++kcnt, k[kcnt]=0;
                while(m%prime[i]==0)
                    m/=prime[i], k[kcnt]++;
            }
            ++i;
        }
        if(m > 1)
            k[++kcnt] = 1;
        ans = 1;
        ll sum;
        for(i = 1; i <= kcnt; i++){
            ll end = MIN(k[i], n);
            sum = 0;
            for(j = 1; j <= end; j++){
                sum += C(k[i]-1, j-1)*C(n, j)%P;
            }
            ans = ans*sum%P;
        }

        printf("%lld\n", ans);
    }

    return 0;
}

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

#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d", &a); a; } )

const int N = 5e5 + 9;
const int mod = 1e9 + 7;

template <class T>
struct BIT
{
    ///1-indexed
	int sz;
	vector<T> t;

	void init(int n) ///max size of array
	{
		sz = n;
		t.assign(sz,0);
	}

	T query(int idx)
	{
		T ans = 0;
		for(; idx >= 1; idx -= (idx & -idx)) ans += t[idx];
		return ans;
	}

	void upd(int idx, T val)
	{
		if(idx <= 0) return;
		for(; idx <sz; idx += (idx & -idx)) t[idx] += val;
	}

	void upd(int l, int r, T val)
	{
	    upd(l,val);
	    upd(r+1,-val);
	}

	T query(int l, int r) { return query(r) - query(l - 1); }
};
BIT<int> t[26];
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for(int i = 0; i < 26; i++) t[i].init(N);
    int n; cin >> n;
    string s; cin >> s;
    s = "#" + s;
    for(int i = 1; i <= n; i++){
        t[s[i] - 'a'].upd(i, 1);
    }
    int q; cin >> q;
    while(q--){
        int ty; cin >> ty;
        if(ty == 1){
            int i; char ch; cin >> i >> ch;
            t[s[i] - 'a'].upd(i, -1);
            s[i] = ch;
            t[s[i] - 'a'].upd(i, 1);
        }
        else{
            int l, r; cin >> l >> r;
            int ans = 0;
            for(int k = 0; k < 26; k++){
                ans += t[k].query(l, r) > 0;
            }
            cout << ans << nl;
        }
    }
    return 0;
}



Measured memory_bytes: 53808
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int t = sc.nextInt();
		int max=0;
		int sum=0;
		for(int i = 0; i < t; i++){
			int l = sc.nextInt();
			if(max<l){
				sum+=max;
				max=l;
			}else{
				sum+=l;
			}
		}
		if(sum>max){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

ll N;

int main(void) {
  cin >> N;

  ll ans = N + 1;
  if(N % 2 == 0) ans = 1;
  else {
    ll pow2 = 1;
    while(pow2 <= N) {
      if(((N - pow2 + 1) / pow2) % 2 == 0) {
        ans = pow2;
        break;
      }
      pow2 *= 2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K, A, B;
  cin >> K;
  cin >> A >> B;
  bool ans = false;
  for (int i=A; i<=B; i++){
    if (i % K == 0){
      ans = true;
    }
  }
  if (ans == true){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3636
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define lint long long

using namespace std;

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

  lint ans=0;

  if(N%2==1){
    ans = 0;
  }else{
    N/=2;
    while(N>=1){
      ans+=(N/5);
      N/=5;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lf;

ll M, K;

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

	cin >> M >> K;
	if (M == 1) {
		if (K != 0) {
			cout << -1 << "\n";
			return 0;
		}
		for (ll i = 0; i < (1LL << M); i++) {
			cout << i << " " << i << " \n"[i == (1LL << M)-1];
		}
		return 0;
	}
	if (K >= (1LL << M)) {
		cout << -1 << "\n";
		return 0;
	}

	bool first = true;
	for (ll i = 0; i < (1LL << M); i++) {
		if (i == K) continue;
		if (first) first = false;
		else cout << " ";
		cout << i;
	}
	if (first) first = false;
	else cout << " ";
	cout << K;
	for (ll i = (1LL << M)-1; i >= 0; i--) {
		if (i == K) continue;
		if (first) first = false;
		else cout << " ";
		cout << i;
	}
	if (first) first = false;
	else cout << " ";
	cout << K << "\n";
}

Measured memory_bytes: 1792
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
    def find(self, x):
        """
        x が属するグループを探索して親を出す。
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]



N,M = map(int,input().split())
A = []; B = []
for i in range(M):
  a,b = map(int,input().split())
  a-=1;b-=1 #0index
  A.append(a);B.append(b)

uf = UnionFind(N)
for i in range(M):
  uf.union(A[i],B[i])

ans = 0
for x in range(N):
  temp = uf.get_size(x)
  ans = max(ans,temp)
print(ans)

Measured memory_bytes: 140432
def main():
    s = list(input())
    k = int(input())
    n = len(s)
    for i in range(n):
        if s[i] != "1":
            ans = s[i]
            break
        if i == k-1:
            ans = s[i]
            break
        if i == n-1:
            ans = s[0]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9116
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
const double EPS = 1e-5;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int main(){
	ll n;
	cin >> n;
	if(n&1){
		cout << 0 << endl;
		return 0;
	}

	ll ans = n / 10;
	ll sum = 50;
	rep(i,100){
		if(sum>n){
			break;
		}
		ans += n / sum;
		sum *= 5;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())

ab = [list(map(int, input().split())) for _ in range(n)]
ab_a = sorted(ab, key=lambda x:int(x[0]))
ab_b = sorted(ab, key=lambda x:int(x[1]))

if n%2 == 1:
    print(ab_b[n//2][1]-ab_a[n//2][0]+1)
else:
    print(int(((ab_b[n//2][1]+ab_b[n//2-1][1])/2.0-(ab_a[n//2][0]+ab_a[n//2-1][0])/2.0)*2+1))

Measured memory_bytes: 123516
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 1000010;
// cnt[i][0]->a_iの0の数
// cnt[i][1]->a_iの1の数
int cnt[60][2];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	rep(i, n) {
		rep(j, 60) {
			// bit演算
			// ビットa[i]にj番目のフラグが立っているかどうか
			cnt[j][(bool)(a[i] & (1LL << j))]++;
		}
	}
	ll ans = 0;
	for (int i = 59; i >= 0; i--) {
		ans = (ans * 2) % MOD;
		ans += cnt[i][0] * cnt[i][1] % MOD;
	}
	cout << ans % MOD << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

bool reversecompare(int a, int b)
{
    return a > b;
}

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

    string S, news;

    cin >> S;

    news = "";
    for (int i = 0; i < S.length(); i++)
        if (i == 3)
            news += "8";
        else
            news += S[i];

    cout << news << endl;


    return 0;
}

Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n;
    cin>>n;
    vll a(n);
    rep(i,n)cin>>a[i];
    ll cnt=0;
    rep(i,n){
        while(a[i]>0){
            if(a[i]%2==0){
                cnt++;
                a[i]=a[i]/2;
            }else{
                break;
            }
        }
    }

    cout<<cnt<<endl;
}

Measured memory_bytes: 3728
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

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

using namespace std;
typedef long long ll;

int main() {

    int A,B;
    cin >> A >> B;
    int out = max(A+B,A-B);
    cout << max(out,A*B) << endl;
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    if ((s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
    ||  (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
    ||  (s[1] == s[2] && s[0] == s[3] && s[1] != s[0]))
    {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

int main(void){
	int a,b;
	cin>>a>>b;
	if(a==b){
		cout<<a+b<<endl;
	}else{
		cout<<max(a,b)*2-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

// 約数列挙
//  (O√n)
std::vector<long long> divisor(const long long n, const bool to_sort) {
    std::vector<long long> ret;
    if (n > 1) for(long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
             ret.emplace_back(i);
             if (i != n / i && i != 1) {
                 ret.emplace_back(n / i);
             }
        }
    }

    if (to_sort) {
        std::sort(std::begin(ret), std::end(ret));
    }

    return ret;
}

// 素数判定
// O(√n)
bool is_prime(long long n) {
    if (n < 2) {
        return false;
    }
    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main(void) {
    LL A, B;
    cin >> A >> B;

    auto a_div = divisor(A, false);
    a_div.EB(A);
    a_div.EB(1);

    set<LL> ab_div;

    FORE(e, a_div) if (B >= e && B % e == 0) {
        ab_div.emplace(e);
    }

    int ans = 0;
    FORE(e, ab_div) if (e == 1 || is_prime(e)) {
        ans++;
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int mod = 1e9 + 7;

int32_t main(){
	cin.tie(0); ios::sync_with_stdio(0);
	
	int h, w;
	cin >> h >> w;
	string grid[h];
	int dp[h+1][w+1];
	memset(dp, 0, sizeof dp);
	for(int i = 0; i < h; i++) 	{
		cin >> grid[i];
	}
	
	dp[0][1] = 1;
	for(int i = 1; i <= h; i++) 	for(int j = 1; j <= w; j++){
		if(grid[i-1][j-1] == '.'){
			dp[i][j] = dp[i-1][j] + dp[i][j-1];
			dp[i][j] %= mod;
		}
	}
	
	cout << dp[h][w] << endl;
}


Measured memory_bytes: 5248
n=int(input())
l=list(map(int,input().split()))

count=0
for i in range(n):
    m=i
    for j in range(i,n):
        if l[j]<l[m]:
            m=j
    l[i],l[m]=l[m],l[i]
    if l[i]!=l[m]:
        count+=1
print(*l)
print(count)


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

public class Main {
	
	//read input
	public static void main(String[] args) {
		int N = 0;
		int W = 0;
		
		Scanner sc = new Scanner(System.in);
		
		 N = sc.nextInt();
		 int[] v = new int[N+1]; //0 to v
		 W = sc.nextInt();
		 int[] w = new int[N+1]; //0 to W
		
		for(int i = 1; i <= N; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}
		
		long[][] dp = new long[N+1][W+1]; //dp[i][j] max value from 1 to i with max weight j
		for (int i = 1; i <= N; ++i) {
			for(int j = 1; j <= W; ++j) {
				dp[i][j] = Math.max(dp[i-1][j], (j-w[i] >= 0) ? dp[i-1][j-w[i]] + v[i] : 0);
			}	
		}
		
	   
	   System.out.println(dp[N][W]);
	}
}

Measured memory_bytes: 127956
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second
#define Mat vector<vector<ll>>
#define Arr vector<ll>

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a;
    cin >> x >> a;
    cout << (x < a ? 0 : 10);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int a[10];
  for(int i=0; i<10; i++) {
    cin >> a[i];
  }
  sort(a, a+10, greater<int>());
  for(int i=0; i<3; i++) {
    cout << a[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 1176
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const T &a) {
    for (auto e : a) cout << e << ' ';
    cout << '\n';
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    long long N, X, M; cin >> N >> X >> M;
 
    bool flag = false;

    set<int> se;
    int x = X;
    for (int i = 0; i < M; i++) {
        se.insert(x);
        x = ((long long)x*x) % M;
        if (se.find(x) != se.end()) {
            flag = true;
            break;
        }
    }

    int xx = x, cnt = 0;
    long long sum = 0;
    for (int i = 0; i < M; i++) {
        cnt++;
        sum += xx;
        xx = ((long long)xx*xx) % M;
        if (xx == x) {
            break;
        }
    }

    long long ans = 0;
    xx = X;
    for (int i = 0; i < M; i++) {
        ans += xx;
        xx = ((long long)xx*xx) % M;
        if (xx == x) {
            N -= i+1;
            break;
        }
    }

    ans += sum * (N/cnt);

    if (flag) {
        int m = N % cnt;
        for (int i = 0; i < m; i++) {
            ans += x;
            x = ((long long)x*x) % M;
        }
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 5940
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-16 08:47:49
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int X, Y, Z;

int sum(int n)
{
  return n * Y + (n + 1) * Z;
}

int main()
{
  cin >> X >> Y >> Z;
  int ans = 0;
  for (auto i = 1; i < 100010; i++)
  {
    if (sum(i) > X)
    {
      ans = i - 1;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  bool ok = true;
  int k = S.size() - 1;
  while (k > 0) {
    if (S.at(k) == 'm') {
      if (k > 3) {
        if (S.at(k - 1) == 'a' && S.at(k - 2) == 'e' && S.at(k - 3) == 'r' && S.at(k - 4) == 'd') {
          k -= 5;
        }
        else {
          ok = false;
          break;
        }
      }
      else {
        ok = false;
        break;
      }
    }
    else if (S.at(k) == 'e') {
      if (k > 3) {
        if (S.at(k - 1) == 's' && S.at(k - 2) == 'a' && S.at(k - 3) == 'r' && S.at(k - 4) == 'e') {
          k -= 5;
        }
        else {
          ok = false;
          break;
        }
      }
      else {
        ok = false;
        break;
      }
    }
    else if (k > 1) {
      if (S.at(k - 2) == 'm') {
        if (k > 5) {
          if (S.at(k - 1) == 'e' && S.at(k - 3) == 'a' && S.at(k) == 'r' && S.at(k - 4) == 'e' && S.at(k - 5) == 'r' && S.at(k - 6) == 'd') {
            k -= 7;
          }
          else {
            ok = false;
            break;
          }
        }
        else {
          ok = false;
          break;
        }
      }
      else if (S.at(k - 2) == 's') {
        if (k > 4) {
          if (S.at(k - 1) == 'e' && S.at(k - 3) == 'a' && S.at(k) == 'r' && S.at(k - 4) == 'r' && S.at(k - 5) == 'e') {
            k -= 6;
          }
          else {
            ok = false;
            break;
          }
        }
        else {
          ok = false;
          break;
        }
      }
      else {
        ok = false;
        break;
      }
    }
    else {
      ok = false;
      break;
    }
  }
  if (ok) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}
 

Measured memory_bytes: 3644
import java.util.*;

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

        int N = sc.nextInt();
        int k = sc.nextInt();
        String S = sc.next();
        char[] str = new char[N];

        for(int i = 0;i < N;i++){
            str[i] = S.charAt(i);
            if(i == k-1){
                if(str[i] == 'A')
                str[i] = 'a';
                if(str[i] == 'B')
                str[i] = 'b';
                if(str[i] == 'C')
                str[i] = 'c';
            }
        }

        for(int i = 0;i < N;i++){
            System.out.print(str[i]);
        }

        

    }
}

Measured memory_bytes: 23764
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	int n,t;
	cin >> n >> t;
	int s=0,f=0;
	for(int i = 0;i < n;i++){
		int ti;
		cin >> ti;
		if(ti < f) s -= f-ti;
		s += t;
		f = ti+t;
	}
	cout << s << endl;
}


Measured memory_bytes: 256