akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

UL J[3001][3001]={};
UL O[3001][3001]={};
UL I[3001][3001]={};

int main(){
 UL H,W; scanf("%u%u",&H,&W);
 rep(y,H){
  scanf(" ");
  rep(x,W){
   char c; scanf("%c",&c);
   if(c=='J') J[y][x]++;
   if(c=='O') O[y][x]++;
   if(c=='I') I[y][x]++;
  }
 }

 ULL ans=0;
 for(UL y=H-1; y!=~0u; y--) for(UL x=W-1; x!=~0u; x--){
  O[y][x]+=O[y][x+1];
  I[y][x]+=I[y+1][x];
  if(J[y][x]) ans+=O[y][x]*I[y][x];
 }

 printf("%llu\n",ans);

 return 0;
}



Measured memory_bytes: 108704
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
signed main(){
	int n,ans=0;
	cin>>n>>n;
	vector<P>v(n);
	r(i,n){
		int a,b;
		cin>>a>>b;
		v[i]=P(b,a);
	}
	sort(v.begin(),v.end());
	int now=-1;
	r(i,n){
		int en=v[i].first;
		int st=v[i].second;
		if(now<=st)now=en,ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1920
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;


class P
{
    static void Main()
    {
        int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        bool[] contained = new bool[hw[1]];
        List<char[]> map = new List<char[]>();
        for (int _ = 0; _ < hw[0]; _++)
        {
            char[] line = Console.ReadLine().ToArray();
            if (line.All(x => x != '#')) continue;
            map.Add(line);
            for (int i = 0; i < hw[1]; i++) contained[i] |= line[i] == '#';
        }
        Console.WriteLine(string.Join("\n", map.Select(x => string.Join("", x.Where((_, ind) => contained[ind])))));
    }
}


Measured memory_bytes: 13524
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,temp;
  cin>>a>>b>>c;
  temp=a;
  a=b;
  b=temp;
  temp=a;
  a=c;
  c=temp;
  cout<<a<<" "<<b<<" "<<c;
  
}
  

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

int n, m;
int a[100010]; // delay
int b[100010]; // reward

int main() {
    while (cin >> n >> m) {
        for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
        vector<pair<int,int>> tasks(n); // delay, reward
        for (int i = 0; i < n; ++i) tasks[i] = make_pair(a[i], b[i]);
        sort(tasks.begin(), tasks.end());
        reverse(tasks.begin(), tasks.end());

        priority_queue<pair<int,int>> queue; // (reward, delay)
        int ans = 0;
        for (int i = 1; i <= m; ++i) {
            while (tasks.size() > 0 && tasks.back().first <= i) {
                int d, r;
                tie(d, r) = tasks.back();
                tasks.pop_back();
                queue.emplace(r, d);
            }
            if (queue.size() > 0) {
                int d, r;
                tie(r, d) = queue.top();
                queue.pop();
                ans += r;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
int main(){
       int a,b;
       string s;
       cin>>a>>b>>s;
       for(int i=0;i<s.size();i++){
           if(i==a){
              if(s[i]=='-'){
                 continue; 
              }
              else{
                 cout<<"No"<<endl;
                 return 0;
              }
           }
           else{
            if(s[i]=='-'){
               cout<<"No"<<endl;
               return 0;
            }
            else{
             continue;   
            }
           }
       }
       cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
vector<int>adj[200005];
int vis[200005];
int level[200005];
void bfs(int n){
    vis[n]=1;
    queue<int>Q;
    Q.push(n);
    while(!Q.empty()){
        int u=Q.front();
        Q.pop();
        for(int i=0;i<adj[u].size();i++){
            int v=adj[u][i];
            if(vis[v]==0){
                Q.push(v);
                vis[v]=1;
                level[v]=u;
            }
        }
    }
}
int main(){
    Fast;
    int n,m;
    cin>>n>>m;
    int ok=0;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        if(u==1 || v==1){
            ok=1;
        }
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if(ok){
        bfs(1);
        cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++){
            cout<<level[i]<<endl;
        }
        return 0;
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 13316
s, t = input(), input()
ret = len(t)
for i in range(len(s)-len(t)+1):
    u = s[i:len(t)+i]
    count_diff = 0
    for j in range(len(u)):
        if u[j] != t[j]:
            count_diff += 1
    ret = min(ret, count_diff)
print(ret)

Measured memory_bytes: 67760
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)
  val a = sc.nextInt()
  val b = sc.nextInt()

  private val res: String = if (a > b) {
    Seq.fill(a)(b.toString).reduce(_ ++ _)
  } else {
    Seq.fill(b)(a.toString).reduce(_ ++ _)
  }
    println(res)

}



Measured memory_bytes: 25416
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int>as(N);
	for (int i = 0; i < N; i++)
	{
		cin >> as[i];
	}
	sort(as.begin(), as.end());
	int Alice = 0;
	int Bob = 0;
	for (int i = N - 1; i >= 0; i = i - 2)
	{
		Alice += as[i];
	}
	for (int i = N - 2; i >= 0; i = i - 2)
	{
		Bob += as[i];
	}
	int ans = Alice - Bob;
	cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
constexpr int INF = (numeric_limits<int>::max() == INT_MAX ? (int)1e9 : (long long)1e18);
constexpr long double eps = 1e-6;
const string el = "\n";
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;using pii = pair<int,int>;using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void fast_io(){ios::sync_with_stdio(false); cin.tie(nullptr);}
int out(int a){cout << a << el; return 0;}
int out(string s = "NO"){cout << s << el; return 0;}
template <class T>
inline int out(vector<T>&v,string c = " "){
    for(int i = 0; i < v.size(); ++i){
        if(i) cout << c; cout << v[i];
    } cout << el;return 0;
}
signed main(){
    int H,N; cin >> H >> N;
    vector<string>s(H);
    for(auto& t : s) cin >> t;
    string t(N + 2,'#');
    cout << t << endl;
    for(auto e : s) cout << '#' << e << '#' << endl;
    cout << t << el;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  ll x;
  cin >> x;
  x = abs(x);
  ll k,d;
  cin >> k >> d;
  if(k < (x+d-1)/d){
    cout << x-k*d << endl;
  }
  if(k >= (x+d-1)/d){
    if(k%2 == 1) x += d;
    cout << min(x%(2*d),2*d-x%(2*d)) << endl;
  }
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
/**************************************************************************/
const int N = 2e5+2;
vector<int> adj[N];
int visit[N];
int a[N];
void dfs(int src,int add)
{
    visit[src] = 1;
    a[src]+=add;
    for(auto it:adj[src])
    {
        if(!visit[it])
        {
            dfs(it,a[src]);
        }
    }
}
signed main()
{
    fast;
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n-1;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(int i=0;i<q;i++)
    {
        int inc,root;
        cin>>root>>inc;
        a[root]+=inc;
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
        cout<<a[i]<<" ";
}

Measured memory_bytes: 22784
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let s: Vec<_> = sc
        .chars()
        .into_iter()
        .map(|c| c as usize - 'a' as usize)
        .collect();
    let n = s.len();

    let mut hash = 0;
    let mut dp: Vec<u32> = vec![n as u32; 1 << 26];
    let mut opt = vec![n as u32; n + 1];
    opt[0] = 0;
    for i in 0..n {
        hash ^= 1 << s[i];
        for j in 0..26 {
            let x = 1 << j;
            opt[i + 1] = cmp::min(opt[i + 1], dp[hash ^ x] + 1);
        }
        if hash.count_ones() <= 1 {
            opt[i + 1] = 1;
        }
        opt[i + 1] = cmp::min(opt[i + 1], dp[hash]);
        dp[hash] = cmp::min(dp[hash], opt[i + 1]);
    }
    println!("{}", opt[n]);
}

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: 268668
#include <bits/stdc++.h>
using namespace std;



int main() {
	long long a, b, k;
	cin >> a >> b >> k;
	long long x = min(a, k);
	a -= x;
	k -= x;
	x = min(b, k);
	b -= x;

	cout << a << " " << b;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    bool answered = false;
    for(int i = 0; i < s.length() && i < t.length(); i++){
        if(s[i] > t[i]){
            cout << "No" << endl;
            answered = true;
            break;
        }else if(s[i] < t[i]){
            cout << "Yes" << endl;
            answered = true;
            break;
        }
    }
    if(answered == false){
        if(s.length() < t.length()){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try(Scanner scanner = new Scanner(System.in)) {
            int num1 = scanner.nextInt();
            int num2 = scanner.nextInt();
            if ((num1 * num2) % 2 == 0) {
                System.out.println("Even");
            } else {
                System.out.println("Odd");
            }
        }
    }
}


Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

#define MOD 2019

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	long long A[100004] = {0};
	long long B[100004] = {0};
	long long C[100004] = {0};

	cin >> N;
	for(int i=1; i<=N+1; i++){ cin >> A[i]; }
	for(int i=1; i<=N; i++){ cin >> B[i]; }

	long long ans = 0;
	for(int i=1; i<=N; i++){
		if(C[i - 1] < B[i - 1]){
			ans += ( min(A[i], B[i - 1] - C[i - 1]) );
			A[i] = max(A[i] - (B[i - 1] - C[i - 1]), 0LL);
		}
		C[i] = min(B[i], A[i]);
		ans += C[i];
	}
	ans += (min(A[N + 1], B[N] - C[N]));

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

Measured memory_bytes: 2560
/*******************************
* BASMILLAHHIR RAHMANNIR RAHIM *
* MD SHAHINUR RAHMAN           *
* DATE: 16/sep/2020            *
* DEPT. OF CSE                 *
* LEADING UNIVERSITY, SYLHET   *
*******************************/
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<string>
#include<stdlib.h>
#include<math.h>
#define shahin std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
const int nax=1000*1007;
const int mod = 1e9 + 7;
 
using namespace std;
char wcz[nax];
 
bool fu(int a, int b){
    return (a>b);
}
int gcd(int x,int y){
    return x?gcd(y%x, x):y;
}
 
void fun(){
    ll n,s=0;
    cin >> n;
    
    for(int i=1;i<=n;i++){
                    ll a = (n-1)/i;
                    s += a;
    }
    
    cout << s << endl;
}
int main()
{
    shahin
 /*   int tc,i=1,sum=0,A=0,B=0;
    cin >> tc;
    while(tc--)
    {
    //cout << "Case " << i << ": ";
        fun();
    //i++;
    }*/ 
    fun();
   
}

Measured memory_bytes: 3648
/* Focus your enery towards light */

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(int i=0;i<n;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265
#define inf 1e18

/******************************************************************************************************/
void file() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
/******************************************************************************************************/

// const ll nax = 2e5 + 1;
// const ll mod = 1e9 + 7;



int main() {

    sync

    int testCases = 1;
    // cin >> testCases;

    while (testCases--) {
        int n;
        cin >> n;
        vector<int> ans(n + 1);

        fore (i, 1, n) {
            fore (j, 1, n) {
                int x = i, y = j, z = 0;
                int oh = x * x + y * y + z * z + x * y + y * z + x * z;
                if (oh > n) break;
                fore (k, 1, n) {
                    int x = i, y = j, z = k;
                    int oh = x * x + y * y + z * z + x * y + y * z + x * z;
                    if (oh > n) break;
                    ans[oh]++;
                }
            }
        }
        fore (i, 1, n) {
            cout << ans[i] << endl;
        }
    }
    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vvi vector<vector<int>>;
#define mi  map<int,int>
#define mii map<pii,int>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(x) (int)x.size()
#define all(v) (v).begin(), (v).end()
#define ret(x) return cout<<x,0;
#define rety return cout<<"YES",0;
#define retn return cout<<"NO",0;
#define fl fflush(stdout)   
#define hell 1000000007  
#define hell2 998244353 
#define pi 3.14159265358979323846

int solve(){
    int x,a,b,c,t=0;
    cin>>a>>b>>c>>x;
    rep(i,0,min(a+1,x/500+1)){
        int y=x-500*i;
        rep(j,0,min(b+1,y/100+1)){
            int z=y-100*j;
            if(z/50<=c)t++;//,cout<<i<<" "<<j;
          /*  rep(k,0,min(c,z/50+1)){
                t++;
                cout
            }*/
        }
    }
    cout<<t;
    return 0;
}

signed main(){
    auto start = high_resolution_clock::now();
    IOS;
    int t=1;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
   // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cerr<<"Time taken:"<<duration.count()/1000000.0<<"seconds"<<"\n";
    return 0;
} 

Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
using namespace std;

bool all[110*60+1], one[110*60+1];

inline int fix(int t) { return t / 100 * 60 + t % 100; }

int main()
{
  int n, p, q;
  while (cin >> n >> p >> q, n | p | q) {
    p = fix(p); q = fix(q);
    memset(all, true, sizeof(all));
    for (int i = 0; i < n; ++i) {
      int k; cin >> k;
      memset(one, false, sizeof(one));
      for (int j = 0; j < k; ++j) {
        int s, t; cin >> s >> t;
        s = fix(s); t = fix(t);
        for (int l = s; l < t; ++l) {
          one[l] = true;
        }
      }
      for (int j = p; j < q; ++j) {
        all[j] &= one[j];
      }
    }
    int ans = 0, len = 0;
    all[q] = true;
    for (int i = p; i <= q; ++i) {
      if (all[i]) {
        ans = max(ans, len);
        len = 0;
      } else {
        ++len;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))

s = sum(a[::2]) - sum(a[1::2])
ans = []

for i in range(n):
  ans.append(s)
  s = 2 * a[i] - s

print(' '.join(list(map(str, ans))))

Measured memory_bytes: 19148
using System;
using System.Linq;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            int[] input;
            while(((input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray())[0] | input[1]) != 0) {
                for(int i = 0; i < input[0]; ++i){
                    Console.WriteLine(new String('#', input[1]));
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 5720
n = int(input())
a = list(map(int,input().split()))
c = 1
flag = True
for _ in a:
    c *= _
    if c > 10**18:
        flag = False
        c = 1
    if c == 0:
        print(0)
        quit()
if flag:
    print(c)
else:
    print(-1)

Measured memory_bytes: 21600
#include <stdio.h>

int n, A[50];

int solve(int i, int m) {
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(void) {
    int q, M, i;

    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++) {
        scanf("%d", &M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2040
#include <stdio.h>

int main(void) 
{
	int n, x;
	while (scanf("%d%d", &n, &x) == 2 && (n | x) != 0) 
	{
		int i, j;
		int count = 0;
		for (i = 1; i <= n; i++)
		{
			for (j = i + 1; j <= n; j++) 
			{
				int k = x - i - j;
				if (j < k && k <= n) count++;
			}
		}
		printf("%d\n", count);
	}
	return 0;
}


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

using namespace std;

int main(){
	string s;
	cin >> s;
	int ans1,ans2;
	ans1=ans2=0;
	for(int i=0;i<s.size();i++){
		if(i%2==0){
			ans1+=(s[i]!='1');
			ans2+=(s[i]!='0');
		}
		else{
			ans1+=(s[i]!='0');
			ans2+=(s[i]!='1');
		}
	}
	cout << min(ans1,ans2) << endl;
	return 0;
}


Measured memory_bytes: 512
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    let answer = 0;
    
    for(let i=1; i<=N; i++) {
        let temp;
        let x = 1 / N;
        
        if(i >= K) {
            answer += x * 1;
        } else {
            let j = 0;
            
            while(i * Math.pow(2, j) < K) {
                j++;
            }
            
            let y = Math.pow((1 / 2), j);
            answer += x * y;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<stdio.h>

int main(void)
{
  char a[5];
  scanf("%s", a);
  if(a[0] == a[1] && a[1] == a[2])
  {
    printf("No\n");
  }
  else
  {
    printf("Yes");
  }
  
  return (0);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define inf 0x7f7f7f7f7f7f7f7f 
#define maxn 1000010
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define mod 998244353
#define db(x) cout << x << endl; 
#define eps 0.0001
using namespace std;
int a[50][50],c[50];
int v[20];
int ans[maxn];
int ss=inf;
int n,m,x;
int sum = 0;
il void update(int x,int op)
{
	if(op)
	for(int i=1;i<=m;i++)
		ans[i] += a[x][i];
	else
		for(int i=1;i<=m;i++)
		ans[i] -= a[x][i];
}
void dfs(int p)
{
	update(p,1);
	sum+=c[p];
	int flag = 1;
	for(int i=1;i<=m;i++)
		if(ans[i] < x)
			flag = 0;
	if(flag)
	{
		ss = min(sum,ss);
		return;
	}
	for(int i=p+1;i<=n;i++)
	{
		dfs(i);
		sum-=c[i];
		update(i,0);
	}
}
signed main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m >> x;
	for(int i=1;i<=n;i++)
	{
		cin >> c[i];
		for(int j=1;j<=m;j++)
			cin >> a[i][j],ans[j]+=a[i][j];
	}
	for(int i=1;i<=m;i++)
	{
		if(ans[i]<x)
		{
			cout<<-1;
			return 0;
		}
	}
	for(int i=1;i<=m;i++)
		ans[i] = 0;
	for(int i=1;i<=n;i++)
	{
		dfs(i);
		sum-=c[i];
		update(i,0);
	}
	cout << ss;
	return 0;
}

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

using namespace std;

bool check[200001];

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

	memset(check,true,sizeof(check));
	string s;

	cin >> s;

	stack <int> stk;

	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='S')
		{
			stk.push(i);
		}
		else
		{
			if(!stk.empty())
			{
				check[stk.top()] = false;
				stk.pop();
				check[i] = false;
			}
		}
	}

	int res = s.length();
	for(int i=0;i<s.length();i++)
	{
		if(check[i]==false)
		{
			res-=1;
		}
	}

	cout << res << '\n';
	
	return 0;
}

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

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

int main(){
	int n;
	cin >> n;
	int ans=0;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		ans=gcd(ans,a);
	}
	cout << ans << endl;
	return 0;
}


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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define X first
#define Y second

using namespace std;

int n, m;
vector<int> vx, vy;
int tx[5005], ty[5005], unzipx[5005], unzipy[5005], imos[5005][5005];
map<int, int> zipx, zipy;
pair< pair<int,int>, pair<int,int> > p[500005];

int main() {
  cin>>n>>m;
  REP(i,0,n){
    cin>>tx[i]>>ty[i];
    vx.push_back(tx[i]);
    vy.push_back(ty[i]);
  }
  REP(i,0,m){
    cin>>p[i].F.X>>p[i].F.Y>>p[i].S.X>>p[i].S.Y;
  }

  //compression
  sort(vx.begin(), vx.end());
  sort(vy.begin(), vy.end());
  //vx.erase(.unique(vx.begin(), vx.end()), vx.end());
  //vy.erase(unique(vy.begin(), vy.end()), vy.end());
  REP(i,0,vx.size()){
    zipx[vx[i]] = i;
    unzipx[i] = vx[i];
  }
  REP(i,0,vy.size()){
    zipy[vy[i]] = i;
    unzipy[i] = vy[i];
  }

  //Initializing imos array
  REP(i,0,5005)REP(j,0,5005) imos[i][j] = 0;
  REP(i,0,n){
    imos[zipy[ty[i]]][zipx[tx[i]]]++;
  }
  //creating imos array
  REP(i,0,vy.size()){
    REP(j,1,vx.size()){
      imos[i][j] += imos[i][j-1];
    }
  }
  REP(j,0,vx.size()){
    REP(i,1,vy.size()){
      imos[i][j] += imos[i-1][j];
    }
  }

  REP(i,0,m){
    /*
    cout<<"xSize:"<<vx.size()<<", "<<"ySize:"<<vx.size()<<endl;
    cout<<"test: "<<(lower_bound(vx.begin(),vx.end(),p[i].F.X)-vx.begin())<<" ";
    cout<<(lower_bound(vy.begin(),vy.end(),p[i].F.Y)-vy.begin())<<" ";
    cout<<(lower_bound(vx.begin(),vx.end(),p[i].S.X)-vx.begin())<<" ";
    cout<<(lower_bound(vy.begin(),vy.end(),p[i].S.Y)-vy.begin())<<endl;
    */
    vector<int>::iterator a1x = lower_bound(vx.begin(),vx.end(),p[i].F.X),
      a1y = lower_bound(vy.begin(),vy.end(),p[i].F.Y),
      a2x = upper_bound(vx.begin(),vx.end(),p[i].S.X)-1,
      a2y = upper_bound(vy.begin(),vy.end(),p[i].S.Y)-1;
    int z1x = zipx[*a1x], z1y = zipy[*a1y], z2x = zipx[*a2x], z2y = zipy[*a2y];
    int ans = imos[z2y][z2x];
    if(z1y > 0) ans -= imos[z1y-1][z2x];
    if(z1x > 0) ans -= imos[z2y][z1x-1];
    if(z1y > 0 && z1x > 0) ans += imos[z1y-1][z1x-1];

    if(p[i].F.Y > unzipy[vy.size()-1] || p[i].F.X > unzipx[vx.size()-1]) cout<<0<<endl;
    else if(p[i].S.Y < unzipy[0] || p[i].S.X < unzipx[0]) cout<<0<<endl;
    else cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 109420
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int count(int N)
{
        int cnt = 0;
        while (N)
        {
                cnt += N % 10;
                N /= 10;
        }
        return cnt;
}

int main()
{
        int W, H, N;
        cin >> W >> H >> N;
        int Xmi = 0, Ymi = 0;
        rep(i, N)
        {
                int x, y, a;
                cin >> x >> y >> a;
                if (a == 1)
                {
                        Xmi = max(Xmi, x);
                }
                else if (a == 2)
                {
                        W = min(W, x);
                }
                else if (a == 3)
                {
                        Ymi = max(Ymi, y);
                }
                else
                {
                        H = min(H, y);
                }
        }
        int ans = 0;

        if (W - Xmi > 0 && H - Ymi > 0)
        {

                ans = (W - Xmi) * (H - Ymi);
        }
        cout << ans << endl;

        return 0;
}


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

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

    int ans = 1;
    int d = 0;
    rep(i, n) {
        int l;
        cin >> l;
        d += l;
        if (d <= x) ans++;
    }

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


Measured memory_bytes: 256
unittest
{
	assert( [ "5 3", "3 1 4", "1 5 9", "2 6 5", "3 5 8", "9 7 9" ].solve == 56 );
	assert( [ "5 3", "1 -2 3", "-4 5 -6", "7 -8 -9", "-10 11 -12", "13 -14 15" ].solve == 54 );
	assert( [ "10 5", "10 -80 21", "23 8 38", "-94 28 11", "-26 -2 18", "-69 72 79", "-26 -86 -54", "-72 -50 59", "21 65 -32", "40 -94 87", "-62 18 82" ].solve == 638 );
	assert( [ "3 2", "2000000000 -9000000000 4000000000", "7000000000 -5000000000 3000000000", "6000000000 -1000000000 8000000000" ].solve == 30000000000 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	auto xyzs = new long[ 3 ][ n ];
	foreach( ref xyz; xyzs )
	{
		input.popFront;
		xyz = input.front.split.to!( long[] );
	}
	
	auto ans = 0L;
	ans = max( ans, solve2( m, xyzs, [ +1L, +1L, +1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ +1L, +1L, -1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ +1L, -1L, +1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ +1L, -1L, -1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L, +1L, +1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L, +1L, -1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L, -1L, +1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L, -1L, -1L ] ) );
	return ans;
}

auto solve2( long m, long[ 3 ][] xyzs, long[ 3 ] ss )
{
	auto ts = new long[ xyzs.length ];
	foreach( ref t, xyz; lockstep( ts, xyzs ) )
	{
		t += xyz[ 0 ] * ss[ 0 ] + xyz[ 1 ] * ss[ 1 ] + xyz[ 2 ] * ss[ 2 ];
	}
	ts.sort!( ( a, b ) => b < a );
	return ts[ 0 .. m ].sum;
}


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

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

	int n;
	cin>>n;
	multiset<int> present;
	vector<int> arr;
	for(int i=0; i<n; ++i){
		int x; cin>>x;
		present.insert(x);
		arr.push_back(x);
	}
	int ans = 0;
	for(int i=0; i<n; ++i){
		present.erase(present.find(arr[i]));
		bool ok = true;
		for(int j=1; j<=sqrt(arr[i]); ++j){
			if( arr[i] % j == 0 ){
				int f1 = j;
				int f2 = arr[i] / j;
				if( present.find(f1) != present.end() ){ ok=false; break;}
				if( present.find(f2) != present.end() ){ ok=false;
				break;}
			}
		}
		if(ok){ ans++; }
		present.insert(arr[i]);
	}
	cout<<ans<<'\n';


	return 0;
}


Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
   
   int s, t;
   cin >> s >> t;
   if(s <= t)
  	cout << "unsafe";
   else
   cout << "safe";
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;
#define mp make_pair
const int mod = 1e9+7;

signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(auto& i:a)cin>>i;
  int suma=0,land=0;
  for(auto i:a)suma=(suma+i)%mod;
  int res=0;

  bool ref=true;
  int p=1,cnt,ps=0;
  while(ref){
    ref=false;
    cnt=ps=0;
    for(auto& i:a)if(i){
      ref=true;
      if(i&1)++cnt;
      i>>=1;
    }
    ps=cnt%mod*cnt%mod*p%mod;
    land=(land+ps)%mod;
    p<<=1;
    p%=mod;
  }
  res=suma%mod*n%mod;
  res=(res-land)%mod;
  while(res<0)res+=mod;
  cout<<res%mod<<endl;
}

Measured memory_bytes: 2560
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N, K = map(int,input().split())
As = list(map(int,input().split()))
As.sort()

fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)

rlt = 0
for i in range(N-K+1):
  rlt += (As[-i-1] - As[i])*cmb(N-i-1,K-1,p)
  rlt %= p
  
print(rlt)

Measured memory_bytes: 104268
import java.awt.Point;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	final static PrintStream so = System.out;
	final static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int H = sc.nextInt();
		int W = sc.nextInt();
		int[][] s = new int[H][W];
		int dots = 0;
		
		for (int h = 0; h < H; h++) {
			String line = sc.next();
			
			for (int w = 0; w < W; w++) {
				s[h][w] = line.charAt(w) == '.' ? 0 : -1;
				if (s[h][w] == 0) dots++;
			}
		}
		
		Queue<Point> queue = new ArrayDeque<>();
	    /* Point(2, 3) -> s[3][2] (x, y -> w, h) */
		
		queue.add(new Point(0, 0));
		s[0][0] = 1;
		
		int[] mx = {0, 1, 0, -1};
		int[] my = {1, 0, -1, 0};
		
		while (!queue.isEmpty()) {
			Point current = queue.poll();
			int cx = current.x;
			int cy = current.y;
			
			for (int i = 0; i < my.length; i++) {
				int nx = cx + mx[i];
				int ny = cy + my[i];
				
				if (inRange(nx, 0, W) && inRange(ny, 0, H) && s[ny][nx] == 0) {
					s[ny][nx] = s[cy][cx] + 1;
					queue.add(new Point(nx, ny));
				}
			}
		}
		
		so.println(s[H-1][W-1] == 0 ? -1: dots-s[H-1][W-1]);
	}
	
	static boolean inRange(int x, int l, int r) {
		return l <= x && x < r;
	}
}


Measured memory_bytes: 23508
import math
x=int(input())
def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(math.sqrt(n)) +1):
        if n % i == 0:
            return False
    return True
for i in range(x, 100003+1):
    if is_prime(i):
        print(i)
        exit()

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

int main() {
  string S,T;
  int n, ans;
  cin >> S >> T;
  n=S.size();
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    if (S.at(i)==T.at(i)) {
      vec.at(i)=1;
    }
    else {
      vec.at(i)=0;
    }
  }
  ans=0;
  for (int j = 0; j < n; j++) {
    ans = ans + vec.at(j);
  }
  cout << n-ans << endl;
}


Measured memory_bytes: 4556
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(v) for (int i = 0; i < (v).size(); i++) { cin >> (v)[i]; }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

//for A以上B未満でI探索 for (int I = A; i <= B; i++)
//string s = to_string(i);
int a = 0, b = 0, c = 0, x = 0, y = 0, z = 0, n = 0, sum = 0;
string s = ""; asas; cncn;

int main(void) {
	cin >> a >> b >> c;
	if (a * c <= b)cout << c << rt;
	if (a * c > b)cout << b / a << rt;
	please AC;
}

Measured memory_bytes: 256
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n,m = map(int,input().split())
    p = list(map(int,input().split()))
    xy = [list(map(int,input().split())) for j in range(m)]
    un = UnionFind(n)
    for i in range(m):
        un.union(xy[i][0]-1,xy[i][1]-1)
    ans = 0
    for i in range(n):
        if un.same_group_or_no(i,p[i]-1):
            ans += 1
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================
    

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

vector<int> nums;
int n;

int main() {
	cin >> n;
	nums.push_back(1);
	for (int i = 6; i <= n; i *= 6) {
		nums.push_back(i);
	}
	for (int i = 9; i <= n; i *= 9) {
		nums.push_back(i);
	}
	sort(nums.begin(), nums.end());
	int size = nums.size();
	vector<vector<int>> dp(size, vector<int>(n + 1, INT32_MAX));
	for (int i = 0; i <= n; i++) dp[0][i] = i;
	for (int i = 0; i < size; i++) dp[i][0] = 0;
	for (int i = 1; i < size; i++) {
		for (int j = 1; j <= n; j++) {
			if (nums[i] > j) dp[i][j] = dp[i - 1][j];
			else {
				dp[i][j] = min(dp[i - 1][j], dp[i][j - nums[i]] + 1);
			}
		}
	}
	cout << dp[size - 1][n] << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	LL k;
	cin >> k;

	LL seven = 7;
	LL ans = 1;

	REP(i, static_cast<LL>(1e7)) {
		if (seven % k == 0) {
			col(ans);
			return 0;
		}
		seven = (seven * 10 + 7) % k;
		ans++;
	}

	col(-1);
	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>

int main()
{
	int i, u, w, N, M, s[21], t[21], adj[51][51] = {};
	scanf("%d", &N);
	for (i = 1; i < N; i++) {
		scanf("%d %d", &u, &w);
		adj[u][w] = i;
		adj[w][u] = i;
	}
	scanf("%d", &M);
	for (i = 0; i < M; i++) scanf("%d %d", &(s[i]), &(t[i]));
	
	int prev[51], q[51], head, tail;
	long long bit[51] = {1}, P[21] = {};
	for (i = 1; i <= 50; i++) bit[i] = bit[i-1] << 1;
	for (i = 0; i < M; i++) {
		for (u = 1; u <= N; u++) prev[u] = -1;
		q[0] = s[i];
		prev[s[i]] = s[i];
		for (head = 0, tail = 1; head < tail; head++) {
			u = q[head];
			for (w = 1; w <= N; w++) {
				if (adj[u][w] == 0) continue;
				else if (w == t[i]) break;
				else if (prev[w] == -1) {
					prev[w] = u;
					q[tail++] = w;
				}
			}
			if (w <= N) break;
		}
		for (; w != u; w = u, u = prev[u]) P[i] |= bit[adj[u][w]];
	}
	
	int j, sum[2];
	long long n, ans = (long long)1 << N - 1, white;
	for (n = 1; n < bit[M]; n++) {
		white = 0;
		for (i = 0; i < M; i++) {
			if ((n | bit[i]) == n) white |= P[i];
		}
		for (j = 1, sum[0] = 0; j < N; j++) sum[0] += white / bit[j] % 2;
		for (i = 0, sum[1] = 0; i < M; i++) sum[1] += n / bit[i] % 2;
		if (sum[1] % 2 == 1) ans -= bit[N-1-sum[0]];
		else ans += bit[N-1-sum[0]];
	}

	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

#define ll long long
#define PB push_back
#define PII pair<int, int>
#define MP make_pair
#define all(x) x.begin(), x.end()
#define REP(x, y, z) for(int x = (y); x <= (z); x++)
#define REPP(x, y, z) for(int x = (y); x >= (z); x--)
#define F first
#define S second
#define MSET(x, y) memset(x, y, sizeof(x)) 
#define EB emplace_back
#define maxn

//structure

//declaration

//functions

int main(void)
{
	#ifdef DBG
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
	#endif

	char c;
  	scanf("%c", &c);
  
  	printf("%c\n", c+1);

	return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair

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

	/*#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r+", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w+", stdout);
	#endif*/

    int n,m;
    cin >> n >> m;
    int tot = 0;
    vector <int> a(n);
    for(int i=0;i<n;i++) {
    	cin >> a[i];
    	tot+=a[i];
    }
    int mxm = ceil((double)tot / (4 * m));
    int count = 0;
    for(int i=0;i<n;i++) {
    	if(a[i] >= mxm) {
    		count++;
    	}
    }
    if(count >= m) {
    	cout << "Yes" << '\n';
    }
    else {
    	cout << "No" << '\n';
    }

}

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

ll max(ll a , ll b)
{
  return (a > b) ? a: b;
}
ll min(ll a , ll b)
{
  return (a < b) ? a : b;
}
void memset(ll *arr , int n , ll value)
{
    for(int i= 0; i<n ; i++)
    {
        arr[i] = value;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n , w;
    cin>>n>>w;
    ll *weight = new ll[n];
    ll *values = new ll[n];
    for(int i= 0; i< n ; i++)
    {
        cin>>weight[i];
        cin>>values[i];
    }
    ll *dp = new ll[w+1];
    memset(dp , w+1 , 0);
    for(int i=0 ; i<n; i++)
    {
        for(int j = w ; j>=weight[i] ; j--)
        {
            dp[j] =max(dp[j] , dp[j - weight[i]] + values[i]);
        }
    }
    cout<<dp[w];
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	deque<char> str;
	bool dir = true;
	string s;
	cin>>s;
	for(auto x : s){
		str.push_back(x);
	}
	int q;
	cin>>q;
	int type, f;
	char c;
	while(q--){
		cin>>type;
		if(type == 1){
			dir = !dir;
		}else{
			cin>>f>>c;
			if(f == 1){
				if(dir)str.push_front(c);
				else str.push_back(c);
			}else{
				if(!dir)str.push_front(c);
				else str.push_back(c);
			}
		}
	}
	if(!dir)reverse(str.begin(), str.end());
	for(auto x : str){
		cout<<x;
	}

	return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n;
	string s, t;
	cin >> n >> s >> t;
	string ans;
	for (int i = 0;i < (int)n;i++) {
		ans = ans + s[i]+t[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;
int main() {
    int n;
    cin >> n;

    int x;
    int mn = 110, mx = 0;
    vector<int> point(n);
    rep(i, 0, n) {
        cin >> x;
        point[i] = x;
        mn       = min(mn, x);
        mx       = max(mx, x);
    }

    int mSum = 10000000;
    int tSum;
    repe(i, mn, mx) {
        tSum = 0;
        for (int p : point) {
            tSum += (p - i) * (p - i);
        }
        mSum = min(mSum, tSum);
    }

    cout << mSum << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll a,d,mod = 1e9+7;
vec<vec<ll>> g;

vec<vec<ll>> mul_matr(vec<vec<ll>> m, vec<vec<ll>> n){
    vec<vec<ll>> o(a, vec<ll>(a));
    for(int q=0; q<a; q++){
        for(int w=0; w<a; w++){
            for(int e=0; e<a; e++){
                o[q][w] += m[e][w]*n[q][e];
                o[q][w] %= mod;
            }
        }
    }
    return o;
}

vec<vec<ll>> binpow(vec<vec<ll>> m, ll k){
    if(k==1) return m;
    auto kek = mul_matr(m, m);
    return k%2==0 ? binpow(kek, k/2) : mul_matr(m, binpow(kek, k/2));
}

int main() {
    fast;
    cin>>a>>d;
    g = vec<vec<ll>>(a, vec<ll>(a));
    for(int q=0; q<a; q++){
        for(int w=0; w<a; w++) cin>>g[q][w];
    }
    auto o = binpow(g, d);
    ll cnt = 0;
    for(int q=0; q<a; q++){
        for(ll i : o[q]) cnt += i;
    }
    cout<<cnt%mod;
}

Measured memory_bytes: 2944
import java.util.*;

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

    int count = 0;
    int i = 0;
    while (i < n - 2) {
        if (s.substring(i, i + 3).equals("ABC")) {
            count++;
            i = i + 3;
        } else {
            i++;
        }
    }
    System.out.println(count);
  }
}


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



int main(){
  int64_t N,K;
  cin>>N>>K;
  
  int64_t x=N%K;
  int64_t y=abs(x-K);
  
  if(x<y) cout<<x<<endl;
  else cout<<y<<endl;
  
  
    
    
}
   

Measured memory_bytes: 3644