akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,m;
    cin >> n >> m;
    VI num(n,-1);
    int r,c; 
    REP(i,0,m){
        cin >> r >> c;
        --r;
        if (num[r] != -1 && num[r] != c) {
            cout << -1 << endl;
            return;
        }
        num[r] = c;
    }
    if (n > 1 && num[0] == 0) {
        cout << -1 << endl;
        return;
    }
    if (n > 1 && num[0] == -1) num[0] = 1;

    REP(i,0,n) cout << ((num[i] == -1) ? 0 : num[i]);
    cout << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};






void solve(){
    ll n,ans=0;
    cin>>n;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        ans+=(b-a+1);
    }
    cout<<ans<<endl;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    ll q;
    q=1;
    rep(_,q){

        solve();

    }
    

    return 0;
}


Measured memory_bytes: 256
def print_list(a):
    for x in a[:-1]:
        print(x, end=" ")
    print(a[-1])


def print_mat(a):
    for i in range(len(a)):
        print_list(a[i])


n = int(input())
adj = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    s = [int(x) for x in input().split()]
    u = s[0]
    for v in s[2:]:
        adj[u - 1][v - 1] = 1


print_mat(adj)


Measured memory_bytes: 6384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int max =a+b;
		if(max<a-b){
			max=a-b;
		}
		if(max<a*b){
			max=a*b;
		}
		System.out.println(max);
	}


}


Measured memory_bytes: 23764
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
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; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;


