akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct CumulativeSum{
    vector<int> data;
    CumulativeSum(int sz) : data(sz, 0) {};
    void add(int k, int x){
        data[k] += x;
    }
    void build(){
        for(int i = 1; i < data.size(); i++){
            data[i] += data[i - 1];
        }
    }
    int query(int k){
        if(k < 0) return 0;
        return (data[min(k, (int)data.size() - 1)]);
    }
    int query(int l, int r){
        return query(r - 1) - query(l - 1);
    }
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    rep(i, 0, n) cin >> c[i];
    int ans = 0;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<int> ab(n), bc(n);
    CumulativeSum cs(n);
    rep(i, 0, n){
        ab[i] = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
        bc[i] = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
        cs.add(i, n - bc[i]);
    }
    cs.build();
    rep(i, 0, n){
        int tmp = cs.query(ab[i], n);
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0&&c>0){
		c-=b;
		if(c<=0)break;
		a-=d;
	}
	if(a<=0)cout<<"No";
	else cout<<"Yes";
	getchar();getchar();
}

Measured memory_bytes: 3596
#include<iostream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdlib>
#include <math.h>
#include <algorithm>
#include <deque>

using namespace std;


int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for (auto&& it : a) {
    cin>>it;
  }
  deque<int> dq;
  for(int i=0;i<n;i++){
    if(i%2==0){
      dq.push_back(a[i]);
    }else{
      dq.push_front(a[i]);
    }
  }
  if(n%2==0){
    for(auto itr = dq.begin();itr != dq.end();++itr){
      cout << *itr ;
      if(itr!=dq.end()-1)cout <<" ";
      else cout <<endl;
    }
  }else{
    for(auto itr = dq.rbegin();itr != dq.rend();++itr){
      cout << *itr ;
      if(itr!=dq.rend()-1)cout <<" ";
      else cout <<endl;
    }
  }

  return 0;
}


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int const MAX_N = 100010;
vector<ll> prime;
vector<bool> is_prime(MAX_N,true);
void Eratosthenes() {
    is_prime[0] = is_prime[1] = false;
    for (ll i = 2;i*i < MAX_N;++i) if (is_prime[i]) for (ll j = 2*i;j < MAX_N;j += i) is_prime[j] = false;
    for (ll i = 0;i < MAX_N;++i) if (is_prime[i]) prime.push_back(i);
}

vector<P> prime_factorization(ll a) {
    vector<P> prime_factor;
    if (is_prime[0]) Eratosthenes();
    for (ll& i : prime) {
        if (i*i > a) break;
        if (a%i == 0) {
            P p = P(i,0);
            while (a%i == 0) {
                a /= i;
                p.second++;
            }
            p.second %= 3;
            if (p.second) prime_factor.push_back(p);
        }
    }
    if (a != 1) prime_factor.push_back(P(a,1));
    return prime_factor;
}

