akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<double,double>P;


int main()
{
    int n;
    cin>>n;
    vector<P>r(n);
    vector<int>c(n);
    double sum=0.0;
    double perm=1.0;
    rep(i,n)
    {
        cin>>r[i].first>>r[i].second;
    }
    rep(i,n)
    {
        c[i]=i;
        perm*=(i+1);
    }
    do
    {
        double lsum=0.0;
        rep(i,n-1)
        {
            lsum+=sqrt(pow(r[c[i]].first-r[c[i+1]].first,2.0)+pow(r[c[i]].second-r[c[i+1]].second,2.0));
        }
        sum+=lsum;
    } while (next_permutation(c.begin(), c.end()));
    
    cout<<setprecision(10)<<sum/perm<<endl;

}  

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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










int main(){
    int L, R, d;
    std::cin >> L >> R >> d;
    std::cout << R/d - (L-1)/d << std::endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A, B, C;
  int input;
  for(int i=0; i<N; i++){
    cin >> input;
    A.push_back(input);
  }
  for(int i=0; i<N; i++){
    cin >> input;
    B.push_back(input);
  }
  for(int i=0; i<N; i++){
    cin >> input;
    C.push_back(input);
  }
  sort(A.begin(), A.end(), less<int>());
  sort(C.begin(), C.end(), less<int>());

  long long ret = 0;
  for(vector<int>::iterator b=B.begin(); b!=B.end(); b++){
    int val = *b;
    vector<int>::iterator a = lower_bound(A.begin(), A.end(), val);
    vector<int>::iterator c = upper_bound(C.begin(), C.end(), val);
    ret += ((long long)(a - A.begin()) * (long long)(C.end() - c));
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 1784
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int P[100000];
int inv[100000];
int main(){
  int KL2GvlyY, Q5VJL1cS, i, k, lef1, lef2, rig1, rig2;
  long long res=0;
  multiset<int> s;
  multiset<int>::iterator it1, it2;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(P[Lj4PdHRW]);P[Lj4PdHRW] += (-1);
    }
  }
  for(i=0;i<(N);i++){
    inv[P[i]] = i;
  }
  for(KL2GvlyY=0;KL2GvlyY<(2);KL2GvlyY++){
    s.insert(-1);
  }
  for(Q5VJL1cS=0;Q5VJL1cS<(2);Q5VJL1cS++){
    s.insert(N);
  }
  for(k=N-1;k>=0;k--){
    i = inv[k];
    it1 = it2 = s.insert(i);
    lef1 = *(--it1);
    lef2 = *(--it1);
    rig1 = *(++it2);
    rig2 = *(++it2);
    res += (long long) (k+1) * (lef1-lef2) * (rig1 - i);
    res += (long long) (k+1) * (rig2-rig1) * (i - lef1);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190902-1

// --- original code ---
// int N, P[1d5];
// int inv[1d5];
// {
//   int i, k, lef1, lef2, rig1, rig2;
//   multiset<int> s;
//   multiset<int>::iterator it1, it2;
//   ll res = 0;
//   
//   rd(N,(P--)(N));
//   rep(i,N) inv[P[i]] = i;
// 
//   rep(2) s.insert(-1);
//   rep(2) s.insert(N);
// 
//   for(k=N-1;k>=0;k--){
//     i = inv[k];
//     it1 = it2 = s.insert(i);
//     lef1 = *(--it1);
//     lef2 = *(--it1);
//     rig1 = *(++it2);
//     rig2 = *(++it2);
// 
//     res += (ll) (k+1) * (lef1-lef2) * (rig1 - i);
//     res += (ll) (k+1) * (rig2-rig1) * (i - lef1);
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 5760
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, A, B;
	string S, T;

	cin >> S >> T;
	cout << T << S << endl;


	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

const int MAX = 2001000;
const int mod = 1000000007;

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;
}
//a^n (mod m)
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//mod mでの a の逆元を求める
ll modinv(ll a) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    
    ll k;
    string s;
    cin>>k>>s;
    int n = s.size();
    COMinit();
    ll ans = 0;
    for(int i=0;i<=k;i++){
        ans += (modpow(25,k-i) * COM(n-1+k-i,k-i) % mod) * modpow(26,i) % mod;
        ans %= mod;
    }
    cout << ans << endl;

}

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

using namespace std;

#define rep(i,m,n) for(long i=m;i<n;i++)
#define repr(i,m,n) for(long i=n-1;i>=m;i--)

struct UnionFind {
    vector<int> par,si; 

    UnionFind(int N) : par(N), si(N,1) { 
        rep(i,0,N) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        x = root(x); 
        y = root(y); 
        if (x == y) return; 
        si[y]+=si[x];
        par[x] = y; 
    }

