akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <string>

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  int r, c;
  cin >> r >> c;
  vector <char> red(c);
  vector <vector <char> > mat(r,red);
  for (int i = 0; i < r; i++)
   for (int j = 0; j < c; j++)
    cin >> mat[i][j];
  vector <int> red1(c,1<<29);
  vector <vector <int> > sp(r,red1);
  sp[0][0] = 0;
  int beg = 0;
  if (mat[0][0] == '#')
   beg++;
  queue <pair<pair<int,int>,int> > bfs;
  bfs.push(make_pair(make_pair(0,0),beg));
  while (!bfs.empty()){
    int x = bfs.front().first.first, y = bfs.front().first.second, co = bfs.front().second;
    bfs.pop();
    sp[x][y] = co;
    if (y < c - 1){
     if (mat[x][y] == '.' &&  mat[x][y+1] == '#'){
      if (sp[x][y+1] > co + 1)
       sp[x][y+1] = co + 1, bfs.push(make_pair(make_pair(x,y+1),co+1));
      } else {
       if (co < sp[x][y+1])
        sp[x][y+1] = co, bfs.push(make_pair(make_pair(x,y+1),co));
      }
    }
    if (x < r - 1){
     if (mat[x][y] == '.' &&  mat[x+1][y] == '#'){
      if (sp[x+1][y] > co + 1)
       sp[x+1][y] = co + 1, bfs.push(make_pair(make_pair(x+1,y),co+1));
      } else {
       if (co < sp[x+1][y])
        sp[x+1][y] = co, bfs.push(make_pair(make_pair(x+1,y),co));
      }
    }
  }
  cout << sp[r-1][c-1]; 
}

