akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,i,j,c = 0,ny,nx,dy,dx,vy[4] = {1,0,-1,0},vx[4] = {0,1,0,-1},s;cin >> h >> w;
  char m[h][w];queue<pair<int,int>> q;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cin >> m[i][j];
      if(m[i][j]=='#') q.push(make_pair(i,j));
    }
  }
  while(!q.empty()){
    s = q.size();
    for(i=0;i<s;i++){
      ny = q.front().first;nx = q.front().second;
      for(j=0;j<4;j++){
        dy = ny+vy[j];dx = nx+vx[j];
        if(dy>=0 && dx>=0 && dy<h && dx<w && m[dy][dx] == '.'){
          m[dy][dx] = '#';q.push(make_pair(dy,dx));
        }
      }
      q.pop();
    }
    c++;
  }
  cout << c-1 << endl;
}

Measured memory_bytes: 9360
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int longDistance = in.nextInt();
            int shortDistance = in.nextInt();
            int hour = in.nextInt();
            int minute = in.nextInt();

            double kakudo = ((double) (60 * hour + minute) / (60 * 12)) * 360;
            double kakudoShort = ((double) minute / 60) * 360;
            double diff = Math.abs(kakudo - kakudoShort);

            double ans = Math.pow(longDistance, 2) +
                    Math.pow(shortDistance, 2) -
                    (2 * longDistance * shortDistance * Math.cos(Math.toRadians(diff)));

            out.append(String.valueOf(Math.sqrt(ans)));

        }

    }
}



Measured memory_bytes: 35908
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		try{	
			int a = sc.nextInt();

    		System.out.printf("%d:%d:%d\n", a/3600, (a/60)%60, a%60 );
		}
		catch(Exception e){}
    }
}



Measured memory_bytes: 26232
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	boolean[][] map;
	int MAX = 21;
	int dx[] = {-1,0,1,0};
	int dy[] = {0,-1,0,1};
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if( n==0 ) break;
			
			map = new boolean[MAX][MAX];
			for(int i=0;i<n;i++) map[sc.nextInt()][sc.nextInt()] = true;
			
			int m = sc.nextInt();
			int x = 10, y = 10;
			int cnt = 0;
			for(int i=0;i<m;i++) {
				char c = sc.next().charAt(0);
				int l = sc.nextInt();
				int d;
				if( c == 'W' ) d = 0;
				else if( c == 'N' ) d = 3;
				else if( c == 'E' ) d = 2;
				else d = 1;
				for(int j=0;j<l;j++) {
					x += dx[d];
					y += dy[d];
					if( map[x][y] ) {
						cnt++;
						map[x][y] = false;
					}
				}
			}
			System.out.println( (cnt == n? "Yes": "No") );
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
var n;
var x = [];

function init(){
	x[0] = 0;
	rep(1, n, function(i){
		x[i] = x[i - 1] + i;
	});
}

function search(v){
	var l = 0, r = n;
	while(r - l > 1){
		var m = (l + r) >> 1;
		if(x[m] <= v){
			l = m;
		}
		else{
			r = m;
		}
	}
	return x[l] === v;
}

function main(){
	while(n = scan()){
		init();
		var ans = 0;
		rep(0, n - 1, function(i){
			if(search(x[i] + n)){
				++ans;
			}
		});
		print(ans);
	}
}

function rep(a, b, c){
	if(c === undefined){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}

var input = '';

function scan(){
	return +input.pop();
}
function scan_string(){
	return input.pop();
} 
function print(val){
	console.log(val);
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.trim().split(/\s+/).reverse();
	main();
});

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n, weight; cin >> n >> weight;
    vi w(n), v(n); rep(i,n) cin >> w[i] >> v[i];

    vec<vll> dp(n+1, vll(112345, 0));

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= weight; ++j) {
            //選ぶ遷移。重さが変わる。if文はDPtable外参照を防ぐ
            if(j+w[i] <= weight) chmax(dp[i+1][j+w[i]], dp[i][j] + v[i]);
            //選ばない遷移
            chmax(dp[i+1][j], dp[i][j]); 
        }
    }
    cout << dp[n][weight] << '\n';

}

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

int main()
{
    int N, M, C;
    cin >> N >> M >> C;
    int B[M];
    for (int i = 0; i < M; i++)
        cin >> B[i];
    
    int answer = 0;
    
    for (int i = 0; i < N; i++) {
        long sum = 0;
        for (int j = 0; j < M; j++) {
            int a = 0;
            cin >> a;
            sum += a * B[j];
        }
        sum += C;
        if (sum > 0)
            answer++;
    }
    cout << answer << endl;
}


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  for(int i=1;i<=b*2;i++){
    if(i*a%b==c){
      cout<<"YES"<<endl;
      return 0;
      }
    }
  cout<<"NO"<<endl;
}