int main() {
    int x = 330,y = 9593;
    Eratosthenes();
    int n;
    cin >> n;
    vector<P> s(n,P(1,1));
    unordered_map<ll,int> mp;
    unordered_map<ll,ll> sq;
    for (ll& p : prime) sq[p*p] = p;
    for (int i = 0;i < n;++i) {
        ll a;
        cin >> a;
        for (int j = 0;j < x;++j) {
            if (prime[j]*prime[j] > a) break;
            if (a%prime[j]) continue;
            int cnt = 0;
            while (a%prime[j] == 0) {
                cnt++;
                a /= prime[j];
            }
            cnt %= 3;
            if (cnt == 0) continue;
            for (int k = 0;k < cnt;++k) s[i].first *= prime[j];
            for (int k = 0;k < 3-cnt;++k) {
                if (1e11/prime[j] < s[i].second) {
                    s[i].second = -1;
                    break;
                }
                s[i].second *= prime[j];
            }
        }
        if (sq.find(a) != sq.end()) {
            s[i].first *= a;
            if (1e11/sq[a] < s[i].second) s[i].second = -1;
            else s[i].second *= sq[a];
            a = 1;
        }
        if (a > 1) {
            s[i].first *= a;
            for (int j = 0;j < 2;++j) {
                if (1e11/a < s[i].second) {
                    s[i].second = -1;
                    break;
                }
                s[i].second *= a;
            }
        }
        mp[s[i].first]++;
        if (s[i].first > s[i].second) swap(s[i].first,s[i].second);
    }
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(),s.end()),s.end());
    int ans = 0;
    for (P& p : s) {
        if (p.first == 1) ans += 1;
        else ans += max(mp[p.first],mp[p.second]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9416
N,M = map(int,input().split())

position = [int(i) for i in input().split()]

sort_position = sorted(position,reverse = True)

#print(sort_position)
judge = sum(sort_position)/(4*M)

for i in range(M):
    if sort_position[i] < judge:
        ans = "No"
        break
    else:
        ans ="Yes"

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int n,m,q,a[51][51],dx[2][6]={{-1,-1,-1,0,1,0},{0,-1,0,1,1,1}},dy[6]={1,0,-1,-1,0,1};
bool u[51][51],u2[51][51];
bool check(int x, int y) {return (x>=0&&y>=0&&x<n&&y<m);}
 
int dfs(int x, int y, int k, bool o) {
  if(k!=a[x][y]) return 0;
  u[x][y]=u2[x][y]=true;
  if(o) a[x][y]=0;
  int sum=0;
  for(int i=0; i<6; i++) {
    if(check(x+dx[y%2][i],y+dy[i]) && !u2[x+dx[y%2][i]][y+dy[i]]) sum+=dfs(x+dx[y%2][i],y+dy[i],k,o);
  }
  return sum+1;
}
 
int main() {
  cin >> n >> m;
  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      char c;
      cin >> c;
      a[i][j]=(int)c;
    }
  }
  cin >> q;
  for(int t=0; t<=q; t++) {
    if(t) {
      int x,y;
      cin >> y >> x;
      x=n-x-1;
      int cnt=0;
      for(int i=0; i<6; i++) if(check(x+dx[y%2][i],y+dy[i])) cnt++;
      if(cnt==6) for(int i=0; i<5; i++) swap(a[x+dx[y%2][i]][y+dy[i]],a[x+dx[y%2][i+1]][y+dy[i+1]]);
    }
    while(1) {
      for(int i=n*2-1; i>=0; i--) {
        for(int j=i%2; j<m; j+=2) {
          int h=i/2;
          while(h<n-1 && a[h][j]) {
            for(int k=3; k<6; k++) if(check(h+dx[j%2][k],j+dy[k]) && a[h+dx[j%2][k]][j+dy[k]]) goto end;
            h++;
            swap(a[h][j],a[h-1][j]);
          }
        end:;
        }
      }
      bool ck=true;
      memset(u,0,sizeof(u));
      for(int i=0; i<n; i++) {
        for(int j=0; j<m; j++) {
          memset(u2,0,sizeof(u2));
          if(!u[i][j] && a[i][j] && dfs(i,j,a[i][j],0)>=3) {
            memset(u2,0,sizeof(u2));
            dfs(i,j,a[i][j],1);
            ck=false;
          }
        }
      }
      if(ck) break;
    }
  }
  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) cout << (a[i][j]?(char)a[i][j]:'.');
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3124
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

// #define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T>
T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T>
T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void)
{
  int num;
  int n;
  cin >> n;
  vector<int> a(n);

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

  int m = 0;
  num = 1;
  for (int i = 0; i < n; ++i)
  {
    if (i == 0)
      continue;

    if (a[i - 1] < a[i])
    {
      if (m < 0)
      {
        ++num;
        m = 0;
      }
      else
      {
        ++m;
      }
    }
    if (a[i - 1] > a[i])
    {
      if (m > 0)
      {
        ++num;
        m = 0;
      }
      else
      {
        --m;
      }
    }
  }
  cout << num << endl;
}


Measured memory_bytes: 640
// abc153_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    REP(i, N) cin >> H[i];
    sort(ALL(H), greater<ll>());

    ll ans = 0;
    REPN(i, K, N) ans += H[i];

    print(ans);

    return 0;
}


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

using ll = long long;
using edge = struct { ll to, cost;};

const ll inf = 1ll << 60ll;
vector<vector<edge>> graph(100005);
vector<ll> x(100005, inf);
vector<bool> color(100005, false);
ll n, m;

bool dfs(ll node, ll pos);

