akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  string s[n];
 
  
  REP(i,n){
    cin >> s[i];
    sort(s[i].begin(),s[i].end());
  }
  int num[26] = {0};
  REP(i,s[0].size()){
    // a = 19
    //cout << s[0][i]%26 << endl;
    num[s[0][i]%26]++;
  }
  
  for(int i = 1;i < n;i++){
    int num2[26] = {0};
    REP(j,s[i].size()){
      num2[s[i][j]%26]++;
    }
    REP(j,26){
      num[j] = min(num[j],num2[j]);
    }
  }
  /*REP(i,26){
    cout << num[i] << endl;
    }*/
  
  for(int i = 19;i < 19+26;i++){
    for(int j = 0;j < num[i%26];j++){
      char t = 97+(i-19);
      cout << t;
    }
  }
  cout << endl;
  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    long n, c, t;
    cin >> n >> c;

    vector<long> w;
    vector<long> v;

    long total_value = 0;
    for (int i = 0; i < n; i++) {
        cin >> t;
        w.push_back(t);
        cin >> t;
        v.push_back(t);
        total_value += t;
    }

    vector<vector<long>> dp(2, vector<long>(total_value + 1, c + 1));

    for (int i = 0; i < 2; i++) {
        dp[i][0] = 0;
    }

    long ans = 0;
    for (int i = 1; i < n + 1; i++) {
        for (int j = 0; j < total_value + 1; j++) {
            dp[i % 2][j] = dp[(i - 1) % 2][j];
            if (j >= v[i - 1])
                dp[i % 2][j] = min(dp[i % 2][j], w[i - 1] + dp[(i - 1) % 2][j - v[i - 1]]);
        }
    }

    for (int j(0); j < total_value + 1; j++)
        if (dp[n % 2][j] <= c) {
            ans = (long) j;
        }
    cout << ans << endl;
}


