akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int x, a, b;

int main() {
	cin >> x >> a >> b;
	cout << (x - a) % b << endl;
	
	return 0;	
}

Measured memory_bytes: 256
from collections import deque, defaultdict
H, W = map(int, input().split())
sheet = [[0]*(W+2) for i in range(H+2)]
dist = defaultdict(int)
cnt = 0
for i in range(1,H+1):
  inf = input()
  for j in range(1, W+1):
    if inf[j-1]=='.':
      sheet[i][j]=1
      cnt += 1
deq = deque([(1,1,1)])
dist[(1,1)] = 1
while deq:
  x,y,d = deq.popleft()
  flag = False
  for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)]:
    nx = x+dx
    ny = y+dy
    if sheet[ny][nx]==1 and dist[(nx,ny)]==0:
      deq += [(nx,ny,d+1)]
      dist[(nx,ny)]=d+1
      if nx==W and ny==H:
        flag= True
        break
  if flag:
    print(cnt-dist[(W,H)])
    break
else:
  print(-1)

Measured memory_bytes: 40688
import sys

N = int(input())
A = list(map(int, input().split()))
ans = 1
A.sort()

if A[0] == 0:
    print(0)
    sys.exit()

for a in A:
    ans *= a
    if ans > 10 ** 18:
        print(str(-1))
        break
else:
    print(ans)

Measured memory_bytes: 88760
import java.util.*;

public class Main {

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

        if(m == n)
        {
            System.out.println(n*2);

        } else {
            int max = Math.max(m,n);
            System.out.println(max*2-1);
        }
    }
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int a,b;
    cin >> s;
    int count=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='Z'){a=i;}
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            b=i;
            break;
        }
    }
    cout << a-b+1 << endl;


    return 0;
}

Measured memory_bytes: 720
a,b,k = map(int, input().split())
l = []
for i in range(k):
    if a+i<=b:
        l.append(a+i)
for i in range(k):
    if not b-k+i+1 in l and a<=b-k+i+1:
        l.append(b-k+1+i)
l.sort()
for x in l:
    print(x)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
int n,k,q;
  scanf("%d%d%d",&n,&k,&q);
  int a[q];
  for(int i=0;i<q;i++){
    scanf("%d",&a[i]);
  }

  int anscount[n];
  
  for(int i=0;i<n;i++){
    anscount[i]=0;
  }
  for(int i=0;i<q;i++){
    anscount[a[i]-1]++;
  }
  for(int i=0;i<n;i++){
   if(k-q+anscount[i]>0)printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}
        

Measured memory_bytes: 1280
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    E = [[] for i in range(N+1)]
    counter = [0] * (N+1)

    for i in range(N-1):
        a, b = map(int, input().split())
        E[a].append(b)
        E[b].append(a)

    for i in range(Q):
        # 頂点p を根とする部分木に含まれるカウンターにxを足す
        p, x = map(int, input().split())
        counter[p] += x

    queue = []

    parent = [1]
    def mktree(v, parent, E):
        children = E[v]
        children.remove(parent)
        for child in children:
            mktree(child, v, E)

    while parent:
        p = parent.pop()
        for child in E[p]:
            E[child].remove(p)
            parent.append(child)

    def get(v, children, counter):
        c = counter[v]
        for child in children[v]:
            counter[child] += c
            get(child, children, counter)
    """
    parent = [1]
    while parent:
        p = parent.pop()
        c = counter[p]
        for child in E[p]:
            counter[child] += c
            parent.append(child)
    """
    get(1, E, counter)
    print(" ".join(str(x) for x in counter[1:]))

main()






