akhauriyash/Code-Regression huggingface dataset:
import qualified Data.ByteString.Char8 as B
import Data.List
import qualified Data.Vector.Unboxed as UV

a#b = abs$a-b

main = do
    [n,k] <- map read.words<$>getLine
    h <- UV.unfoldr(B.readInt.B.dropWhile(<'!'))<$>B.getLine
    print $ f n k h

inf = (maxBound::Int) `div` 2

f n k vh = UV.last $ UV.constructN n m where
    m v0
        | i == 0 = 0
        | otherwise = minimum $ map (\j->((vh UV.! i) # (vh UV.! j)) + v0 UV.! j) [(max 0 (i-k))..i-1]
        where i = UV.length v0


Measured memory_bytes: 5884
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

int t[1005],a[1005];
int main(){
    int n;
    cin>>n;
    rep(i,1,n)
        cin>>t[i]>>a[i];
    ll A=1,B=1;
    ll k;
    rep(i,1,n){
        ll ka=A/t[i],kb=B/a[i];
        ka+=(A%t[i]==0)?0:1;
        kb+=(B%a[i]==0)?0:1;
        k=max(ka,kb);
        A=t[i]*k,B=a[i]*k;
    }
    cout<<A+B<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

const ll MXV=1e5;
vl G[MXV];
vvl d(2,vl(MXV,INF));

void bfs(ll s,ll x){
    queue<ll> q;
    q.push(s);
    d[x][s]=0;
    while(q.size()){
        ll v=q.front();
        q.pop();
        ll k=G[v].size();
        rep(i,k){
            if(d[x][G[v][i]]==INF){
                q.push(G[v][i]);
                d[x][G[v][i]]=d[x][v]+1;
            }
        }
    }
}

int main() {
    ll N;
    cin >> N;
    rep(i,N-1){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    bfs(0,0);
    bfs(N-1,1);
    ll cnt0=0,cnt1=0;
    rep(i,N){
        if(d[0][i]<=d[1][i]){
            cnt0++;
        }
        else{
            cnt1++;
        }
    }
    if(cnt0>cnt1){
        cout << "Fennec" << endl;
        return 0;
    }
    cout << "Snuke" << endl;
}

Measured memory_bytes: 10992
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

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

    int N;cin >> N;
    vector<pair<pair<string,int>,int>> str;
    for(int a = 0;a < N;a++){
        string s;cin >> s;
        int p;cin >> p;
        str.push_back(make_pair(make_pair(s, -p),a));
    }
    sort(str.begin(),str.end());
  //  reverse(str.begin(),str.end());
    for(int a = 0;a < N;a++){
        cout<<str.at(a).second+1<<endl;
    }

}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n, i, a[100];
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }

  for(i = n - 1;i >= 0 ; i--){
    if(i != n - 1){
	  printf(" ");
	}
	printf("%d",a[i]);
  }
  printf("\n");

  return 0;
}

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

int sx, sy, tx, ty;

int main()
{
    cin >> sx >> sy >> tx >> ty;
    tx -= sx;
    ty -= sy;
    string res = "";
    rep(i, tx)
    {
        res.push_back('R');
    }
    rep(i, ty)
    {
        res.push_back('U');
    }
    rep(i, tx)
    {
        res.push_back('L');
    }
    rep(i, ty)
    {
        res.push_back('D');
    }

    res.push_back('L');
    rep(i, ty + 1)
    {
        res.push_back('U');
    }
    rep(i, tx + 1)
    {
        res.push_back('R');
    }
    res.push_back('D');
    res.push_back('R');
    rep(i, ty + 1)
    {
        res.push_back('D');
    }
    rep(i, tx + 1)
    {
        res.push_back('L');
    }
    res.push_back('U');
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S1 = list(input())
S2 = list(input())

if len(S1) == 1:
    print(3)
elif len(S1) == 2:
    print(6)
else:
    if S1[0] != S2[0]:
        t = 2
        i = 2
        a = 6
    else:
        t = 1
        i = 1
        a = 3
    while True:
        if S1[i] != S2[i]:
            if t == 2:
                a *= 3
            else:
                a *= 2
            i += 2
            t = 2
        else:
            if t == 2:
                a *= 1
            else:
                a *= 2
            i += 1
            t = 1
        a %= 1000000007
        if i == len(S1):
            print(a)
            break


Measured memory_bytes: 8884
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vdouble = vector<double>;

int gcd(int a, int b) {
    if (b==0) return a;
   	else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}



int main(){
	ll N,min,sum=1;
	cin>>N;
	vll P(N);
	REP(i,N) cin>>P[i];
	min=P[0];
	
	REP(i,N-1) {
		if(min>P[i+1]){
			sum++;
			min=P[i+1];
		}
	}
	cout<<sum<<endl;
	
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, q = map(int, input().split())
d = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    d[a].append(b)
    d[b].append(a)
d2 = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    d2[p-1] += x

ans = [0] * n

def dfs(cur, pre, point):
    point += d2[cur]
    ans[cur] = point
    for e in d[cur]:
        if e != pre:
            dfs(e, cur, point)
dfs(0, -1, 0)
print(" ".join(map(str, ans)))


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

vector<long long int> num[20][10];
long long int power(long long int i)
{
    if (i == 0)
        return 1;
    long long int ans = power(i / 2);
    ans = ans * ans;
    if (i % 2 == 1)
        ans = ans * 10;
    return ans;
}
int main()
{
    int k;
    cin >> k;
    vector<long long int> ans;
    long long int d = 1, sz = 2;
    for (int i = 1; i <= 9; i++)
    {
        ans.push_back(i);
        num[i][1].push_back(i);
    }
    num[0][1].push_back(0);
    while (ans.size() < k)
    {
        if (d == 1)
        {
            for (int j = -1; j <= 1; j++)
                for (auto it : num[d + j][sz - 1])
                {
                    num[d][sz].push_back(d * power(sz - 1) + it);
                    ans.push_back(d * power(sz - 1) + it);
                }
        }
        else
        {
            for (int j = -1; j <= 1; j++)
                for (auto it : num[d + j][sz - 1])
                {
                    num[d][sz].push_back(d * power(sz - 1) + it);
                    ans.push_back(d * power(sz - 1) + it);
                }
        }
        d++;
        if (d == 10)
        {
            for (auto it : num[0][sz - 1])
                num[0][sz].push_back(it);
            for (auto it : num[1][sz - 1])
                num[0][sz].push_back(it);
            d = 1;
            sz++;
        }
    }
    // for (auto it : ans)
    //     cout << it << " ";
    cout << ans[k - 1];
}

Measured memory_bytes: 2420
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, K = map(int, input().split())
    D = [str(i) for i in input().split()]
    ans = 0

    for m in range(N, 10**6):
        if canbuy(N, D, m):
            ans = m
            break

    print(m)

def canbuy(N, D, m):
    m = str(m)

    for d in D:
        if m.find(str(d)) != -1:
            return False

    return True


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

void max_self(ll& a, ll b){
	a = max(a, b);
}

int main() {
	int N, W;
	scanf("%d%d", &N, &W);
	vector<ll> dp(W+1);
	// dp[i] - the maximum value with exactly the weight of i
	for (int i = 0; i < N; ++i){
		int weight, value;
		scanf("%d%d", &weight, &value);
		for (int weight_already = W - weight; weight_already >= 0; --weight_already){
			max_self(dp[weight_already+weight], dp[weight_already] + value);
		}
	}
	
	ll answer = 0;
	for (int i = 0; i<=W; ++i){
		max_self(answer, dp[i]);
	}
	
	printf("%lld\n", answer);
}


Measured memory_bytes: 4024
N = int(input())

ans = 0
A = []
for _ in range(N):
    a = int(input())
    ans += a // 2
    if a % 2 == 1:
        A.append(1)
    elif a != 0:
        ans -= 1
        A.append(2)
    else:
        A.append(0)

a1 = 0
for a in A:
    if a > 0:
        a1 += a
    else:
        ans += a1 // 2
        a1 = 0

ans += a1 // 2

print(ans)

Measured memory_bytes: 3884
//In The Name Of GOD

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll mod = 998244353;
const ll inf = 2000000000;
const ll infll = (ll)2*1000*1000*1000*1000*1000*1000;
const ll maxn = 8*1001+1;
#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);

int main(){
  IO;
  ll n;
  cin>>n;
  cout<<(n)*(n-1)/2;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		if(b > a) {
			if(b - (a + W) <= 0) {
				System.out.println(0);
			} else {
				System.out.println(b - (a + W));
			}
		} else {
			if(a - (b + W) <= 0) {
				System.out.println(0);
			} else {
				System.out.println(a - (b + W));
			}
		}
		scan.close();

	}

}


Measured memory_bytes: 21844
n,q = map(int,input().split())
ki = [0] * (n+1)
c = [0] * (n+1)
for i in range(n-1):
    a,b = map(int,input().split())
    ki[b] = a
for i in range(q):
    p,x = map(int,input().split())
    c[p] += x

for i in range(2,n+1):
    c[i] += c[ki[i]]
print(*c[1:])

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int stoi(string s) {
  stringstream ss;
  ss << s;
  int sum;
  ss >> sum;
  return sum;
}

int main() {
  int n;
  cin >> n;
  string s[51][4] = {};
  int ind[1001] = {};
  vector<map<string, int> > pak(51);
  map<string, int> mp;
  rep(i, 0, 1001) ind[i] = -1;
  rep(i, 1, n + 1) {
    int a;
    cin >> a >> s[i][0];
    if(s[i][0] == "ADD" || s[i][0] == "SUB") {
      cin >> s[i][1] >> s[i][2] >> s[i][3];
      mp[s[i][1]] = 0, mp[s[i][2]] = 0;
      if(s[i][3][0] > '9') mp[s[i][3]] = 0;
    }else if(s[i][0] == "SET") {
      cin >> s[i][1] >> s[i][2];
      mp[s[i][1]] = 0;
      if(s[i][2][0] > '9') mp[s[i][2]] = 0;
    }else if(s[i][0] == "IF") {
      cin >> s[i][1] >> s[i][2];
      mp[s[i][1]] = 0;
    }
    ind[a] = i;
  }
  for(int i = 1; i < n + 1; i++) {
    int sum;
    int f = false;
    if(s[i][0] == "ADD") {
      if(s[i][3][0] >= '0' && s[i][3][0] <= '9') {
        sum = stoi(s[i][3]);
        f = true;
      }
      if(f && mp[s[i][2]] + sum > 15) break;
      if(!f && mp[s[i][2]] + mp[s[i][3]] > 15) break;
      mp[s[i][1]] = mp[s[i][2]] + (f ? sum : mp[s[i][3]]);
    }else if(s[i][0] == "SUB") {
      if(s[i][3][0] >= '0' && s[i][3][0] <= '9') {
        sum = stoi(s[i][3]);
        f = true;
      }
      if(f && mp[s[i][2]] - sum < 0) break;
      if(!f && mp[s[i][2]] - mp[s[i][3]] < 0) break;
      mp[s[i][1]] = mp[s[i][2]] - (f ? sum : mp[s[i][3]]);
    }else if(s[i][0] == "SET") {
      if(s[i][2][0] >= '0' && s[i][2][0] <= '9') {
        sum = stoi(s[i][2]);
        f = true;
      }
      mp[s[i][1]] = f ? sum : mp[s[i][2]];
    }
    else if(s[i][0] == "IF") {
      sum = stoi(s[i][2]);
      if(mp[s[i][1]]) {
        if(ind[sum] == -1) break;
        i = ind[sum] - 1;
        int f = false;
        for(map<string, int>::iterator itr = mp.begin(); itr != mp.end(); itr++) {
          if(pak[i][itr->first] != itr->second) {
            f = true;
            pak[i][itr->first] = itr->second;
          }
        }
        if(!f) {
          cout << "inf" << endl;
          return 0;
        }
      }
    }else {
      break;
    }
  }

  for(map<string, int>::iterator i = mp.begin(); i != mp.end(); i++) {
    cout << i->first << "=" << i->second << endl;
  }
}

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

class Filler {
	std::vector<std::vector<char>> vec;
	char _fill, _space;
public:
	Filler(int fill_count, char fill, char space) :_fill{ fill }, _space{ space }, vec(21, std::vector<char>(100, space)) {
		for (auto i = 0; i < 10 && fill_count != 0; ++i) {
			for (auto j = 0; j < 50 && fill_count != 0; ++j) {
				vec[i * 2 + 1][j * 2] = fill;
				--fill_count;
			}
		}
	}
	const std::vector<std::vector<char>> &to_vector() const {
		return vec;
	}
};
std::ostream &operator<<(std::ostream &os, const Filler &filler) {
	for (const auto &l : filler.to_vector()) {
		for (const auto &c : l) {
			os << c;
		}
		os << '\n';
	}
	return os;
}
int main() {
	int a, b;
	std::cin >> a >> b;
	Filler black(a - 1, '.', '#'), white(b - 1, '#', '.');
	std::cout << 42 << ' ' << 100 << std::endl;
	std::cout << black << white;
}

Measured memory_bytes: 256
#include<stdio.h>
char s[110],a[110],b,i,t;
main(){
  while(fgets(s,110,stdin)){
    if(s[1]=='\n'&&s[0]==46)break;
    for(t=1,b=0,i=0;s[i]&&t;++i){
      if(s[i]==40||s[i]==91) a[b++]=s[i];
      else if(s[i]==41||s[i]==93) {
        if(!b){t=0;break;}
        if((s[i]==41&&a[b-1]==40)||(s[i]==93&&a[b-1]==91)) --b;
        else t=0;
      }
    }
    puts(((t&&!b)?1:0)?"yes":"no");
  }
  0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

// Union-Find
class UnionFind {
   public:
    vector<int> parent;  // 根の番号
    vector<int> height;  // 木の高さ
    vector<int> count;   // 根に含まれるノードの数

    // 要素数nで初期化
    UnionFind(int n) : parent(n), height(n, 1), count(n, 1) {
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

    // 木の根を求める
    int root(int x) {
        // 根の場合
        if (parent.at(x) == x) return x;
        // 根ではない場合:経路圧縮しながら根を求める
        return parent.at(x) = root(parent.at(x));
    }

    // xとyが同じ集合に属するか否か
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {
        int rx = root(x), ry = root(y);
        // 既に同じ集合にある場合
        if (rx == ry) return;

        // 木の高さが低い方を高い方につなげる
        if (height[rx] < height[ry]) {
            parent.at(rx) = ry;
            // 小さい方の大きさを大きい方に足す
            count.at(ry) += count.at(rx);
        } else {
            parent.at(ry) = rx;
            count.at(rx) += count.at(ry);
            // 同じときはyの親をxにしてxの高さを1増やす
            if (height.at(rx) == height.at(ry)) height.at(rx)++;
        }
    }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;

    vector<vector<int>> fr(n, vector<int>(0));
    vector<vector<int>> bl(n, vector<int>(0));

    UnionFind tree(n);

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        // a, bを[1, n-1]の範囲にする
        a--;
        b--;
        // 友達関係は同じ連結成分
        tree.unite(a, b);
        // i番目の人の友達関係を記録
        fr.at(a).push_back(b);
        fr.at(b).push_back(a);
    }

    rep(i, k) {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        // i番目の人のブロック関係を記録
        bl.at(c).push_back(d);
        bl.at(d).push_back(c);
    }

    vector<int> ans(n, 0);

    rep(i, n) {
        // i番目の人が持つ関係の数
        int count = 0;

        // 友達関係であれば連結
        count += fr.at(i).size();

        // i番目の人のブロック関係を調べる
        for (int bb : bl.at(i)) {
            // ブロック関係と連結していたならプラス1
            if (tree.same(i, bb)) count++;
        }

        // 頂点iの連結サイズ - 同じ連結成分の中の関係の数 - 1
        ans.at(i) = tree.count.at(tree.root(i)) - count - 1;
        cout << ans.at(i) << " ";
    }
    cout << endl;
}


Measured memory_bytes: 13432
#include<bits/stdc++.h>
#define llong __int128
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

map<llong,llong> mp;
llong n,A,B,C,D;

void read128(__int128 &x) {long long y; scanf("%lld",&y); x = y;}

llong absl(llong x) {return x<0?-x:x;}

void updmin(llong &x,llong y) {x = min(x,y);}

void dfs(llong x)
{
	if(mp.count(x)) {return;}
	llong ret = x*D,t;
	t = x/2ll; dfs(x/2ll); updmin(ret,mp[x/2ll]+min((x-x/2ll)*D,A+(x%2ll)*D));
	t = (x+1)/2ll; dfs((x+1)/2ll); updmin(ret,mp[(x+1)/2ll]+min((x-(x+1ll)/2ll)*D,A+(2ll-x%2ll)%2ll*D));
	t = x/3ll; dfs(x/3ll); updmin(ret,mp[x/3ll]+min((x-x/3ll)*D,B+(x%3ll)*D));
	t = (x+2)/3ll; dfs((x+2)/3ll); updmin(ret,mp[(x+2)/3ll]+min((x-(x+2ll)/3ll)*D,B+(3ll-x%3ll)%3ll*D));
	t = x/5ll; dfs(x/5ll); updmin(ret,mp[x/5ll]+min((x-x/5ll)*D,C+(x%5ll)*D));
	t = (x+4)/5ll; dfs((x+4)/5ll); updmin(ret,mp[(x+4)/5ll]+min((x-(x+4ll)/5ll)*D,C+(5ll-x%5ll)%5ll*D));
	mp[x] = ret;
	return;
}

int main()
{
	int T = read(); while(T--)
	{
		read128(n),read128(A),read128(B),read128(C),read128(D);
		mp.clear(); mp[0] = 0ll; mp[1] = D;
		dfs(n);
		printf("%lld\n",(long long)mp[n]);
	}
	return 0;
}

Measured memory_bytes: 4824
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int i, n, result = 0;
	set<int> s;
	cin >> n;
	for (i = 0; i < n; i++){
		int a;
		cin >> a;
		s.insert(a);
		result += a;
	}
	if (result % 10 == 0){
		for (int a : s){
			if (a % 10 != 0){
				result -= a;
				break;
			}
		}
	}
	if (result % 10 == 0) cout << 0 << endl;
	else cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
typedef pair<ll, ll> LP;
 
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1)%MOD;
}
 
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a, ll m) {
    ll x, y;
    extGCD(a, m, x, y);
    return mod(x, m);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return m%MOD*COM(m-1,n)%MOD*modinv(m-n,MOD)%MOD;
}
 