Measured memory_bytes: 2560
N = int(input())
L = [ int(input()) for i in range(N)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

x = L[0]
for i in range(len(L)-1):
    y = lcm(x, L[i+1])
    x = y
    
print(x)

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

int main() {
  long long int n,d;
  cin>>n>>d;
  int cnt=0;

  while(n--) {
    long long int x,y;
    cin>>x>>y;

    double dist=sqrt(x*x+y*y);
    if(dist<=d) {
      cnt++;
    }

  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

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

  vector<int> t;
  while (n > 0) {
    int b = n % 10;
    if (b == 1) t.pb(9);
    else t.pb(1);
    n /= 10;
  }

  for (int i = 2; i >= 0; --i) cout << t[i];

  END;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.nextLine();
        String s = sc.nextLine();
        int l = 0;
        int r = s.length() - 1;
        int cost = 0;
        while (r > l){
            while (s.charAt(l) == 'R'){
                l+=1;
                if(l == s.length()){
                    System.out.println(0);
                    System.exit(0);
                }
            }
            while (s.charAt(r) == 'W'){
                r-=1;
                if(r == -1){
                    System.out.println(0);
                    System.exit(0);
                }
            }
            if (r > l) {
                cost += 1;
                l += 1;
                r -= 1;
            }
        }
        System.out.println(cost);
    }
}


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

using namespace std;

int main(void)
{
	int h,w;
	cin >> h >> w;
	string map[h];
	
	for(int i=1;i<=h;i++)
		cin >> map[i-1];

	int able[105][105]={};
	
	for(int i=1;i<=h;i++)
	{
		int count=0;
		for(int j=1;j<=w;j++)
		{
			if(map[i-1][j-1]=='.')count++;
			else break;
		}
		if(count==w)
			for(int j=1;j<=w;j++)
				able[i-1][j-1]=1;
	}
	for(int i=1;i<=w;i++)
	{
		int count=0;
		for(int j=1;j<=h;j++)
		{
			if(map[j-1][i-1]=='.')count++;
			else break;
		}
		if(count==h)
			for(int j=1;j<=h;j++)
				able[j-1][i-1]=1;
	}

	for(int i=1;i<=h;i++)
	{
		bool flag=false;
		for(int j=1;j<=w;j++)
		{
			if(able[i-1][j-1]==0)
			{
				flag = true;
				cout << map[i-1][j-1];
			}
		}
		if(flag == true)
			cout << endl;
	}
}





Measured memory_bytes: 256
// Problem : D - Menagerie
// Contest : AtCoder - AtCoder Beginner Contest 055
// URL : https://atcoder.jp/contests/abc055/tasks/arc069_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n;cin>>n;
string s;
cin>>s;
string ans=s;
for(int i=0;i<=1;i++)
for(int j=0;j<=1;j++)
{
	if(i==0) ans[size(ans)-1]='W';
	else ans[n-1]='S';
	if(j==0) ans[size(ans)-2]='W';
	else ans[n-2]='S';
	int ch=0;
	for(int k=0;k<n-2;k++)
	{
		char c=k-1>=0?ans[k-1]:ans[n+k-1];
		char c2=k-1>=0?s[k-1]:s[n+k-1];
		char c3=k-2>=0?ans[k-2]:ans[n+k-2];
		if(c=='W')
		{
			
			if(c2=='o')
			{
				//different
				if(c3=='W')
				ans[k]='S';
				else
				ans[k]='W';
			}
			else
			{
				//same
				ans[k]=c3;
			}
		}
		else
		{
			if(c2=='o')
			{
				ans[k]=c3;
			}
			else
			{
				if(c3=='W')
				ans[k]='S';
				else
				ans[k]='W';
			}
		}
	}
	string ans2=ans;
	for(int k=n-2;k<=n-1;k++)
	{
		char c=k-1>=0?ans[k-1]:ans[n+k-1];
		char c2=k-1>=0?s[k-1]:s[n+k-1];
		char c3=k-2>=0?ans[k-2]:ans[n+k-2];
		if(c=='W')
		{
			
			if(c2=='o')
			{
				//different
				if(c3=='W')
				ans[k]='S';
				else
				ans[k]='W';
			}
			else
			{
				//same
				ans[k]=c3;
			}
		}
		else
		{
			if(c2=='o')
			{
				ans[k]=c3;
			}
			else
			{
				if(c3=='W')
				ans[k]='S';
				else
				ans[k]='W';
			}
		}
	}
	if(ans==ans2)
	{
		cout<<ans;
		return;
	}
}
	cout<<-1;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 720
import java.util.Arrays;
import java.util.Scanner;

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

        for (int i = 0; i < n; i++) {
            side[0] = sc.nextInt();
            side[1] = sc.nextInt();
            side[2] = sc.nextInt();

            Arrays.sort(side);

            if (side[0] * side[0] + side[1] * side[1] == side[2] * side[2]) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}


Measured memory_bytes: 33888
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val P: IndexedSeq[(Long, Long)] =
      (0 until N). map { _ =>
        val x, y = sc.nextLong()
        (x, y)
      }

    if (P.size == 1)
      println(1)
    else {
      val candidates = for {
        (bx, by) <- P
        (nx, ny) <- P
        if bx != nx || by != ny
      } yield (nx - bx, ny - by)
      val cost0 = candidates.groupBy(identity).values.map(_.size).max
      println(N - cost0)
    }
  }

}

Measured memory_bytes: 30008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

vector<vector<char>> grid;
vector<vector<bool>> seen;
bool ok = false;
int tx[2] = {0, 1};
int ty[2] = {1, 0};
int h, w;

void dfs(int i, int j) {
    seen[i][j] = true;
    if(i == h-1 && j == w-1) {
        for(int ii = 0; ii < h; ii++) for(int jj = 0; jj < w; jj++) {
            if(grid[ii][jj] == '#' && !seen[ii][jj]) return;
        }
        ok = true;
    }
    for(int k = 0; k < 2; k++) {
        int ni = i + tx[k];
        int nj = j + ty[k];
        if(ni >= 0 && ni < h && nj >= 0 && nj < w && !seen[ni][nj] && grid[ni][nj] == '#') {
            dfs(ni, nj);
        }
    }
    seen[i][j] = false;
}

int main(){
    cin >> h >> w;
    grid.assign(h, vector<char>(w));
    seen.assign(h, vector<bool>(w, false));
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> grid[i][j];
    dfs(0, 0);
    printf("%s\n", ok?"Possible":"Impossible");
}

Measured memory_bytes: 256
s = gets.chomp
k = gets.to_i
m = s.length

dp = Array.new(2){Array.new(m+1){[0]*(k+2)}}
dp[1][0][0] = 1

m.times do |i|
  (k+1).times do |j|
    d = s[i].to_i
    if d == 0
      dp[0][i+1][j] += dp[0][i][j]
      dp[1][i+1][j] += dp[1][i][j]
    else
      dp[0][i+1][j] += dp[0][i][j] + dp[1][i][j]
      dp[1][i+1][j+1] += dp[1][i][j]
    end
    dp[0][i+1][j+1] += dp[0][i][j] * 9 + dp[1][i][j] * [0, d-1].max
  end