int main()
{
    ll l, r, d;
    bool f = true;

    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> d;

        graph[l].push_back((edge){r, d});
        graph[r].push_back((edge){l, -d});

        color[l] = true;
        color[r] = true;
    }

    for (int i = 1; i <= n; i++) {

        if (x[i] == inf) {
            f &= dfs(i, 0);
        }
    }

    cout << (f ? "Yes" : "No") << endl;
}

bool dfs(ll node, ll pos)
{
    if (x[node] == inf) {
        x[node] = pos;
    }

    bool res = true;

    for (int i = 0; i < graph[node].size(); i++) {

        ll nnode = graph[node][i].to;
        ll ncost = pos + graph[node][i].cost;

        if (color[nnode] &&
            (x[nnode] == inf || x[nnode] == ncost)) {
            
            color[nnode] = false;
            res &= dfs(nnode, ncost);
        }
        else if (x[nnode] != ncost) {
            return false;
        }
    }

    return res;
}


Measured memory_bytes: 16512
fn naive(n: usize, x: usize, m: usize) -> usize {
    let mut ans = 0;
    let mut y = x;
    for _ in 0..n {
        ans += y;
        y = y * y % m;
    }
    ans
}

fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    let n: usize = rd.get();
    let x: usize = rd.get();
    let m: usize = rd.get();

    // println!("{}", naive(n, x, m));
    //
    // let mut y = x;
    // let mut seen = std::collections::HashSet::new();
    // for i in 0..1000 {
    // println!("{} {}", i, y);
    // if !seen.insert(y) {
    // break;
    // }
    // y = y * y % m;
    // }

    let mut last = vec![0; m];
    let mut a = vec![];
    let mut y = x;
    for i in 0..n {
        if last[y] > 0 {
            let p = last[y];
            let q = i - p;
            let r = (n - p) / q;
            assert!(r >= 1);
            let s = (n - p) % q;
            // println!("{:?}", &a[0..p]);
            // println!("{:?}", &a[p..]);
            // println!("{:?}", &a[p..(p + s)]);
            let ans = a[0..p].iter().sum::<usize>()
                + a[p..].iter().sum::<usize>() * r
                + a[p..(p + s)].iter().sum::<usize>();
            println!("{}", ans);
            return;
        }
        a.push(y);
        last[y] = i;
        y = y * y % m;
    }
    println!("{}", a.iter().sum::<usize>());
}

/*

17 2 1001
=> 4838

*/

pub struct ProconReader<R: std::io::Read> {
    reader: R,
}

impl<R: std::io::Read> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self { reader }
    }
    pub fn get<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r')
            .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r')
            .collect::<Vec<_>>();
        std::str::from_utf8(&buf)
            .unwrap()
            .parse()
            .ok()
            .expect("Parse Error.")
    }
}

Measured memory_bytes: 3104
#include <stdio.h>