int main()
{
  ll a,b,k;
  cin >> a >> b >> k;
  rep(i,k){if(i%2==0){b+=a/2;
                     a/=2;
                    }
           else{a+=b/2;
                b/=2;
               }
          }
  printf("%lld %lld",a,b);
}

Measured memory_bytes: 256
t_hp, t_ap, a_hp, a_ap = map(int,input().split())

while t_hp > 0 or a_hp > 0:
    a_hp -= t_ap
    if a_hp <= 0:
        print('Yes')
        break

    t_hp -= a_ap
    if t_hp <= 0:
        print('No')
        break

Measured memory_bytes: 9148
import numpy as np
import sys
N, M = [int(x) for x in input().split()]
s = []
c = []
for i in range(M):
  a, b = [int(x) for x in input().split()]
  s.append(a)
  c.append(b)
  
ans = np.full(N+1, -1)
for i in range(M):
  if(ans[s[i]]==-1):
    ans[s[i]] = c[i]
  elif(ans[s[i]]!=c[i]):
    print(-1)
    sys.exit()
if(ans[1]==-1)and(N>1):
  ans[1] = 1
ans = np.where(ans==-1, 0, ans)
 
if(ans[1]==0)and(N!=1):
  print(-1)
  sys.exit()
Ans = 0
for i in range(1, N+1):
  Ans += 10**(N-i)*ans[i]