end

p dp[0][m][k] + dp[1][m][k]


Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
    ll N;
    ll ans = 0;
    int i = 1;
    cin >> N;

    if (N%2==0) {
        N/=2;
        while (N>0) {
            ans+=N/5;
            N/=5;
        }
    }
    cout << ans << endl;
}


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

int main()
{
    ll N, K;
    cin >> N >> K;
    ll res = K;
    rep(i, N - 1)
    {
        res *= K - 1;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int R, G;
    cin >> R >> G;
    cout << R + (G - R) * 2 << endl;
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    string s, t;
    cin >> s >> t;

    int n = s.size();
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (s[i] != t[i]);
    }
    cout << ans << newl;

    return 0;
}

Measured memory_bytes: 3780
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
H,W = LI()
s = [S() for _ in range(H)]
ans = 1
for i,j in itertools.product(range(H),range(W)):
    if s[i][j]=='.':
        continue
    uh,uw,dh,dw = i-1,j,i+1,j
    lh,lw,rh,rw = i,j-1,i,j+1
    if not (0<=uh<=H-1) or not (0<=dh<=H-1) or not (0<=lh<=H-1) or not (0<=rh<=H-1):
        continue
    if not (0<=uw<=W-1) or not (0<=dw<=W-1) or not (0<=lw<=W-1) or not (0<=rw<=W-1):
        continue
    if s[uh][uw]=='#' or s[dh][dw]=='#' or s[lh][lw]=='#' or s[rh][rw]=='#':
        continue
    else:
        ans = 0
        break
print({1:'Yes',0:'No'}[ans])


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

pair<int,int> f(int x) {
    int a = x % 10;
    int b;
    while (x) {
        b = x;
        x /= 10;
    }
    return make_pair(a, b);
}
int main() {
    int n; cin >> n;
    map<pair<int,int>, int> m;
    for (int i = 1; i <= n; i++) {
        m[f(i)]++;
    }
    int ans=0;
    for (int i = 1; i <= 9;i++) {
        for (int j = 1; j <= 9; j++) {
            ans += m[make_pair(i,j)] * m[make_pair(j, i)];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        byte N=sc.nextByte(),A[][]=new byte[2][100];
        short res=0;
        for(byte i=0;i<2;i++){
            for(byte j=0;j<N;j++){
                A[i][j]=sc.nextByte();
            }
        }
        for(byte i=0;i<N;i++){
            short temp=0;
            for(byte j=0;j<N;j++){
                if(j<i){
                    temp+=A[0][j];
                }
                else if(i==j){
                    temp+=A[0][j]+A[1][j];
                }
                else{
                    temp+=A[1][j];
                }
            }
            res=(temp>res?temp:res);

        }
        System.out.println(res);
    }
}


Measured memory_bytes: 36148
#include <cstdio>
int main()
{
	long long N, M, x;
	scanf("%lld%lld", &N, &M);
	x = N < M/2 ? N : M/2;
	N -= x;
	M -= x*2;
	x += N ? 0 : M/4;
	printf("%lld\n", x);
}

Measured memory_bytes: 128
n, m = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(1<<n):
  good = True
  for j in range(m):
    cur = 0
    for e in s[j][1:]:
      if i&(1<<(e-1)):
        cur += 1
    if cur%2!=p[j]:
      good = False
      break
  if good:
    ans += 1
print(ans)

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var as [2][]int
	for i := range as {
		as[i] = make([]int, n)
		for j := range as[i] {
			fmt.Scan(&as[i][j])
		}
	}

	max := 0
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j <= i; j++ {
			sum += as[0][j]
		}
		for k := i; k < n; k++ {
			sum += as[1][k]
		}
		if sum > max {
			max = sum
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

m = []
am = min(a)
bm = min(b)

for i in range(M):
    x, y, z = map(int, input().split())

    m.append(a[x-1] + b[y-1] - z )



if am + bm > min(m):
    print(min(m))
else:
    print(am + bm)

Measured memory_bytes: 18488
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
  int H,W;
  cin >> H >> W;

  vector<string>grid(H);
  for(int i=0;i<H;i++){
    cin >> grid[i];
  }

  vector<vector<int> >L(H,vector<int>(W,0));
  vector<vector<int> >R(H,vector<int>(W,0));
  vector<vector<int> >U(H,vector<int>(W,0));
  vector<vector<int> >D(H,vector<int>(W,0));

  for(int i=0;i<H;i++){
    if(grid[i][0] == '#')
      L[i][0] = 0;
    else
      L[i][0] = 1;
    for(int j=1;j<W;j++){
      if(grid[i][j] == '#')
        L[i][j] = 0;
      else
        L[i][j] = L[i][j - 1] + 1;
    }
  }

  for(int i=0;i<H;i++){
    if(grid[i][W - 1] == '#')
      R[i][W - 1] = 0;
    else
      R[i][W - 1] = 1;
    for(int j=W - 2;j >= 0;j--){
      if(grid[i][j] == '#')
        R[i][j] = 0;
      else
        R[i][j] = R[i][j + 1] + 1;
    }
  }

  for(int j=0;j<W;j++){
    if(grid[0][j] == '#')
      U[0][j] = 0;
    else
      U[0][j] = 1;
    for(int i=1;i<H;i++){
      if(grid[i][j] == '#')
        U[i][j] = 0;
      else
        U[i][j] = U[i - 1][j] + 1;
    }
  }

  for(int j=0;j<W;j++){
    if(grid[H - 1][j] == '#')
      D[H - 1][j] = 0;
    else
      D[H - 1][j] = 1;
    for(int i=H - 2;i>=0;i--){
      if(grid[i][j] == '#')
        D[i][j] = 0;
      else
        D[i][j] = D[i + 1][j] + 1;
    }
  }

  /*
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << L[i][j];
    }
    cout << endl;
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << R[i][j];
    }
    cout << endl;
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << U[i][j];
    }
    cout << endl;
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << D[i][j];
    }
    cout << endl;
  }
  */

  int ans = 0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int total = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3;
      if(total > ans)
        ans = total;
    }
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 69248
// Problem : E - ∙ (Bullet)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z)                                                       \
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define dbp(x) \
  cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl;
#define dbv(v)                         \
  {                                    \
    cout << #v << " : ";               \
    for (auto x : v) cout << x << ' '; \
    cout << endl;                      \
  }
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#define die(x) return cout << x << '\n', 0;

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int MOD = 1000000007;
ll modulo(ll a, ll b, ll n) {
  ll x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y) % n;  // multiplying with base
    }
    y = (y * y) % n;  // squaring the base
    b /= 2;
  }
  return x % n;
}