Measured memory_bytes: 269816
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vvi k(n);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    k[a].pb(b);
  }
  for(auto i : k[0]){
    for(auto j : k[i]){
      if(j == n-1){
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 8576
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	int f = 0;
	while (n) {
		if (n % 10 == 7) f = 1;
		n /= 10;
	}
	if (f) cout << "Yes";
	else cout << "No";







}

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

int main(){
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        int cnt = 1;
        if (s[i+1][j] == '#') {
          cnt++;
        }
        if (s[i-1][j] == '#') {
          cnt++;
        }
        if (s[i][j+1] == '#') {
          cnt++;
        }
        if (s[i][j-1] == '#') {
          cnt++;
        }
        if (cnt == 1){
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int lserch(int A[],int B[],int m,int n){
    int count=0;
    for(int j=0;j<m;j++){
        int i=0;
        int key=B[j];
        while(A[i]!=key){
            i++;
        }
        if(i<n){
            count++;
        }
    }
    return count;
}
int main(){
    int A[10000]={};
    int B[10000]={};
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>B[i];
    }
    cout<<lserch(A,B,m,n)<<endl;
    return 0;
}


Measured memory_bytes: 3196
from itertools import product
H, W = map(int, input().split())
a = []
for i in range(H): a.append(list(input()))
for i in range(H):
    for j in range(W):
        b = 0
        if a[i][j] == '#':continue
        for k,l in product([-1,0,1], repeat=2):
            if k == l == 0:continue
            h = i + k
            w = j + l
            if h < 0 or h >= H: continue
            if w < 0 or w >= W: continue
            if a[h][w] == '#':b+=1
        a[i][j] = b

for i in range(H):
    print(''.join(map(str,a[i])))

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{

	public static void main(String[] args){

		Scanner sc =new Scanner(System.in);

		while(true) {

			int n=sc.nextInt();
			if(n==0) break;

			int s[]=new int [n];

			int sum=0;

			for(int i=0;i<n;i++) {
				s[i]=sc.nextInt();
				sum+=s[i];
			}

			double m=sum/(double)n;

			System.out.printf("%.8f\n",Math.sqrt(Dispersion(s,m)));

		}

	}

	private static double Dispersion(int s[],double m) {
		double x=0;
		for(int i=0;i<s.length;i++)
			x+=(s[i]-m)*(s[i]-m);
		return x/s.length;
	}


}



Measured memory_bytes: 31540
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main()
{
    long long N, M;
    cin >> N >> M;

    unordered_map<long long, vector<long long>> Map;

    long long a, b;
    for (int i = 0; i < M; i++)
    {
        cin >> a >> b;
        a--;
        b--;
        Map[a].push_back(b);
        Map[b].push_back(a);
    }

    vector<long long> tmp;
    for (int i = 0; i < Map[0].size(); i++)
    {
        tmp.push_back(Map[0][i]);
    }

    for (int i = 0; i < tmp.size(); i++)
    {
        for (int j = 0; j < Map[tmp[i]].size(); j++)
        {
            if (Map[tmp[i]][j] == N - 1)
            {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 21296
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
#define diup(v,a) distance((v).begin(),upper_bound((v).begin(),(v).end(),(a)))
#define dilo(v,a) distance((v).begin(),lower_bound((v).begin(),(v).end(),(a)))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};

struct D21{
  int is,js;
  D21(int isize,int jsize){
    is = isize;
    js = jsize;
  }
  int operator()(int i,int j){
    return i*js+j;
  }
};

void Main(){
  string s,t;
  cin>>s>>t;
  int n = s.length();
  int m = t.length();

  vvi dp(n+1,vi(m+1,0));
  vvi prev(n+1,vi(m+1,-2));

  rep(i,n){
    rep(j,m){
      if(s[i]==t[j]) {
        dp[i+1][j+1] = dp[i][j] + 1;
        prev[i+1][j+1] = j;
      } else {
        if( chmax(dp[i+1][j+1], dp[i+1][j]) ) prev[i+1][j+1] = j  ;
        if( chmax(dp[i+1][j+1], dp[i][j+1]) ) prev[i+1][j+1] = j+1;
      }
    }
  }

  int now = dp[n][m];
  string ans;
  ans.reserve(10);
  int a = n+1;
  while(--a){
    int b = m+1;
    while(--b){
      if(dp[a][b]==now and dp[a-1][b-1]==now-1 and dp[a-1][b]==now-1 and dp[a][b-1]==now-1){
        --now;
        ans = s[a-1] + ans;
        break;
      }
    }
  }
  cout<<ans<<endl;
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 70912
#include<stdio.h>

int main()
{
	int n,x,i,j,k;
	
	while(1)
	{
		int c = 0;
		scanf("%d %d",&n,&x);
		if(n == 0 && x == 0)
		{
			break;
		}
		for(i=1;i<=n;i++)
		{
			for(j=i+1;j<=n;j++)
			{
				for(k=j+1;k<=n;k++)
				{
					if(i+j+k==x)
					{
						c++;
					}
				}
			}
		}
		printf("%d\n",c);
	}
    return 0;
}

Measured memory_bytes: 600
module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
import           Data.Ord
import           Data.Vector.Algorithms.Search
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.IO                 as AIO
import qualified Data.Set                      as S

main = do
    [aS, aW] <- getIL
    putStrLn $ if aS > aW then "safe" else "unsafe"


getVUIL :: IO (VU.Vector Int)
getVUIL = VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
readI :: BSC8.ByteString -> Int
readI = fst . fromJust . BSC8.readInt
readIL :: BSC8.ByteString -> [Int]
readIL = map readI . BSC8.words
readIT2 :: BSC8.ByteString -> (Int, Int)
readIT2 bs =
    let words = BSC8.words bs in (readI $ head words, readI $ last words)
getI :: IO Int
getI = readI <$> BSC8.getLine
getIL :: IO [Int]
getIL = readIL <$> BSC8.getLine
getIT2 :: IO (Int, Int)
getIT2 = readIT2 <$> BSC8.getLine

getNIS :: Int -> IO [(Int, BSC8.ByteString)]
getNIS 0 = return []
getNIS n = do
    [aFst, aSnd] <- BSC8.words <$> BSC8.getLine
    next         <- (getNIS (n - 1))
    return ((readI aFst, aSnd) : next)

il2ss :: [Int] -> String
il2ss = unwords . map show

il2sn :: [Int] -> String
il2sn = unlines . map show

modNum = 10 ^ 9 + 7
newtype Mint = M Int
instance Num Mint where
    (M a) + (M b) = M $ mod (a + b) modNum
    (M a) - (M b) = M (a - b)
    (M a) * (M b) = M $ mod (a * b) modNum
    fromInteger a = M $ mod (fromInteger a) modNum
    abs (M a) = M $ abs a
    signum (M a) = M $ signum a
instance Show Mint where
    show (M a) = show (mod a modNum)

int2MInt :: Int -> Mint
int2MInt a = M (mod a modNum)


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

int main() {
  int sum = 0;
  int ans = 100000;
  vector<int> vec(5);
  for(int i=0;i<5;++i){
    cin >> vec.at(i);
  }

  for(int i=0;i<5;++i){
    for(int j=0;j<4;++j){
      sum += vec.at(j);
      if(sum % 10 != 0){
        sum += 10 - vec.at(j)%10;
      }
    }
    sum += vec.at(4);
    if(ans > sum) ans = sum;
    sum = 0;
    vec.push_back(vec.at(0));
    vec.erase(vec.begin());
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3580
#N,K = map(str,input().split())
N = int(input())
#K = int(input())
#X = list(map(int,input().split()))
c=1
if N==1:
    print(1)
    exit()
flag=True
while flag==True:
    c = c*2
    if c > N:
        flag=False
        c=c//2
    elif c==N:
        flag=False
print(c)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue

#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n;
pii seg[MN];
pii seg2[MN];

bool comp1(pii a, pii b){
    if(a.s != b.s) return a.s < b.s;
    return a.f < b.f;
}
bool comp2(pii a, pii b){
    if(a.f != b.f) return a.f > b.f;
    return a.s > b.s;
}


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

    cin >> n;
    F0R(i, n){
        cin >> seg[i].f >> seg[i].s;
        seg2[i] = seg[i];
    }
    n++;
    sort(seg, seg+n, comp1);
    sort(seg2, seg2+n, comp2);

    ll ans = 0;
    int cur = 0;
    while(seg[cur].s < seg2[cur].f){
        ans += 2LL*(seg2[cur].f-seg[cur].s);
        cur++;
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

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

    int tot = 0;
    for(int i = 0; i<n; ++i) {
    	if(s[i] == 'R')
    		tot++;
    }

    int cnt = 0;
    for(int i = 0; i<n; ++i) {
    	if(i<tot && s[i]=='R')
    		cnt++;
    }

    cout<<tot-cnt<<endl;
}

Measured memory_bytes: 3708
from fractions import gcd
from math import sqrt


def prime_factorize(n):
    result = []
    for i in range(2, int(sqrt(n)) + 1):
        if n % i != 0:
            continue
        t = 0
        while n % i == 0:
            n //= i
            t += 1
        result.append((i, t))
        if n == 1:
            break
    if n != 1:
        result.append((n, 1))
    return result


A, B = map(int, input().split())
print(len(prime_factorize(gcd(A, B))) + 1)

Measured memory_bytes: 5304
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 998244353;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    string s; cin >> s;
    ll ans = 1;
    ll rc = 0, bc = 0, gc = 0, rem = n, rem1 = 0, rem2 = 0;
    REP(i, s.size()) {
        if (s[i] == 'R') {
            rc++;
            if (rc > bc && rc > gc) {
                (ans *= rem) %= MOD;
                rem--;
                rem1++;
            } else if (rc <= bc && rc <= gc) {
                (ans *= rem2) %= MOD;
                rem2--;
            } else {
                (ans *= rem1) %= MOD;
                rem1--;
                rem2++;
            }
        } else if (s[i] == 'B') {
            bc++;
            if (bc > rc && bc > gc) {
                (ans *= rem) %= MOD;
                rem--;
                rem1++;
            } else if (bc <= rc && bc <= gc) {
                (ans *= rem2) %= MOD;
                rem2--;
            } else {
                (ans *= rem1) %= MOD;
                rem1--;
                rem2++;
            }
        } else {
            gc++;
            if (gc > rc && gc > bc) {
                (ans *= rem) %= MOD;
                rem--;
                rem1++;
            } else if (gc <= rc && gc <= bc) {
                (ans *= rem2) %= MOD;
                rem2--;
            } else {
                (ans *= rem1) %= MOD;
                rem1--;
                rem2++;
            }
        }
    }

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


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

int main(){
ll int n,x,t;
cin>>n>>x>>t;
int res;
if(n%x==0){
    res=n/x;
    res=res*t;
}
else {
    res=floor(n/x)+1;
    res=res*t;
    }
cout<<res<<endl;
return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  ll ans = 1;
  if(abs(n - m) >= 2) {
    cout << 0 << endl;
    return 0;
  }
  for(int i = 1; i <= n; ++i) (ans *= i) %= mod;
  for(int i = 1; i <= m; ++i) (ans *= i) %= mod;
  if(n == m) (ans *= 2) %= mod;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main ()
{
    int N,n,a,b,c,d;
    cin>>N;
    b=(N/1000);
    c=b+1;
    n=c*1000;
    a=n-N;
    d=N%1000;
    if(d!=0)
        cout<<a;
        else
    cout<<"0";
}


Measured memory_bytes: 3156
from __future__ import division
from collections import defaultdict, deque
from heapq import heappush, heappop
from sys import stdin

class UnionFindSet:
	def __init__(self, nodes):
		self.fa = {}
		for n in nodes:
			self.fa[n] = n

	def find(self, x):
		if self.fa[x] == x:
			return x
		else:
			self.fa[x] = self.find(self.fa[x])
			return self.fa[x]

	def union(self, x, y):
		fx = self.find(x)
		fy = self.find(y)
		if fx == fy:
			return fx
		else:
			self.fa[fx] = fy
			return fy


"""
graph is a hash
graph["nodes"] is a list of all nodes in the graph
graph["edges"] is a list of all edges in the graph in (x, y, w) form
  - x is the first nodes
  - y is the second nodes
  - w is the weight of the edges
graph["relation"] is the graph relation of the graph
"""

def kruscal(graph):
	"kruscal minimum spanning tree algorithm"
	ufset = UnionFindSet(graph["nodes"])

	ret = 0

	for (x, y, w) in sorted(graph["edges"], key = lambda x: x[-1]):
		fx = ufset.find(x)
		fy = ufset.find(y)
		if fx != fy:
			ret += w
			ufset.union(fx, fy)
		else:
			pass
	return ret


def dijkstra(graph, root):
	"dijkstra algorithm for single source shortest algorithm"
	dis, vis = {}, {}
	for n in graph["nodes"]:
		dis[n] = 10 ** 9
		vis[n] = False

	heap = []
	dis[root] = 0
	heappush(heap, (0, root))

	while heap:
		_, n = heappop(heap)
		vis[n] = True
		for (y, w) in graph["adj"][n]:
			if not vis[y] and dis[n] + w < dis[y]:
				dis[y] = dis[n] + w
				heappush(heap, (dis[y], y))

	return dis

def belmanFord(graph, root):
	dis = {}
	for n in graph["nodes"]:
		dis[n] = 10 ** 9

	dis[root] = 0

	# update for n - 1 times
	for _ in range(len(graph["nodes"]) - 1):
		for (x, y, w) in graph["edges"]:
			if dis[x] + w < dis[y]:
				dis[y] = dis[x] + w

	connect = set([root])
	que = deque([root])

	while que:
		n = que.popleft()
		for (y, _) in graph["adj"][n]:
			if not y in connect:
				connect.add(y)
				que.append(y)

	dis["negcicle"] = False
	for (x, y, w) in graph["edges"]:
		if dis[x] + w < dis[y] and x in connect:
			dis["negcicle"] = True

	dis["con"] = connect
	return dis

if __name__ == '__main__':
	V, E, root = map(int, stdin.readline().strip().split())
	graph = {}
	graph["nodes"] = [i for i in range(V)]
	graph["edges"] = []
	graph["adj"] = defaultdict(list)
	for _ in range(E):
		x, y, w = map(int, stdin.readline().strip().split())
		graph["edges"].append((x, y, w))
		graph["adj"][x].append((y, w))

	dis = belmanFord(graph, root)

	if dis["negcicle"]:
		print "NEGATIVE CYCLE"
	else:
		for n in graph["nodes"]:
			print dis[n] if dis[n] < 10 ** 9 and n in dis["con"] else "INF"

Measured memory_bytes: 5404
def square(a)
  length_candidates = a.group_by(&:itself).each_with_object([]) do |(k, v), arr|
    [v.size / 2, 2].min.times { arr << k }
  end
  return 0 if length_candidates.size < 2
  length_candidates.sort[-2..-1].inject(:*)
end

gets
a = gets.split.map(&:to_i)
p square(a)


Measured memory_bytes: 23428
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();

        int N = cin.nextInt();
        string[] s = new string[N];
        for (int i = 0; i<N; i++) {
            s[i]= cin.nextString();
        }

        for (int i = 1; i<N; i++) {
            if (s[i][0] != s[i-1][s[i-1].Length-1]) {
                Console.WriteLine("No");
                return;
            }
        }

        Array.Sort(s);
        for (int i = 1; i<N; i++) {
            if (s[i] == s[i-1]) {
                Console.WriteLine("No");
                return;
            }
        }

        Console.WriteLine("Yes");
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


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

#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define endl "\n"
#define e "\n"
#define show(arr) REP(i,arr.size()){cout<<arr[i]<<" ";}
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

#define N 5010

void solve()
{
    int a,b;
    cin >> a >> b;
    if (a*b<=0)
    {
        cout<<"Zero";
    }
    else {
        if (a<0){
            if ((abs(b-a)+1)%2==1){
                cout<<"Negative";
            }
            else {
                cout<<"Positive";
            }
        }
        else {
            cout<<"Positive";
        }
    }
}

signed main()
{
    int t=1;
    //cin>>t;
    WL(t)solve();

    return 0;
}




Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)

//dpテーブルをローカルで宣言したらセグフォになった...

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 dp[110][100010]={0};

int main(){
  ll n,W;
  cin >> n >> W;
  ll w[200];
  ll v[200];
  rep(i,n)cin >> w[i] >> v[i];
  rep(i,n){
    rep(sum,W+1){
      if(sum-w[i]>=0){
        chmax(dp[i+1][sum],dp[i][sum-w[i]]+v[i]);
      }
      chmax(dp[i+1][sum],dp[i][sum]);
    }
  }
  cout << dp[n][W] << endl;
}


Measured memory_bytes: 79360
import java.util.StringTokenizer
import java.io.PrintWriter

fun main() {
    val reader = System.`in`.bufferedReader()
    var tokenizer: StringTokenizer = StringTokenizer("")
    val writer = PrintWriter(System.out, false)

    fun next(): String {
        while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
        return tokenizer.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextDouble() = next().toDouble()
    fun nextLine() = reader.readLine()

    fun solve() {
        var n = nextInt()
        var arr = LongArray(n){next().toLong()}

        var sum = arr.sum()

        var map = mutableMapOf<Long,Long>()

        for (i in arr){
            map[i] = map.getOrDefault(i,0L) + 1
        }



        repeat(nextInt()){
            var b = next().toLong()
            var c=  next().toLong()

            if (b !in map)writer.println(sum)
            else {
                var diff = (c-b)*map[b]!!
                sum+=diff
                writer.println(sum)
                var v = map[b]!!
                map.remove(b)
                map[c] = map.getOrDefault(c,0) + v
            }


        }



    }

    solve()
    writer.flush()


}




Measured memory_bytes: 74244
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
typedef long long ll;

using namespace std;


int main() {
	string s; cin >> s;
	if (s == "SUN") cout << 7 << endl;
	else if (s == "MON") cout << 6 << endl;
	else if (s == "TUE") cout << 5 << endl;
	else if (s == "WED") cout << 4 << endl;
	else if (s == "THU") cout << 3 << endl;
	else if (s == "FRI") cout << 2 << endl;
	else if (s == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;



int main(void)
{
   int n, d;
   cin >> n >> d;

   int ans = (n + 2 * d )/(2*d + 1);

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

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

int main(){
int r=0, b=0, i;
  string s;
cin >> s;
  
  for(i=0; i<s.length(); i++){
    if(s[i]=='0')
      r++;
      else
       b++;
  }
  cout << s.length()-abs(r-b);
return 0;
}

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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int A[100000];

int main()
{
	int N;
	int cntA = 0, cntB = 0, cntC = 0;
	ll ans = 1;

	cin >> N;
	rep(i, N) cin >> A[i];

	rep(i, N) {
		int p = 0;

		if (A[i] == 0) {
			if (cntA == 0) {
				cntA++;
				ans = (ans * 3) % MOD;
			}
			else if (cntB == 0) {
				cntB++;
				ans = (ans * 2) % MOD;
			}
			else if (cntC == 0) cntC++;
			else ans = 0;
			continue;
		}

		if (A[i] == cntA) p++;
		if (A[i] == cntB) p++;
		if (A[i] == cntC) p++;

		if (A[i] == cntA) cntA++;
		else if (A[i] == cntB) cntB++;
		else if (A[i] == cntC) cntC++;

		ans = (ans * p) % MOD;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
N=int(input())
S=input()
K=int(input())
#A,B,C=map(int,input().split())
#A=list(map(int,input().split()))
T=""
for i in S:
    if i!=S[K-1]:
        T+="*"
    else:
        T+=S[K-1]
print(T)


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

int main(){
  char buf[40];
  int kld[]={1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1,0,1};
  int bi,wasleftk,kccnt;

  while (1){
    cin >> buf;
    if (buf[0]=='#')break;
    bi=0;
    wasleftk=2;
    kccnt=-1;
    while (buf[bi]!='\0'){
      if (kld[buf[bi]-'a']!=wasleftk){
	kccnt++;
	wasleftk=kld[buf[bi]-'a'];
      }
      bi++;
    }
    cout << kccnt << endl;
  }
  return 0;
}

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

// clang-format off
#define forn(i, x, y) for(int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
// clang-format on

using VI = vector<int>;

int main()
{
  IOS;
  int N, K;
  cin >> N >> K;
  VI A(N);
  forn(i, 0, N) cin >> A[i];

  VI dp(K + 1);
  for (int i = 0; i <= K; i++)
  {
    if (!dp[i]) // could win at this state
      for (int j = 0; j < N && i + A[j] <= K; j++)
        dp[i + A[j]] = 1;
  }
  cout << (dp[K] ? "First" : "Second") << endl;

  return 0;
}


Measured memory_bytes: 3704
N = int(input())
l = [input() for _ in range(N)]
ch = {'AC': 0, 'WA':0, 'TLE':0, 'RE':0}

for key, value in ch.items():
  ch[key] = l.count(key)

for key, value in ch.items():
  print(key + ' x ' + str(value))

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    char c;
    int x=0,y=0;
    
    rep(i,4){
        cin >> c;
        if(i<2){
            x = x*10 + ctoi(c);
        }else{
            y = y*10 + ctoi(c);
        }
    }
    
    bool YYMM=false;
    if(1<=y && y<=12){
        YYMM=true;
    }
    
    bool MMYY=false;
    if(1<=x && x<=12){
        MMYY=true;
    }
    
    if(YYMM && MMYY){
        cout << "AMBIGUOUS" << endl;
    }else if(YYMM){
        cout << "YYMM" << endl;
    }else if(MMYY){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
    
    
    //cout << "x:y " << x << ":" << y << endl;
}


Measured memory_bytes: 256
import numpy as np
import itertools
N, M, X = map(int,input().split())
ca_lst = []
for i in range(N):
    ca_lst.append(np.array(list(map(int,input().split()))))

oklst = []
for n in range(1,N+1):
    for lst in itertools.combinations(ca_lst,n):
        tmp = sum(lst)
        for i in tmp[1:]:
            if i < X:
                break
        else:
            price = 0
            for m in lst:
                price += m[0]
            oklst.append(price)
if len(oklst) > 0:
    print(min(oklst))
else:
    print(-1)



Measured memory_bytes: 27320
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
  string s, t, ans;
  cin >> s >> t;
  for(int i=0; i<s.size(); i++) {
    ans += s[i];
    if(i==s.size()-1 && s.size()!=t.size()) break;
    for(int j=0; j<1; j++) {
      ans += t[i];
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

int main(void) {
  int d;
  cin >> d;
  arrll(c,26);
  vecll2(s, d, 26);
  rep(i,d){
    rep(j,26){
      cin >> s[i][j];
    }
  }

  vecll ans;

  srand(time(NULL));

  vecll human(26);
  vecll last(26);

  rep(i,d){
    int id = 0;
    ll mx = s[i][0];
    rep(j,26){
      if(mx < s[i][j]){
        id = j;
        chmax(mx, s[i][j]);
      }
    }
    ans.pb(id+1);
  }

  rep(i,d){
    prt(ans[i]);
  }
}


Measured memory_bytes: 3732
import sys
N=int(input())
if N >81:
  print("No")
  sys.exit()
if N==81:
  print("Yes")
else:
  for i in range(1,9):
    a=N/i
    b=(a.is_integer())
    if a<10 and b==True:
      print("Yes")
      break
  else:
    for i in range(1,9):
      c=N/i
      d=(c.is_integer())
      if d==False:
        print("No")
        break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
using namespace std;
template<class T>
inline void read(T &a){
    T s = 0, w = 1;
    char c = getchar();
    while(c < '0' || c > '9') {if(c == '-') w = -1; c = getchar();}
    while(c >= '0' && c <= '9'){s = (s << 1) + (s << 3) + (c ^ 48); c = getchar();}
    a = s*w;
}
int n,p;
int ans = 1;
int a[1000001];
signed main(){
    read(n); read(p);
    int k = p;
    for (int i = 2; i * i <= k; i++){
           while(p % i == 0){
                 a[i]++;
                 p/=i;
            }
    }
    if(n == 1) 
    {
        printf("%lld", k); return 0;
    }
    //24 2*2*2
    for (int i = 1; i *i <= k; i++){
        if(a[i] >= n) ans *= pow(i, a[i]/n);
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

int main(){
	int H,W;
	cin >> H >> W;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			string s;
			cin >> s;
			if(s.compare("snuke")==0){
				cout << (char)('A'+j) << (i+1) << endl;
			}
		}
	}
	return 0;
}


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

int main() {

    map<string,int> mp;

    mp["Magro_Gokitai_Kudasai"] = 0;

    int n;
    cin >> n;

    while(n--){
        string s;
        cin >> s;
        mp[s]++;
    }

    int m;
    cin >> m;

    while(m--){
        string s;
        cin >> s;
        mp[s]--;
    }

    int ans = -500000;

    for(auto a : mp){
        ans = max(ans,a.second);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int x, y;
    int maxX = -1000;
    int minY = 1000;
    for (int i = 0; i < N; i++){
        cin >> x;
        maxX = max(maxX, x);
    }

    for (int i = 0; i < M; i++){
        cin >> y;
        minY = min(minY, y);
    }

    bool flag = false;
    if (maxX < minY){
        for(int i = maxX + 1; i <= minY; i++){
            if (X < i && i <= Y){
                flag = true;
                break;
            }
        }
    }

    if (flag)cout << "No War" << endl;
    else cout << "War" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int vis[500001];
struct node
{
	int x,y;
}p[500001];
bool cmp(node a,node b){return a.y<b.y;}
map<int,int>mp1,mp2;
vector<int>e[500001];
void dfs(int u)
{
	vis[u]=1;
	for(int i=0;i<e[u].size();i++)
	{
		int to=e[u][i];
		if(vis[to]==0)
			dfs(to);
	}
}
int a[500001],b[500001];
signed main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p[i].x);
		a[i]=p[i].x;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p[i].y);
		b[i]=p[i].y;
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
		if(a[i]>b[i])
		{
			printf("No");
			return 0;
		}
	for(int i=1;i<n;i++)
		if(a[i+1]<=b[i])
		{
			printf("Yes");
			return 0;
		}
	for(int i=n;i>=1;i--)
		mp1[a[i]]=i,mp2[b[i]]=i;
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		e[i].push_back(n+mp1[p[i].x]);
		e[n+mp1[p[i].x]].push_back(mp2[b[mp1[p[i].x]]]);
	}
	int res=0;
	for(int i=1;i<=2*n;i++)
		if(!vis[i])
		{
			dfs(i);
			res++;
		}
	if(res==1)
		printf("No");
	else
		printf("Yes");
	return 0;
}
/*
5
1 2 3 4 5 
5 1 2 3 4
*/


Measured memory_bytes: 40960
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;


signed main(){
	//cout << fixed << setprecision(10);
	ll n,x,t; cin >>n>>x>>t;
	cout << ((n/x)+(n %x!=0))*t<<endl;

	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
int md = 100000;
#define addm(X, Y) ((X) = ((X) + (Y) % md) % md)

int n, x;
int a[100000 + 5];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> x;
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep2(i, 1, n) {
        if (a[i] + a[i - 1] > x) {
            if (a[i - 1] > x) {
                ans += a[i - 1] - x;
                a[i - 1] = x;
            }
            ans += a[i] - (x - a[i - 1]);
            a[i] = x - a[i - 1];
        }
    }
    cout << ans << endl;

}


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

int d[100], a[100];
map<vector<int>, int>id;
map<int, vector<int>>re;
int dp[100][5040];

int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &d[i]);
	rep(i, n)scanf("%d", &a[i]);
	vector<int>v(7); iota(v.begin(), v.end(), 0);
	int p = 0;
	do {
		id[v] = p; re[p] = v;
		int cnt = 0, t = 0;
		for (int i : v) {
			rep(j, 7) {
				if ((t >> j & 1) && abs(j - i) <= d[j])cnt += a[j];
			}
			t |= 1 << i;
		}
		dp[0][p] = cnt;
		p++;
	} while (next_permutation(v.begin(), v.end()));
	int ans = 0;
	for (int i = 1; i + 6 < n; i++)rep(j, 5040) {
		vector<int>v = re[j];
		rep(k, 8) {
			vector<int>t = v;
			t.insert(t.begin() + k, 7);
			int cnt = 0, p = 0;
			for (int u : t) {
				if (u == 7) {
					rep(y, 8) {
						if ((p >> y & 1) && y + d[i - 1 + y] >= 7)
							cnt += a[i - 1 + y];
					}
				}
				if ((p >> 7 & 1) && 7 - d[i + 6] <= u)cnt += a[i + 6];
				p |= 1 << u;
				vector<int>q(7); int o = 0;
				for (int c : t) {
					if (c)q[o++] = c - 1;
				}
				int v = id[q];
				dp[i][v] = max(dp[i][v], dp[i - 1][j] + cnt);
				ans = max(ans, dp[i][v]);
			}
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 6296
def dudge(k):
    for i in reversed(range(n)):
        p = (k >> i) % 2
        #print(' i = ', i, ' p = ', p)
        if p == 0: continue

        for claim in xy[i]:
            x = claim[0]
            y = claim[1]

            truth = (k >> x-1) % 2
            #print('   x = ', x,  ' y = ', y, ' t = ', truth)
            if truth == 1 and y == 0:
                return False
            elif truth == 0 and y == 1:
                return False
    return True


n = int(input())

xy = []
for i1 in range(n):
    ai = int(input())
    xy.append([])

    for i2 in range(ai):
        xi,yi = map(int, input().split())
        xy[i1].append((xi, yi))

#print(xy)

result = 0
for k in reversed(range(1 << n)):
    #print(bin(k))

    if dudge(k):
        #print('    True')
        #l = [i for i in range(n) if (k >> i) % 2 == 1]
        cnt = 0
        for i in range(n):
            if (k >> i) % 2 == 1: cnt += 1
        #print('    ', l, len(l))
        #result = max(result, len(l))
        result = max(result, cnt)

print(result)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;



void solve()
{
    int n;
    scanf("%d", &n);
    int i,j;
    int ans=0;
    for(i=1; i<=n; i+=2) {
        int cnt=0;
        for(j=1; j<=i; j++) {
            if(i%j==0) cnt++;
        }
        if(cnt==8) ans++;
    }
    printf("%d\n", ans);


    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 128