print(int(Ans))

Measured memory_bytes: 27200
#include<iostream>    
#include<cstdio>  
#include<stdio.h>  
#include<cstring>    
#include<cstdio>    
#include<climits>    
#include<cmath>   
#include<vector>  
#include <bitset>  
#include<algorithm>    
#include <queue>  
#include<map> 
#define inf 9999999; 
using namespace std;

int n,i,ans,x;
bool a[11];
int main()
{
	int sum=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		if(x>=1&&x<=399)
			a[1]=true;
		else if(x>=400&&x<=799)
			a[2]=true;
		else if(x>=800&&x<=1199)
			a[3]=true;
		else if(x>=1200&&x<=1599)
			a[4]=true;
		else if(x>=1600&&x<=1999)
			a[5]=true;
		else if(x>=2000&&x<=2399)
			a[6]=true;
		else if(x>=2400&&x<=2799)
			a[7]=true;
		else if(x>=2800&&x<=3199)
			a[8]=true;
		else
		{
			a[9]=true;
			sum++;
		}
	}
	ans=0;
	for(i=1;i<=8;i++)
	{
		if(a[i]==true)
			ans++;
	}
	if(a[9]==true)
	{
		if(ans==0)
			cout<<1<<" "<<ans+sum<<endl;
		else
			cout<<ans<<" "<<ans+sum<<endl;
	}
	else 
		cout<<ans<<" "<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