    bool same(int x, int y) { 
      return root(x)== root(y);
    }
    int size(int x){
       return si[root(x)];
    }

};

int main(){
  long n,m;
  cin >> n >> m;
  vector<long> a(m),b(m);
  UnionFind u(n);
  rep(i,0,m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  
  long num=n*(n-1)/2;
  vector<long> res;
  repr(i,0,m){ 
    res.push_back(num);
    
    if(!u.same(a[i],b[i])){
      num-=u.size(a[i])*u.size(b[i]); 
      u.unite(a[i],b[i]);  
      
    }
  }
  repr(i,0,res.size()) cout << res[i] << endl;
  
}


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

#define F first
#define S second
const int LIM = 1e9+5;

using namespace std;
typedef pair<int,int> P;
int n,m;
vector<P> V;

void input(){
  cin >> n >> m;
  V.resize(n);
  for(int i = 0; i < n; i++) cin >> V[i].F >> V[i].S;
}

void solve(){
  sort(V.begin(),V.end());
  P p1,p2;
  for(int i = 0; i < m; i++){
    cin >> p1.F >> p1.S >> p2.F >> p2.S;

    int ans = 0;
    int l = p1.F,r = p2.F,d = p1.S,u = p2.S;
    
    vector<P>::iterator ite = lower_bound(V.begin(),V.end(),P(l,-LIM));
    
    while(ite < V.end()){
      if(ite->F > r) break;
      //  cout << ite->F << " " << ite->S << endl;
      if(d <= ite->S && ite->S <= u){
	ans++;
      }//else ite = lower_bound(V.begin(),V.end(),P(ite->F+1,-LIM));
      ite++;
    }
    cout << ans << endl;
  }
}

int main(){
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
#define PI 3.14159265359

int main() {
  string S, T;
  cin >> S >> T;
  ll count = 0;
  for (auto i = 0;i < S.size();i ++) {
    if (S[i] != T[i]) {
      count ++;
    }
  }
  cout << count << endl;
  return 0;
}

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


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    while(cin>>n){
        string s;
        int a=0,t=0,w=0,r=0;
        rep(i,1,n){
            cin>>s;
            if(s[0]=='A')a++;
            else if(s[0]=='T') t++;
            else if(s[0]=='W') w++;
            else if(s[0]=='R') r++;
        }
        cout<<"AC x "<<a<<endl;
        cout<<"WA x "<<w<<endl;
        cout<<"TLE x "<<t<<endl;
        cout<<"RE x "<<r<<endl;
    }
    //system("pause");
    return 0;
}

Measured memory_bytes: 3656
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m: usize = sc.read();

    let mut uf = UnionFind::new(n);
    for _ in 0..m {
        let x = sc.read::<usize>() - 1;
        let y = sc.read::<usize>() - 1;
        let z = sc.read::<u64>();
        let _sum_even = z % 2 == 0;
        uf.unite(x, y);
    }
    println!("{}", uf.size);
}
pub struct UnionFind {
    parent: Vec<usize>,
    sizes: Vec<usize>,
    size: usize,
}

impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: (0..n).map(|i| i).collect::<Vec<usize>>(),
            sizes: vec![1; n],
            size: n,
        }
    }

    pub fn find(&mut self, x: usize) -> usize {
        if x == self.parent[x] {
            x
        } else {
            let px = self.parent[x];
            self.parent[x] = self.find(px);
            self.parent[x]
        }
    }

    pub fn unite(&mut self, x: usize, y: usize) -> bool {
        let parent_x = self.find(x);
        let parent_y = self.find(y);
        if parent_x == parent_y {
            return false;
        }

        let (large, small) = if self.sizes[parent_x] < self.sizes[parent_y] {
            (parent_y, parent_x)
        } else {
            (parent_x, parent_y)
        };

        self.parent[small] = large;
        self.sizes[large] += self.sizes[small];
        self.sizes[small] = 0;
        self.size -= 1;
        return true;
    }
}
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6396
# -*- coding: utf-8 -*-

N = int(input())
D,X = map(int,input().split())
A = []
for i in range(0,N):
    data = int(input())
    A.append(data)

choco = X

for i in A:
    if D % i == 0: 
        choco = choco + int(D/i) - 1 + 1
    else:
        choco = choco + int(D/i) + 1

print(choco)

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int a;
    cin >> a;
    int res = a + a * a + a * a * a;
    c(res);
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct{
  char name[100];
  int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b){return a < b ? a : b;}