int32_t main() {
  fastio;
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
  int testcases;
  testcases = 1;
  // cin>>testcases;

  while (testcases--) {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    map<pii, int> mp;
    int ans = 1;
    rep(i, 0, n - 1) {
      cin >> a[i] >> b[i];
      if (a[i] == 0 && b[i] == 0) {
        ans = (ans + 1) % MOD;
        continue;
      }
      int sign = 1;
      if ((a[i] > 0 && b[i] < 0) || (a[i] < 0 && b[i] > 0)) {
        sign = -1;
      }
      a[i] = llabs(a[i]);
      b[i] = llabs(b[i]);
      int g = __gcd(a[i], b[i]);
      if (g != 0) {
        a[i] = a[i] / g;
        b[i] = b[i] / g;
      }
      if (b[i] == 0) sign = 1;
      a[i] = sign * a[i];
      pii p = {a[i], b[i]};
      // dbp(p);
      mp[p]++;
    }
    int temp = 1;
    for (auto it : mp) {
      pii p = it.first;
      int cnt = it.second;
      if (cnt == 0) continue;
      pii t;
      t.first = -p.second;
      t.second = p.first;
      int sign = 1;
      if ((t.first > 0 && t.second < 0) || (t.first < 0 && t.second > 0)) {
        sign = -1;
      }
      if (t.second == 0) sign = 1;
      t.first = llabs(t.first) * sign;
      t.second = llabs(t.second);
      // dbp(t);
      // if (!mp.count(t) || mp[t] == 0) continue;
      int cnt2 = mp[t];
      // db2(cnt, cnt2);
      temp =
          (temp * (modulo(2, cnt, MOD) + modulo(2, cnt2, MOD) - 1) % MOD) % MOD;
      mp[t] = 0;
    }
    ans = (ans + temp) % MOD;
    cout << (ans - 2LL + MOD) % MOD;
  }

  return 0;
}


Measured memory_bytes: 31280
#include<iostream>
long long GCD(const long long x ,const long long y){
  if (y==0) return x;
  return GCD(y,x % y);
}

long long LCM(const long long x , const long long y){
  return x / GCD(x,y) * y;
}

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

    long long X; std::cin >> X;

    long long count=LCM(X,360);

    std::cout << (count / X);

    return 0;
}