void Draw(int h,int w){
	int i,j;
	for(i = 0;i < h;i++){
		for(j = 0;j < w;j++){
			printf("#");
		}
		printf("\n");
	}

	printf("\n");

	return;
}

int main(void){
	int H,W;

	while(1){
		scanf("%d %d", &H, &W);

		if(H == 0 && W == 0){
			break;
		}else if(H <= 300 && W <= 300){
			Draw( H, W);
		}
	}

	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 2 == 1) {
			cout << "first" << endl;
			return 0;
		}
	}
	cout << "second" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 3005
#define MAXT 6005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

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

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,T,dp[MAXN][MAXT],best[MAXN],res;
pii food[MAXN];

int main(){
	scanf("%d %d",&len,&T);
	for(int i=1; i<=len; i++)
		scanf(" %d %d",&food[i].first,&food[i].second);
	sort(food+1,food+len+1);
	for(int i=len; i>=1; i--)
		best[i] = max(best[i+1],food[i].second);
	res = best[1];
	for(int i=1; i<=len; i++){
		for(int t=1; t<=6000; t++){
			if(t < food[i].first) dp[i][t] = dp[i-1][t];
			else dp[i][t] = max(dp[i-1][t],dp[i-1][t-food[i].first]+food[i].second);
			if(t < T) res = max(res,dp[i][t]+best[i+1]);
		}
	}
	printf("%d\n",res);
}