int main(void){
  char s[4] = { '\0' };
  scanf("%s", s);
  if(s[2] == '\0') printf("%s\n", s);
  else {
    char temp = s[0];
    s[0] = s[2];
    s[2] = temp;
    printf("%s\n", s);
  }
  return 0;
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            Map<Long, Integer> cnt = new HashMap<>();
            long ans = 0;
            long sum = 0;
            cnt.put(0L, 1);
            for (int i = 0; i < n; i++) {
                sum += in.nextInt();
                ans += cnt.getOrDefault(sum, 0);
                cnt.put(sum, cnt.getOrDefault(sum, 0) + 1);
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 54352
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define MAXN 2000100
#define ll long long
#define inf 1000000000
int n, m, sum, a[MAXN];
int main()
{
	scanf("%d",&n);
	int u;
	for(int i=2;i<=n;i++)
	{
		scanf("%d",&u);
		a[u]++;
	}
	for(int i=1;i<=n;i++) printf("%d\n",a[i]);
	
	return 0;
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define int long long
using namespace std;
const int N=5e5+5;
int n;
int cl[N],a[N];
string S;
vector<int> ke[N];
void DFS(int u)
{
    cl[u]=1;
    for(int v:ke[u])
    {
        if(!cl[v]) DFS(v);
        a[u]=max(a[u],a[v]+1);
    }
}
main()
{
    //freopen("A_.inp","r",stdin);
    cin>>S;
    S=' '+S;
    n=S.size();
    forinc(i,1,n-1)
    {
        if(S[i]=='<') ke[i+1].push_back(i);
        else ke[i].push_back(i+1);
    }
    forinc(i,1,n) if(!cl[i]) DFS(i);
    int sum=0;
    forinc(i,1,n) sum+=a[i];
    cout<<sum;
}


Measured memory_bytes: 59288
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    
    int tasu,hiku,kakeru;
    
    tasu = A+B;
    hiku = A-B;
    kakeru = A*B;
    
    cout << max({tasu,hiku,kakeru}) << endl;
return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class _Class
{
	void _()
	{
		var _ = _Ss();

		var s = _[0];

		var a = s.Substring(0, 5);
		a+= " ";
		a += s.Substring(6,7);
		a += " ";
		a += s.Substring(14,5);



		Console.WriteLine(a);
	}

	static void Main(string[] args)
  {
    new _Class()._();
  }

  #region

  string _S()
  {
    return Console.ReadLine();
  }

  string[] _Ss()
  {
    return Console.ReadLine().Split();
  }

  int[] _N(int n)
  {
    var x = new int[n];
    for (var i = 0; i < n; i++)
    {
      x[i] = int.Parse(Console.ReadLine());
    }
    return x;
  }

  int[] _Ns()
  {
    var ss = Console.ReadLine().Split();

    var x = new int[ss.Length];
    for (var i = 0; i < ss.Length; i++)
      x[i] = int.Parse(ss[i]);

    return x;
  }
  #endregion
}


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

int main(){
    int n;
    cin>>n;
    int b[n];
    bool ok=true;
    for(int i=0;i<n;i++){
        cin>>b[i];
        if(b[i]>i+1) ok=false;
    }
    if(!ok) {cout<<-1<<endl;return 0;}
    vector<int> ans;
    for(int i=0;i<n;i++){
        auto it=ans.begin();
        it +=b[i]-1;    
        ans.insert(it,b[i]);
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int s, w; cin >> s >> w;

	if (w >= s)
		cout << "unsafe";
	else
		cout << "safe";
	return 0;
}

Measured memory_bytes: 3656
a = list(map(int, list(input())))

if(len(a) == 2):
	if(a[0] == 9):
		print('Yes')
	elif(a[1] == 9):
		print('Yes')
	else:
		print('No')

else:
	if(a[0] == 9):
		print('Yes')
	else:
		print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define IOS                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
typedef long long ll;
using namespace std;
int main()
{
    IOS;
    string s;
    cin >> s;
    long long int x = 0;
    for (int i = 0; i < s.length(); i++)
    {
        x += (s[i] - '0');
    }
    if (x % 9 == 0)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

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

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//べき//
ll squ(ll n, ll p, ll m){
	if(p==0) return 1;
	if(p%2==0){
		ll t=squ(n, p/2, m);
		return t*t%m;
	}
	return n*squ(n,p-1,m);
	
}


//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nが大

ll com(ll n,ll m){
	if(n<=0 || m<=0 || n==m){
		return 1;
	}
	if(n<m){
		return 0;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}


//


////////////////////////////////////////////////////////////////////
int main(){
ll n,k;
cin>>n>>k;
ll a[n+1];
for(int i=1;i<=n;i++){
    cin>>a[i];
}

ll dp[n+1][k+1];

for(int i=0;i<=n;i++){
    for(int j=0;j<=k;j++){
        dp[i][j]=0;
    }
}

for(ll i=0;i<=k;i++){
    if(i<=a[1]){
    dp[1][i]=i+1;}
    else{
        dp[1][i]=dp[1][i-1];
    }
}


ll sum=a[1];
for(int i=1;i<=n-1;i++){
    sum+=a[i+1];
    for(int j=0;j<=min(sum,k);j++){
        if(j-a[i+1]-1>=0){
dp[i+1][j]=dp[i][j]-dp[i][j-a[i+1]-1]+MOD;
dp[i+1][j]%=MOD;}
else{
    dp[i+1][j]=dp[i][j];
    dp[i+1][j]%=MOD;
}
   
    }
for(int j=1;j<=k;j++){
    dp[i+1][j]+=dp[i+1][j-1];
    dp[i+1][j]%=MOD;
}

}




if(k){
    cout<<((dp[n][k]-dp[n][k-1])+MOD)%MOD<<endl;}
    else{
        cout<<dp[n][k]<<endl;
    }

return 0;


}




Measured memory_bytes: 79104
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	string a[200];
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)
	cout<<a[i];
}

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

int main() {
	int n, m = 0;
	cin >> n >> m;
	vector<int> days(m);
	for (int i = 0; i < m; i++) {
		cin >> days.at(i);
	}
	for (int i = 0; i < m; i++) {
		n -= days.at(i);
	}
	if (n >= 0) {
		cout << n << endl;
	}
	else {
		cout << "-1" << endl;
	}
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)n; ++i)
const int INF = (int)1e9;

int main() {
    for(int N; cin >> N, N; ) {
        static int D[10][10];
        REP(i,10) REP(j,10) D[i][j] = INF;
        REP(i,10) D[i][i] = 0;
        set<int> town;
        REP(i,N) {
            int a, b, c; cin >> a >> b >> c;
            town.insert(a);
            town.insert(b);
            D[a][b] = c;
            D[b][a] = c;
        }
        REP(k,10) REP(i,10) REP(j,10) D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
        int t = -1;
        int d = INF;
        for(auto it : town) {
            int ds = 0;
            for(auto it2 : town) {
                ds += D[it][it2];
            }
            if(ds < d) {
                t = it;
                d = ds;
            }
        }
        cout << t << ' ' << d << endl;
    }
}

Measured memory_bytes: 1196
import java.util.*;
import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int sum = 0;

        List<Integer> list = new ArrayList<>();

        for(int i = 0; i < n; i++){
            list.add(sc.nextInt());
            sum += list.get(i);
        }
        double vote = (double)sum/(4.0*(double)m);
        Collections.sort(list);
        Collections.reverse(list);
        // for(int i: list){
        //     System.out.print(i+" ");
        // }
        if(list.get(m-1) < Math.ceil(vote)) System.out.println("No");
        else System.out.println("Yes");
    }
}

Measured memory_bytes: 23124
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    ps = [LS() for _ in range(m)]
    c = collections.defaultdict(int)
    r = 0
    o = 0
    for p,s in ps:
        if c[p] == -1:
            continue
        if s == 'AC':
            r += 1
            o += c[p]
            c[p] = -1
        else:
            c[p] += 1

    return JA([r,o]," ")


print(main())





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

int main()
{
	string M,N;

	int num1,num2;

	cin >> N;

	M = N;

	num1 = N[0];
	num2 = N[2];
	N[0] = num2;
	N[2] = num1;

	if (M == N)
	{
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define FF 1000000000000000000
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
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;
}
int main() {
    int n;cin>>n;
    ll ans=1;
    bool ak=1;bool dd=1;
    rep(i,n){
    ll a;cin>>a;
    if(a==0){dd=0;break;}
    long double aa=(ans/1000000000)*(a/1000000000);
    long double cc=1.0000000000000000000;
    if(aa>cc){
        ak=0;
    }
    ans*=a;
    if(ans>1000000000000000000){
        ak=0;
    }
    }
    if(dd){
        if(ak){
            cout<<ans<<endl;
        }else{
            cout<<-1<<endl;
        }
    }else{
        cout<<0<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;
const int MAX=200001;
int fac[MAX],finv[MAX],inv[MAX];
int rui[MAX];

void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

void make_Table(){
    rui[1]=1;
    for(int i=2;i<MAX;i++){
        rui[i]=(rui[i-1]+inv[i])%MOD;
    }
}


int COM(int n,int k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int powMOD(int n,int r){
    if(r==0)return 1;
    if(r%2==0)return powMOD(n,r/2)*powMOD(n,r/2)%MOD;
    if(r%2==1)return powMOD(n,r-1)*n%MOD;
}

signed main(){
    COMinit();
    make_Table();
    int N;cin>>N;
    int ans=0;
    REP(i,N){
        int a;cin>>a;
        ans+=a*fac[N]%MOD*(rui[N-i]+rui[i+1]-1)%MOD;
        ans%=MOD;
    }
  	while(ans<0)ans+=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 6528
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  long ans = 0;
  ans += min(A+B, 2*C) * min(X, Y);
  if (X > Y) ans += min(A, 2*C) * (X-Y);
  if (X < Y) ans += min(B, 2*C) * (Y-X);
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

int main() {
    long int a , b ;
    cin >> a >> b;
    if ((a > 0 && b >= a )|| (a <= b && b < 0 && (b-a+1)%2 == 0)) cout << "Positive";
    if (a <= 0 && b >= 0) cout << "Zero";
    if (a <= b && b < 0 && (b-a+1)%2 != 0) cout << "Negative" ; 
	return 0;
}

Measured memory_bytes: 3612
s = gets.chomp

ans = 'Yes'
RUD = %w[R U D].freeze
LUD = %w[L U D].freeze

s.each_char.with_index do |v, i|
  next if i.even? && RUD.include?(v)
  next if i.odd? && LUD.include?(v)

  ans = 'No'
end
puts ans

Measured memory_bytes: 1788
s = input()
a = 0
if len(s) % 2 == 1:
    print('No')
    exit(0)
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == 'h':
            pass
        else:
            a += 1
    else:
        if s[i] == 'i':
            pass
        else:
            a += 1

if a == 0:
    print('Yes')
else:
    print('No')


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

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

  string ans = "";
  for (int i = 0; i < s.size(); i ++) {
    if (s.at(i) == 'B' && ans.size() > 0) {
      ans.pop_back();
    } else if (s.at(i) != 'B') {
      ans += s.at(i);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, ll> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

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

    int n;
    cin >> n;
    vector<vector<P>> xy(n);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        for(int j = 0; j < a; ++j){
            int x, y;
            cin >> x >> y;
            --x;
            xy[i].push_back(P(x, y));
        }
    }
    
    int res = 0;
    for(int i = 0; i < (1 << n); ++i){
        bool flag = true;
        
        vector<bool> tmp(n);
        int cnt = 0;
        for(int d = 0; d < n; ++d){
            if((i >> d) & 1){
                tmp[d] = true;
                ++cnt;
            }
            else    tmp[d] = false;
        }

        for(int j = 0; j < n; ++j){
            if(!tmp[j]) continue;
            for(int k = 0; k < (int)xy[j].size(); ++k){
                if(xy[j][k].second != tmp[xy[j][k].first]){
                    flag = false;
                    break;
                }
            }
            if(!flag)   break;
        }

        if(flag){
            res = max(res, cnt);
        }
    }

    cout << res << endl;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>s;
      ans=700;
      rep(i,Size(s)){
        if(s[i]=='o')ans+=100;
      }
     Cout(ans);

       
return 0;
}


Measured memory_bytes: 256
a[4],s[3];main(x){for(;~scanf("%d,%s",&x,s);a[x]++)x=*s>99?2:*s=='A'?0:*s=='O'?3:1;printf("%d\n%d\n%d\n%d\n",*a,a[1],a[2],a[3]);exit(0);}

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

int bubbleSort(vector<int> &a, int n)
{
    bool flag = true;
    int count = 0;
    while (flag)
    {
        flag = false;
        for (int j = n - 1; j > 0; j--)
        {
            if (a.at(j) < a.at(j - 1))
            {
                swap(a.at(j), a.at(j - 1));
                count++;
                flag = true;
            }
        }
    }
    return count;
}

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N)
    {
        cin >> a.at(i);
    }

    int counts = bubbleSort(a, N);

    for (int i = 0; i < N; i++)
    {
        if (i == a.size() - 1)
        {
            cout << a.at(i) << endl;
        }
        else
        {
            cout << a.at(i) << " ";
        }
    }

    cout << counts << endl;

    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
#define hash hush
typedef long long ll;
typedef long double ld;
int a[100000];
signed  main() {
	int a=20000, b=-1, n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int c;
		cin >> c;
		a = min(a, c);
		b = max(b, c);
	}
	cout << b - a << endl;
	getchar(); getchar();
}

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

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 998244353;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    string T, S, U;
	int x, y;
  	cin >> T >> S >> x >> y >> U;
  	if (U == T) x--;
	if (U == S) y--;
  	cout << x _ y << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int n;
	cin >> n;
	int s[n];
	rep (i, n) cin >> s[i];

	int sum = 0;
	rep (i, n) sum += s[i];

	int m = 1000;
	rep (i, n) if (s[i] % 10) chmin(m, s[i]);

	if (sum % 10) cout << sum << endl;
	else if (m != 1000) cout << sum - m << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
def s2int(a):
    dot_idx = -1
    for j in range(len(a)):
        if a[j] == '.':
            dot_idx = j
            break
    # .がないので末尾につける
    if dot_idx == -1:
        a += ".000000000"
    # .の場所に応じて後ろにつける
    else:
        while len(a) < 10+dot_idx:
            a += "0"
    tmps = ""
    for j in range(len(a)):
        if a[j] == '.':continue
        tmps += a[j]
    return int(tmps)

def Count_two_five(x):
    c2 = 0
    c5 = 0
    while x > 0 and x % 2 == 0:
        x //= 2
        c2 += 1
    while x > 0 and x % 5 == 0:
        x //= 5
        c5 += 1
    c2 = min(c2, 18)
    c5 = min(c5, 18)
    return c2, c5

def main():
    N = int(input())

    C2 = [0] * N
    C5 = [0] * N

    for i in range(N):
        C2[i], C5[i] = Count_two_five(s2int(str(input())))

    Cc = [[0] * 19 for _ in range(19)]

    for i in range(N):
        Cc[C2[i]][C5[i]] += 1

    ans = 0
    for i in range(N):
        Cc[C2[i]][C5[i]] -= 1

        for j in range(19):
            for k in range(19):
                if C2[i] + j >= 18 and C5[i] + k >= 18:
                    ans += Cc[j][k]

        Cc[C2[i]][C5[i]] += 1

    print(ans//2)

main()

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

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

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

  string s, t; cin >> s >> t;
  if(s == t.substr(0, SZ(s))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}
























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

int main()
{
  int A, B, N;
  cin >> A >> B >> N;
  int m = min(A, B);
  for(int i=m; i>=1; i--)
  {
    if(A % i == 0 && B % i == 0)
    {
      N--;
      if(N == 0) cout << i << endl;
    }
  }  
  return 0;
}

  

Measured memory_bytes: 3524
#include <string>
#include <iostream>

using namespace std;

int main(void) {
  string buf;
  long m , a, r, c, h;
  long N;
  long long p;
  
  cin >> N;
  m = a = r = c = h = 0;
  for (int i = 0; i < N; i++) {
    cin >> buf;
    switch (buf[0]) {
      case 'M' : m++; break;
      case 'A' : a++; break;
      case 'R' : r++; break;
      case 'C' : c++; break;
      case 'H' : h++; break;
      default  : break;
    }
  }
  p = 0;
  p = m * a * r + m * a * c + m * a * h
    + m * r * c + m * r * h
    + m * c * h
    + a * r * c + a * r * h + a * c * h
    + r * c * h;
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 256
ary = []
count = Hash.new(0)
while tmp = gets
  break if tmp.to_i == 0
  ary << tmp.to_i
end

ary.each do |ary_i|
  count[ary_i] += 1
end

max = count.map(&:last).max
# p count.select{|_,v| v == max }
count.select{|_,v| v==max}.sort_by{|k,_| k }.each do |k,_|
  puts k
end



Measured memory_bytes: 6852
def read(): return list(map(int, input().split()))


n = int(input())
p = read()

cnt = [0 for i in range(n)]
for i, v in enumerate(p):
    if i == v - 1:
        cnt[i] = 1

ans = 0
for i in range(n - 1):
    if cnt[i] and cnt[i + 1]:
        ans += 1
        cnt[i] = cnt[i + 1] = 0

ans += sum(cnt)
print(ans)

Measured memory_bytes: 13880
#include <stdio.h>
#define max(p,q)((p)>(q)?(p):(q))

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int ans=0;
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		ans+=max(0,t-m);
	}
	if(ans)printf("%d\n",ans);
	else puts("kusoge");
}


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

int main(){
        int n;
        scanf("%d", &n);
        int a[n];
        for(int i=0; i<n; i++) scanf("%d", &a[i]);
        std::sort(a, a+n, std::greater<int>());

        int al=0, bo=0;
        for(int i=0; i<n; i++){
                if(i%2) bo += a[i];
                else al += a[i];
        }
        printf("%d\n", al-bo);
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string L;
    cin >> L;
    ll sum = 0;
    int count1 = 0;
    REP(i,L.size()){
        if(L.at(i) == '1'){
            ll count2 = 1,count3 = 1;
            REP(l,count1){
                if(l == 0){
                    REP(q,(count1) / 30){
                        count2 *=73741817;
                        count2 %= 1000000007;
                        }
                    l += ((count1) / 30)*30;
                }
                if(l != count1){
                    count2 *= 2;
                    count2 %= 1000000007;
                }
            }
            REP(l,L.size()-i-1){
                if(l == 0){
                    REP(q,(L.size()-i-1) / 19){
                        count3 *=162261460;
                        count3 %= 1000000007;
                        }
                    l += ((L.size()-i-1) / 19)*19;
                }
                if(l != L.size()-i-1){
                    count3 *= 3;
                    count3 %= 1000000007;
                }
            }
            sum += count2 * count3;
            sum %= 1000000007;
            count1++;
        }
    }
    ll count2 = 1;
    REP(l,count1){
        if(l == 0){
            REP(q,(count1) / 30){
                count2 *=73741817;
                count2 %= 1000000007;
                }
            l += ((count1) / 30)*30;
        }
        if(l != count1){
            count2 *= 2;
            count2 %= 1000000007;
        }
    }
    sum += count2;
    cout <<sum % 1000000007<< "\n";
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

string s;
int n, q;
char c[200005], d[200005];

bool probaj(int x, bool p){
	for(int i = 0 ; i < q ; ++i){
		if(s[x] == c[i]){
			if(d[i] == 'L'){
				x--;
			}
			else{
				x++;
			}
			if(x <= 0 && !p)
				return 1;
			if(x > n && p)
				return 1;
		}
	}
	return 0;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
cin >> s;
s = "$" + s + "$";
for(int i = 0 ; i < q ; ++i){
	cin >> c[i] >> d[i];
}
int l = 1, r = n;
while(l <= r){
	int mid = (l + r) / 2;
	if(!probaj(mid, 0)){
		r = mid - 1;
	}
	else{
		l = mid + 1;
	}
}
//cout << l << ' ' << r << endl;
int sol = r;
l = 1;
r = n;
while(l <= r){
	int mid = (l + r) / 2;
	if(!probaj(mid, 1)){
		l = mid + 1;
	}
	else{
		r = mid - 1;
	}
}
sol += (n + 1 - l);
sol = n - sol;
cout << sol << endl;

return 0;
}



Measured memory_bytes: 976
#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}


ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

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

ll dp[3005][3005];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    string s1,s2;
    cin >> s1 >> s2;
    int n = s1.length(),m=s2.length();
    string str = "";
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
        }
    }
    /*for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
            cout << dp[i][j] << " ";
        cout << "\n";
    }*/
    int j=m;
    int i = n;
    for(;dp[i][j]!=0;)
    {
        if(dp[i][j]==(dp[i-1][j-1]+1)&&s1[i-1]==s2[j-1])
        {
            str = s1[i-1]+str;
            i--;
            j--;
        }
        else
        {
            if(dp[i][j]==dp[i-1][j])
            {
                i--;
            }
            else
                j--;
        }
    }
    cout << str;
}


Measured memory_bytes: 70784
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
ll mod=1000000007;

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> LR(2*N);//-1L,1R
    if(S[0]=='W' || S[2*N-1]=='W'){
        cout << 0 << endl;
        return 0;
    }

    LR[0]=-1;
    LR[2*N-1]=1;
    int cnt=1;
    for(int i=1; i<2*N-1; i++){
        if(S[i]==S[i-1]) LR[i]=LR[i-1]*-1;
        else LR[i]=LR[i-1];

        if(LR[i]==1) cnt++;
    }

    if((S[2*N-2]==S[2*N-1] && LR[2*N-2]==LR[2*N-1]) || (S[2*N-2]!=S[2*N-1] && LR[2*N-2]!=LR[2*N-1]) || cnt!=N){
        cout << 0 << endl;
        return 0;
    }

    int c_L=0;
    ll ans=1;
    for(int i=0; i<2*N; i++){
        if(LR[i]==-1) c_L++;
        else{
            ans*=c_L;
            c_L--;
            ans%=mod;
        }
    }
    for(int i=0; i<N; i++){
        ans*=(i+1);
        ans%=mod;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1412