Measured memory_bytes: 3608
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
vector<int> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m;
  if(n>m)n--;
    cout << n << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

struct moves
{
    char ch, direction;

    moves(){}

    moves(char C, char D)
    {
        ch = C, direction = D;
    }
};

using namespace std;


int displacement(string &S, int position, vector <moves> &M)
{ //cout << position << " final = ";
    for(int i = 1; i < M.size(); i++)
    {
        if(S[position] == M[i].ch)
        {
            position += (M[i].direction == 'L' ? -1 : 1);
        }

        if(position == 0 || position == S.size() - 1)
        {
            break;
        }
    }// cout << position << endl;

    return position;
}

int main()
{
    int length, no_of_moves;
    string S;
    cin >> length >> no_of_moves >> S;

    S = '*' + S + '*';

    vector <moves> M(no_of_moves + 1);
    for(int i = 1; i <= no_of_moves; i++)
    {
        cin >> M[i].ch >> M[i].direction;
    }

    int left = 0, right = length + 1;
    while(right - left > 1)
    {
        int mid = (left + right)/2;

        if(displacement(S, mid, M) == 0)
        {
            left = mid;
        }
        else
        {
            right = mid;
        }
    }
    int rightmost_to_fall_left = left; //cout << "R = " << rightmost_to_fall_left << endl;

    left = 0, right = length + 1;
    while(right - left > 1)
    {
        int mid = (left + right)/2;

        if(displacement(S, mid, M) == length + 1)
        {
            right = mid;
        }
        else
        {
            left = mid;
        }
    }
    int leftmost_to_fall_right = right; //cout << "L = " << leftmost_to_fall_right << endl;

    int remaining = (leftmost_to_fall_right - 1) - rightmost_to_fall_left;
    cout << remaining;

    return 0;
}


Measured memory_bytes: 984
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
ll high_order_bit(ll n){
    ll tmp=1,i=-1;
    while(tmp<=n){
        tmp*=2;
        i++;
    }
    if(n==0) return 0;
    else return i;
}
vector<ll> binary_expansion(ll n){
    vector<ll> B(high_order_bit(n)+1);
    ll tmp=n;
    for(ll i=high_order_bit(n);i>=0;i--){
        B[i]=tmp/pw2[i];
        tmp%=pw2[i];
    }
    return B;
}
vector<ll> divisor(ll x){
    vector<ll> div;
    for(int i=1;i*i<=x;i++){
        if(i*i!=x && x%i==0){
            div.pb(i);
            div.pb(x/i);
        }
        else if(x%i==0) div.pb(i);
    }
    return div;
}
vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}

int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    ll count=0;
    vector<ll> V=vectorprime(55555);
    rep(i,sz(V)){
        if(V[i]%5==2){
            cout<<V[i]<<" ";
            count++;
        }
        if(count==N) break;
    }
}

Measured memory_bytes: 3724
#include <iostream>

void dump(int a[],int s,int n)
{
  for (int codeTest = s; codeTest < n; ++codeTest) {
    if (codeTest!=0)std::cout << " ";
    std::cout << a[codeTest];
  }
}

int partition(int *a,int p,int r) {
  int x = a[r];
  int i = p-1;
  for (int j = 0; j < r; ++j) {
    if (a[j]<=x){
      ++i;
      std::swap(a[i],a[j]);
    }
  }
  std::swap(a[i+1],a[r]);
  return i+1;
}
int main() {
  int n;
  int a[100000];
  std::cin >> n;
  for (int i = 0; i < n; ++i) {std::cin >> a[i];}
  int k=partition(a,0,n-1);
  dump(a,0,k);
  std::cout << " [" <<a[k] <<"]";
  dump(a,k+1,n);
  std::cout  << '\n';

  return 0;
}



Measured memory_bytes: 3424
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    int x,n;cin>>x>>n;
    V<int>p(n);
    map<int,int>m;
    for(int i=0;i<n;i++){
        cin>>p[i];
        m[p[i]]++;
    }
    for(int c=0;;c++){
        int l=x-c;
        if(m[l]==0){
            cout<<l<<endl;
            return 0;
        }
        int r=x+c;
        if(m[r]==0){
            cout<<r<<endl;
            return 0;
        }
    }
    //-------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


















































Measured memory_bytes: 3664
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

ABCDE = [[INT()] for i in range(5)]