Measured memory_bytes: 70656
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
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 (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
ll n;
int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    cin>>n;
    string ans = "";

    while(n>0) {
        n -= 1;
        ans += (char)((n % 26) + (int)'a');    
        n /= 26;
    }
    for(int i=ans.size()-1;i>=0;i--) cout << ans[i];
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int mod = 998244353;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n, k;
    cin>>n>>k;
    int v[k][2];
    for (int i=0; i<k; i++){
        cin>>v[i][0]>>v[i][1];
    }

    vector<int> dp(n+1);
    vector<int> pre(n+1);
    dp[1] = 1;
    pre[1] = 1;
    for (int i=2; i<=n; i++){
        for (int j=0; j<k; j++){
            int l = v[j][0], r = v[j][1];
            int ll = max(1LL, i-r);
            int rr = max(0LL, i-l);
            dp[i] = (dp[i]+(pre[rr]-pre[ll-1]))%mod;
            dp[i] = (dp[i]+mod)%mod;
        }
        pre[i] = (dp[i]+(i-1>=0?pre[i-1]:0))%mod;
//        cout<<dp[i]<<" ";
    }
//    cout<<endl;

    cout<<dp[n]<<endl;


    return 0;
}





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


int main(){

    int n,x;
    cin >> n >> x;
    while(n!=0 && n!=0) {
        int ans = 0;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++) {
                for(int k=j+1;k<=n;k++) {
                    if(i+j+k == x) ans++;
                }
            }
        }
        cout << ans << endl;
        cin >> n >> x;
    }
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
 
