akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int judge(int x,int y,int z){
	if(x*x==y*y+z*z)return 1;
	if(y*y==x*x+z*z)return 1;
	if(z*z==y*y+x*x)return 1;
	else return 0;
}
int main(void){
	int n,x,y,z;
	scanf("%d",&n);
	while(n--){
		scanf("%d%d%d",&x,&y,&z);
		if(judge(x,y,z))printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int x=sc.nextInt();
        int y=sc.nextInt();
        if(n>k) System.out.println(x*k+(n-k)*y);
        else System.out.println(x*n);

     }
}

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

int main(void){
    int f;
    cin>>f;
    if(f==1)
        cout<<"Hello World"<<endl;
    else if(f==2){
        int A,B;
        cin>>A>>B;
        cout<<A+B<<endl;
    }
    return 0;
}


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


int main() {
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for (int i = 0; i < N; ++i) {
        cin >> S.at(i);
    }

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

    string ans;
    for (int i = 0; i < N; ++i) {
        ans += S.at(i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,k;
	bool flag=false;
	cin>>k>>a>>b;
	for(int i=1;;i++){
		int tmp=k*i;
		if(tmp>=a&&tmp<=b){
			flag=true;
			break;
		}
		if(tmp>b)break;
	}
	if(flag)cout<<"OK"<<endl;
	else cout<<"NG"<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <map>

using namespace std;

int main() {
    int s;
    cin >> s;
    map<int,int> m;
    m[s]++;
    int ans = 2;

    while(1) {
        s = (s % 2 == 0) ? s / 2 : (s * 3 + 1);
        
        m[s]++;
        if (m[s] == 2) {
            cout << ans << endl;
            return 0;
        }
        ans++;
    }

    return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<double> p(201010);
  p[k] = 1.;
  for (int i = 200000; i > 0; i--) {
    if (i >= k) p[i] = 1.;
    else p[i] = p[i * 2] / 2;
  }
  double ans = 0;
  for (int i = 0; i < n; i++) {
    ans += p[i + 1];
  }
  ans /= n;
  printf("%.13lf\n", ans);
  return 0;
}


Measured memory_bytes: 1792
csum_a = []
r, c = list(map(int, input().split()))
array = [[int(j) for j in input().split()] for i in range(r)]

for i in range(c):
    csum = 0 #列ごとに初期化
    for j in range(r):
        csum = csum + array[j][i]
    csum_a.append(csum)
array.append(csum_a)
#ここの時点で(r+1)行×c列の配列になっている

for i in range((r+1)):
    rsum = 0 #行ごとに初期化
    for j in range(c):
        rsum = rsum + array[i][j]
    array[i].append(rsum)

for i in array:
    print(*i)


Measured memory_bytes: 6248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    string s;
    int q;
    cin>>s>>q;
    
    deque<char> dq;
    rep(i,s.size()){
        dq.push_back(s[i]);
    }

    bool rev=false;
    while(q--){
        int t;
        cin>>t;
        if(t==1) rev=!rev;
        else{
            int f;
            char c;
            cin>>f>>c;
            if(f==1){
                if(rev) dq.push_back(c);
                else dq.push_front(c);
            }
            else{
                if(!rev) dq.push_back(c);
                else dq.push_front(c);
            }
        }
    }

    if(rev) reverse(all(dq));
    while(!dq.empty()){
        char ans=dq.front();
        dq.pop_front();
        cout<<ans;
    }
    cout<<endl;
}

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

const int MAX_N = (int)2e5 + 5;
const lint MOD = (lint)1e9 + 7;
lint fact[MAX_N], fact_inv[MAX_N], ap[MAX_N], bp[MAX_N], inv_ab[MAX_N], inv[MAX_N];

void mod_add(lint &a, lint b){
    a = (a+b) % MOD;
}

lint mod_pow(lint n, lint x){
    lint res = 1;
    while(x){
        if(x&1) res = res * n % MOD;
        x >>= 1, n = n * n % MOD;
    }
    return res;
}

lint comb(int n, int r){
    return fact[n] * fact_inv[r] % MOD * fact_inv[n-r] % MOD;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N; cin >> N;
    lint A, B, C; cin >> A >> B >> C;
    fact[0] = ap[0] = bp[0] = inv_ab[0] = 1;
    for(int i=1;i<=(int)2e5;i++){
        fact[i] = fact[i-1] * i % MOD;
        ap[i] = ap[i-1] * A % MOD;
        bp[i] = bp[i-1] * B % MOD;
        inv_ab[i] = mod_pow(A+B, MOD-i-1);
    }
    fact_inv[2*N] = mod_pow(fact[2*N], MOD-2);
    for(int i=2*N-1;0<=i;i--) fact_inv[i] = fact_inv[i+1] * (i+1) % MOD;
    for(int i=1;i<=100;i++) inv[i] = mod_pow(i, MOD-2);

    lint ans = 0;
    for(int i=N;i<2*N;i++){
        mod_add(ans, comb(i-1, N-1)*((ap[N]*bp[i-N]%MOD+ap[i-N]*bp[N]%MOD)%MOD)%MOD*i%MOD*inv_ab[i]%MOD*inv[100-C]%MOD*100%MOD);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
int main(){
int a,b,dp[102][10002],i,j,v[102],w[102];
scanf("%d %d\n",&a,&b);
for(i=1;i<=a;i++){
scanf("%d %d\n",&v[i],&w[i]);
}
for(i=0;i<=b;i++){
dp[0][i]=0;
}
for(i=1;i<=a;i++){
for(j=0;j<=b;j++){
if(j>=w[i]){
if(dp[i-1][j]>dp[i-1][j-w[i]]+v[i]){
dp[i][j]=dp[i-1][j];
}
else{
dp[i][j]=dp[i-1][j-w[i]]+v[i];
}
}
else{
dp[i][j]=dp[i-1][j];
}
}
}
printf("%d\n",dp[a][b]);
return 0;
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    const int N_MAX = 100000;
    int a[N_MAX + 1];
    a[0] = 0;
    int mul[] = {6, 9};
    FOR(i, 1, N_MAX + 1) {
        int m = a[i - 1] + 1;
        for (int x: mul) {
            for (int s = x; s <= i; s *= x) {
                amin(m, a[i - s] + 1);
            }
        }
        a[i] = m;
    }
    int N;
    cin >> N;
    cout << a[N] << endl;
    return 0;
}


Measured memory_bytes: 640
n=int(input())
h=list(map(int, input().split()))

dp=[10**9 for i in range(n)]
dp[0]=0
for i in range(n):
    if i+1<n:dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]))
    if i+2<n:dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]))