int main(){
  int elaps = 0,c;
  int i, k;
  P u;
  scanf("%d %d",&n, &k);

  for(i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head = 1;
  tail = n + 1;

  while(head != tail){
    u = dequeue();
    c = min(k,u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0)enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }

  return 0;
}



Measured memory_bytes: 11924
n, k = map(int,input().split())
ans = 0
n_list = [i for i in range(n+1)]
l = sum(n_list[:k])
r = sum(n_list[len(n_list)-k:])
ans += r-l+1

for i in range(k,n+1):
    l += n_list[i]
    r += n_list[len(n_list)-i-1]
    ans += r-l+1
    ans = ans%1000000007

print(ans)


Measured memory_bytes: 18476
/*
 *
 * Author: r3gz3n
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <utility>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int x;
		in >> x;
		if (x < 1200) out << "ABC" << endl;
		else out << "ARC" << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;
const INF: usize = 1 << 30;

fn dfs(v: usize, p: usize, d: &mut Vec<usize>, g: &Vec<Vec<usize>>) {
    for &nv in g[v].iter() {
        if nv != p {
            d[nv] = d[v] + 1;
            dfs(nv, v, d, &g);
        }
    }
}
fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut g = vec![Vec::new(); n];
    for _ in 1..n {
        let a = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let b = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        g[a].push(b);
        g[b].push(a);
    }

    // 0から / n - 1から
    let mut d1 = vec![INF; n];
    let mut d2 = vec![INF; n];
    d1[0] = 0;
    d2[n - 1] = 0;
    dfs(0, 0, &mut d1, &g);
    dfs(n - 1, n - 1, &mut d2, &g);

    let mut w = 0;
    let mut b = 0;
    for i in 0..n {
        if d1[i] <= d2[i] {
            b += 1;
        } else {
            w += 1;
        }
    }
    if b > w {
        println!("Fennec");
    } else {
        println!("Snuke");
    }
}


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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

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

constexpr int MOD = 1000000007;
constexpr int INF = 1001001001;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main() {
    int x, a;
    cin >> x >> a;
    
    int ans = (x < a ? 0 : 10);
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
 using namespace std;
 
int main() {
  vector<int> dish(5);
  for(int i=0; i < 5; ++i){
    cin >> dish[i];
  }
  vector<int> result(5);
  for(int i=0; i < 5; ++i){
    for(int j=0; j < 5; ++j){
      if(i==j){
        result[i] += dish[j];
      }
      else{
        float temp; temp = ((double) dish[j])/10;
        int ans; ans = ceil(temp) * 10;
        result[i] += ans;
      }
    }
  }
  int min = *min_element(result.begin(), result.end());
  cout << min << endl;
}

Measured memory_bytes: 256
//This code is solely the property of StarnyC
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define hell 1000000007
#define hellx 998244353
#define pb push_back
#define mp make_pair
#define reset(a,b) memset(a,b,sizeof(a))
#define Go_Baby_Go  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define deb(x)     cout << (#x) << " is " << (x) << endl;
#define F  first
#define S  second
#define pii pair<ll,ll>
#define all(c) (c).begin(),(c).end()

bool secsort(const pii &a,const pii &b){
    return a<b;}

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

ll binexp(ll x,ll n,ll m){
   if(!n)return 1;
else if(n&1)return (x%m)*binexp((x%m)*(x%m),n/2,m)%m;
else if(!(n&1))return binexp((x%m)*(x%m),n/2,m)%m; 
return 0;}

int val[105];
int weight[105];
int dp[105][100005];

int32_t solve(ll _,ll _t)
{  
   int n,W,v=0;
   cin>>n>>W;

   for (int i=0;i<n;++i){
    cin>>weight[i+1]>>val[i+1];
    v+=val[i+1];
   }

        for(int j=0;j<=v;j++) dp[0][j]=2e10;

      dp[0][0]=0;
      ll ans=0;

    // cout<<fun(n-1,0,W)<<endl;

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

          if(j-val[i]>=0)
          dp[i][j]=min(dp[i-1][j],dp[i-1][j-val[i]]+weight[i]);
          else dp[i][j]=dp[i-1][j];

          if(ans<j&&dp[i][j]<=W)ans=j;
        }

   // for(int i=0;i<n;i++)
   // { for(int j=0;j<20;j++)
   //    cout<<dp[i][j]<<" ";

   //    cout<<endl;}
        cout<<ans;

 








return 0;
}


int32_t main()
{
 Go_Baby_Go
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" ;


ll _=1;
//cin>>_;
ll _t=_;
while(_--)
solve(_,_t);

}


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

int main() {
  int N;
  cin >> N;
  vector<string>S(N);
  int A=0;
  int W=0;
  int T=0;
  int R=0;
  for(int i=0;i<N;i++){
    cin>>S[i];
    if(S[i]=="AC"){
      A+=1;
    }
    else if(S[i]=="WA"){
      W+=1;
    }
    else if(S[i]=="TLE"){
      T+=1;
    }
    else if(S[i]=="RE"){
      R+=1;
    }
  }
  cout<<"AC"<<" "<<"x"<<" "<<A<<endl;
  cout<<"WA"<<" "<<"x"<<" "<<W<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<T<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<R<<endl;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int) (n); i++)
void MAIN();
int main() {
    MAIN();
    return 0;
}

const int N = 100032;
int n, m;
vector<int> G[N];
bitset<N> in;

void MAIN() {
  while (scanf("%d%d", &n, &m) == 2) {
    REP(i, n) G[i].clear(), in[i] = false;
    int u, v; 
    REP(i, m) {
      scanf("%d%d", &u, &v); u--; v--;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    
    deque<int> path{u, v}; in[u] = in[v] = true;
    while (true) {
      bool modified = false;
      u = path.front(); v = path.back();
      for (int w : G[u]) if (!in[w]) {
        path.push_front(w);
        in[w] = true;
        u = w;
        modified = true;
        break;
      }
      for (int w : G[v]) if (!in[w]) {
        path.push_back(w);
        in[w] = true;
        v = w;
        modified = true;
        break;
      }
      if (!modified) break;
    }
    printf("%d\n", (int) path.size());
    REP(i, path.size()) printf("%d%c", path[i] + 1, " \n"[i+1==path.size()]);
  }
}



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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        int a,b; cin>>a>>b;
        cout<<(a-1)*(b-1)<<endl;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
P, S = Array.new(M), Array.new(M)
M.times do |i|
  tmp, S[i] = gets.split
  P[i] = tmp.to_i
end

ac = {}
result = [0,0]
wa_count = {}
M.times do |i|
  pro = P[i]
  next if ac[pro]
  if S[i] == "AC"
    ac[pro] = true
    result[0] += 1
    result[1] += wa_count[pro] || 0
  else
    wa_count[pro] ||= 0
    wa_count[pro] += 1
  end
end

puts result.join(' ')

Measured memory_bytes: 16636
input = raw_input
N,K = map(int, input().strip().split(" "))
H = list(map(int, input().strip().split(" ")))

dp = [[0]*K for i in range(N)]

for i in range(1,N):
    for j in range(1, K+1):
        jj = max(0, i-j)
        dp[i][j-1] = dp[jj][0] + abs(H[i]-H[jj])
    dp[i][0] = min(dp[i])
print(min(dp[N-1]))


Measured memory_bytes: 125384
N = gets.to_i
As = gets.split.map(&:to_i)

require 'prime'

ul = As.max
ps = Prime.each(ul).to_a
h = As.tally; h.default = 0
s = ps.map{|p| p.step(ul, p).inject(0){|r, q| r + h[q]}}.max || 0
puts (s <= 1 ? 'pairwise' : s == N ? 'not' : 'setwise') + ' coprime'

Measured memory_bytes: 147440
#include<stdio.h>
 
int main(){
	int A, i;
	scanf("%d", &A);
	long long int sum = 0;
	for (i = 1; i <= A; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
		{
			sum += i;
		}
	}
		
	printf("%lld\n", sum);
	
	return 0;
}

Measured memory_bytes: 1728
from sys import stdin


def a(input_string):
    N, M = [int(x) for x in input_string[0].split()]
    C = input_string[1:]
    temp = [string.split() for string in C]
    D = []
    for i in range(len(temp)):
        D.append([int(word) for word in temp[i]])
    #print(D)
    get_count = 0
    min_cost = 10000000000000000
    cost = 0
    D = sorted(D, key=lambda x: x[0])
    for i in range(N):
        for j in range(D[i][1]):
            get_count += 1
            cost += D[i][0]
            if get_count >= M:
                return cost
    return cost


def main():
    input_line = stdin.readlines()
    answer = a(input_line)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62044
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  string S; cin >> S;
  
  rep(i,S.size()) {
    for(char c = 'a'; c <= 'z'; c++) {
      if (!count(all(S),c)) {
        cout << c << endl;
        return 0;
      }
    }
  }
  cout << "None" << endl;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll k,x;
  cin >> k >> x;

  if(500*k>=x) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  //cout << fixed << setprecision(10);
  return 0;
}


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

int main() {
  ll n;
  cin >> n;
  vector<ll> num(n);
  ll ans = 1;
  double ans1 = 1;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
    if (num[i] == 0)
      ans = 0;
    if (ans != -1) {
      ans *= num[i];
      ans1 *= num[i];
    }
    if (ans1 > 2e18) {
      ans = -1;
    }
    // cout << ans << " " << ans1 << endl;
  }
  if (ans > 1000000000000000000)
    ans = -1;
  printf("%lld", ans);
}

Measured memory_bytes: 4044
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    ll n;
    scanf("%lld",&n);
    ll c[n],s[n],f[n-1];
    rep(i,0,n-1){
        scanf("%lld%lld%lld",&c[i],&s[i],&f[i]);
    }
    ll t,time[n];
    rep(i,0,n-2){
        t=c[i]+s[i];
        rep(j,i+1,n-1){
            if(t<s[j]){
                t = s[j]+c[j];
            }else{
                if(t%f[j]==0){
                    t+=c[j];
                }else{
                    t+=f[j]-t%f[j]+c[j];
                }
            }
        }
        time[i]=t;
    }
    time[n-2] = c[n-2] + s[n-2];
    time[n-1]=0;
    rep(i,0,n){
        printf("%lld\n",time[i]);
    }
    return 0;
}


Measured memory_bytes: 128
# ABC138D - Ki
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def dfs(v: int, p: int) -> None:
    x = cnt[v]
    for u in T[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += x  # cumulative sum
            dfs(u, v)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    global T, cnt
    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, N+1: 1-idx
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

Measured memory_bytes: 265772
k,n=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort() ; maxx=0
for i in range(len(a)-1):
    if a[i+1]-a[i]>maxx: maxx=a[i+1]-a[i]
if k+a[0]-a[-1]>maxx: maxx=k+a[0]-a[-1]
print(k-maxx)

Measured memory_bytes: 77500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

int main()
{
    fastread();


    ll n;
    cin>>n;


    string str;

    cin>>str;


    ll cnt=0,a=0,b=0,c=0;

    for(ll i=2;str[i];i++)
    {
        if(str[i-2]=='A'  and str[i-1]=='B' and str[i]=='C')
        {
            cnt++;
            i++;
            i++;
        }


    }

    cout<<cnt<<endl;


}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int h, w, n;

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> h >> w >> n;

    int mx = max(h, w);
    int ans = (n+mx-1)/mx;

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


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long int long64;

long64 fact(long64 n){
	if(n==1) return 1;
	else return(n*fact(n-1));
}

int main(void){
	int n;
	cin >> n;
	cout << fact((long64)n) << endl;
	return 0;
}

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

int main (){
  long long a,b;
  cin>>a>>b;
  
  for(int i=0;i<max(a,b);i++){
    if(abs(a-i)==abs(b-i)){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int a,b,n;
  while(1){
  scanf("%d ",&a);
  scanf("%d",&b);
    if(3<=a&&a<=20&&3<=b&&b<=20)
      break;
  }
  
  if(a>b)
  {
    n=a-1;
    b=n;
  }
  else if(a<b)
  {
   n=b-1;
   a=n;
  }
  
  printf("%d",a+b);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=998244353;
const int maxn=1<<19;
int n;
ll S,a[maxn],b[maxn],iv2;
ll ksm(ll x,ll y) {
	ll res=1;
	while (y) {
		if (y&1) res=res*x%mod;
		x=x*x%mod; y>>=1;
	} return res;
}
void FWT(ll *a,int flag) {
	for (int i=1;i<n;i*=2)
	for (int j=0;j<n;j+=i*2)
	for (int k=0;k<i;k++) {
		int x=a[j+k],y=a[i+j+k];
		a[j+k]=(x+y)%mod,a[i+j+k]=(x-y+mod)%mod;
		if (flag==-1) a[j+k]=a[j+k]*iv2%mod,a[i+j+k]=a[i+j+k]*iv2%mod;
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	iv2=ksm(2,mod-2);
	
	read(n); n=1<<n;
	for (int i=0;i<n;i++) read(b[i]),S=(S+b[i])%mod;
	S=ksm(S,mod-2);
	for (int i=0;i<n;i++) b[i]=b[i]*S%mod;
	b[0]=(b[0]-1+mod)%mod;
	
	a[0]=n-1;
	for (int i=1;i<n;i++) a[i]=mod-1;
	
	FWT(a,1);
	FWT(b,1);
	
	int pos=0;
	for (int i=0;i<n;i++) {
		if (b[i]) a[i]=a[i]*ksm(b[i],mod-2)%mod;
		else a[i]=0,pos=i;
	}
	FWT(a,-1);
	
	ll tmp=(mod-a[0])*n%mod;
	
	FWT(a,1);
	a[pos]=tmp;
	FWT(a,-1);
	for (int i=0;i<n;i++) printf("%lld\n",a[i]);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 11008
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.length()<=k)
    {
        cout<<s<<endl;
    }
    else
    {
        for(int i=0;i<k;i++)
        {
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
}


Measured memory_bytes: 3100
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;
  for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}

Measured memory_bytes: 2476
n=int(input())
zoro=0
L=False
for i in range(n):
  p,q=map(int,input().split())
  if p==q:
    zoro+=1
    if zoro==3:
      L=True
  else:
    zoro=0
if L:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9176
#include <iostream>
#include <string>
using namespace std;
int main(){
    string S;
    cin >> S;
    int bn,t;
    t=0;
    bn = S.size()-1;
    for(int i=0;bn>0;i++){
        if (S[bn]=='m' && S[bn-1]=='a' && S[bn-2]=='e' && S[bn-3]=='r' && S[bn-4]=='d'){
            bn-=5;
        }
        else if (S[bn]=='r' && S[bn-1]=='e' && S[bn-2]=='m' && S[bn-3]=='a' && S[bn-4]=='e' && S[bn-5]=='r' && S[bn-6]=='d'){
            bn-=7;
        }
        else if (S[bn]=='e' && S[bn-1]=='s' && S[bn-2]=='a' && S[bn-3]=='r' && S[bn-4]=='e'){
            bn-=5;
        }
        else if(S[bn]=='r' && S[bn-1]=='e' && S[bn-2]=='s' && S[bn-3]=='a' && S[bn-4]=='r' && S[bn-5]=='e'){
            bn-=6;
        }
        else {
            t++;
            break;
        }
    }
    if(t==0){
        cout << "YES" <<endl;
    }
    else{
        cout << "NO" <<endl;
    }
}

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

int main() {
    int N;
    cin >> N;
  
  	int m;
  	m = N %10;
  	switch(m) {
      case 3:
        cout << "bon" << endl;
        break;
        
      case 0:
      case 1:
      case 6: 
      case 8:
        cout << "pon" << endl;
        break;
        
      default:
        cout << "hon" << endl;
        break;
        
    }
}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N,A,x,y;
  cin>>N;
  vector<int> tru(N);
 vector<vector<int>> data(N, vector<int>(N));
  
  rep(i,N){rep(j,N){data.at(i).at(j)=-1;}}
  rep(i,N){cin>>A;
          rep(j,A){cin>>x>>y;
                  data.at(i).at(x-1)=y;}
          }
  
  int Ans=0;
  int tmp=0;
  int flg=1;
 
  for (int bit = 0; bit < (1<<N); ++bit){
    for (int i = 0; i < N; ++i) {
      if (bit & (1<<i)){tru.at(i)=1;tmp++;}
      else{tru.at(i)=0;}
    }

    
    rep(k,N){if(tru.at(k)==1){
      rep(l,N){if(data.at(k).at(l)==1&&tru.at(l)==0){flg=0;}
               if(data.at(k).at(l)==0&&tru.at(l)==1){flg=0;}
              }
    }
    
            }      
            if(flg==1){Ans=max(Ans,tmp);}   
    flg=1;tmp=0;
}
  cout<<Ans<<endl;
}

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

using namespace std;

long long int k, n, i, j, a, b, a1, b1, c, h;
const int maxn = 100 + 1;
int e[maxn][maxn];
int q[maxn];
int w[maxn];

int main()
{
	string s;
	cin >> s;
	n = s.size();
	for(i = 0; i < n; i++) {
		if(s[i] == 'N'){
			a++;
		}
		if(s[i] == 'S') {
			a1++;
		}
		if(s[i] == 'W') {
			b++;
		}
		if (s[i] == 'E') {
			b1++;
		}
	}
	if(((a == 0 and a1 > 0) or (a1 == 0 and a > 0)) or ((b == 0 and b1 > 0) or (b1 == 0 and b > 0))){
		cout <<"No";
	}
	else{
		cout << "Yes";
	}
}

Measured memory_bytes: 256
n,m,k = gets.split(" ").map(&:to_i)
a = gets.split(" ").map(&:to_i)
b = gets.split(" ").map(&:to_i)

as = [0]
a.each_with_index do |v, i|
  as[i+1] = v + as[i]
end

bs = [0]
b.each_with_index do |v, i|
  bs[i+1] = v + bs[i]
end

max = 0
as.each_with_index do |at, an|
  t = k - at
  break if t < 0
  
  bn = 0
  left = 0
  right = m
  loop do
    if t == bs[right]
      bn = right
      break
    else
      center = (left + right) / 2
      if center == left
        bn = left
        break
      elsif bs[center] <= t
        left = center
      else
        right = center
      end
    end
  end
  
  max = [max, an + bn].max
end

puts max

Measured memory_bytes: 50556
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=1e9+7;
const int MAX=1010;
//Ford-Fulkerson
struct edge{
    int to,cap,rev;
};

vector<edge>G[MAX];
vector<int>level(MAX);
vector<int>iter(MAX);

void add_edge(int from,int to,int cap){
    int ts=G[to].size();
    int fs=G[from].size();
    G[from].push_back((edge){to,cap,ts});
    G[to].push_back((edge){from,0,fs});
}

void bfs(int s){
    for(int i=0;i<MAX;i++)level[i]=-1;
    queue<int>q;
    level[s]=0;
    q.push(s);
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(auto &e:G[v]){
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[v]+1;
                q.push(e.to);
            }
        }
    }
}

int dfs(int v,int t,int f){
    if(v==t)return f;
    for(auto &e:G[v]){
        if(e.cap>0&&level[v]<level[e.to]){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow=0;
    while(1){
        bfs(s);
        if(level[t]<0)return flow;
        for(int i=0;i<iter.size();i++)iter[i]=0;
        int f;
        while((f=dfs(s,t,inf))>0){
            flow+=f;
        }
    }
}

signed main(){
    ll h,w;cin>>h>>w;
    vector<string>g(h);
    rep(i,h){
        cin>>g[i];
    }
    ll s=0,t=h+w+1;
    ll sx,sy,tx,ty;
    rep(i,h){
        rep(j,w){
            if(g[i][j]=='S'){
                sx=i,sy=j;
                add_edge(0,i+1,inf);
                add_edge(0,h+j+1,inf);
            }
            if(g[i][j]=='T'){
                tx=i,ty=j;
                add_edge(i+1,h+w+1,inf);
                add_edge(j+h+1,h+w+1,inf);
            }
            if(g[i][j]=='o'){
                add_edge(i+1,h+j+1,1);
                add_edge(h+j+1,i+1,1);
            }
        }
    }
    if(sx==tx||sy==ty){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=max_flow(s,t);
    cout<<ans<<endl;
}

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define endl "\n"
// const int N=2e5+10;


void solve()
{
    int x,n;
    cin>>x>>n;

    vector<int> a(n);
    set<int> s;
    f(i,0,n)
    {
        cin>>a[i];
        s.insert(a[i]);
    }

    int ans;
    int no1=x,no2=x;
    while(1)
    {
        if(s.find(no1)==s.end())
        {
            ans=no1;break;
        }
        if(s.find(no2)==s.end())
        {
            ans=no2;break;
        }
        no1--;no2++;
    }
    cout<<ans<<endl;
    
}


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--) 
    {
        solve();
    }
    return 0;
}


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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

vector<bool> isprime;
vector<int> Era(int n) {
    isprime.resize(n, true);
    vector<int> res;
    isprime[0] = false; isprime[1] = false;
    for (int i = 2; i < n; ++i) isprime[i] = true;
    for (int i = 2; i < n; ++i) {
        if (isprime[i]) {
            res.push_back(i);
            for (int j = i*2; j < n; j += i) isprime[j] = false;
        }
    }
    return res;
}

int main(){
	vector<int> primes = Era(55556);
	vector<int> primes_1;
	for(int i = 0; i < primes.size(); ++i){
		  if(primes[i]%5==1) primes_1.push_back(primes[i]);
    }
    int n; cin >>n;
    for(int i = 0; i < n; ++i){
    	  cout << primes_1[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a[3]={"Sunny","Cloudy","Rainy"};
	string s;
	cin >> s;
	for(int i=0;i<3;i++){
		if(a[i]==s){
			if(i+1==3){
				cout << a[0];
			}
			else
			cout << a[i+1];
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
   int X, Y;
   std::cin >> X >> Y;
   if (((4*X-Y) % 2 == 0) && ((Y-2*X) % 2 == 0)){
      if ((4*X-Y >= 0) && (Y-2*X >= 0)){
         if ((4*X-Y == 0) && (Y-2*X == 0)){
            std::cout << "No" << std::endl;
         } else{
            std::cout << "Yes" << std::endl;
         }
      } else{
         std::cout << "No" << std::endl;
      }
   } else{
      std::cout << "No" << std::endl;
   }
}



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

int main() {
	long int r,D,temp;
	cin>>r>>D>>temp;
	long int x=temp;
	
	
	for(int i=0;i<10;i++){
		x=r*temp-D;
		cout<<x<<endl;
		temp=x;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template <typename T>
vector<T> dijkstra(Int s,vector<vector<pair<Int, T> > > & G){  
  const T INF = numeric_limits<T>::max();    
  using P = pair<T, Int>;
  Int n=G.size();
  vector<T> d(n,INF);
  vector<Int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s]=0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    Int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      Int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
        d[u]=d[v]+c;
        b[u]=v;
        q.emplace(d[u],u);
      }
    }
  }
  return d;
}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  Int s,t;
  cin>>s>>t;
  s--;t--;
  vector<Int> d(n);
  for(Int i=0;i<n;i++) cin>>d[i];
  using P = pair<Int, Int>;
  vector<vector<P> > G(n);
  for(Int i=0;i<m;i++){
    Int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b,d[b]);
  }
  for(Int i=0;i+1<n;i++) G[i+1].emplace_back(i,0);
  cout<<dijkstra(s,G)[t]<<endl;
  return 0;
}



Measured memory_bytes: 15156
import java.util.Scanner;


public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		
		String a[] = new String[H];
		
		for(int i=0;i<H;i++){
			a[i] = sc.next();
		}
		
		for(int j=0;j<W+2;j++){
			System.out.print("#");
		}
			System.out.print("\n");

		
		for(int k=0;k<H;k++){
			System.out.println("#"+a[k]+"#");
		}

		for(int j=0;j<W+2;j++){
			System.out.print("#");
		}
			System.out.print("\n");
		
		
	}

}

Measured memory_bytes: 22868
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int ans = 0;
  for (int i = n - 1; i >= n - k; i--) ans += a[i];
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<queue>
#include<set>
typedef long long ll;
using namespace std;


int main(){
    int n,w;
    cin>>n>>w;
    vector<int>val(n+1);
    vector<int>cost(n+1);
    for(int i=1;i<=n;i++){
        cin>>cost[i]>>val[i];
    }
    vector<vector<long long>>dp(n+1,vector<long long>(w+1,0));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            dp[i][j] = j < cost[i] ? dp[i-1][j] : max(val[i] + dp[i-1][j-cost[i]],dp[i-1][j]);
        }
    }
    
    cout<<dp[n][w]<<endl;
    return 0;
}

Measured memory_bytes: 80256
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.Char
import Control.Monad

count :: Int -> Int
count n 
    | n `rem` 4 == 0 = 2
    | n `rem` 2 == 0 = 1
    | otherwise = 0 

classify :: VUM.IOVector Int -> Int -> IO ()
classify vec n
    | c == 0 = VUM.modify vec (+1) 0
    | c == 1 = VUM.modify vec (+1) 1
    | c >= 2 = VUM.modify vec (+1) 2
    | otherwise = return ()
    where
        c = count n

main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    res <- VUM.replicate 3 0
    forM_ [0..n-1] $ \i -> classify res (xs VU.! i)
    r <- VUM.read res 0
    s <- VUM.read res 1
    t <- VUM.read res 2
    
    if (s == 0)
        then putStrLn $ if t >= (r-1) then "Yes" else "No"
        else putStrLn $ if t >= r then "Yes" else "No"

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> f(m, n);
  for(int i=0; i<n; i++) {
    int k;
    cin >> k;
    for(int j=0; j<k; j++) {
      int a;
      cin >> a;
      f.at(a-1)--;
    }
  }
  int count = 0;
  for(int i=0; i<m; i++) {
    if(f.at(i) == 0) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n,m int
	fmt.Scan(&n,&m)

	d := make([][]int,m)
	for i := 0; i < m; i++ {
		var k int
		fmt.Scan(&k)
		for j := 0; j < k; j++ {
			var s int
			fmt.Scan(&s)
			d[i] = append(d[i],s)
		}
	}

	p := make([]int,m)
	for i := 0; i < m; i++ {
		fmt.Scan(&p[i])
	}

	ans := 0

	for i := 0; i < (1<<uint(n)); i++ {
		f := true
		for j := 0; j < m; j++ {
			on := 0
			for _, e := range d[j] {
				if i & (1<<uint(e-1)) == (1<<uint(e-1)) {
					on++
				}
			}

			if on%2 != p[j] {
				f = false
				break
			}
		}

		if f {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
import sys
readline = sys.stdin.readline

def solve():
    N = int(readline())
    C = readline().rstrip()

    reds = [i for i in range(len(C)) if C[i] == 'R']
    whites = [i for i in range(len(C)) if C[i] == 'W']

    i = 0
    n = min(len(reds), len(whites))
    while i < n and reds[-1-i] > whites[i]:
        i += 1
    
    print(i)

solve()

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

string s;
int r, b;
int main() {
    scanf("%*d");
    cin >> s;
    for(auto g : s) {
        if(g == 'R') r++;
        else if(g == 'B') b++;
    }
    if(r > b) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  ll N;
  cin >> N;
  ll result = 1;
  for (ll i = 1; i <= N; i++) {
    result = result * i % 1000000007;
  }
  cout << result << endl;
}

Measured memory_bytes: 256