using namespace std;
 
int sum(int n,int a,int b)
{ 
   int s=0;
  while(n!=0)
  {
    s+=n%10;
    n/=10;
  }
  
  if(s>=a && s<=b)
       return 1;
  
  else
     return 0;
}
  
 
 
 
int main()
{
   
   int n,a,b,i,sum1=0;
  scanf("%d%d%d",&n,&a,&b);
  for(i=1;i<=n;++i)
  {    if(sum(i,a,b)==1)
          sum1+=i;
  }
    
  printf("%d",sum1);
  
}

Measured memory_bytes: 256
def solve(N, W, weight_values):
  sum_values = 0
  for w_v in weight_values:
    sum_values += w_v[1]

  # dp[i] maximum total weight with total value exactly i
  dp = [float('inf') for _ in range(sum_values + 1)]
  dp[0] = 0

  for i in range(N):
    i_weight, i_value = weight_values[i]
    for v in range(sum_values, i_value - 1, -1):
      temp = dp[v - i_value] + i_weight
      if temp < dp[v]:
        dp[v] = temp

  ans = 0
  for v in range(sum_values + 1):
    if dp[v] <= W:
      ans = max(ans, v)

  print(ans)

  
def iln(): return list(map(int, input().split()))


N, W = iln()
w_v = []
for i in range(N):
  w_v.append(iln())
  
solve(N, W, w_v)


Measured memory_bytes: 7344
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll a,b;cin>>a>>b;
	if(a>=13){
		cout<<b<<endl;
	}else if(a>=6 && a<=12){
		cout<<b/2<<endl;
	}else{
		cout<<0<<endl;
	}
	











	
}

Measured memory_bytes: 764
w,h,n=map(int,input().split())
L=[list(map(int,input().split())) for i in range(n)]
r=w
l=0
u=h
d=0
for i in range(n):
    if L[i][2]==1:
        l=max(l,L[i][0])
    elif L[i][2]==2:
        r=min(r,L[i][0])
    elif L[i][2]==3:
        d=max(d,L[i][1])
    else:
        u=min(u,L[i][1])
if l<r and d<u:
    print((r-l)*(u-d))
else:
    print(0)

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

int main() {
	string S;
	cin>>S;
	int N=S.size();
	int ans=0;
	rep(i,N){
		if(S[i]=='A'){
			rep(j,N){
				if(S[i+j]=='Z'&&i+j<N)ans=max(ans,j+1);
			}
			break;
		}
	}
	cout<<ans<<endl;
}

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

using ll = long long int;
const int mod = 1e9+7;
const int inf = 1e9+5;


int main(){
	int n, W;
	cin>>n>>W;
	///what will be the state in this case
	vector<pair<int, int>>arr;
	for(int i = 0; i < n; i++){
		int w, v;
		cin>>w>>v;
		arr.emplace_back(w, v);
	}
	//calculating total value
	ll sum_value = 0LL;
	for(int i = 0; i < n; i++){
		sum_value += (arr[i].second);
	}
	//dp[i] = minimum weight with value i
	//just changing the definition of dp
	vector<ll>dp(sum_value+1, inf);
	dp[0] = 0;
	for(int item = 0; item < n; item++){
		for(int already_value = sum_value-arr[item].second; already_value >= 0; --already_value){
			int index = already_value+arr[item].second;
			dp[index] = min(dp[index], dp[already_value]+arr[item].first);
		}
	}
	ll ans = 0LL;
	for(int i = 0; i <= sum_value; i++){
		if(dp[i] <= W){
			ans = max(ans, (ll)i);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


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;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd



int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<char>> a;
  a.resize(h);
  rep(i,h)a[i].resize(w);
  vector<bool> flagh(h);
  vector<bool> flagw(w);
  rep(i,h)flagh[i]=false;
  rep(i,w)flagw[i]=false;
  rep(i,h){
    rep(j,w){
      cin>>a[i][j];
      if(a[i][j]=='#'){
        flagh[i]=true;
        flagw[j]=true;
      }
    }
  }
  rep(i,h){
    int flag=0;
    rep(j,w){
      if(flagh[i]==true&&flagw[j]==true){
        cout<<a[i][j];
        flag=1;
      }
    }
    if(flag==1) cout<<endl;
  }
    
	return 0;
}


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


using namespace std;
using ll = long long;

#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define trav(a, x) for(auto& a: x)

const ll INF = 1e18;

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
  
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(3));
    for (int i = 0; i < n; ++i) 
        for (int j = 0; j < 3; ++j)
            cin >> a[i][j];
    vector<vector<int>> dp(n+1, vector<int>(3, 0));
    for (int i = 0; i < 3; ++i)
        dp[0][i] = 0;
    for (int i = 1; i < n + 1; ++i) {
        for (int j: { 0, 1, 2}) {
            for (int k: {0, 1, 2}) {
                if (j != k)
                    dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i-1][j]);
            }
        }
    }cout << max ({dp[n][0], dp[n][1], dp[n][2]}) << '\n';

    return 0;
}