print(dp[-1])


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

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  for (int i = 1; i < B; i++) {
    if (i * A % B == C) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}


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


void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

#define ll long long
#define ld long double
#define ull unsigned long long
#define ull unsigned long long
#define mod 1000000007
#define pi (3.1415926)

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

#define scd(a)  scanf("%lld",&a)
#define scdd(a,b)	scanf("%lld%lld",&a,&b)
#define scddd(a,b,c)	scanf("%lld%lld%lld",&a,&b,&c)
#define ptab(a)	printf("%lld ",a)
#define pdn(a)	printf("%lld\n",a)
#define pddn(a,b)	printf("%lld %lld\n",a,b)
#define pdddn(a,b,c)	printf("%lld %lld %lld\n",a,b,c)

#define Filein(N) freopen("N", "r", stdin);
#define Fileout(N) freopen("N", "w", stdout);

#define forr(n) for(ll i=0;i<n;i++)
#define rev(n) for(ll i=n-1;i>=0;i--)
#define forp(x, y) for(ll i=x;i<y;i++)
#define loop( j, k, in) for (ll i=j ; i<k ; i+=in)

#define en "\n"
#define sp " "
#define eps 1.0E-14
#define l length()
#define preci(x) cout << fixed<<setprecision(x)
#define inf LONG_LONG_MAX
#define ninf LONG_LONG_MIN

ull fastpow(ull a,ull b)
{
  ull wynik=1;
  while (b)
  {
    if (b&1)wynik=(wynik*a)%mod;
    a=(a*a)%mod;
    b>>=1;
  }
  return wynik;
}

bool odd(int n)
    {
        int x = sqrt(n);
    for (int i=2 ; i<=x ; ++i)

    {
        if(n%i == 0)return false;
    }

    return true;
    }
ll fact(int n ){

long long fact =1;

for (int i =2 ;i<=n;++i)

{
    fact*=i;
}
return fact;
}

bool prim(long long a){

long long s = sqrt(a);

for (int i=2 ; i<= s ;++i){

    if (a % i == 0)return false;
}
return true;
}

ll sum (int n ){return ((n*(n+1)) / 2) ;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

bool myfunction (string i,string j) /* this function to check who is grater in
sorting strings as numbers ////////
int n;
    cin>>n;
    vector <string> arr(n);
    for(int i=0;i<n;i++)
        cin>>arr[i];


    sort(arr.begin(),arr.end(),myfunction);

    for(int i=0;i<n;i++)1
        cout<<arr[i]<<endl;
*/
{
    int n=i.length();
    int m=j.length();
    if(n==m)
        return (i<j);

    return n<m;
}
long long solve (int a, int b)
{
    return min(a,min(b , (a+b) / 3));
}
int main()
{
    init();
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int a[5];

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

        if (a[i] == 0) {cout << i+1 ; break;}

}
}