for i in range(5):
    if ABCDE[i][0] % 10 == 0:
        ABCDE[i].append(ABCDE[i][0])
        ABCDE[i].append(0)
        
    else:
        wait = ((ABCDE[i][0] // 10) + 1) * 10
        ABCDE[i].append(wait)
        ABCDE[i].append(wait - ABCDE[i][0])

ABCDE.sort(key = lambda x : x[2])

ans = ABCDE[4][0]

for i in range(4):
    ans += ABCDE[i][1]
    
print(ans)

Measured memory_bytes: 62072
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };


int main(void) {

	ll n, a, b;
	ll total = 0;
	ll x[100001];

	cin >> n >> a >> b;
	FOR(i, 1, n) {
		cin >> x[i];
	}

	FOR(i, 1, n - 1) {
		if (b < a*(x[i + 1] - x[i])) {
			total += b;
		}
		else {
			total += a * (x[i + 1] - x[i]);
		}
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 1024
from collections import deque
N,M = map(int,input().split())
dis = [[-1,-1,-1] for _ in range(N+1)]
Tree = [[] for _ in range(N+1)]
for i in range(M):
    ui,vi = map(int,input().split())
    Tree[ui].append(vi)
S,T = map(int,input().split())
d = deque([(S,0)])
dis[S][0] = 0
while d:
    x,z = d.popleft()
    for y in Tree[x]:
        if dis[y][(z+1)%3] == -1:
            dis[y][(z+1)%3] = dis[x][z] + 1
            d.append((y,(z+1)%3))
if dis[T][0] == -1:
    print(-1)
else:
    print(dis[T][0]//3)

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

int n, k;
int a[510];
int sum, ans;
vector<int> v;

void f(int x) {
    v.clear();
    int s = 0;
    int t = 0;
    for(int i=0; i<n; i++) {
        v.push_back(a[i] % x);
        s += a[i] % x;
    }
    s /= x;

    sort(v.begin(), v.end());

    for(int i=n-1; i>=0; i--) {
        if(s == 0) t += v[i];
        else s--;
    }

    if(t <= k) ans = max(ans, x);
}

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

    cin >> n >> k;

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

    for(int i=1; i*i <= sum; i++) {
        if(sum%i==0) f(i), f(sum/i);
    }

    cout << ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream> 
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define ull unsigned long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-18
#define maxn 100010
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll ans=1; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;}
using namespace std;
int x[110],y[110],d[110];
int a[30],base[30];
int n,m,l;
int main()
{
	l=read();
	if(l<=2){
		printf("2 %d\n",l);
		for(int i=0;i<l;i++)
			printf("1 2 %d\n",i);
		return 0;
	}
	int len=0;
	while(1<<len<=l)++len;
	n=len; m=0;
	for(int i=0;i<len-1;i++){
		x[++m]=i+1; y[m]=i+2; d[m]=0;
		x[++m]=i+1; y[m]=i+2; d[m]=1<<i;
	}
	for(int i=len-2;i>=0;i--)
		if(l&(1<<i)){
			x[++m]=i+1; y[m]=n; d[m]=l>>(i+1)<<(i+1);
		}
	printf("%d %d\n",n,m);
	for(int i=1;i<=m;i++)
		printf("%d %d %d\n",x[i],y[i],d[i]);
	return 0;
}

Measured memory_bytes: 256
# 長さ
N = int(input())
A = input()
B = input()
C = input()

result = 0

for i in range(N):
    if A[i] == B[i]  and B[i] == C[i] and A[i] == C[i]:
        # 全文字同じ
        pass
    elif A[i] == B[i]  or B[i] == C[i] or A[i] == C[i]:
        # 1個だけ違う
        result = result + 1
    else:
        result = result + 2

print(result)

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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;


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

    ll x, y;
    cin >> x >> y;
    ll r = 0;
    if(x == 1){
        r += 300000;
    }else if(x == 2){
        r += 200000;
    }else if(x == 3){
        r += 100000;
    }
    if(y == 1){
        r += 300000;
    }else if(y == 2){
        r += 200000;
    }else if(y == 3){
        r += 100000;
    }
    if(x == 1 && y == 1){
        r += 400000;
    }
    cout << r << endl;

    return 0;
}


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

int main(){
    int h, w;
    string s;
    cin >> h >> w;

    for (int i = 0; i < h; i++)
    {
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }

    return 0;
}

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

#define rep(i, n)     for (int i = 0; i < (int) (n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp)   for (auto &i : mp)

const int INF = 1001001001;

int main()
{
  string s;
  cin >> s;
  string ans;
  if (s.back() == 's') {
    // s.pop_back();
    // std::cout << "vvv" << '\n';
    s.push_back('e');
    s.push_back('s');
    ans = s;
  }
  else {
    s.push_back('s');
    ans = s;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
H, W = map(int, input().split())
lines = [input() for _ in range(H)]
dp = [[0 for _ in range(W)] for _ in range(H)]

dp[0][0] = 1 if lines[0][0] == '#' else 0

for i in range(1, W):
  if lines[0][i-1] != '#' and lines[0][i] == '#':
    dp[0][i] = dp[0][i-1] + 1
  else:
    dp[0][i] = dp[0][i-1]

for i in range(1, H):
  if lines[i-1][0] != '#' and lines[i][0] == '#':
    dp[i][0] = dp[i-1][0] + 1
  else:
    dp[i][0] = dp[i-1][0]

for i in range(1, H):
  for j in range(1, W):
    if lines[i-1][j] != '#' and lines[i][j] == '#':
      a = dp[i-1][j] + 1
    else:
      a = dp[i-1][j]

    if lines[i][j-1] != '#' and lines[i][j] == '#':
      b = dp[i][j-1] + 1
    else:
      b = dp[i][j-1]

    dp[i][j] = min(a, b)

# for l in dp:
#   print(l)
print(dp[H-1][W-1])

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

#define int long long
signed main(){
    int n, m;
    cin >>n >>m;
    int k[n]={};
    k[0] = 1;
    int w[n];
    for(int i =0; i<n;i++){
        w[i]=1;
    }
    int x,y;
    for(int i =0;i<m;i++){
        cin >> x >> y;
        k[y-1] += k[x-1];
        w[y-1]++;w[x-1]--;
        if(w[x-1]==0){
            k[x-1]=0;
        }
    }
    int t = 0;
    for(int i =0; i<n;i++){
        if(k[i]!=0){
            t++;
        }
    }
    cout << t;
   
    
    return 0;
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, x, m, ans, i, pre, sum=0, nok, cnt=0;
    map<long long, long long > mp;
    cin >> n >> x >> m;
    pre=x;ans=x;
    for(i=2;i<=n;i++){
        ans+=(pre*pre)%m;
        if(((pre*pre)%m) == 0) break;
        pre=(pre*pre)%m;
        mp[pre]++;
        if(mp[pre]>1) break;
    }
    nok=n-i;
    if(nok>0){
        for(i=2;i<=n;i++){
            cnt++;
            sum=sum+(pre*pre)%m;
            if(((pre*pre)%m) == 0) break;
            pre=(pre*pre)%m;
            mp[pre]++;
            if(mp[pre]>2 && cnt!=0) break;
        }
        ans+=sum*(nok/cnt);
        nok-=(nok/cnt)*cnt;
        for(i=0;i<nok;i++){
            ans+=(pre*pre)%m;
            pre=(pre*pre)%m;
        }

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

Measured memory_bytes: 6728
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(decltype(N+k) i=k; i<N;i++)
#define rep(i,N) for(decltype(N) i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return 約数unordered_set 1 <= x <= n
auto divv = [](auto n) {
  unordered_set<decltype(n)> v;
  for(decltype(n) i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.insert(i);
      if(i*i != n) v.insert(n/i);
    }
  }
  return v;
};

// check prime (and n>=2) or not
auto isPrime = [](auto n){
  if(n <= 1) return false;
  for(decltype(n) i = 2; i <= sqrt(n); ++i) {
      if(n % i == 0) {
          return false;
      }
  }
  return true;
};

int main() {
    ll a,b;
    cin>>a>>b;
    if(a<b) swap(a,b);

    auto r = a % b;
    auto x = a*b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    pr(x/b);
 

}


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

int main()
{
  int N;
  cin >> N;
  double sum = 0.;
  for (int i = 0; i < N; ++i)
  {
    int A;
    cin >> A;
    sum += 1./A;
  }
  cout << 1./sum;
  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){ T x; cin >> x; return (x); }

class sushi{
public:
	ll d,t,p;

	sushi()=default;
	sushi(ll a,ll b,ll c):d(a),t(b),p(c){}
	bool operator>(const sushi& rhs)const{
		return p>rhs.p;
	}
};

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

	int N=in(),K=in();
	vector<sushi> s(N);
	for(auto& x:s){
		ll t=in<ll>(),d=in<ll>();
		x = sushi(d,t,0LL);
	}
	sort(ALL(s),[&](sushi& lhs,sushi& rhs){return lhs.d>rhs.d;});
	priority_queue<sushi,vector<sushi>,greater<sushi>> eat;
	set<ll> ul;
	ll unum=0;
	ll dsum=0;
	REP(i,N){
		auto r = ul.emplace(s[i].t);
		if(r.second){
			s[i].p += 1e12;
			if(i<K) unum++;
		}
		s[i].p+=s[i].d;
		if(i<K){
			eat.push(s[i]);
			dsum += s[i].d;
		}
	}
	vector<sushi> z;
	if(N-K>0){
		copy(s.begin()+K,s.end(),back_inserter(z));
		sort(ALL(z),[&](sushi& lhs,sushi& rhs){return (lhs.t!=rhs.t)?lhs.t<rhs.t:(lhs.p>rhs.p);});
		z.erase(unique(ALL(z),[&](sushi& lhs,sushi& rhs){return lhs.t==rhs.t;}),z.end());
		sort(ALL(z),greater<sushi>());
	}
	ll maxs=dsum+unum*unum;
	for(int i=0,ei=z.size();i<ei;i++){
		if(z[i].p<1e12) break;
		auto b = eat.top();
		if(b.p>=1e12) break;
		eat.pop();
		dsum += z[i].d-b.d;
		unum++;
		maxs = max(maxs,dsum+unum*unum);
	}

	cout << maxs << endl;
	return 0;
}


Measured memory_bytes: 10804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(void){
    string S;
    cin>> S;
    int n = S.size();
    bool check = true;
    for(int i = 0; i < n; i++){
        if(S.at(i) != S.at(n-1-i)) check = false;
    }
    for(int i = 0; i < n/2; i++){
        if(S.at(i) != S.at(n/2 -1 - i)) check = false;
    }
    for(int i = 0; i < n/2; i++){
        if(S.at(i+n/2+1) != S.at(n-1-i)) check = false;
    }
    if(check) cout << "Yes" <<endl;
    if(!check) cout << "No" <<endl;




}


Measured memory_bytes: 256
N=int(input())
S=input()

cost=[]
left=0
right=0
for i in range(N):
	if S[i]=='#':
		right+=1

cost.append(N-right)
for i in range(0,N):
	if S[i]=='#':
		left+=1
		right-=1
	cost.append(left+N-i-1-right)

cost.sort()
print(cost[0])

Measured memory_bytes: 12168
/*------------------------------------ 
........Bismillahir Rahmanir Rahim.... 
..........created by Abdul Aziz....... 
------------------------------------*/ 
#include <iostream> 
#include <algorithm> 
#include <stdio.h> 
#include <cmath> 
#include <vector> 
#include <set> 
#include <map> 
#include <cstring> 
#include <unordered_map> 
#include <queue> 
#define   mod  998244353 
#define   int  long long 
#define   ld   long double 
#define   pb   push_back 
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   sz(x)  (int)x.size() 
#define   all(a) (a.begin(),a.end()) 
#define   ff   first 
#define   ss   second 
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std; 
 
int n,k; 
map <int,bool> mp; 
int h[9],l=0,ans=100000000; 
 
void fun(int num){ 
	if (num >= n){
		ans = min(ans,num);
		return;
	}
	for (int i=0;i<l;i++){
		int x=num*10+h[i];
		if (x) fun(x);
	}
} 
 
inline void solve(){ 
    cin >> n >> k ; 
    for (int i=1;i<=k;i++) { 
    	int a; cin >> a; 
    	mp[a] = true; 
    } 
    for (int i=0;i<10;i++) 
    	if (!mp[i]) h[l++] = i; 
    fun(0);
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s;
    cin >> s;
    int ans = 0, n = s.length();

    int t = 0;
    REP(i,n){
        if (s[i] > '0'){
            int tmp = t + (s[i] - '0' - 1);
            FOR(j,i+1,n-1) tmp += 9;
            ans = max(ans, tmp);
        }
        t += (s[i] - '0');
    }
    ans = max(ans, t);
    cout << ans << endl;
    

    return 0;
}


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

using namespace std;

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

    vector<bool> check(3,false);
    for(int i=0;i<s.length();i++){
        check[s[i]-'a']=true;
    }
    for(int i=0;i<3;i++){
        if(check[i]==false){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main() {
  int n;

  cin >> n;

  vector<int> a;

  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  int cnt = 0;
  bool flag = true;

  while (flag) {
    for (int i = 0; i < n; i++) {
      if (a.at(i) % 2 == 0)
        a.at(i) /= 2;
      else
        flag = 0;
    }
    if (flag) cnt++;
  }

  cout << cnt;

  return 0;
}

Measured memory_bytes: 256