Measured memory_bytes: 14256
[_x, _k, _d] = list(map(int, input().split(" ")))
_x = abs(_x)

if _x >= _d:
  _y = _x//_d
  if _k < _y:
    _y = _k
  _x = abs(_x - _d * _y)
  _k -= _y
if _k % 2 == 1:
  _x = abs(_x - _d)

print(_x)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=3005,INF=1<<30;

ll dp[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A,B,C,D;cin>>A>>B>>C>>D;
    
    dp[A][B]=1;
    
    for(ll i=A;i<=C;i++){
        for(ll j=B;j<=D;j++){
            dp[i+1][j]+=dp[i][j]*j%mod;
            dp[i+1][j]%=mod;
            
            dp[i][j+1]+=dp[i][j]*i%mod;
            dp[i][j+1]%=mod;
            
            dp[i+1][j+1]+=mod-dp[i][j]*i%mod*j%mod;
            dp[i+1][j+1]%=mod;
        }
    }
    
    cout<<dp[C][D]<<endl;
}



Measured memory_bytes: 74108
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

template <class T>
class SegmentTree{
  ll N;                         //葉の数
  vector<T> data;               //データを格納(要素数2*N-1)
  T def;                        //初期値かつoperationの単位元
  function<T(T,T)> operation;   //区間クエリで使う関数ラムダ式で入れる
  function<T(T,T)> update;      //一点更新で使う関数

  T _query(ll a,ll b,ll k,ll l,ll r){   //区間(a,b)を考え半開区間[l,r)が管轄
      if(b <= l || r <= a) return def;  
      if(a <= l && r <= b){
          return data[k];
      }else{
          T c1 = _query(a,b,k*2+1,l,(l+r)/2);   //左の子
          T c2 = _query(a,b,k*2+2,(l+r)/2,r);   //右の子
          return operation(c1,c2);
      }
  }
  public:
  SegmentTree(size_t _N,T _def,function<T(T,T)> _operaition,function<T(T,T)> _update):def(_def),operation(_operaition),update(_update){
          N = 1;                //N必要サイズにNを調整
          while(N < _N){
              N *= 2;
          }
          data = vector<T>(2*N-1,def);
  }

  void change(ll i,T x){
      i += N-1;
      data[i] = update(data[i],x);
      while(i > 0){
          i = (i-1)/2;
          data[i] = operation(data[i*2+1],data[i*2+2]);
      }
  }

  T query(ll a,ll b){
      return _query(a,b,0,0,N);
  }

  T operator[](ll i){
      return data[i+N-1];
  }
};


int main(){
    ll N;
    string S;
    ll Q;
    cin >> N >> S >> Q;
    auto f = [](ll a,ll b){return a + b;};
    auto g = [](ll a,ll b){return b;};
    vector<SegmentTree<ll>> STs(26,SegmentTree<ll>(N+10,0,f,g));
    rep(i,N){
        ll n = S[i] - 'a';
        STs[n].change(i,1);
    }
    rep(i,Q){
        ll t;
        cin >> t;
        if(t == 1){
            ll x;
            char c;
            cin >> x >> c;
            x--;
            if(S[x] == c) continue;
            STs[S[x] - 'a'].change(x,STs[S[x] - 'a'][x] - 1);
            STs[c - 'a'].change(x,STs[c - 'a'][x] + 1);
            S[x] = c;
        }else{
            ll cnt = 0;
            ll l,r;
            cin >> l >> r;
            l--;
            rep(j,26){
                if(STs[j].query(0,r) - STs[j].query(0,l)) cnt++;
            }
            cout << cnt << endl;
        }
    }
}

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

using namespace std;

typedef long long LL;

int main()
{
	int n;
	scanf("%d", &n);

	long long bits[62][2];

	for(int i = 0; i < 62; i++)
	{
		bits[i][0] = bits[i][1] = 0;
	}

	for(int i = 0; i < n; i++)
	{
		long long v;
		scanf("%lld", &v);
		for(int j = 0; j < 62; j++)
		{
			if(v&1LL)
				bits[j][1]++;
			else
				bits[j][0]++;
			v >>= 1;
		}
	}

	long long resp = 0;
	long long mod = 1000000007;

	for(int i = 0; i < 62; i++)
	{
		long long qt = bits[i][0] * bits[i][1];
		resp += ((qt%mod)*((1LL << i)%mod))%mod;
	}

	printf("%lld\n",resp%mod);

	return 0;
}


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

#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout)
ll mod = 1000000007;