Measured memory_bytes: 3692
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

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

    vector<int> a(N);
    rep(i, N) cin >> a[i];

    // rep(i, N) {
    //     cout << showbase;
    //     cout << bitset<16>(a[i]) << endl;
    //     cout << noshowbase;
    // }

    int sum = a[0];
    for (int i = 1; i < N; i++) {
        sum = sum ^ a[i];
    }
    // cout << showbase;
    // cout << bitset<16>(sum) << endl;
    // cout << noshowbase;

    for (int i = 0; i < N; i++) {
        cout << (sum ^ a[i]) << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
  int i,a=0;
  ll ans=0;
  string s,t;
  cin >> s;
  for (i=0;i<s.size();i++){
    if (i<s.size()-1 && s[i]=='B' && s[i+1]=='C'){
      t.push_back('D');
      i++;
    }else t.push_back(s[i]);
  }
  
  for (i=0;i<t.size();i++){
    if (t[i]!='A' && t[i]!='D'){
      a=0;
      continue;
    }
    while (i<t.size() && t[i]=='A'){
      a++;
      i++;
    }
    while (i<t.size() && t[i]=='D'){
      ans+=a;
      i++;
    }
    i--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
using namespace std;
const int N=205;
int n,a[N],ans;
int main(){
	scanf("%d",&n); n*=2;
	rep (i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for (int i=1;i<=n;i+=2) ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    REP(i,n) {
        if (a[i] < a[i-1]) {
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3976
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var sum = 0L;
            for(var i=0;i<N;++i)
            {
                var (l, r) = Slice2<long>();
                sum += r - l + 1;
            }
            WriteLine(sum);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28216
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int N=1<<18;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int a[N],R[N],up[N],low[N];
vector<PR> e[N];
int ans[N];
int main()
{
	int n=gi(),i,t;
	for (i=0;i<1<<n;i++) a[i]=gi()-1,R[i]=R[i>>1]>>1|(i&1)<<(n-1);
	for (i=(1<<n)-1;~i;i--) {
		up[i]=~a[i]?a[i]:(1<<n)-1;
		for (t=0;t<n;t++)
			if (!(i>>t&1))
				upmin(up[i],up[i|1<<t]);
	}
	for (i=0;i<1<<n;i++) {
		low[i]=~a[i]?a[i]:0;
		for (t=0;t<n;t++)
			if (i>>t&1)
				upmax(low[i],low[i^(1<<t)]);
	}
	for (i=0;i<1<<n;i++)
		if (low[i]>up[i])
			return puts("NO"),0;
		else
			e[up[i]].pb(mp(low[i],-i));
	priority_queue<PR>q;
	for (i=(1<<n)-1;~i;i--) {
		for (auto t:e[i]) q.push(t);
		if (q.empty()||q.top().first>i) return puts("NO"),0;
		ans[R[-q.top().second]]=i;q.pop();
	}
	puts("YES");
	for (i=0;i<1<<n;i++)
		printf("%d ",ans[i]+1);
	return 0;
}


Measured memory_bytes: 21248
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,t,a,b;
    cin>>n;
    int pt=0,pa=0,pb=0;
    for(i=0;i<n;i++)
    {
        cin>>t>>a>>b;
        int tt=t-pt;
        int z=abs(a-pa)+abs(b-pb);
        pt=t;pa=a;pb=b;
        if(tt<z)
            return cout<<"No"<<endl,0;
        else if(tt>z)
        {
            if((tt%2)!=(z%2))
                return cout<<"No"<<endl,0;
        }
    }
    cout<<"Yes"<<endl;
}


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

int main(void){
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M), a, b;
    for(ll i = 0; i < N; i++) cin >> A.at(i);
    for(ll i = 0; i < M; i++) cin >> B.at(i);
    a.push_back(0);
    b.push_back(0);
    for(ll i = 0; i < N; i++) a.push_back(a[i] + A[i]);
    for(ll i = 0; i < M; i++) b.push_back(b[i] + B[i]);

    ll ans = 0, j = M;
    for(ll i = 0; i < N+1; i++){
        if(a[i] > K) break;
        while(b[j] > K-a[i]) j--;
        ans = max(ans, i+j);
    }
    /* debug
    for(ll i = 0; i < a.size(); i++){
        cout << "a[" << i << "]=" << a[i] << endl;
    }
    for(ll i = 0; i < b.size(); i++){
        cout << "a[" << i << "]=" << b[i] << endl;
    }
    */
    cout << ans << endl;
    return 0;
}

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

int N, Q;
int const inf = INT_MAX;

struct SegmentTree {
private:
    int n;
    vector<int> node;
public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1;
        // 2の累乗の大きさにする
        while (n < sz) n *= 2;
        // 余りをinfで埋める
        node.resize(2*n-1, inf);
        // 葉を構築
        for (int i = 0; i < sz; i++) {
            node[i+n-1] = v[i];
        }
        // 親を構築
        for (int i = n - 2; i >= 0; i--) {
            node[i] = min(node[2*i+1], node[2*i+2]);
        }
    }

    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }

    int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return inf;
        if (a <= l && r <= b) return node[k];
        int vl = getmin(a, b, 2*k+1, l, (l+r) / 2);
        int vr = getmin(a, b, 2*k+2, (l+r) / 2, r);
        return min(vl, vr);
    }
};

int main() {
    cin >> N >> Q;
    SegmentTree seg( vector<int>(N, inf) );
    for (int i = 0; i < Q; i++) {
        int c, x, y; cin >> c >> x >> y;
        if (c == 0) seg.update(x, y);
        else cout << seg.getmin(x, y+1) << endl;
    }
}


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

int main()
{
	int n, r, p, c;
	while (cin >> n >> r, n || r) {
		vector<int> vec(n + 1),sw(n + 1);
		for (int i = 0; i < n; i++) {
			vec[i + 1] = n - i;
		}
		for (int i = 0; i < r; i++) {
			cin >> p >> c;
			for (int j = 1; j < p; j++) {
				sw[j] = vec[j];
			}
			for (int j = 0; j < c; j++) {
				vec[j + 1] = vec[p + j];
			}
			for (int j = 1; j < p; j++) {
				vec[j + c] = sw[j];
			}
		}
		cout << vec[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
A,B = [int(i) for i in input().split()]
S = input()
s = list(S)

if s[A] == "-":
    s[A] = "1"
else:
    s[A] = "x"

S = "".join(s)
if S.isdigit():
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;

int n, m, k;
int a[N];
int ans, sum;

int main()
{
	//File("");
	cin >> k >> n;
	for (int i = 1; i <= n; i+=1)
	{
	    cin >> a[i];
	    if (i > 1)
	        ans = max(ans, a[i] - a[i - 1]);
	}
	ans = max(ans, k - a[n] + a[1]);
	cout << k - ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
const long long int mod=1e9+7;
typedef long long ll;
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
double reabs(double in){
    if(in<0){
        return (-1)*in;
    }else{
        return in;
    }
}

int main(){
    int N;
    cin>>N;
    vector<int> p;
    FOR(i,N){
        int tmp;
        cin>>tmp;
        p.push_back(tmp);
    }
    bool t;
    FOR(i,N){
        for(int j=i;j<N;j++){
            t=true;
            swap(p[i],p[j]);
            FOR(i,N){
                int tmp;
                
                if(i==0){
                    tmp=p[i];
                }else{
                    if(tmp>p[i]){
                        t=false;
                        break;
                    }
                    tmp=p[i];
                }
            }
            if(t){
                cout<<"YES"<<endl;
                return 0;
            }
            swap(p[i],p[j]);

        }
    }
    
    cout<<"NO"<<endl;

   
    return 0;
}




Measured memory_bytes: 256
/*
 * Edit Distance (Levenshtein Distance)
 *
 * Find the edit distance between given two words s1 and s2.
 *
 * The disntace is the minimum number of single-character edits required to
 * change one word into the other. The edits including the following operations:
 *
 * insertion: Insert a character at a particular position.
 * deletion: Delete a character at a particular position.
 * substitution: Change the character at a particular position to a different
 * character
 * Input
 * s1
 * s2
 * Two words s1 and s2 are given in the first line and the second line
 * respectively. The words will consist of lower case characters.
 *
 * Output
 * Print the edit distance in a line.
 *
 * Constraints
 * 1 ≤ length of s1 ≤ 1000
 * 1 ≤ length of s2 ≤ 1000
 */

#include <algorithm>
#include <iostream>
using namespace std;

#define MAXN 1010
#define INF (int)1e9

int dp[MAXN][MAXN];

int main() {
  for (int i = 0; i < MAXN; ++i)
    fill(dp[i], dp[i] + MAXN, 0);
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  // dp[i][j]=cost of aligning s[i...n-1] with t[j..m-1]
  for (int i = 0; i < n; ++i)
    dp[i][m] = n - i;
  for (int j = 0; j < m; ++j)
    dp[n][j] = m - j;
  for (int i = n - 1; i >= 0; --i)
    for (int j = m - 1; j >= 0; --j)
      dp[i][j] = min(min(dp[i + 1][j] + 1, dp[i][j + 1] + 1),
                     dp[i + 1][j + 1] + (s[i] != t[j]));
  cout << dp[0][0] << endl;
}


Measured memory_bytes: 7200
#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<vector<int>> children;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
void hukasa(vector<vector<int>> s,vector<vector<int>> table,int &ans,pii frm,int n,int m){
  int x,y;
  tie(x,y) = frm;
  set<pii> se;
  if(x-1 >= 0)se.insert(pii(x-1,y));
  if(x+1 < n)se.insert(pii(x+1,y));
  if(y-1 >= 0)se.insert(pii(x,y-1));
  if(y+1 < m)se.insert(pii(x,y+1));
  for(auto t:se){
    int tx,ty;
    tie(tx,ty) = t;
    if(s.at(tx).at(ty) && table.at(tx).at(ty) == -1){
      table.at(tx).at(ty) = table.at(x).at(y) + 1;
      ans = max(ans,table.at(tx).at(ty));
      hukasa(s,table,ans,t,n,m);
      table.at(tx).at(ty) = -1;
    }
  }
}
void daiku(int frm,vector<vector<pii>> g,vector<int> &cost,int n){
  priority_queue<pii,vector<pii>,greater<pii>> q;
  q.push(pii(cost.at(frm),frm));
  vector<bool> kakutei(n,false);
  while(!q.empty()){
    pii now = q.top();
    q.pop();
    int n1,n2;
    tie(n1,n2) = now;
    if(kakutei.at(n2))continue;
    kakutei.at(n2) = true;
    for(auto t:g.at(n2)){
      int tx,ty;
      tie(tx,ty) = t;
      if(cost.at(tx) > n1 + ty){
        cost.at(tx) = n1 + ty;
        q.push(pii(cost.at(tx),tx));
      }
    }
  }
}

int main(){
  int x;
  cin >> x;
  if(x)cout << 0;
  else cout << 1;
}

Measured memory_bytes: 3632
import Data.List
main=do
 s<-getLine;t<-getLine
 putStrLn[if c=='?' then 'a' else c|c<-(((sort(f s (length s) s (length s) t (length t)))++["UNRESTORABLE"])!!0)]
  where f o w s n t m = if n<m then [] else ((if (h (take m s) t m) then [(take (w-n) o)++t++(drop m s)] else [])++(f o w (tail s) (n-1) t m))
        h a b m = if m==0 then True else (if (head a)=='?'||(head a)==(head b) then (h (tail a) (tail b) (m-1)) else False)

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






//１２２－B
int main(void) {
	string S; cin >> S;
	vector<char>Ans;
	int ANS = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
			Ans.push_back(S[i]);
			if (ANS <= Ans.size()) {
				ANS = Ans.size();
			}
		}
		else {
			if (ANS <= Ans.size()) {
				ANS = Ans.size();
			}
			Ans.clear();
		}
	}
	cout << ANS << endl;
}

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


int main() {
  int N;
  int h;
  int max_height = 0;
  int sum_height = 0;
  int prev = 0;
  cin >> N;

  int ans = 0;
  rep(i, N) {
    cin >> h;
    if (prev > h) {
      ans += prev - h;
    }
    prev = h;
  }
  ans += prev;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AtCoder
{
	public class Program
	{
		// ABC111-C
		static void Main(string[] args)
		{
			Dictionary<string, int> odd = new Dictionary<string, int>();
			Dictionary<string, int> even = new Dictionary<string, int>();

			int n = int.Parse(Console.ReadLine());
			string[] vs = Console.ReadLine().Split((string[])null, StringSplitOptions.RemoveEmptyEntries);
			for (int i = 0; i < n; i++) {
				if (i % 2 != 0) {
					if (!odd.ContainsKey(vs[i])) {
						odd[vs[i]] = 0;
					}
					odd[vs[i]]++;
				} else {
					if (!even.ContainsKey(vs[i])) {
						even[vs[i]] = 0;
					}
					even[vs[i]]++;
				}
			}

			string odd1Str = "", odd2Str = "", even1Str = "", even2Str = "";
			int odd1Cnt = 0, odd2Cnt = 0, even1Cnt = 0, even2Cnt = 0;
			FindMax(odd, ref odd1Str, ref odd1Cnt, ref odd2Str, ref odd2Cnt);
			FindMax(even, ref even1Str, ref even1Cnt, ref even2Str, ref even2Cnt);

			int result = 0;
			if (odd1Str != even1Str) {
				// 奇数の最頻値と偶数の最頻値が違う
				result = n - odd1Cnt - even1Cnt;
			} else {
				// 奇数の最頻値と偶数の最頻値が同じ
				if (odd1Cnt + even2Cnt > even1Cnt + odd2Cnt) {
					result = n - odd1Cnt - even2Cnt;
				} else {
					result = n - even1Cnt - odd2Cnt;
				}
			}
			Console.WriteLine(result);
		}

		private static void FindMax(Dictionary<string, int> dic, ref string max1Str, ref int max1Cnt, ref string max2Str, ref int max2Cnt)
		{
			foreach (var item in dic) {
				if (item.Value > max1Cnt) {
					max2Str = max1Str;
					max2Cnt = max1Cnt;
					max1Str = item.Key;
					max1Cnt = item.Value;
				} else if (item.Value > max2Cnt) {
					max2Str = item.Key;
					max2Cnt = item.Value;
				}
			}
		}
	}
}


Measured memory_bytes: 25440
#include <vector>
#include <utility>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
#define MP make_pair
#define PB push_back
const int N=1e3+10;
int a[N*4],flag[N*4];
void add(int n,int x,int l,int r,int L,int R){
    if(L<=l&&r<=R){
        a[n]+=x;
        flag[n]+=x;
    }
    else if(!(L>r||l>R)){
        int mid=(l+r)>>1;
        if(flag[n]!=0){
            flag[n*2+2]+=flag[n];
            flag[n*2+1]+=flag[n];
            a[n*2+2]+=flag[n];
            a[n*2+1]+=flag[n];
            flag[n]=0;
        }
        add(n*2+1,x,l,mid,L,R);
        add(n*2+2,x,mid+1,r,L,R);
        a[n]=max(a[n*2+1],a[n*2+2]);
    }
    return ;
}
int main(){
    int n,x1,x2,y1,y2,ans=0;
    vector<pi> l[N],r[N];
    scanf("%d",&n);
    memset(a,0,sizeof(a));
    memset(flag,0,sizeof(flag));
    for(int i=0;i<n;i++){
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        l[y1].PB({x1+1,x2});
        r[y2].PB({x1+1,x2});
    }
    for(int i=0;i<N;i++){
        for(auto u:l[i])add(0,1,0,N-1,u.F,u.S);
        for(auto u:r[i])add(0,-1,0,N-1,u.F,u.S);
        ans=max(ans,a[0]);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 5108
# problem: https://atcoder.jp/contests/abc051/tasks/abc051_b

K, S = [int(i) for i in input().split()]
res = 0

for i in range(K+1):
    for j in range(K+1):
        k = S - i - j
        if 0 <= k <= K: res += 1

print(res)

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

int main(){
  ll k,a,b;
  cin >> k >> a >> b;
  if(a+2>=b||k<=a){
    cout << k+1 << endl;
    return 0;
  }
  
  cout << a+(k-a+1)/2*(b-a)+(k-a+1)%2 << endl;
}

Measured memory_bytes: 3632
n,m = gets.chomp.split.map(&:to_i)
ls = m.times.map{gets.chomp.split.map(&:to_i)}
ps = gets.chomp.split.map(&:to_i)

ans = 0
(2 ** n).times do |i|
	flag = true
	m.times do |j|
		cnt = 0
		ls[j].each_with_index do |s,k|
			next if k == 0
			if i[s-1] == 1
				cnt += 1
			end
		end

		if cnt % 2 != ps[j]
			flag = false
			break
		end

	end
	ans += 1 if flag
end

puts ans

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cerr<<v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll N;
    cin >> N;

    vector<pll> P(N);
    REP(i, N){
        cin >> P[i].first >> P[i].second;
    }

    ll mi = N;
    REP(i, N){
        REP(j, N){
            if(i==j) continue;
            ll dx = P[j].first - P[i].first;
            ll dy = P[j].second - P[i].second;

            if(dx==0 and dy==0) continue;

            ll tmp = N;
            REP(k, N){
                REP(l, N){
                    if(k==l) continue;
                    ll tx = P[l].first - P[k].first;
                    ll ty = P[l].second - P[k].second;

                    if(dx==tx and dy==ty) tmp--;
                }
            }
            chmin(mi, tmp);
        }
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n;
    while(scanf("%d",&n) == 1)
    {
        int x = n;
        int sum = 0;
        while(x)
        {
            sum += x % 10;
            x /= 10;
        }
        if(n % sum == 0) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <cassert>
#include <bits/stdc++.h>
using namespace std; 
#define DEBUG(numx) cout << '>' << #numx << ':' << numx << endl;
inline bool EQ(double num1, double bin) { return fabs(num1-bin) < 1e-9; }
const int INF = 1<<29;
#define SZ(num1) (int)(num1.ss1())
#define SET(num1,bin) memset(num1,bin,sizeof(num1))
#define LET(numx,num1) __typeof(num1) numx(num1)
#define TR(vecc,iter) for( LET(iter,vecc.begin()) ; iter != vecc.end() ; iter++)
#define repi(idxxx1,num1) for(int idxxx1=0; idxxx1<(int)num1;idxxx1++)
#define si(num1) scanf("%depth",&num1)
#define DRT()  int test; cin>>test; while(test--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define trace1(numx)                cerr << #numx << ": " << numx << endl;
#define trace2(numx, to)             cerr << #numx << ": " << numx << " | " << #to << ": " << to << endl;
#define trace3(numx, to, nn3)          cerr << #numx << ": " << numx << " | " << #to << ": " << to << " | " << #nn3 << ": " << nn3 << endl;
#define trace4(num1, bin, ch, depth)       cerr << #num1 << ": " << num1 << " | " << #bin << ": " << bin << " | " << #ch << ": " << ch << " | " << #depth << ": " << depth << endl;
#define trace5(num1, bin, ch, depth, make_pair1)    cerr << #num1 << ": " << num1 << " | " << #bin << ": " << bin << " | " << #ch << ": " << ch << " | " << #depth << ": " << depth << " | " << #make_pair1 << ": " << make_pair1 << endl;
#define trace6(num1, bin, ch, depth, make_pair1, det) cerr << #num1 << ": " << num1 << " | " << #bin << ": " << bin << " | " << #ch << ": " << ch << " | " << #depth << ": " << depth << " | " << #make_pair1 << ": " << make_pair1 << " | " << #det << ": " << det << endl;
using namespace std;
#define forn(i, n)          for(int i=0;i<n;++i)
#define VI vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
#define pb push_back
#define vi vector
#define pii pair<ll,ll>
#define fr(i,vc1,vc2)	for( ll i=vc1; i<vc2; i++)
#define Fr(i,vc1,vc2)	for( ll i=vc1; i<=vc2; i++)
#define rfr(i,vc1,vc2)	for( ll i=vc1; i>vc2; i--)
#define rFr(i,vc1,vc2)	for( ll i=vc1; i>=vc2; i--)
const int N = 3e5;
using namespace std;
map <pair<string, int>, int> idxx;
 
bool cmp(pair<string, int> x, pair<string, int> y) {
  if(x.first == y.first) return x.second > y.second;
  return x.first < y.first;
}
 
int main() {
  int n;
  cin >> n;
  vector <pair<string, int>> v, scoreSave;
  for(int i = 1; i <= n; i++) {
    string ss;
    cin >> ss;
    int sc;
    cin >> sc;
    scoreSave.push_back({ss, sc});
    v.push_back({ss, sc});
    idxx[{ss, sc}] = i;
  }
  sort(v.begin(), v.end(), cmp);
  int l = 1;
  for(pair<string, int> c : v) {
    cout << idxx[c] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// Created by Sharat Sachin
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(ll i=0;i<(n);++i)
#define repA(i,a,n) for(ll i=a;i<=(n);++i)
#define repD(i,a,n) for(ll i=a;i>=(n);--i)

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    n = 3;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    sort(v.begin(), v.end());
    if(v[0]==5 && v[1]==5 && v[2]==7) cout<<"YES";
    else cout<<"NO";
    
    
    return 0;
}

Measured memory_bytes: 3556
n = int(input())
l = list(map(int,input().split()))
p = []
cnt = 0
for i in range(len(l)-1):
    if l[i+1] > l[i]:
        p.append(cnt)
        cnt = 0

    else:
        cnt = cnt+1

p.append(cnt)
p.sort()
print(p[-1])

Measured memory_bytes: 84408
import sys
from functools import lru_cache
 
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())
n=read()
a,b=[0]*n,[0]*n
for i in range(n):
  a[i],b[i]=reads()
a=sorted(a)
b=sorted(b)
if n%2==1:
  print(b[(n-1)//2]-a[(n-1)//2]+1)
else:
  mi=(a[n//2-1],a[n//2])
  ma=(b[n//2-1],b[n//2])
  res=(ma[0]+ma[1])-(mi[0]+mi[1])+1
  print(res)

Measured memory_bytes: 27440
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int K = sc.nextInt();
    int cnt = 0;
    for(int i = Math.max(A,B); i>=1; i--){
      if(A%i == 0 && B%i==0){
        cnt++;
        if(cnt == K){
          System.out.println(i);
          break;
        }
      }
    }
  }
}


Measured memory_bytes: 21972
// By Shreehari Bodas
 
#include <bits/stdc++.h>
 
#define PB push_back
#define MP make_pair
#define MT make_tuple
 
#define forn(i,n) for(int i=0;i<n;i++)
#define forsn(i,s,n) for(int i=s;i<n;i++)
#define rforn(i,n) for(int i=n;i>=0;i--)
#define rforsn(i,s,n) for(int i=n;i>=s;i--)
#define forstl(a,s) for(auto a:s)
 
using namespace std;
 
typedef long long LL;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
 
const int MOD=1e9+7;
 
LL pow(LL a, LL b){
	if(b==0) return 1;
	LL res=pow(a,b/2);
	if(b%2 ==1) return res*res*a;
	else if(b%2 ==0) return res*res;
}
 
int main(){
 
	int s,w; cin>>s>>w;
	if(w>=s) cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;
 
	return 0;
} 

Measured memory_bytes: 3676
#23:13-23:51
N=int(input())
A=list(map(int,input().split()))
X=sum(A)
x=0
ans=10**10
for i in range(len(A)):
    x+=A[i]
    if i+1<N:
        ans=min(ans,abs(X-2*x))
print(ans)

Measured memory_bytes: 23792
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

struct SegmentTree {
    int n;
    vec seg;
    int id_e = INT_MAX;

    SegmentTree(int n_) {
        n = 1;
        while (n < n_) n *= 2;

        seg.resize(2 * n - 1);
        rep(i, 2*n-1) seg[i] = id_e;
    }

    void update(int k, int a) {
        k += n - 1;
        seg[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]);
        }
    }

    int query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return id_e;

        if (a <= l && r <= b) return seg[k];
        else {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};

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

    SegmentTree st(n);

    rep(i, q) {
        int com;
        cin >> com;

        if (com == 0) {
            int p, x;
            cin >> p >> x;
            st.update(p, x);
        }
        else {
            int l, r;
            cin >> l >> r;
            r++;
            cout << st.query(l, r, 0, 0, st.n) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3908
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, m, x  = map(int, input().split())
li  = [list(map(int, input().split())) for _ in range(n)]
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

ans = 10**9
for i in range(2**n): # 総当り
    s = f'{i:012b}'[12-n:]

    # TODO:金額break

    rikaido = [0] * m
    price = 0
    for i2, b in enumerate(s): # 選んだやつ
        if b == '1':
            price += li[i2][0]
            for i3 in range(m): # 理解度を足す
                rikaido[i3] += li[i2][i3+1]

    # 理解してるか
    for r_ in rikaido:
        if r_ < x:
            break
    else:
        if price < ans:
            ans = price

print(-1 if ans == 10**9 else ans)


Measured memory_bytes: 69044
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[l,r]=i2()
z=10**9+7
dp=[[[[0 for l in range(2)]for k in range(2)]for j in range(2)]for i in range(61)]
dp[60][0][0][0]=1
for n in range(60)[::-1]:
 lb=l>>n&1
 rb=r>>n&1
 for x in range(2):
  for y in range(2):
   for i in range(2):
    for j in range(2):
     for k in range(2):
      ni=i+0
      nj=j+0
      nk=k+0
      if x>y:
         continue
      if k==0 and x!=y:
         continue
      if x&y:
         nk=1
      if i==0 and x<lb:
         continue
      if  x>lb:
         ni=1
      if j==0 and y>rb:
         continue
      if y<rb:
         nj=1
      dp[n][ni][nj][nk]+=dp[n+1][i][j][k]
      dp[n][ni][nj][nk]%=z
print((dp[0][1][1][1]+dp[0][0][1][1]+dp[0][1][0][1]+dp[0][0][0][1])%z)

Measured memory_bytes: 39920
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=15000007;
const ll MAX=9187201950435737471;
const int N=100005;
const ll INF=1e17;
const long double PI=acos(-1);

ll po(int x){
    if(x==0){
        return 1;
    }
    ll ret=1;
    for(int i=0;i<x;i++){
        ret=(ret%MOD * 10)%MOD;
    }
    return ret;
}
bool a[200];

void solve(int T){
    int x,n;
    cin>>x>>n;
    if(n==0){
        cout<<x;
        return;
    }
    for(int i=0;i<n;i++){
        int r;
        cin>>r;
        a[r]=true;
    }
    int mn=102,ans=102;
    for(int i=0;i<=101;i++){
        if(a[i]==false){
            if(abs(x-i)<mn){
                ans=i;
                mn=abs(x-i);
            }
        }
    }
    cout<<ans<<"\n";
}

int main() {
    fastio
    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}
/*

for(int i=1;i<n;i++){
        for(int j=1;j<n;j++){
            cout<<i<<" "<<j<<" "<<n-(i*j)<<"\n";
        }
    }
    */


Measured memory_bytes: 3552
import numpy as np

if __name__=='__main__':
    N = int(input())
    p = np.array(list(map(float,input().split())))
    
    dp = np.zeros([N+1,N+1],dtype=float)
    dp[0][0] = 1.0
    
    for i,p in enumerate(p):
        dp[i+1][:] = dp[i][:]*(1-p)
        dp[i+1][1:] += dp[i][:-1]*p
    
    
    ans = N//2 + 1
    print(dp[N][ans:].sum())

Measured memory_bytes: 82760
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pi 3.14159265358979323846264
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
int n, a[1005];
int main() {
    scanf("%d", &n);
    for (int i=0;i<n;i++) scanf("%d", &a[i]);
    sort (a, a+n);
    printf("%d\n", a[n-1]-a[0]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;

const int N = 200228;
vector<int> e[N];
vector<int> erev[N];

int n;

int p[N];
int pr[N];

int w[N];
int curv;

int av[N], au[N];

void nein() {
    cout << -1 << "\n";
    exit(0);
}

bool dfs(int v) {
    if (w[v] == curv) {
        return false;
    }

    w[v] = curv;

    for (int u: e[v]) {
        if (p[u] == 0) {
            p[u] = v;
            return true;
        }
    }

    for (int u: e[v]) {
        if (dfs(p[u])) {
            p[u] = v;
            return true;
        }
    }

    return false;
}

bool go[N];

void dfsgo(int v) {
    go[v] = true;
    for (int u: erev[v]) {
        if (!go[pr[u]]) {
            av[u] = v;
            au[u] = pr[u];
            dfsgo(pr[u]);
        }
    }
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);

    cin >> n;

    for (curv = 1; curv < n; ++curv) {
        int s;
        cin >> s;
        e[curv].resize(s);
        for (int& v: e[curv]) {
            cin >> v;
            erev[v].push_back(curv);
        }

        if (!dfs(curv)) {
            nein();
        }
    }

    for (int i = 1; i <= n; ++i) {
        pr[p[i]] = i;
    }

    int root = 1;
    while (p[root]) {
        ++root;
    }

    dfsgo(root);
    for (int i = 1; i <= n; ++i) {
        if (!go[i]) {
            nein();
        }
    }

    for (int i = 1; i < n; ++i) {
        cout << av[i] << " " << au[i] << "\n";
    }
}



Measured memory_bytes: 22784
from itertools import combinations

h, w, k = map(int, input().split(" "))
colored_blocks = []
result = 0
for i in range(h):
    for j, v in enumerate(list(input())):
        if v == "#":
            colored_blocks.append({"row": i, "col": j})

for i in range(0, h + 1):
    for t_r in combinations(list(range(h)), i):
        row_filtered_candidates = [b for b in colored_blocks if b["row"] not in t_r]
        for j in range(0, w + 1):
            for t_c in combinations(list(range(w)), j):
                col_filtered_candidates = [
                    b for b in row_filtered_candidates if b["col"] not in t_c
                ]
                if len(col_filtered_candidates) == k:
                    result += 1
print(result)

Measured memory_bytes: 68808