void solve() {
	int N, M; cin >> N >> M;
	string S; cin >> S;
	int now = N;
	vector<int>ans;
	while (now > 0) {
		bool found = false;
		int pre = now;
		for (int i = max(0, pre - M); i < pre; i++) {
			if (S[i] == '0') {
				found = true;
				ans.push_back(now - i);
				now = i; break;
			}
		}
		if (!found) {
			print(-1); return;
		}
	}
	VREVERSE(ans);
	print_space(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 1096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    string s;
    cin>>k>>s;
    if(s.size()<=k)
    {
        cout<<s;
    }
    else
    {
        for(int i=0;i<k;i++)
        {
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
}


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

int main()
{
    string s1, s2;

    cin >> s1 >> s2;

    map<char, int> cnt1, cnt2;
    for (int i = 0; i < (int)s1.length(); i++) {
        cnt1[s1[i]]++;
        cnt2[s2[i]]++;
    }

    vector<int> store1, store2;
    for (auto x : cnt1) {
        store1.push_back(x.second);
    }
    for (auto x : cnt2) {
        store2.push_back(x.second);
    }

    sort(store1.begin(), store1.end());
    sort(store2.begin(), store2.end());

    if (store1 == store2) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  rep(i, n) p[i]++;
  int mx = 0;
  int s = 0;
  queue<int> q;
  rep(i, n){
    s += p[i];
    q.push(p[i]);
    if(q.size() > k) {
      s -= q.front(); q.pop();
    }
    if(q.size() == k) {
      mx = max(mx, s);
    }
  }
  double ans = mx;
  ans /= 2;
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll Abs(ll x,ll y){
    if(x>=y)return x-y;
    else return y-x;
}

int main(void){
    ll n;
    cin>>n;
    vector<ll>x(n+1),y(n+1),t(n+1);
    bool flag = true;
    ll X = 0,Y = 0,T=0;;
    for(ll i=0;i<n;i++){
        cin>>t[i]>>x[i]>>y[i];
        ll dist = Abs(X,x[i])+Abs(Y,y[i]);
        ll delta = t[i]-T;
        if(dist>delta)flag = false;
        else{
            if((dist%2)!=(delta%2))flag = false;
        }
        X = x[i];
        Y = y[i];
        T = t[i];
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

struct Node{
    int v, c;
    Node(int v, int c){
        this->v = v;
        this->c = c;
    }
    Node(){
        this->v = 0;
        this->c = 0;
    }
};

int main(){
    LL N, M;
    cin >> N >> M;
    vector<vector<int> > G(N, vector<int>());
    REP(i, M){
        int u, v;
        cin >> u >> v;
        u--,v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    LL ind = 0;
    LL bipartite = 0;
    LL not_bipartite = 0;
    vector<int> color(N, -1);
    REP(i, N){
        if(G[i].size()==0){
            ind++;
            continue;
        }
        if(color[i]!=-1)continue;
        //cerr << "start:" << i << endl;
        stack<Node> st;
        st.push(Node(i, 0));
        bool is_bipertite = true;
        while(!st.empty()){
            Node n = st.top();st.pop();
            if(color[n.v]!=-1){
                if(color[n.v]!=n.c)is_bipertite = false;
                continue;
            }
            color[n.v] = n.c;
            REP(j, G[n.v].size()){
                st.push(Node(G[n.v][j], 1-n.c));
            }
        }
        if(is_bipertite)bipartite++;
        else not_bipartite++;
    }

    LL res = ind*(2LL*N-ind);
    res += 2LL * bipartite * bipartite;
    res += 1LL * (not_bipartite * not_bipartite + 2LL * not_bipartite * bipartite);
    //cerr << "info:" << not_bipartite << " " << bipartite<< endl;

    cout << res << endl;

    return 0;
}


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

ans = 'Yes'

pre_t = 0
pre_x = 0
pre_y = 0
for n in range(N):
  t,x,y = map(int, input().split())
  
  # 条件を満たせないようなら、ansを変更してbreak

  ## 1.絶対値的にその地点にたどり着けるかをチェック
  dif_t = t - pre_t
  dif_x = abs(x - pre_x)
  dif_y = abs(y - pre_y)
  if dif_t < (dif_x + dif_y):
    ans = 'No'
    break    
  
  ## 2.パリティチェック
  if t%2 != (x+y)%2:
    ans = 'No'
    break


print(ans)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	while(1){
		int N;
		cin>>N;
		if(N==0)
			return 0;
		int ans=0;
		int maxi=0,mini=INF;
		for(int i=0;i<N;i++){
			int s;
			cin>>s;
			ans+=s;
			maxi=max(s,maxi);
			mini=min(s,mini);
		}
		ans-=maxi+mini;
		cout<<ans/(N-2)<<endl;
	}
	return 0;
}


Measured memory_bytes: 2980
stringToInt :: String -> Int
stringToInt = read

yesOrNo :: (Ord a) => a -> a -> a -> String
yesOrNo a b c
    | a < b && b < c = "Yes"
    | otherwise = "No"

main = do
    line <- getLine
    let [a, b, c] = map stringToInt $ words line
    putStrLn $ yesOrNo a b c



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

#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))

int main() {
   int N, X, Y;
   cin >> N >> X >> Y;
   vector<int> v(N);
   rep (i, N) cin >> v[i];

   if (N >= 2) {
      cout << max( abs(v[N-1]-Y), abs(v[N-2]-v[N-1]) ) << endl;
   } else {
      cout << abs(v[0] - Y) << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include "stdio.h"
#include <vector>
#include <functional>
#include "math.h"
#include <set>
#include <iomanip>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int H,W,K;
vector<string> a;
vector<vector <int> > ans;


int main()
{
	cin >> H>>W>>K;
	a.resize(H);
	ans.resize(H);
	REP(i,H){
		cin >> a[i];
	}
	REP(i,H){
		REP(j,W){
			ans[i].push_back(-1);
		}
	}

	int k = 1;
	int ii = -1;
	REP(i,H){
		if(a[i].find('#') == -1) continue;
		if(ii==-1){
			ii = i;
		}
		bool flag = false;
		REP(j,W){
			if(a[i][j] == '#'){
				if(flag){
					k++;
				} else{
					flag = true;
				}
			}
			ans[i][j] = k;
		}
		k++;
	}


	REP(i,H){

		if(ans[i][0] != -1)
			continue;
		REP(j,W){
			if(i < ii){
				ans[i][j] = ans[ii][j];
			} else{
				ans[i][j] = ans[i-1][j];
			}
		}
	}
	REP(i,H){
		REP(j,W){
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
}



Measured memory_bytes: 1536
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    x,n = LI()
    p = LI()
    f = [1]*(200)
    for i in p:
        f[i] = 0
    ans = x
    m = 0
    for i in range(200):
        if f[i]:
            d = abs(i-x)
            if d < ans:
                ans = d
                m = i
    print(m)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 65576
from fractions import gcd
a, b, c, d = map(int, input().split())
s = b - a + 1

def dev(x):
    if a % x == 0:
        return b // x - a // x + 1
    return b // x - a // x

g = gcd(c, d)
print(s - (dev(c) + dev(d) - dev(c * d // g)))


Measured memory_bytes: 5052
#include <iostream>

int main()
{
    long long a, b, x;
    std::cin >> a >> b >> x;

    if (a == b && b == 0) {
        std::cout << 1 << std::endl;
        return 0;
    }

    if (a == 0) {
        std::cout << b / x + 1 << std::endl;
        return 0;
    }
    std::cout << b / x - (a - 1) / x << std::endl;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
)

const inf = 1e9 + 1

func main() {
    var n, w int
    fmt.Scan(&n, &w)
    is := make([][]int, n)
    for i := 0; i < n; i++ {
        var a, b int
        fmt.Scan(&a, &b)
        is[i] = []int{a, b}
    }

    // dp[i][v] i番目まで価値の合計がvになる最小の重さ
    dp := make([][]int, n+1)
    for i := 0; i <= n; i++ {
        dp[i] = make([]int, 1e3*n+1)
        for j := range dp[i] {
            dp[i][j] = inf
        }
    }

    dp[0][0] = 0
    for i := 1; i <= n; i++ {
        wt, v := is[i-1][0], is[i-1][1]
        for j := range dp[i] {
            if j-v >= 0 && dp[i-1][j-v]+wt <= w {
                dp[i][j] = min(dp[i-1][j-v]+wt, dp[i-1][j])
            } else {
                dp[i][j] = dp[i-1][j]
            }
        }
    }
    var m int
    for i := range dp {
        for j := range dp[i] {
            if dp[i][j] != inf && j > m {
                m = j
            }
        }
    }

    fmt.Println(m)
}

func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}

func abs(n int) int {
    if n < 0 {
        return -n
    }
    return n
}


Measured memory_bytes: 82304
#include <iostream>
#include<string>
#include<vector>
using namespace std;
int main(void){
    int x,a,b;
    cin>>x>>a>>b;
    if(b<=a)cout<<"delicious"<<endl;
    else if(b<=a+x)cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;
    return 0;
}


Measured memory_bytes: 384
/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define MOAE ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const ll mod = 1e9 + 7;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
/*down, up, right, left*/

int main()
{
	ll l, r, d, cnt = 0;
	cin >> l >> r >> d;
	multiset<ll> ms;
	for (int i = l; i <= r; i++)
		ms.insert(i);
	for (int i = 1;; i++)
	{
		if (i > r)
		{
			break;
		}
		else if (ms.count(i * d))
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	
	set<int> s = {1,2,3};
	int a;
	cin >> a;
	s.erase(s.find(a));
	cin >> a;
	s.erase(s.find(a));
	cout << *(s.begin());
	
	

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    
    
    
    
    while(1) {
        
        char str[1001];
        int i,sum = 0;
        gets(str);
        
        if (str[0] == '0') {
            break;
        }
        for (i = 0; str[i] != '\0'; i++) {
            
            sum += (str[i]-48);
            
        }
        
        printf("%d\n",sum);
        
        
    }
    
    return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int maxValue = 0, minValue = 1e9;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        maxValue = max(maxValue, A[i]);
        minValue = min(minValue, A[i]);
    }
    cout << abs(maxValue - minValue) << endl;
}


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

#define fastio        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll            long long
#define fl            long double
#define pll           pair<ll,ll>
#define onebits(x)    __builtin_popcountll(x)
#define pb            push_back
#define mk            make_pair
#define endl          "\n"
#define ff            first
#define ss            second
#define mt            make_tuple
#define np            next_permutation
#define pi            3.141592653589793238
#define deb(x)        cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define vll           vector<ll>
#define vp            vector<pair<ll,ll>>
#define all(x)        x.begin(),x.end()
#define revpq         priority_queue <int, vector<int>, greater<int>>
#define ps(x,y)       fixed<<setprecision(y)<<x
const ll mod = 1e9 + 7;
const ll INF = 1e18;
ll power(ll a, ll b) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod % mod; a = a * a % mod;} return res;}

int main()
{
    fastio;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll i, j, t , n , m, l, k;
    cin >> n;
    char c[n];
    ll cr = 0, cw = 0;
    for (i = 0; i < n; i++)
    {
        cin >> c[i];
        if (c[i] == 'R')
        {
            cr++;
        }
        else
        {
            cw++;
        }
    }
    ll ans = 0;
    for (i = 0; i < cr; i++)
    {
        if (c[i] == 'W')
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3808
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[30]={},ans=1;
  string s;
  cin >> n >> s;
  for(int i=0; i<n; i++) {
    a[s[i]-'a']++;
  }
  for(int i=0; i<30; i++) {
    ans*=a[i]+1;
    ans%=MOD;
  }
  cout << ans-1 << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int a[100010],b[100010];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read(),m=read(),q=read(),mn;
    for(int i=1;i<=n;i++)
	{
		a[i]=read();
		if(i==1)mn=a[i];
		else mn=min(mn,a[i]);
	}
	int ans=mn;
    for(int i=1;i<=m;i++)
	{
		b[i]=read();
		if(i==1)mn=b[i];
		else mn=min(mn,b[i]);
	}ans+=mn;
    for(int i=1;i<=q;i++)
    {
    	int x=read(),y=read(),c=read();
    	ans=min(ans,a[x]+b[y]-c);
    }pr2(ans);
    return 0;
}

Measured memory_bytes: 896
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep = ' ', end = '\n'):
    print(*var, file=sys.stderr, end = end, sep = sep)

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

primes = []
M = 1000000
p = [1] * M
for i in range(2, M):
    if p[i]:
        for j in range(2*i, M, i):
            p[j] = 0
        primes.append(i)

x, = I()
for i in primes:
    if i >= x:
        print(i)
        break

Measured memory_bytes: 14420
package main

import (
	"fmt"
)

func main() {
	var x int
	fmt.Scan(&x)
	m := sieve_of_eratosthenes()

	for i := x; i < len(m); i++ {
		if m[i] == 1 {
			fmt.Println(i)
			return
		}
	}
}

func sieve_of_eratosthenes() []int {
	MAX := 301010
	is_prime := make([]int, MAX)
	for i := 0; i < MAX; i++ {
		is_prime[i] = 1
	}
	is_prime[0] = 0
	is_prime[1] = 0

	for i := 2; i < MAX; i++ {
		if is_prime[i] == 0 {
			continue
		}
		for j := i * 2; j < MAX; j += i {
			is_prime[j] = 0
		}
	}

	return is_prime
}


Measured memory_bytes: 4200
N=int(input())
A=list(map(int, input().split()))

count=0
m=abs(A[0])
SUM=0
for a in A:
  if a<0:
    count+=1
  m=min(m, abs(a))
  SUM+=abs(a)

if count%2==0:
  print(SUM)
else:
  print(SUM-2*m)

Measured memory_bytes: 14284
import sys

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    S = SI()
    bit_len = len(S)-1
    for i in range(2**bit_len):
        ls = ['-' for _ in range(bit_len)]
        for j in range(bit_len):
            if (i >> j) & 1:
                ls[j] = '+'
        calc = []
        for n in range(len(S)):
            calc.append(S[n])
            if n != len(S)-1:
                calc.append(ls[n])
        if eval("".join(calc)) == 7:
            print("".join(calc)+"=7")
            sys.exit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 9116
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    import math
    a,b,h,m=map(int, input().split())
    akaku=h*30+m*0.5
    bkaku=m*6
    kaku=max(akaku,bkaku)-min(akaku,bkaku)
    kaku=math.radians(min(kaku,360-kaku))
    xx=a**2+b**2-2*a*b*math.cos(kaku)
    print(xx**0.5)
resolve()

Measured memory_bytes: 62532
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from copy import deepcopy

INF = 10 ** 20
sys.setrecursionlimit(2147483647)

def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n,m=LI()
G=[[]for _ in range(n)]
cnt=[0]*n
for _ in range(n-1+m):
    a,b=LI()
    G[a-1]+=[b-1]
    cnt[b-1]+=1

r=cnt.index(0)
D=[0]*n
q=deque([r])
ans=[0]*n
while q:
    u=q.popleft()
    for v in G[u]:
        cnt[v]-=1
        ans[v] = u + 1
        if not cnt[v]:
            q+=[v]


print(*ans,sep="\n")








Measured memory_bytes: 99768
/**********************************************************
* @Author: 			   Kirito
* @Last Modified by:   Kirito
* @Remark:
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn=1111;
int k;
char str[maxn];

int main()
{
    cin>>k;cin>>str;
    if(strlen(str)<=k) cout<<str<<endl;
    else{
        for(int i=0;i<k;i++) cout<<str[i];
        cout<<"..."<<endl;
    }
	return 0;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
from sys import setrecursionlimit
setrecursionlimit(10**9)

def inpl(): return list(map(int, input().split()))
N = int(input())
D = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = inpl()
    D[a].append(b)
    D[b].append(a)

C = sorted(inpl())
ans = [-1]*(N+1)
ans[1] = C.pop()
score = 0
def dfs(i):
    global score
    for j in D[i]:
        if ans[j] == -1:
            ans[j] = C.pop()
            score += min(ans[i], ans[j])
            dfs(j)

dfs(1)
print(score)
print(*ans[1:])

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

const ll mod = 1000000007;

void add(int &a, int b){
  a += b;
  a %= mod;
}

bool AGC(int a, int b, int c){
  if(a == 1 && b == 2 && c == 3) return true;
  else return false;
}
int dp[101][4][4][4]; //dp[i][a][b][c]は全部でi文字で0-T,1-A,2-G,3-Cとして...abcと並んでいる

int main(){
  int n; cin >> n;
  dp[0][0][0][0] = 1;
  for(int i = 1; i <= n; i++){
    for(int a = 0; a < 4; a++){
      for(int b = 0; b < 4; b++){
        for(int c = 0; c < 4; c++){ //cまではi-1の時の文字
          for(int d = 0; d < 4; d++){ //dはiの一番右の文字
            if(AGC(b, c, d) || AGC(c, b, d) || AGC(b, d, c)) continue;
            if(AGC(a, c, d) || AGC(a, b, d)) continue;
            add(dp[i][b][c][d], dp[i-1][a][b][c]);
          }
        }
      }
    }
  }
  int ans = 0;
  for(int i = 0; i < 4; i++){
    for(int j = 0; j < 4; j++){
      for(int k = 0; k < 4; k++){
        add(ans, dp[n][i][j][k]);
      }
    }
  }
  cout << ans << endl;
}
          

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

int main(int argc, char* argv[]){
  string s;
  for(int i=0; i<3; i++){
    cin >> s;
    cout << s[0];
  }

  cout << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j;
  scanf("%d",&n);
  int a[n],b[n],c[n];
  for(i=0;i<n;i++){
    scanf("%d %d %d",&a[i],&b[i],&c[i]);
  }
  for(i=0;i<n;i++){
    j=0;
    if(a[i]*a[i]+b[i]*b[i]==c[i]*c[i]){
      printf("YES\n");
      j++;
    }
    if(a[i]*a[i]+c[i]*c[i]==b[i]*b[i]){
      printf("YES\n");
      j++;
    }
    if(c[i]*c[i]+b[i]*b[i]==a[i]*a[i]){
      printf("YES\n");
      j++;
    }
    if(j==0){
      printf("NO\n");
    }
  }
  return(0);
}

Measured memory_bytes: 1020
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n, k;
    cin >> n >> k;
    k--;
    string s;
    cin >> s;

    if (s[k] == 'A') {
        s[k] ='a';
    }
    else if ( s[k] == 'B') {
        s[k] = 'b';
    }
    else if ( s[k] == 'C') {
        s[k] = 'c';
    }
    cout <<  s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int lis[100];
    for(int i=0;i<N;i++){
        cin>>lis[i];
    }
    long long int ans=-5000000000000;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            if(N<i+j||K<i+j)continue;
            int karilis[100]={0};
            int karinum=0;
            for(int k=0;k<i;k++){
                karilis[karinum]=lis[k];
                karinum++;
            }
            for(int k=0;k<j;k++){
                karilis[karinum]=lis[N-1-k];
                karinum++;
            }
            sort(karilis,karilis+karinum);
            if(i==2&&j==1){
                for(int k=0;k<karinum;k++){
                    //printf("[%d]",karilis[k]);
                }
                //puts("");
            }
            int kokokara;
            for(int k=0;i+j+k<=K&&k<karinum;k++){
                kokokara=k;
                if(0<=karilis[k])break;
            }
            long long int karians=0;
            for(int k=kokokara;k<karinum;k++){
                karians+=karilis[k];
            }
            //printf("[%d][%d][%lld]\n",i,j,karians);
            ans=max(ans,karians);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, W;
  cin >> N >> W;
  int weight[110], value[110];
  for(int i = 0; i < N; i++){
    cin >> weight[i] >> value[i];
  }
  long int dp[110][100010];
  for(int w = 0; w <= W; w++) dp[0][w] = 0;
  for(int i = 0; i < N;i++){
    for(int w = 0; w <= W; w++){
      if(w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }
  cout << dp[N][W] << endl;
}

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

const ll maxs = 1e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e9;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert


int main(){
    //freopen("input00.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    ll T = 1;
    //cin>>T;
    while(T--){
        mod = 998244353;
        ll N;
        cin>>N;
        vector<pair<ll,ll>> A(N);
        for(ll i=0;i<N;i++){
            cin>>A[i].ff>>A[i].ss;
        }
        sort(A.begin(),A.end());
        ll DP[N+1];
        stack<pair<ll,ll> > stk;
        stk.push(mp(N,1e9));
        DP[N] = 1;
        for(ll i=N-1;i>=0;i--){
            while(stk.top().ss < A[i].ff + A[i].ss )
                stk.pop();
            ll j = stk.top().ff;
            stk.push(mp(i,A[i].ff));
            DP[i] = (DP[i+1] + DP[j])%mod;
        }
        cout << DP[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 6656
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
using namespace std;
int main(){
    int A,B,C;
    int ans;
    cin >> A >> B >> C;
    ans = B/A;
    if(C < ans){
        ans = C;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/
signed main(){
  int n;
  cin>>n;
  int ans=0;
  vi a(n),b(n),c(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  rep(i,n-1)cin>>c[i];
  
  rep(i,n){
    ans+=b[i];
  }

  rep(i,n-1)if(a[i+1]-a[i]==1) ans+=c[a[i]-1];

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


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	m := make(map[int][]int, N)
	var from, to int
	for i := 0; i < M; i++ {
		fmt.Scan(&from, &to)
		m[from] = append(m[from], to)
	}

	found := false
	if len(m[1]) == 0 {
		found = false
	} else {
	L:
		for _, v := range m[1] {
			for _, w := range m[v] {
				if w == N {
					found = true
					break L
				}
			}
		}
	}
	if found {
		fmt.Println("POSSIBLE")
	} else {
		fmt.Println("IMPOSSIBLE")
	}
}


Measured memory_bytes: 19072
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
typedef pair<int, int> P;

int main(void){
  int w, h;
  int num=0;
  int map[51][51];
  int dir[8][2]={{1,0},{1,1},{1,-1},{0,1},{0,-1}, {-1,0},{-1,1},{-1,-1}};
  queue<P> que;
  cin >> w >> h;
  while(w+h){
    //input
    for (size_t y = 0; y < h; y++) {
      for (size_t x = 0; x < w; x++) {
        cin >> map[y][x];
      }
    }

    //output
    for (size_t y = 0; y < h; y++) {
      for (size_t x = 0; x < w; x++) {
        if (map[y][x]==1) {
          //search islands & added que & replace 0
          que.push(P(y, x));
          map[y][x]=0;
          while(que.size()){
            P p = que.front(); que.pop();
            for (size_t i = 0; i < 8; i++) {
              if (0<=p.first+dir[i][0] && p.first+dir[i][0]<h &&
              0<=p.second+dir[i][1] && p.second+dir[i][1]<w) {
                if(map[ p.first+dir[i][0] ][ p.second+dir[i][1] ]==1){
                  //added que & replace 0
                  que.push(P(p.first+dir[i][0], p.second+dir[i][1]));
                  map[ p.first+dir[i][0] ][ p.second+dir[i][1] ]=0;
                }
              }
            }
          }
          num+=1;
        }
      }
    }
    cout << num << endl;
    cin >> w >> h;
    num=0;
  }
  return 0;
}



Measured memory_bytes: 3104
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		HashSet<String> set = new HashSet<>();
		for(int i = 0; i < count; i++) {
			String num = sc.next();
			if(set.contains(num)) set.remove(num);
			else set.add(num);
		}

		System.out.println(set.size());

	}
}


Measured memory_bytes: 55992
#include<bits/stdc++.h>
#define v(i,s,n) for(int i=s;i<n;i++)
#define z while(true)
using namespace std;int n,t[100][100],h[5100][8],w,dp[100][5100],a;void Nh(int n){w=0;int c[7]={0},i;z{c[0]++,i=0;z{if(c[i]==n){if(i==n-1)goto op;c[i+1]++,c[i]=0;}else break;i++;}bool ok=true;v(f,0,n-1)v(g,f+1,n)if(c[f]==c[g])ok=false;if(ok){v(k,0,n)h[w][k]=c[k];w++;}}op:;return;}int main(){cin>>n;v(i,0,n)v(j,0,n)t[i][j]=0;v(i,0,n){cin>>a;v(j,max(0,i-a),min(a+i+1,n))t[i][j]=1;}v(i,0,n){cin>>a;v(j,0,100)t[i][j]*=a;}Nh(min(n,7));v(i,0,n)v(j,0,w)dp[i][j]=0;int ans=0;v(i,0,w){int cnt=0;v(f,0,min(n,7))v(g,0,min(n,7))if(h[i][f]>h[i][g])cnt+=t[g][f];dp[6][i]=cnt,ans=max(ans,cnt);}v(r,7,n)v(i,0,w)v(j,0,8){int cnt=0,c[7];v(k,0,7){c[k]=h[i][k];if(h[i][k]<j)cnt+=t[r-7+k][r];else cnt+=t[r][r-7+k],c[k]++;if(k>0){if(h[i][k]>h[i][0])c[k]--;c[k-1]=c[k];}}c[6]=j;if(h[i][0]<j)c[6]--;int l=0,ri=w,m;z{if(l>=ri-1)break;m=(l+ri)/2;int s=0,q=6;v(k,0,7){if(h[m][q]<c[q]){s=1;break;}if(h[m][q]>c[q]){s=-1;break;}q--;}if(s==0)break;if(s==1)l=m;else ri=m;}dp[r][m]=max(dp[r][m],dp[r-1][i]+cnt);}v(i,0,w)ans=max(ans,dp[n-1][i]);cout<<ans<<endl;return 0;}

Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

long long int gcd(long long int a, long long int b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    
    if (b == 0) return a;
    else return gcd(b, a % b);
}

long long int modpow(int b, int p){
    long long int num = 1, power = b;
    for(int i=0; i<=30; i++){
        if((p>>i) & 1) num *= power;

        num %= MOD;
        power *= power;
        power %= MOD;
    }
    return num;
}

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

    int count = 0;
    map<pair<long long int, long long int>, int> ab;
    for(int i=0; i<n; i++){
        long long int a, b;
        cin >> a >> b;

        if(a == 0 && b == 0) count += 1;
        else{
            if(a == 0) b = 1;
            else if(b == 0) a = 1;
            else{
                long long int d = gcd(a,b);
                a /= d;
                b /= d;
                if(b < 0){ b *= -1; a *= -1; }
            }

            if(ab.find(make_pair(a,b)) == ab.end()) ab[make_pair(a,b)] = 1;
            else ab[make_pair(a,b)] += 1;
        }
    }

    long long int ans = 1;
    set<pair<long long int, long long int>> visited;
    for(auto p : ab){
        if(visited.find(p.first) != visited.end()) continue;
        long long int a = p.first.first;
        long long int b = p.first.second;
        int num = p.second;

        //cout << "(" << a << ", " << b << ") : " << num << endl;

        long long int c = b;
        long long int d = a;
        if(d < 0){ c *= -1; d *= -1; }
        if(d != 0) c *= -1;
        //c *= -1;
        int cnum = 0;
        pair<long long int, long long int> cp = make_pair(c,d);
        if(ab.find(cp) != ab.end()) cnum = ab[cp];

        //cout << "(" << c << ", " << d << ") : " << cnum << endl;
        
        long long int times = modpow(2, num) + modpow(2, cnum) - 1;
        times = (times % MOD + MOD) % MOD;

        ans *= times;
        ans %= MOD;

        visited.insert(p.first);
        visited.insert(cp);
    }
    ans = ((ans - 1 + count) % MOD + MOD) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 41128
import java.util.*;

//update 2019/12/29

public class Main{

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    int N = nextInt();  int Q = nextInt();
    String[] S = splitString(next()); //N == S.length()

    for(int i=0;i<N-1;i++){ //NでRE、N-1でAC ------------↓
      if(S[i].equals("A") && S[i+1].equals("C")){ //[N-1+1]=[N] ⇒RE
        S[i+1] = "c"; //ACの存在をメモ
      }
    }

    int[] num = new int[N+1];

    for(int i=1;i<=N;i++){
      num[i] += num[i-1]; //今までのを追加
      if(S[i-1].equals("c")){ //num[0]を使わないため。
        num[i] += 1; //i文字目にcがあるので、新たに1追加
      }

    }

    //num[i] i文字目までにあるACの数

    for(int i=0;i<Q;i++){
      int l = nextInt();
      int r = nextInt();
      int ans = num[r]-num[l];
      System.out.println(ans);
    }

  }

  static String next(){
    return sc.next();
  }

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

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char aaa){
    return aaa - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


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

int GCD(int x, int y){
	int gcd = 1;
	int i = 2;
	while(1){
		if(x % i == 0 && y % i == 0){
			x = x / i;
			y = y / i;
			gcd *= i;
			i = 2;
		}else{
			i++;
		}
		if(i > x || i > y) break;
	}
	return gcd;
}

int main(){
	int x, y;
	cin >> x >> y;
	cout << GCD(x, y) << endl;
	return 0;
}

Measured memory_bytes: 1160
while True:
  n, x = map(int, input().split())

  if n == 0 and x == 0:
    break

  count = 0
  for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
      for k in range(j + 1, n + 1):
        if i + j + k == x:
          count += 1
  print(count)


Measured memory_bytes: 5592
#include <iostream>
using namespace std;
int main() {
	int N, M, a, b, i, doro[60] = {};
	cin >> N >> M;
	for (i = 0;i < M;i++) {
		cin >> a >> b;
		doro[a-1]++;
		doro[b-1]++;
	}
	for (i = 0;i < N;i++) {
		cout << doro[i] << endl;
	}
}

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

const int MAXN = 300000;


int32_t main() {
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    vector<int> a(n), b(n);

    int sum = 0;
    int best = -1;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];

        sum += a[i];

        if (a[i] > b[i]) {
            if (best == -1 || b[i] < best) {
                best = b[i];
            }
        }
    }

    if (best == -1) {
        cout << "0\n";
        return 0;
    }

    cout << sum - best << "\n";




    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;


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

    cout << (n-1)*(m-1) << endl;    
    return 0;
}




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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; cin >> N;
  printf("%.10f\n", 1.0 - N / 2 / (1.0 * N));
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	h := getNextInt(scanner)
	w := getNextInt(scanner)
	k := getNextInt(scanner)
	choco := makeInts(h+1, w+1)

	ans := math.MaxInt32
	for i := 0; i < h; i++ {
		s := getNextString(scanner)
		for j := 0; j < w; j++ {
			choco[i+1][j+1] = int(s[j] - '0')
			choco[i+1][j+1] += choco[i+1][j]
		}
	}

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			choco[i+1][j+1] += choco[i][j+1]
		}
	}

	for b := 0; b < 1<<uint(h-1); b++ {
		prev := 0
		a := 0
		cut := make([]int, 0)
		cut = append(cut, 0)
		for i := 0; i < h-1; i++ {
			if b>>uint(i)&1 == 0 {
				continue
			}
			cut = append(cut, i+1)
			a++
		}

		cut = append(cut, h)
		n := len(cut)
		valid := true
		for i := 0; i < w; i++ {
			for j := 1; j < n; j++ {
				if choco[cut[j]][i+1]-choco[cut[j]][prev]-choco[cut[j-1]][i+1]+choco[cut[j-1]][prev] > k {
					a++
					prev = i
					break
				}
			}
		}
		for j := 1; j < n; j++ {
			if choco[cut[j]][w]-choco[cut[j]][prev]-choco[cut[j-1]][w]+choco[cut[j-1]][prev] > k {
				valid = false
			}
		}
		if valid == false {
			continue
		}
		if ans > a {
			ans = a
		}
	}
	fmt.Fprintln(writer, ans)
}

func makeInts(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


Measured memory_bytes: 768