int main() {
	ioso;
	#ifndef ONLINE_JUDGE
	ffe;
	#endif

	ll a, b, n;
	cin >> a >> b >> n;

	ll ff = min(b-1,n);

	cout << (ll)floor((ff*a)/b) << endl;	
}

Measured memory_bytes: 3648
r,c = map(int,input().split())
a = []
for i in range(r):
    a.append(list(map(int, input().split())))
    a[i]+=[sum(a[i])]
    print(*a[i])
a=list(zip(*a[::-1]))
for i in range(c):
  print(sum(a[i]),end=' ')
print(sum(a[c]))


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

#define int long long

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t, n[4] = {0};
	cin >> t;
	string a;
	while(t--){
		cin >> a;
		if (a == "AC")
			n[0]++;
		else if(a == "TLE")
			n[1]++;
		else if(a == "WA")
			n[2]++;
		else
			n[3]++;
	}
	cout << "AC x " << n[0] << "\n";
	cout << "WA x " << n[2] << "\n";
	cout << "TLE x " << n[1] << "\n";
	cout << "RE x " << n[3] << "\n";
	return 0;
}

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

int main() {
    int N, M;
    while (cin >> N >> M) {
        vector<vector<int>> links;
        for (int m = 0; m < M; ++m) {
            int k; cin >> k;
            vector<int> switches;
            for (int n = 0; n < k; ++n) {
                int s; cin >> s;
                switches.push_back(s-1);
            }
            links.push_back(switches);
        }
        vector<int> parities;
        for (int m = 0; m < M; ++m) {
            int p; cin >> p;
            parities.push_back(p);
        }

        int count = 0;
        for (int state = 0; state < (1 << N); ++state) {
            bool ok = true;
            for (int m = 0; m < M; ++m) {
                int p = 0;
                for (auto s : links[m]) {
                    p += (state >> s) % 2;
                }
                if (p % 2 != parities[m]) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                ++count;
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

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

  long long int MOD = 1000000007;
  vector<long long int> count(26, 1);
  for (int i = 0; i < N; i++) {
    count[s[i] - 'a']++;
  }

  long long int ans = 1;
  for (int i = 0; i < 26; i++) {
    ans = (ans * count[i]) % MOD;
  }

  ans--;

  cout << ans << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);  
  
  for (int i=0; i<N; i++){
    cin >> d[i];
  }
  
    sort (d.begin(), d.end());
    int c=1;
  
    for (int i=0; i<(N-1); i++){
       if (d[i+1]>d[i]){
         c++;
       }
     
    }
  
 
 cout << c << endl;     
       
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int n;
int main() {
	int i;
	scanf("%d", &n);
	for(i=0; i*7<=n; i++) {
		if((n-i*7) % 4 == 0) {puts("Yes"); return 0;}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
typedef long long ll;
using namespace std;

int main() {
    ll n, m;
    cin >> n >> m;
    cout << abs((n - 2) * (m - 2)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>

#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)

using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
int A[555555];
map< int, int > setValues;
void clearFrom(int pos) {
	auto it = setValues.lower_bound(pos);
	while(it != setValues.end()) {
		auto itn = it;
		itn++;
		setValues.erase(it);
		it = itn;
	}
}

bool canDo(int chars) {
	setValues.clear();
	for(int i = 1; i < n; i++) {
		if(A[i] > A[i-1])
			continue;
		if(A[i] < A[i-1]) {
			clearFrom(A[i]);
		}
		int raise = A[i]-1;
		bool needNew = false;
		while(raise >= 0) {
			if(setValues[raise] < chars-1) {
				setValues[raise]++;
				clearFrom(raise+1);
				break;
			} else {
				if(raise == 0) {
					needNew = true;
					break;
				} else {
					raise--;
				}
			}
		}
		if(needNew) {
			return false;
		}
	}
	return true;
}

int main() {
	scanf("%d", &n);
	REP(i, n) scanf("%d", A+i);
	bool oneEnough = true;
	REP(i, n) if(i && A[i] <= A[i-1]) oneEnough = false;
	if(oneEnough) {
		printf("1\n");
		return 0;
	}
	int chars = 2;
	int lft = 2, rgt = n+1;
	while(lft+1 < rgt) {
		int mid = (lft+rgt)/2;
		if(canDo(mid)) {
			rgt = mid;
		} else {
			lft = mid;
		}
	}
	printf("%d\n", canDo(lft) ? lft : rgt);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, t[100], m, p[100], x[100], sum = 0;
	cin >> n;
	REP(i, n){
		cin >> t[i];
		sum += t[i];
	}
	cin >> m;
	REP(i, m) cin >> p[i] >> x[i];

	REP(i, m){
		int ssum = sum;
		if(t[p[i]-1] < x[i]) ssum += x[i] - t[p[i]-1];
		else ssum -= t[p[i]-1] - x[i];
		cout << ssum << endl;
	}
	rtn 0;
}

Measured memory_bytes: 256