Measured memory_bytes: 256
def solve(s):
    n = len(s)
    if n==1:
        return True
    if n==2:
        return s[0]==s[1]
    if n==3:
        return s[0]==s[2]
    if n%2==0:
        s1 = s[:n//2]
        s2 = s[n//2:]
        return s1==s2[::-1]
    else:
        s1 = s[:(n-1)//2]
        s2 = s[(n+1)//2:]
        return s1==s2[::-1]

S = input()
N = len(S)
if solve(S) and solve(S[:(N-1)//2]) and solve(S[(N+1)//2:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 40508
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int N;
ll L;
int doub[20][100005];
vector<ll> x(100005, big);

void prepare() {
  int index;
  for(int i=0;i<N;++i) {
    index = upper_bound(x.begin(), x.end(), x[i]+L) - x.begin() - 1;
    doub[0][i] = index;
  }
  for(int i=1;i<20;++i) {
    for(int j=0;j<N;++j) {
      doub[i][j] = doub[i-1][doub[i-1][j]];
    }
  }
}

int solve(int a, int b) {
  int ans = 0;
  int tmp;
  int two;
  while(a<b) {
    tmp = 0;
    two = 1;
    while(doub[tmp+1][a]<b) {
      two *= 2;
      tmp++;
    }
    ans += two;
    a = doub[tmp][a];
  }
  return ans;
}

int main() {
  cin>>N;
  for(int i=0;i<N;++i) cin>>x[i];
  cin>>L;
  prepare();
  int Q;
  cin>>Q;
  int a, b;
  int ans[Q];
  for(int i=0;i<Q;++i) {
    cin>>a>>b;
    a--;
    b--;
    if(a>b) swap(a, b);
    ans[i] = solve(a, b);
  }
  for(int i=0;i<Q;++i) cout<<ans[i]<<endl;
}



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

int main()
{
    rep(i, 3000)
    {
        int x, y;
        cin >> x >> y;
        if (x == 0 && y == 0)
            break;
        if (x > y)
            cout << y << " " << x << endl;
        else
            cout << x << " " << y << endl;
    }
    return 0;
}


Measured memory_bytes: 3060
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(), K = sc.nextInt();
        Susi[] susi = new Susi[N];
        for (int n = 0; n < N; n++) susi[n] = new Susi(sc.nextInt(), sc.nextLong());
        Arrays.sort(susi, Comparator.reverseOrder());
        PriorityQueue<Susi> used = new PriorityQueue<>();
        PriorityQueue<Susi> rem = new PriorityQueue<>((s1, s2) -> -Long.compare(s1.priority, s2.priority));
        Map<Integer, Integer> map = new HashMap<>();
        long max = 0;
        long[] f = new long[N];
        for (int i = 0; i < K; i++) {
            used.add(susi[i]);
            if (map.containsKey(susi[i].t)) {
                int x = map.get(susi[i].t);
                map.put(susi[i].t, x + 1);
            } else {
                map.put(susi[i].t, 1);
            }
            max += susi[i].d;
            f[i] = max + (long) map.size() * (long) map.size();
        }
        for (int i = K; i < N; i++) rem.add(susi[i]);
        int c = 0;
        outside: while (used.size() > 0) {
            Susi s = used.poll();
            if (map.get(s.t) > 1) {
                while (rem.size() > 0) {
                    Susi u = rem.poll();
                    if (!map.containsKey(u.t)) {
                        max += u.d - s.d;
                        map.put(u.t, 1);
                        f[K + c] = max + (long)map.size() * (long)map.size();
                        c++;
                        continue outside;
                    }
                }
            }
        }
        max = f[K - 1];
        for (int i = K; i < N; i++) {
            max = f[i] > max ? f[i] : max;
        }
        System.out.println(max);
        sc.close();
    }
}
class Susi implements Comparable<Susi> {
    int t;
    long d;
    long priority;
    Susi(int t, long d) {
        this.t = t;
        this.d = d;
        priority = d;
    }
    @Override
    public int compareTo(Susi other) {
        return Long.compare(priority, other.priority);
    }
    @Override
    public int hashCode() {
        int prime = 31;
        int result = 1;
        result = prime * result + t;
        result = prime * result + (int)(d ^ (d >>> 32));
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Susi other = (Susi)obj;
        return t == other.t && d == other.d;
    }
}


Measured memory_bytes: 99412
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define ld double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define DOW(i, n) for(int i = n - 1; 0 <= i; --i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);


using namespace std;

int a, b, c;

int main() {
	cin >> a >> b >> c;
	int d = 0;
	int e = 0;
	while(d < c) {
		d += max(a, b);
		e++;
	}
	cout << e;
	
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
char map[107][107];
int x[4]={0,-1,0,1};
int y[4]={-1,0,1,0};
int W,H;
void dfs(int row,int line,char s){
    int new_row,new_line;
    char new_s=s;
    map[row][line]='.';
    for(int i=0;i<4;i++){
            new_row=row+x[i];
            new_line=line+y[i];
            if(map[new_row][new_line]!=new_s||new_row<0||new_row>=H||new_line<0||new_line>=W)
                continue;
            dfs(new_row,new_line,new_s);
    }
}

int main()
{

    while(~scanf("%d%d",&H,&W)&&H&&W)
    {
        int ans=0;
        for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
            {
                cin>>map[i][j];
            }
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(map[i][j]!='.'){
                    ans++;
                    dfs(i,j,map[i][j]);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1704
import java.io.*;
import java.util.*;
public class Main {
    private static void solver(InputReader sc, PrintWriter out) throws Exception {
        String s  = sc.next();
        int a=0,b=0;
        for(int i=0; i<s.length(); i++){
            if(s.charAt(i)=='A') a++;
            else b++;
        }
        if(a>0 && b>0) out.println("Yes");
        else out.println("No");
    }
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}
class Pair {
   int x,y;
   Pair(int x, int y){
       this.x = x;this.y = y;
   }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pair pair = (Pair) o;
        return x == pair.x &&
                y == pair.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }
}

Measured memory_bytes: 21076
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

vector<ll> get_divisor(ll x){
    vector<ll> ans;
    for(ll i = 1; i * i <= x; i++){
        if(x % i == 0){
            ans.push_back(i);
            if(i * i != x)
                ans.push_back(x/i);
        }
    }

    return ans;
}

ll power(int n, int p)
{
    if (p == 0)
        return 1;
    long long res = 1;
    long long add = n;
    while (p > 0)
    {
        if (p & 1)
            res = (res * add);
        p >>= 1;
        add = add*add;
    }
    return res;
}

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

    ll ans = 0;
    auto d1 = get_divisor(n-1);
    ans += d1.size() - 1;
    auto d2 = get_divisor(n);
    for(auto d: d2){
        if(d==1) continue;
        ll tmp = n;
        while(tmp % d == 0) tmp /= d;
        if(tmp % d == 1)
            ans++;
    }


    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 3240
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int A , B , K;
    cin >> A >> B >> K;

    set<int> st;

    for(int i = A; i <= B; i++){
        if(i < A + K || i > B - K )
            st.insert(i);
    }


    for(auto s: st)
    {
        cout << s << endl;
    }

    return 0;

}


Measured memory_bytes: 256
r1, c1, r2, c2 = map(int, input().split())

mod = 10**9+7
fc = [0]*(2*10**6+2)
fc[0] = 1

for i in range(1, 2*10**6+2):
    fc[i] = fc[i-1]*i%mod
    
inv = [1]*(2*10**6+2)
lst = 2*10**6+1
inv[lst] = pow(fc[lst], mod-2, mod)

for i in range(lst, 0, -1):
    inv[i-1] = (inv[i]*i)%mod

def comb(n, r):
    return ((fc[n]*inv[r])%mod)*inv[n-r]%mod

cum=0
for i in range(r1, r2+1):
    d1 = comb(i+1+c2, c2)
    d2 = comb(i+c1, c1-1)
    cum = (cum+(d1-d2))%mod

print(cum)


Measured memory_bytes: 71900
%:pragma GCC optimize(2)
%:pragma GCC optimize(3)
%:pragma GCC optimize("Ofast")
%:pragma GCC optimize("inline")
%:pragma GCC optimize("-fgcse")
%:pragma GCC optimize("-fgcse-lm")
%:pragma GCC optimize("-fipa-sra")
%:pragma GCC optimize("-ftree-pre")
%:pragma GCC optimize("-ftree-vrp")
%:pragma GCC optimize("-fpeephole2")
%:pragma GCC optimize("-ffast-math")
%:pragma GCC optimize("-fsched-spec")
%:pragma GCC optimize("unroll-loops")
%:pragma GCC optimize("-falign-jumps")
%:pragma GCC optimize("-falign-loops")
%:pragma GCC optimize("-falign-labels")
%:pragma GCC optimize("-fdevirtualize")
%:pragma GCC optimize("-fcaller-saves")
%:pragma GCC optimize("-fcrossjumping")
%:pragma GCC optimize("-fthread-jumps")
%:pragma GCC optimize("-funroll-loops")
%:pragma GCC optimize("-fwhole-program")
%:pragma GCC optimize("-freorder-blocks")
%:pragma GCC optimize("-fschedule-insns")
%:pragma GCC optimize("inline-functions")
%:pragma GCC optimize("-ftree-tail-merge")
%:pragma GCC optimize("-fschedule-insns2")
%:pragma GCC optimize("-fstrict-aliasing")
%:pragma GCC optimize("-fstrict-overflow")
%:pragma GCC optimize("-falign-functions")
%:pragma GCC optimize("-fcse-skip-blocks")
%:pragma GCC optimize("-fcse-follow-jumps")
%:pragma GCC optimize("-fsched-interblock")
%:pragma GCC optimize("-fpartial-inlining")
%:pragma GCC optimize("no-stack-protector")
%:pragma GCC optimize("-freorder-functions")
%:pragma GCC optimize("-findirect-inlining")
%:pragma GCC optimize("-fhoist-adjacent-loads")
%:pragma GCC optimize("-frerun-cse-after-loop")
%:pragma GCC optimize("inline-small-functions")
%:pragma GCC optimize("-finline-small-functions")
%:pragma GCC optimize("-ftree-switch-conversion")
%:pragma GCC optimize("-foptimize-sibling-calls")
%:pragma GCC optimize("-fexpensive-optimizations")
%:pragma GCC optimize("-funsafe-loop-optimizations")
%:pragma GCC optimize("inline-functions-called-once")
%:pragma GCC optimize("-fdelete-null-pointer-checks")
#include<cstdio>
#include<iostream>
#include<algorithm>

#define maxn 100001
#define int long long
#define inf 0x7fffffff
using namespace std;

int n,m,pos[maxn];
int abs_pos[maxn],zero,ans=inf;

int abss (int x){
    return x<0?-x:x;
}

signed main()
{
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%lld",&pos[i]);
    for(int i=1;i<=n;i++)
        abs_pos[i]=abss(pos[i]);
    for(int i=0;i<=n;i++){
        if(pos[i]<0&&pos[i+1]>=0){
            zero=i;
            break;
        }
    }
    if(pos[n]<0)
        zero=n;
    for(int i=0;i<=m;i++){
        if(zero<i)       break;
        if(zero-i+m>n)   continue;
        ans=min(ans,abs_pos[zero-i+1]*2+abs_pos[zero+m-i]);
        ans=min(ans,abs_pos[zero-i+1]+abs_pos[zero+m-i]*2);
    }
    if(zero>=m)
        ans=min(ans,abs_pos[zero-m+1]);
    if(m+zero<=n)
        ans=min(ans,abs_pos[m+zero]);
    printf("%lld",ans);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define FOR(i,a,b) for(ull i=a;i<b;i++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define vecout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
//ll mod = 1000000007;
ll a[1000001] = {0};
unsigned long long int n, x, m;
void fun() {

	cin >> n >> x >> m;
	a[1] = x;
	FOR(i, 2, 1000001)a[i] = (a[i - 1] % m * a[i - 1] % m) % m;
}
void solve() {
	fun();
	map<ll, ll> visited;
	vll ns;
	vll cs;
	ll tmp = 0;
	FOR(i, 1, m + 1) {
		if (visited[a[i]] == 1) {
			tmp = a[i];
			br;
		}
		else {
			ns.pb(a[i]);
			visited[a[i]] = 1;
		}
	}
	ull S = ns.size();
	FOR(i, 0, S ) {
		if (ns[i] == tmp) {
			FOR(j, i, S)cs.pb(ns[j]);
			int k = S - i;
			while (k--)ns.pp();
			br;
		}
	}
	ull ans = 0, mine;
	if (n > ns.size())mine = ns.size(); else mine = n;
	FOR(i, 0, mine)ans += ns[i];
	n = n - mine;
	if (n) /*if(!n) Means if(n==0)*/
	{
		if (cs.size()) {
			if ((n / cs.size()))FOR(i, 0, cs.size())ans += cs[i] * (n / cs.size());
			if (n % cs.size())FOR(i, 0, n % cs.size())ans += cs[i];
		}

	}
	cout << ans << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}

Measured memory_bytes: 15240
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<double, null_type, less_equal<double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
typedef long long ll;
typedef double dd;
typedef long double ldd;
typedef pair <int, int> pii;
typedef pair <pii , int> ppii;
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define mp make_pair
#define all(x) x.begin() , x.end()
#define debug(x) cerr<< #x << " = " << x << endl
#define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
#define uop(x, y) pii(min(x, y), max(x, y))
#define mem(a, b) memset(a, b, sizeof a)
#define sq(x) (x) * (x)
#define out return cout << -1 << endl, 0
const int mx = 1e5 + 10;
int x[mx], p[mx], d[mx], ans[mx];
bool mark[mx];
vector < int > v;
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m, k, a;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x[i];
		p[i] = i;
	}
	for(int i = 0; i < n - 1; i++)
		d[i] = x[i + 1] - x[i];
	cin >> m >> k;
	while(m--){
		cin >> a;
		swap(p[a - 1] , p[a - 2]);
	}
	for(int i = 0; i < n; i++)
		if(!mark[i]){
			mark[i] = 1;
			v.pb(i);
			int u = p[i];
			while(u != i){
				v.pb(u);
				mark[u] = 1;
				u = p[u];
			}
			for(int j = 0; j < sz(v); j++)
				ans[v[j]] = v[(j + k) % sz(v)];
			v.clear();
		}
	int s = x[0];
	for(int i = 0; i < n; i++){
		cout << s << ".0" << "\n";
		s += d[ans[i]];
	}
	return 0;
}


Measured memory_bytes: 5620
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N, S;
	cin >> N >> S;
	VI A(N);
	for (int n = 0; n < N; n++)cin >> A[n];
	VVLL DP;
	DP.resize(N, VLL(3001, 0));
	if(A[0] <= 3000)DP[0][A[0]] = 1;
	for(int r = 1;r < N;r++){
		for (int s = 0; s <= 3000; s++) {
			DP[r][s] = DP[r - 1][s];
			if (s >= A[r]) {
				DP[r][s] += DP[r - 1][s - A[r]];
			}
			if (s == A[r])DP[r][s] += r + 1;
			DP[r][s] %= MOD;
		}
	}
	LL ans = 0;
	if (A[0] == S)ans += N;
	for (int r = 1; r < N; r++) {
		if (S >= A[r]) {
			ans += DP[r - 1][S - A[r]]*(N-r);
			ans %= MOD;
		}
		if (S == A[r]) {
			ans += (N - r) * (r + 1);
			ans %= MOD;
		}
	}
	cout << ans << "\n";
	return 0;
}


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

using namespace std;

int main() {
    int a,b,a2,b2;
    int lcm,gcd;
    while(cin >> a >> b){
        a2=a;
        b2=b;
        while(a != b){
        if(a>b){a = a-b;}
        else{b=b-a;}
        }
        lcm = a;
        gcd=a2 / lcm * b2;
        cout << lcm << " " << gcd << endl;
    }

}

Measured memory_bytes: 1160
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

int main()
{
	Ryuga;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("op.txt","w",stdout);
	#endif

	clock_t startTime=clock();

	ll n;
	cin>>n;
	string s;
	if(n==1)
	{
		cout<<"a";return 0;
	}
	while(n>0)
	{
		ll k=n%26;
		if(k==0)
			k=26;
		n-=k;
		s+=char(k-1+'a');
		n/=26;
	}
	reverse(s.begin(), s.end());
	cout<<s<<endl;

	cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, M; cin >> N >> M;
  int Q; cin >> Q;
  VI xs(Q);
  REP(i,Q){
	cin >> xs[i];
	--xs[i];
  }

  vector<bool> use(M);
  VI as;
  for(int i=Q-1;i>=0;--i)
	if(!use[xs[i]]){
	  use[xs[i]] = true;
	  as.PB(xs[i]);
	}
  REP(i,M)
	if(!use[i])
	  as.PB(i);
  //REP(i,M) cout<<as[i]<<" ";cout<<endl;
  VI len(M+1);
  len[0] = N;
  VI idx(M);
  REP(i,M) idx[as[i]] = i;
  for(int i=Q-1;i>=0;--i){
	int x = xs[i];
	if(len[idx[x]]){
	  len[idx[x]+1]++;
	  len[idx[x]]--;
	}
  }
  REP(i,M)
	len[idx[i]+1] += len[idx[i]];
  
  cout << (len[M]==N?"Yes":"No") << endl;
  
  return 0;
}


Measured memory_bytes: 1912
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		String s = in.next();
		String t = in.next();
		String result = "";
		for (int i=0; i<n; i++) {
			result += s.charAt(i) + "" + t.charAt(i);
		}
		System.out.println(result);
	}
}



Measured memory_bytes: 21712
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
import heapq
def main():
    N = int(input())
    A_lsit = list(map(int, input().split()))
    A_lsit.sort(reverse=True)

    answer = A_lsit[0]
    A_heap = [-(A_lsit[1])]*2
    heapq.heapify(A_heap)
    for i in range(2, N):
        max_in_heap = -(heapq.heappop(A_heap))
        answer += max_in_heap
        heapq.heappush(A_heap, -(A_lsit[i]))
        heapq.heappush(A_heap, -(A_lsit[i]))
    print(answer)

if __name__ == "__main__":
    main()



Measured memory_bytes: 31668
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int n;
    scan(n);
    auto v = readln.split.to!(int[]);
    auto c = readln.split.to!(int[]);
    int ans;
    foreach (i ; 0 .. n) {
        ans += max(0, v[i] - c[i]);
    }
    writeln(ans);
}

























int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

int M;
int MOD=1e9+7;
string s;

int sum[10][10];

signed main(){
  cin>>M>>s;

  if( M==0 && (int)s.size()==1 ){
    cout<<0<<endl;
    return 0;
  }

  r(i,10){
    r(j,10){
      int x=0;
      r(k,s.size()){
        x*=10;
        if(s[k]-'0' == i)x+=j;
        x%=MOD;
      }
      sum[i][j]=x;
    }
  }

  int NG=s[0]-'0';
  vector<int>v;
  r(i,10)v.push_back(i);

  do{
    int x=0 , F=0;

    r(i,10){
      if( i==NG && v[i]==0 )F=1;
      x += sum[i][v[i]];
      x %= MOD;
    }

    if( F )continue;

    if( x==M ){
      r(i,s.size()){
        cout<<v[s[i]-'0'];
      }
      cout<<endl;
      return 0;
    }

  }while(next_permutation(v.begin(),v.end()));
  cout<<(-1)<<endl;
}


Measured memory_bytes: 3304
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	auto m = min(A, B) + min(C, D);

	cout << m << endl;

	return 0;
}


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

using namespace std;

typedef long long int lli;

lli BP[51] = { 1 }, B[51] = { 1 };

lli rec(int lev, lli num) {
    if (num <= 0) return 0;
    if (lev == 0) return 1;

    lli res = 0;
    
    if (num >= BP[lev]/2 + 1) res += B[lev-1] + 1 + rec(lev-1, num-BP[lev-1]-2);
    else res += rec(lev-1, num-1);

    return res;
}

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

    lli n, x;
    cin >> n >> x;

    // init
    for (int i=1; i<=n; i++) {
        B[i] = B[i-1]*2 + 1;
        BP[i] = BP[i-1]*2 + 3;
    }

    cout << rec(n, x) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int cmp(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;//昇順
							   //降順ならreturn *(int*)b - *(int*)a;
}
int main()
{
	int n,i;
	int c[1010];
	double ans = 0;
	scanf("%d", &n);
	for (i = 0;i < n;i++)scanf("%d", &c[i]);
	qsort(c, n, sizeof(int), cmp);
	ans= (double)(c[0] + c[1]) / 2;
	for (i = 2;i < n;i++)
	{
		ans =(double)(c[i] + ans) / 2;
	}
	printf("%lf\n", ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		int count = 0;

		for (int i = 1; i <= n ;i++){
			a[i]  = sc.nextInt();
		}

		int wk = 0;
		for (int i = 1; i <= n ;i++){

			wk = a[i];

			if(a[wk] == i){
				count++;
			}
		}



		System.out.println(count/2);
		sc.close();
	}
}


Measured memory_bytes: 32376
#include <bits/stdc++.h>
using namespace std;
int a[30]= {0};
int main()

{
    string s;

    int c=0;
    cin>>s;

    int len = s.size();

    for(int i=0; i<len; i++)
    {
        if(s[i]>='a'&&s[i]<='z')
        {
            a[s[i]-'a']++;
        }
    }
    for(int i=0; i<26; i++)
    {
        if(a[i]%2!= 0)
        {
            c++;
            break;
        }
    }
    if(c==0)

        cout << "Yes" <<endl;
    else
        cout << "No"<<endl;

    return 0;
}


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

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

int x[3];

void init()
{
	int N, A, B;
	cin >> N >> A >> B;
	rep(i, N) {
		int t;
		cin >> t;
		if (t <= A) x[0]++;
		else if (t <= B) x[1]++;
		else x[2]++;
	}
	cout << min({x[0], x[1], x[2]}) << endl;
}


void solve()
{
}





Measured memory_bytes: 256
n = int(input())
b = list(map(int, input().split()))
a = [0] * n

a[0] = b[0]
if n >= 4:
    a[n-1] = b[n-2]
    for i in range(1,n-2):
        if b[i-1] <= b[i] <= b[i+1]:
            a[i] = b[i-1]
            a[i+1] = b[i]
        elif b[i-1] >= b[i] >= b[i+1]:
            a[i] = b[i]
            a[i+1] = b[i+1]
        elif b[i-1] < b[i] > b[i+1]:
            a[i] = b[i-1]
            a[i+1] = b[i+1]
        else:
            a[i] = b[i]
            a[i+1] = b[i]
elif n == 3:
    a[0] = b[0]
    a[1] = min(b[0], b[1])
    a[2] = b[1]
elif n == 2:
    a[0] = b[0]
    a[1] = b[0]

sum = 0
for i in range(n):
    sum += a[i]
print(sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,b; cin >> n >> b;
  vector<int> data(n);
  double vote=0;
  for(int i=0; i<n; i++){
    cin >> data.at(i);
    vote += data.at(i);
  }
  double x = vote/(4*b);
  int count=0;
  for(int i=0; i<n; i++){
    if(data.at(i) >= x) count++;
  }
  if(count>=b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.buffer.readline
N = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
free = [0] * N
f = 0
if N == 1:
  if t[0] == a[0]:
    print(1)
  else:
    print(0)
  exit(0)
if max(a) != max(t):
  print(0)
  exit(0)
for i in range(1, N - 1):
  if t[i - 1] == t[i]:
    free[i] = t[i]
  if t[i - 1] != t[i]:
    if t[i] > a[i]:
      f = 1
      break
  if a[i] != a[i + 1]:
    if a[i] > t[i]:
      f = 1
      break
for i in range(N - 2, 0, -1):
  if a[i + 1] == a[i] and t[i - 1] == t[i]:
    free[i] = min(t[i], a[i])
  else:
    free[i] = 0
res = 1
if f:
  print(0)
  exit(0)
for i in range(N):
  res *= max(1, free[i])
  res %= mod
print(res)

Measured memory_bytes: 63212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int x, a;
  cin >> x >> a;
  if (x < a) cout << 0 << endl;
  else cout << 10 << endl;
}


Measured memory_bytes: 256
import java.awt.Rectangle;
import java.util.Scanner;


public class Main {

	static Scanner sc = new Scanner(System.in);
	static Rectangle[] rec = new Rectangle[26];
	static boolean[] check = new boolean[26];
	
	public static void main(String[] args) {
		int n;
		n = sc.nextInt();	// input
		while(n-- > 0) {
			for(int i=0; i < 26; i++) {	// initialize
				rec[i] = new Rectangle();
				rec[i].x = rec[i].y = 50;
				rec[i].width = rec[i].height = 0;
				check[i] = false;
			}
			int h, w, cnt = 0;
			h = sc.nextInt();	// input
			w = sc.nextInt();	// input
			int map[][] = new int[h][w];
			for(int y=0; y < h; y++) {
				String str = sc.next();
				for(int x=0; x < w; x++) {
					map[y][x] = (int)str.charAt(x); // input
					if(map[y][x] == '.') continue;
					int idx = map[y][x] - 'A';
					if(rec[idx].x > x) rec[idx].x = x;				// start
					if(rec[idx].y > y) rec[idx].y = y;				// start
					if(rec[idx].width < x) rec[idx].width = x;		// end
					if(rec[idx].height < h) rec[idx].height = y;	// end
					check[idx] = true;
				}
			}
			for(int i=0; i < 26; i++) if(check[i]) cnt++;
			boolean flg = true;
			while(flg) {
				flg = false;
				for(int i=0; i < 26; i++) {
					if(check[i]){
						int mozi = 'A' + i;
						boolean success = true;
						for(int y=rec[i].y; y <= rec[i].height; y++)
							for(int x=rec[i].x; x <= rec[i].width; x++){
								if(map[y][x] != mozi && map[y][x] != -1) {
									success = false;
									break;
								}
							}
						if(success){
							for(int y=rec[i].y; y <= rec[i].height; y++)
								for(int x=rec[i].x; x <= rec[i].width; x++){
									map[y][x] = -1;
								}
							flg = true;
							check[i] = false;
							cnt--;
						}
					}
				}
			}
			if(cnt == 0)
				System.out.println("SAFE");
			else
				System.out.println("SUSPICIOUS");
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x.at(i); }


int main() {

    int N = 3;
    CINS(int, a, N);

    cout << ceil(a[2] / a[0]) * a[1];
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

int partition(int A[],int p,int r){
  int x,i,j,q;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      q=A[i];
      A[i]=A[j];
      A[j]=q;
    }
  }
  q=A[i+1];
  A[i+1]=A[r];
  A[r]=q;
  return i+1;
}

int main(){
  int A[N],n,i,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  k=partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i!=0) printf(" ");
    if(i==k) printf("[");
    printf("%d",A[i]);
    if(i==k) printf("]");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
Int powmod(Int x, Int y) {
    if (y == 0) return 1;
    if (y % 2 == 0) return powmod(x*x%MOD, y/2);
    return x*powmod(x, y-1)%MOD;
}
Int inverse(Int x) {
    return powmod(x, MOD-2);
}
int solve(int N, const string& S) {
    vector<vector<int>> dp(N+1, vector<int>(N+1));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i+1][j+1] += dp[i][j] * 2;
            dp[i+1][j+1] %= MOD;
            dp[i+1][max(0, j-1)] += dp[i][j];
            dp[i+1][max(0, j-1)] %= MOD;
        }
    }
    return dp[N][S.size()] * powmod(inverse(2), S.size()) % MOD;
}
int main() {
    int N; cin >> N;
    string S; cin >> S;
    cout << solve(N, S) << '\n';
    return 0;
}


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