Measured memory_bytes: 384
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     loopR(n,i,a)    for(int i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=2e6+10,oo=0x3f3f3f3f,MOD=998244353;
const double PI = acos(-1);

void solve(){
    int n;
    cin>>n;
    int res=0;
    loop(n+1,i,1){
        int x;
        cin>>x;
        res+=(i%2&&x%2);
    }
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();
}

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

using namespace std;


int main(void){

    int n;
    cin >> n;
    
    list<int> a;
    for(int i=0; i<n; i++) {
        int temp;
        cin >> temp;
        if(i%2!=0) {
            a.push_front(temp);
        }
        else {
            a.push_back(temp);
        }
    }
    if(n%2!=0) {
        reverse(a.begin(), a.end());
    }

    for(auto itr=a.begin(); itr!=a.end(); itr++) {
        cout << *itr << " ";
        //if(++itr == a.end()) cout << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
//"谷は0にすることが可能"
int main()
{
    bool res = false;
    std::string s;
    std::cin >> s;
    int n = s.size();
    //飛ばす部分の始点 / 終点
    for(int i = 0; i < n; i++){
        for(int j = i; j <= n; j++){
            std::string x;
            for(int k = 0; k < i; k++)x.push_back(s[k]);
            for(int k = j; k < n; k++)x.push_back(s[k]);
            if("keyence" == x)res = true;
        }
    }
    std::cout << (res ? "YES" : "NO") << std::endl;
}
// 0<3>2>1>0<1<2>0<1<2<3<4<5>2>1>0<

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

int main(){
	// stack<long> S1, ans;
	// stack<pair<long, long> > S2;
	// char ch;
	// long sum = 0;
	// for (long i = 0; cin >> ch; i++){
	// 	if (ch == '\\') S1.push(i);
	// 	else if (ch == '/' && S1.size() > 0){
	// 		long j = S1.top(); S1.pop();
	// 		sum += i - j;
	// 		long a = i - j;
	// 		while (S2.size() > 0 && S2.top().first > j){
	// 			a += S2.top().second; S2.pop();
	// 		}
	// 		S2.push(make_pair(j, a));
	// 	}
	// }
	// cout << sum << endl << S2.size();
	// while (S2.size() > 0){ans.push(S2.top().second); S2.pop();}
	// while (ans.size() > 0){cout << " " << ans.top(); ans.pop();}
	// cout << endl;
	vector<long> S1, ans;
	vector<pair<long, long> > S2;
	char ch;
	long sum = 0;
	for (long i = 0; cin >> ch; i++){
		if (ch == '\\') S1.insert(S1.begin(), i);
		else if (ch == '/' && S1.size() > 0){
			long a = i - S1[0];
			sum += a;
			while (S2.size() > 0 && S2[0].first > S1[0]){
				a += S2[0].second; S2.erase(S2.begin());
			}
			S2.insert(S2.begin(), make_pair(S1[0], a));
			S1.erase(S1.begin());
		}
	}
	cout << sum << endl << S2.size();
	while (S2.size() > 0){cout << " " << S2[S2.size()-1].second; S2.erase(S2.end());}
	cout << endl;
	return 0;
}

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

void factorize(map<long long, int> &A, long long n) {
    for(long long i=2; i * i <= n; ++i) {
        while(n % i == 0) {
            ++A[i];
            n /= i;
        }
    }
    if(n != 1) A[n] += 1;
}

long long num(map<long long, int> A, int n) {
    long long ret = 0;
    for(auto itr = A.begin(); itr != A.end(); ++itr) {
        if(itr->second >= n - 1) ++ret;
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    map<long long, int> A;
    for(int i=2; i<=N; ++i) factorize(A, i);

    long long res = 0;
    res += num(A, 75);
    res += num(A, 25) * (num(A, 3) - 1);
    res += num(A, 15) * (num(A, 5) - 1);
    res += num(A, 5) * (num(A, 5) - 1) * (num(A, 3) - 2) / 2;
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define NL '\n'
#define xx first
#define yy second
#define eps 1e-9
#define ins insert
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(x) x.size()
#define pi 2.0*acos(0.0)
#define sqr(x) ((x) * 1ll * (x))
#define all(x) (x).begin(),(x).end()
#define FIN freopen("input.txt", "r", stdin);
#define FOUT freopen("output.txt", "w", stdout);
#define rep(ii,aa,bb) for(int (ii)=int(aa);(ii)<(int)(bb);++(ii))
#define per(ii,aa,bb) for(int (ii)=int(aa)-1;(ii)>=(int)(bb);--(ii))
#define _fastIO() ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0) 

int fun(int a, int b, int c, int moves){
  if(a>b) swap(a,b); if(b>c) swap(b,c); if(a>b) swap(a,b);
  if(a==b && a==c) return moves;
  if(b==c){
    if(abs(a-b)%2==0) return abs(a-b)/2 + moves; 
    else return abs(a-b)/2 + 2 + moves;
  }
  return fun(a+1, b+1, c, moves+1);
} 



int main(){
  _fastIO();
  int a, b, c;
  cin >> a >> b >> c;
  cout << fun(a, b, c, 0) << NL;
  return 0;
} 

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


void solve(string a, string b){
  string first = "";
  string second = "";
  for(long long i = 0; i < (b[0] - '0'); i++){
    first += a;
  }

  for(long long i = 0; i < (a[0] - '0'); i++){
    second += b;
  }

  cout << ((first < second) ? first : second) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string a, b;
    cin >> a >> b;
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
const double PI = 3.14159265358979323846;
int main() {
    string s, t;
    cin >> s >> t;
    string k = t.substr(0, s.size());
    if(k == s) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int dp[3030][3030];
int pre[3030][3030];

int main() {
    string s, t;
    cin >> s >> t;
    
    rep(i,s.size())rep(j,t.size()) {
        if (dp[i+1][j+1]<dp[i+1][j]) {
            dp[i+1][j+1] = dp[i+1][j];
            pre[i+1][j+1] = 2;
        }
        if (dp[i+1][j+1]<dp[i][j+1]) {
            dp[i+1][j+1] = dp[i][j+1];
            pre[i+1][j+1] = 3;
        }
        
        if (s[i]==t[j]) {
            if (dp[i+1][j+1]<dp[i][j]+1) {
                dp[i+1][j+1] = dp[i][j] + 1;
                pre[i+1][j+1] = 1;
            }
        }
    }
    
    string ans = "";

    int si = s.size();
    int ti = t.size();

    while (si>0 && ti>0) {
        if (pre[si][ti]==1) {
            --si; --ti;
            ans += s[si];
        }
        else if (pre[si][ti]==2) --ti;
        else --si;
    }
    //rep(i,s.size()+1) {
    //    rep(j,t.size()+1) {
    //        cout << dp[i][j] << ' ';
    //    }
    //    cout << endl;
    //}
    //cout << endl;
    //rep(i,s.size()+1) {
    //    rep(j,t.size()+1) {
    //        cout << pre[i][j] << ' ';
    //    }
    //    cout << endl;
    //}
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 71936
import itertools
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
ans = float('inf')
for bit in itertools.product(range(4), repeat=N):
    ABC = [0]*3
    cost = 0
    for i, abc in enumerate(bit):
        if abc == 3:
            continue
        ABC[abc] += L[i]
        if ABC[abc] != L[i]:
            cost += 10
    if 0 in ABC:
        continue
    cost += abs(ABC[0] - A) + abs(ABC[1] - B) + abs(ABC[2] - C)
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 74376
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

const ll MOD = 1e9 + 7;

ll fact(int n) {
    ll ans = 1;
    REP(i, n) {
        ans *= (i + 1);
        ans %= MOD;
    }
    return ans;
}

ll solve(int N, string S) {
    ll n = 0;
    ll ans = 1;
    ll local_ans = 0;
    for (auto ch :S) {
        if (n == 0) {
            if (ch == 'W')
                return 0;
            else {
                n += 1;
                local_ans = 1;
            }
        }
        else if (n % 2 == 1){
            if (ch == 'W') {
                n += 1;
            } else {
                local_ans *= n;
                local_ans %= MOD;
                n -= 1;
            }
        } else {
            if (ch == 'W') {
                local_ans *= n;
                local_ans %= MOD;
                n -= 1;
            } else {
                n += 1;
            }
        }
        if (n == 0) {
            ans *= local_ans;
            ans %= MOD;
        }
    }
    
    if (n != 0) {
        return 0;
    }

    return (ans * fact(N)) % MOD;
}

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    string S;
    
    cin >> N;
    cin >> S;

    cout << solve(N, S) << endl;

    return 0;
}


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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ll a, b;
	cin >> a >> b;
	if(a * 500 >= b)
		cout << "Yes\n";
	else
		cout << "No\n";




	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 764
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()

d = defaultdict(int)
for i in range(n):
    d[input()] += 1

m = max(d.values())
for s in sorted(filter(lambda x: d[x] == m,d)):
    print(s)

Measured memory_bytes: 56508
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b,re1=0,k,w,count=0,count2=0;
    string s;
    vint h;
    cin>>n>>k;
    rep(i,n){
        cin>>a;
        if(a>=k){
            count++;
        }
    }
    cout<<count<<'\n';
    return(0);
}

Measured memory_bytes: 256
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, m): (usize, usize) = parse!(it, 2);
    let mut e = vec![];
    let mut d = vec![vec![std::usize::MAX / 10; n]; n];
    for _ in 0..m {
        let (a, b, c): (usize, usize, usize) = parse!(it, 3);
        e.push((a - 1, b - 1, c));
        d[a - 1][b - 1] = c;
        d[b - 1][a - 1] = c;
    }
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                d[i][j] = std::cmp::min(d[i][k] + d[k][j], d[i][j]);
            }
        }
    }
    let mut ret = 0;
    for (a, b, c) in e {
        if d[a][b] < c {
            ret += 1;
        }
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.00000000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 550555;
const int L = 21;
const int M = 2155;

int cnt = 0, n, m, q;
int A[15];
int a[N], b[N], c[N], d[N];
ll ans = 0;
void rec(int idx){
    if (idx == n+1){
        ll z = 0;
        for (int i = 1; i <= q; i++){
            if (A[b[i]] - A[a[i]] == c[i]) z += d[i];
        }
        ans = max(ans, z);
        return;
    }
    for (int i = A[idx-1]; i <= m; i++){
        A[idx] = i;
        rec(idx+1);
    }
}

void solve() {
    cin >> n >> m >> q;
    for (int i = 1; i <= q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    A[0] = 1;
    rec(1);
    cout << ans;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 

bool compare(pair<pair<int,int>, int> a, pair<pair<int,int>, int> b) {
	return a.first.second < b.first.second;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		int n,q;
		cin>>n>>q;
		int arr[n+1];
		f(i,n) cin>>arr[i];
		int bit[n+1]; 
		vector<pair<pair<int,int>, int> > queries;
		for(int i=0; i<q; i++) {
			int l,r;
			cin>>l>>r;
			queries.pb({{l-1,r-1},i});
		}
		sort(queries.begin(), queries.end(), compare);
	    memset(bit, 0, sizeof(bit));
	    int last_visit[n+1]; 
	    memset(last_visit, -1, sizeof(last_visit)); 
	    int ans[q]; 
	    int query_counter = 0; 
	    f(i,n) { 

	        if (last_visit[arr[i]] !=-1) 
	            update (last_visit[arr[i]] + 1, -1, bit, n);  
	        last_visit[arr[i]] = i; 
	        update(i + 1, 1, bit, n); 
	        while (query_counter < q && queries[query_counter].first.second == i) 
	        { 
	            ans[queries[query_counter].second] = 
	                     query(queries[query_counter].first.second + 1, bit, n)- 
	                     query(queries[query_counter].first.first, bit, n); 
	            query_counter++; 
	        } 
	    } 
	    f(i,q) cout << ans[i] << "\n";
	}
 	return 0;
}


Measured memory_bytes: 17624
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<pll> outputs;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll max = a[n - 1];
  ll min = a[0];
  for (int i = 1; i < n - 1; i++) {
    if (a[i] > 0) {
      outputs.push_back(pll(min, a[i]));
      min -= a[i];
    } else {
      outputs.push_back(pll(max, a[i]));
      max -= a[i];
    }
  }
  outputs.push_back(pll(max, min));
  cout << max - min << endl;
  for (int i = 0; i < outputs.size(); i++) {
    cout << outputs[i].first << " " << outputs[i].second << endl;
  }
}


Measured memory_bytes: 4336
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(_itr, array) { cin >> *(_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,m,c;
	int ans=0;
	int cnt = 0;
	cin >>n>>m>>c;
	Vi b(m);
	VVi a(n, Vi(m));
	input(b);
	rep(i, n) { input(a[i]); }
	rep(i, n) {
		cnt =0 ;
		rep(j, m) { cnt += a[i][j] * b[j]; }
		ans += (cnt > -c);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3624
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();

			System.out.println(Math.max(numA + numB, Math.max(numA - numB, numA * numB)));

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		String numS = "";

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numS = scanner.next();
			String numWk = "";
			int res = 0;
			//			for (int num = 0; num < 2; num++) {
			//
			//				if (num == 0) {
			//					numWk = numS;
			//				} else {
			//					numWk = new StringBuilder(numS).reverse().toString();
			//				}
			numWk = numS;
			//			for (int i = numN / 2; i >= 0; i--) {
			for (int i = numN - 1; i >= 0; i--) {
				char[] val1 = numWk.substring(0, i).toCharArray();
				char[] val2 = numWk.substring(i, numN).toCharArray();

				Set<Character> wkSet1 = new HashSet<Character>();
				for (int j = 0; j < val1.length; j++) {
					wkSet1.add(val1[j]);
				}

				Set<Character> wkSet2 = new HashSet<Character>();
				for (int j = 0; j < val2.length; j++) {
					wkSet2.add(val2[j]);
				}

				Set<Character> chkSet = null;
				Set<Character> resSet = null;
				if (wkSet1.size() > wkSet2.size()) {
					chkSet = wkSet1;
					resSet = wkSet2;
				} else {
					chkSet = wkSet2;
					resSet = wkSet1;
				}

				int cnt = 0;
				for (Character character : chkSet) {
					if (resSet.contains(character)) {
						cnt++;
					}
				}

				res = Math.max(res, cnt);
			}
			//			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

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

    set<string> S ;
    string s ;
    rep(i,n)
    {
        cin >> s ;
        S.insert(s) ;
    }

    cout << S.size() << endl ;
}

Measured memory_bytes: 19224
#pragma region
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define rep(i, a, n) for (long long i = a; i <= n; ++i)
#define per(i, a, n) for (long long i = n; i >= a; --i)
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
template <typename T>
void read(T &x) {
    x = 0;
    char ch = getchar();
    ll f = 1;
    while (!isdigit(ch)) {
        if (ch == '-') f *= -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    x *= f;
}
using namespace std;
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

#pragma endregion
const int maxn = 1e3 + 5;
const ll mod = 1e9 + 7;
ll n, m, dp[maxn][maxn];
char maze[maxn][maxn];
int main() {
    IO;
    cin >> n >> m;
    rep(i, 1, n) cin >> (maze[i] + 1);
    dp[1][1] = 1;
    rep(i, 1, n) rep(j, 1, m) {
        if (maze[i][j] == '#') continue;
        if (j - 1 >= 1 && maze[i][j - 1] - '#') dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
        if (i - 1 >= 1 && maze[i - 1][j] - '#') dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
    }
    cout << dp[n][m] << endl;
}

Measured memory_bytes: 12376
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>
#include <math.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

long myPow(long x, long n, long m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;

    vector <ll> c(N);

    REP(i, N)
    {
        cin >> c[i];
    }
    sort(c.rbegin(), c.rend());

    ll tmp3 = myPow(2, N * 2 - 2, MOD);
    ll tmp2 = tmp3 * 2 % MOD;
    ll res = 0;

    REP(i,N)
    {
        ll tmp;
        tmp = tmp2 * c[i] % MOD;

        res += tmp;
        res %= MOD;

        tmp2 += tmp3;
        tmp2 %= MOD;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template <int mod> struct ModInt {
    int val;
    ModInt() : val(0) {}
    ModInt(long long x) : val(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {
        if ((val += p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((val += mod - p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        val = (int)(1LL * val * p.val % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-val); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return val == p.val; }
    bool operator!=(const ModInt &p) const { return val != p.val; }
    ModInt inverse() const {
        int a = val, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n) const {
        ModInt ret(1), mul(val);
        while (n > 0) {
            if (n & 1)
                ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.val; }
    friend istream &operator>>(istream &is, ModInt &a) {
        long long t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
    static int get_mod() { return mod; }
};
const int MOD = 1000000007; // if inv is needed, this shold be prime.
using modint = ModInt<MOD>;

vector<modint> fact, fact_inv, inv;
// init_nCk pre calculates fact[], fact_inv[], inv[] for combination
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = modint(1);
    fact_inv[0] = fact_inv[1] = modint(1);
    inv[1] = modint(1);
    for (int i = 2; i < SIZE; i++) {
        fact[i] = fact[i - 1] * modint(i);
        inv[i] = modint(0) - inv[MOD % i] * modint(MOD / i);
        fact_inv[i] = fact_inv[i - 1] * inv[i];
    }
}
//#define NDEBUG
modint nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * fact_inv[k] * fact_inv[n - k];
}

using ll = long long;
int main() {
    init_nCk(1000000);
    ll X, Y;
    cin >> X >> Y;

    if ((X + Y) % 3 == 0) {
        // nCk
        ll n = (X + Y) / 3;
        if (X >= n && Y >= n) {
            ll k = X - n;
            cout << nCk(n, k) << endl;
            return 0;
        }
    }
    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N,R;
	scanf("%d %d",&N,&R);

	if(N >= 10){

		printf("%d\n",R);

	}else{

		printf("%d\n",R+100*(10-N));
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,z,w;
    cin>>n>>z>>w;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i];

    cout << ((n>1)?(max(abs(a[n-1]-w),abs(a[n-1]-a[n-2]))):abs(a[0]-w)) <<endl;
    return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<long long>A(N);
  for(int i=0;i<N;i++) cin>>A[i];
  vector<vector<int>>data(N,vector<int>(60));
  for(int i=0;i<N;i++){
    for(int j=0;j<60;j++){
      if(A[i]%2==1) data[i][j]=1;
      A[i]/=2;
    }
  }
  vector<long long>data1(60);
  for(int i=0;i<60;i++){
    for(int j=0;j<N;j++){
      if(data[j][i]==1) data1[i]++;
    }
  }
  long long ans=0;
  for(int i=0;i<60;i++){
    long long x=data1[i]%1000000007;
    long long y=(N-data1[i])%1000000007;
    long long z=pow(2,i);
    z%=1000000007;
    long long p=(x*y)%1000000007;
    ans+=(p*z)%1000000007;
    ans%=1000000007;
  }
  cout<<ans<<endl;
}

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


int main() {
  int n,k;
  cin>>n>>k;
  vector<int>dx;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    dx.push_back(a);
  }
  int sum=0;
  int now=dx.at(0);
  for(int i=0;i<k;i++){
    sum+=abs(now-dx.at(i));
    now=dx.at(i);
  }
  int ans=1<<30;
  for(int i=0;i+k-1<n;i++){
    int L=abs(dx.at(i));
    int R=abs(dx.at(i+k-1));
    int Lro=L+sum;
    int Rro=R+sum;
    ans = min({ans,Lro,Rro}); 
    if(i+k<n){
      sum = sum-abs(dx.at(i)-dx.at(i+1))+abs(dx.at(i+k)-dx.at(i+k-1));    
    }

  }
  cout <<ans;
    
    
}


Measured memory_bytes: 892
class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)


N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
max_A = max(A)

st = SegmentTree([N] * (max_A + 1), min, N)
dp = [0] * (N + 1)
for i, a in enumerate(reversed(A)):
    j = N - 1 - i
    p1 = st.get(a, min(max_A + 1, a + K + 1))
    dp[j] = max(dp[p1] + 1, dp[j])
    p2 = st.get(max(0, a - K), a)
    dp[j] = max(dp[p2] + 1, dp[j])
    st.update(a, j)

print(max(dp))


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

map<int, int> m1, m2;

int main(){
  string s;
  while(getline(cin, s)){
    string n;
    if(s=="")break;
    stringstream ss(s);
    getline(ss, n, ',');
    istringstream is(n);
    int key;
    is>>key;
    if(m1.find(key)!=m1.end())m1[key]++;
    else m1.insert(map<int, int>::value_type(key, 1));
  }
  while(getline(cin, s)){
    string n;
    stringstream ss(s);
    getline(ss, n, ',');
    istringstream is(n);
    int key;
    is>>key;
    if(m2.find(key)!=m2.end())m2[key]++;
    else m2.insert(map<int, int>::value_type(key, 1));
  }
  for(map<int, int>::iterator it=m1.begin(); it!=m1.end(); it++){
    if(m2.find(it->first)!=m2.end()){
      cout<<it->first<<' '<<m1[it->first]+m2[it->first]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1224
#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;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

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

	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int st = 60 * h1 + m1, en = 60 * h2 + m2;
	cout << (en - k - st);

	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	int n,x,l,cnt=1,m=0;
  cin>>n>>x;
  rep(i,n){
    cin >> l;
    m += l;
    if (m<=x){
    cnt += 1;
    }
  }
  printf("%d",cnt);
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a;
  for(int i = 0;i < n;i++){
    int b;
    cin >> b;
    a.push_back(b);
  }
  sort(a.begin(),a.end());
  int alice = 0;
  int bob = 0;
  int flag = 0;
  for(int i = n-1;i >= 0;i--){
    if(flag == 0){
      alice+= a[i];
      flag = 1;
    }
    else{
      bob+=a[i];
      flag = 0;
    }
  }
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
// In the Name of God
#include<bits/stdc++.h>

#define test(t) int t; cin>>t; while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long int
#define em emplace_back
#define pb push_back
#define INF 1e7+5
#define MOD int(1e9+7)
#define print printf
#define in scanf
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

template<class type>
void displaySingle(type &arr)
{
	for(auto i:arr)
		cout<<i<<" ";
	cout<<endl;
}

template<class type>
void displayDouble(type &arr)
{
	for(auto &&i : arr) 
	{
		for(auto &&j : i) 
			cout << j << " ";
		cout << std::endl;
	}
}

int main()
{
	fast
	ll n,w;
	cin>>n>>w;
	vector <ll> costs(n),weights(n);
	REP(i,n)
		cin>>weights[i]>>costs[i];
	vector <vector <ll>> dp(n+1,vector <ll>(w+1));
	//displaySingle(weights);
	//displaySingle(costs);
	FOR(i,1,n+1)
	{
		FOR(j,1,w+1)
		{
			if(j-weights[i-1] >= 0)
			{
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-weights[i-1]]+costs[i-1]);
			}
			else
			{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	//displayDouble(dp);
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 83172
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

int fac[1000005];
int faci[1000005];

int nCr(int n,int r){
    return fac[n]*faci[r]%MOD*faci[n-r]%MOD;
}

signed main(){
    FASTER;
    fac[0]=1;
    faci[0]=1;
    for(int i=1;i<=1e6;i++){
        fac[i]=fac[i-1]*i%MOD;
        faci[i]=poww(fac[i],MOD-2);
    }
    
    int x,y;cin>>x>>y;
    if((2*y-x)%3!=0 || (2*x-y)%3!=0 || 2*y<x || 2*x<y){
        cout<<0;
    }else{
        int p=(2*y-x)/3;
        int q=(2*x-y)/3;
        cout<<nCr(p+q,q);
    }
}

Measured memory_bytes: 19256
import itertools
n,m,x = map(int,input().split(" "))
books = []
for i in range(n):
    books.append(list(map(int,input().split(" "))))
min_cost = 12*10**5+1
book_list = list(itertools.product(range(2),repeat = n))
for book in book_list:
    skills = [x for i in range(m)]
    cost = 0
    for j in range(len(book)):
        if book[j] == 1:
            cost += books[j][0]
            for k in range(m):
                skills[k] -= books[j][k+1]
    flag = True
    for j in range(m):
        if skills[j] > 0:
            flag = False
    if flag and cost != 0:
        min_cost = min(min_cost,cost)
if min_cost == 12*10**5+1:
    print(-1)
else:
    print(min_cost)


Measured memory_bytes: 9620
import Data.List
import Control.Monad.State

main = do
    [n, m] <- map read . words <$> getLine
    xss <- map (map read . tail . words) <$> sequence (replicate n getLine)
    print . fst $ runState (acnt n m xss) (replicate m 0)

fresh :: Int -> Int -> [Int] -> State [Int] Int
fresh n m xs = state $ \s ->
    let xs' = map (\x -> if x `elem` xs then 1 else 0) [1..m]
        s' = zipWith (+) xs' s
        in (length . filter (==n) $ s', s')

acnt :: Int -> Int -> [[Int]] -> State [Int] Int
acnt n m [] = fresh n m (replicate m 0)
acnt n m [xs] = fresh n m xs
acnt n m (xs:xss) = do
    acnt n m [xs]
    acnt n m xss
    s <- get
    return (length . filter (==n) $ s)


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

int main() {
    string N;
    int total = 0;
    cin >> N;
    for (int i = 0; i < N.size(); i++) {
        total += N[i] - '0';
    }
    if (total % 9 == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3724
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <functional>

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    int n, k, x, y; cin >> n >> k >> x >> y;
    int ans = min<int>(n,k)*x;
    int rem = (n >= k ? n - k : 0);
    ans += rem * y;
    cout << ans << endl;
}

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

using namespace std;


int main()
{
  ios::sync_with_stdio(0);

  char s[106];

  char a[100];
  char b[100];

  int n;
  cin>>n;

   cin>>s;


  if(n%2!=0)
    cout<<"No"<<endl;

   else
   { int i,j;
      for( i=0,j=0;i<n/2;i++,j++)
      {
          a[i]=s[j];

      }

       a[i]='\0';

      for( i=0;s[j]!='\0';i++,j++)
      {
          b[i]=s[j];

      }
      b[i]='\0';

      if(strcmp(a,b))
      {

        cout<<"No"<<endl;
      }

      else
      cout<<"Yes"<<endl;

   }





return 0;   }



Measured memory_bytes: 256