long long N;

int main(){
	cin >> N;
	int count = 0;
	for(long long i = 1; i <= N; i++){
		int tmp;
		cin >> tmp;
		if(tmp != i){
			count++;
		}
	}
	if(count == 0 || count == 2){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll cnt=1;
  string s="";
  rep(i,n-1){
    if(a[i]!=a[i+1]){
      if(a[i]<a[i+1]){
        s="up";
        break;
      }
      else{
        s="down";
        break;
      }
    }
  }
  ll i=0;
  while(i<n-1){
    if(s==""){
      i+=1;
      while(i<n-1&&s==""){
        if(a[i]>a[i+1]){
          s="down";
        }
        else if(a[i]<a[i+1]){
          s="up";
        }
        if(s==""){
          i++;
        }
      }
    }
    if(a[i]<a[i+1]&&s=="down"){
      s="";
      cnt++;
    }
    else if(a[i]>a[i+1]&&s=="up"){
      s="";
      cnt++;
    }
    else{
      i++;
    }
  }
  cout << cnt << endl;
}

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

int main() {
    int N;
    std::cin >> N;

    int a[N];
    for (int i = 0; i < N; ++i) {
        std::cin >> a[i];
    }
    std::sort(a, a + N, std::greater<int>());

    int alice = 0, bob = 0; 
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }

    std::cout << alice - bob << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int n,m,a[100010],b[100010],s[100010],L[100010],R[100010],x[20000000],l[20000000],r[20000000],p,q;
LL f[100010],ans;
inline int ll(int i)
{
    if(!l[i])
      l[i]=++q;
    return l[i];
}
inline int rr(int i)
{
    if(!r[i])
      r[i]=++q;
    return r[i];
}
inline void modify(int i,int j,int k,int l0,int r0,int p)
{
    if(l0<=j && k<=r0)
      x[i]=p;
    else
      {
       if(x[i])
         {
          x[ll(i)]=x[rr(i)]=x[i];
          x[i]=0;
         }
       if(l0<=(j+k>>1))
         modify(ll(i),j,j+k>>1,l0,r0,p);
       if(r0>(j+k>>1))
         modify(rr(i),(j+k>>1)+1,k,l0,r0,p);
      }
}
inline int query(int i,int j,int k,int p)
{
    if(x[i])
      return x[i];
    if(!i || j==k)
      return 0;
    if(p<=(j+k>>1))
      return query(l[i],j,j+k>>1,p);
    else
      return query(r[i],(j+k>>1)+1,k,p);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	  {
       scanf("%d%d",&a[i],&b[i]);
       if(b[i]==1 && a[i]*2>m)
         break;
       s[i]=(s[i-1]-2*a[i]%m+m)%m;
      }
    if(i<=n)
      {
       printf("-1\n");
       return 0;
      }
    for(i=1;i<=n;i++)
      if(b[i]==2)
        L[i]=1,R[i]=m;
      else
        L[i]=s[i-1]+1,R[i]=s[i]+1;
    for(p=1;p<m;p<<=1);
    q=1;
    for(i=n;i>=2;i--)
      {
       j=query(1,1,p,L[i]);
       if(j)
         f[i]=f[j]+(L[j]-L[i]+m)%m;
       if(L[i]<=R[i])
         {
          if(L[i]>1)
            modify(1,1,p,1,L[i]-1,i);
          if(R[i]<m)
            modify(1,1,p,R[i]+1,m,i);
         }
       else
         modify(1,1,p,R[i]+1,L[i]-1,i);
      }
    ans=1e18;
    for(i=2;i<=2*n+1;i++)
      {
       if(i&1)
         j=L[i/2];
       else
         j=R[i/2];
       if(L[1]<=R[1] && L[1]<=j && j<=R[1] || L[1]>R[1] && (L[1]<=j || j<=R[1]))
         {
          k=query(1,1,p,j);
          if(!k)
            ans=0;
          else
            ans=min(ans,f[k]+(L[k]-j+m)%m);
         }
      }
    for(i=1;i<=n;i++)
      ans+=2*a[i];
    cout<<ans;
	return 0;
}


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

int main() {
  int A,B,C,K,Z=0;
  cin>>A>>B>>C>>K;
  if(A>=K){
    Z=K;
  }
  else{
    K-=A;
    Z=A;
    Z-=max(0,K-B);
  }
  cout<<Z<<endl;
}





Measured memory_bytes: 3596