akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
typedef long long ll;

const int MAX_N = 1e5 + 10;
const ll MOD = 1e9 + 7;

int T[MAX_N], A[MAX_N];
bool t_is_constant[MAX_N], a_is_constant[MAX_N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> T[i];
    for (int i = 1; i <= N; i++) cin >> A[i];
    for (int i = 1; i <= N; i++) {
        if (T[i - 1] != T[i]) t_is_constant[i] = true;
    }
    for (int i = N; i >= 1; i--) {
        if (A[i + 1] != A[i]) a_is_constant[i] = true;
    }
    ll ans = 1;
    for (int i = 1; i <= N; i++) {
        if (t_is_constant[i] && a_is_constant[i] && T[i] != A[i]) {
            cout << 0 << endl;
            return 0;
        }
        if (t_is_constant[i] && !a_is_constant[i] && T[i] > A[i]) {
            cout << 0 << endl;
            return 0;
        }
        if (!t_is_constant[i] && a_is_constant[i] && T[i] < A[i]) {
            cout << 0 << endl;
            return 0;
        }
        if (!t_is_constant[i] && !a_is_constant[i]) ans = (ans * min(T[i], A[i])) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;

// #include "debug.h"
// #define debug(...) 42

using ll = long long;

void solve() {
   int n;
   cin >> n;
   vector <int> a(n);
   int g = 0;
   for(int i = 0; i < n; i++) {
      cin >> a[i];
      g = __gcd(g, a[i]);
   }
   cout << g << endl;
} 

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


Measured memory_bytes: 3724
import numpy as np

N, S = map(int, input().split())
x = [int(x) for x in input().split()]
 
# 状態リストを作成
m = np.zeros((S+1,3))
p = np.zeros((S+1,3))
p[0,0] = 1

# 前状態から次状態の場合数を計算
for i in range(1,N+1):
    
    # x[i] を加えない場合
    m[:,0] = p[:,0]
    m[:,1] = p[:,0] + p[:,1]  # 今回から開始して加えない、もしくは既に開始しているが、加えない
    m[:,2] = p[:,0] + p[:,1] + p[:,2]  # 今回、開始・終了して加えない、今回開始して加えず終了。

    # x[i] を加える場合
    m[x[i-1]:,1] += p[:-x[i-1],0] + p[:-x[i-1],1]
    m[x[i-1]:,2] += p[:-x[i-1],0] + p[:-x[i-1],1]

    p[:,0] = m[:,0] % 998244353
    p[:,1] = m[:,1] % 998244353
    p[:,2] = m[:,2] % 998244353
            
print(int(p[S,2]))

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

#define ll long long
#define nums vector<int>
#define words vector<string>
#define letrs vector<char>
#define MOD 1000000007
#define pb push_back
#define llnums vector<ll>

using namespace std;

void solve() {

}
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); // A.cpp
    int n;
    cin >> n;
    set<string> d;
    string a;
    for (int i=0; i < n; i++) {
        cin >> a;
        d.insert(a);
    }
    cout << d.size() << '\n';
    return 0;
}



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

//vector<vector<char>> ma(100,vector<char>(100,'0'));
char ma[100][100]={'0'};
int H,W;

vector<int> dx(4,0);
vector<int> dy(4,0);

//int dx[4]={1,0,-1,0};
//int dy[4]={0,1,0,-1};
char cc;

void dfs(char c,int x,int y){
	cc=c;
	ma[x][y]='0';
	for(int i=0;i<4;i++){
		if(x+dx[i]>=0 && x+dx[i]<H && y+dy[i]>=0 && y+dy[i]<W && ma[x+dx[i]][y+dy[i]]==c)dfs(ma[x+dx[i]][y+dy[i]],x+dx[i],y+dy[i]);
	}
	return ;
}
void dfs2(int xx,int yy){
	ma[xx][yy]='0';
	for(int i=0;i<4;i++){
		if(xx+dx[i]>=0 && xx+dx[i]<H && yy+dy[i]>=0 && yy+dy[i]<W && ma[xx+dx[i]][yy+dy[i]]==cc)dfs2(xx+dx[i],yy+dy[i]);
	}
	return ;
}





int main(){
dx[0]=1;
dx[2]=-1;
dy[1]=1;
dy[3]=-1;
	while(cin>>H>>W,H,W){
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cin>>ma[i][j];
			}
		}
		int ans=0;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(ma[i][j]=='#'){
					dfs('#',i,j);
					ans++;
				}
				else if(ma[i][j]=='@'){
					dfs('@',i,j);
					ans++;
				}
				else if(ma[i][j]=='*'){
					dfs('*',i,j);
					ans++;
				}
			}
		}

		cout<<ans<<endl;

	}

}


					





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

int main() {
  	string s;
    cin >> s;
    for (int i=0; i<s.size(); i++){
    	if (i%2==0) {
        	cout << s[i];
        }
	}
    cout << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
struct p{
	int x,y;
};
int cmp(p a,p b){
	return a.y<b.y;
}
int main(){
	int n;
	cin>>n;
	p a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
	}
	sort(a+1,a+n+1,cmp);
	int t=0;
	for(int i=1;i<=n;i++){
		t+=a[i].x;
		if(t>a[i].y){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll ret;
string s;
vector<ll> v;

void input() {
  IN(N);
  IN(s);
}

void solve() {
  ll total_b = 0;
  ll total_w = 0;
  ll now_b = 0;
  ll now_w = 0;
  for (ll i=0; i<s.size(); i++) {
    char c = s[i];
    if(c == '.') {
      total_w++;
    }else if(c == '#'){
      total_b++;
    }else{
      DEBUG("Something Wrong");
    }
  }
  v.push_back(total_w);
  for(ll i=0; i<s.size(); i++) {
    char c = s[i];
    if(c == '.') {
      now_w++;
    }else if(c == '#'){
      now_b++;
    }else{
      DEBUG("Something Wrong");
    }
    ll value = now_b + total_w - now_w;
    v.push_back(value);
  }

  ret = *min_element(v.begin(), v.end());
}

int main(void){
  input();
  solve();
  PRINT(ret);
}


Measured memory_bytes: 2680
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100;

int aa[N], bb[N];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> aa[i] >> bb[i];
	for (int i = 1; i + 1 < n; i++)
		if (aa[i - 1] == bb[i - 1] && aa[i] == bb[i] && aa[i + 1] == bb[i + 1]) {
			cout << "Yes\n";
			return 0;
		}
	cout << "No\n";
	return 0;
}


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

typedef long double ld;

const ld EPS = 1e-9;
const ld INF = 1e10;
const ld PI = M_PI;

struct Point{
  ld x, y;
  Point(ld x, ld y):x(x), y(y){}
  Point(){}
};

Point operator+(const Point &a, const Point &b){
  return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point &a, const Point &b){
  return Point(a.x - b.x, a.y - b.y);
}
Point operator*(const Point &a, const ld b){
  return Point(a.x * b, a.y * b);
}
Point operator*(const Point &a, const Point &b){
  return Point(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x);
}
Point operator/(const Point &a, const ld b){
  return Point(a.x / b, a.y / b);
}

ld cross(const Point &a, const Point &b){
  return a.x*b.y - a.y*b.x;
}

ld dot(const Point &a, const Point &b){
  return a.x*b.x + a.y*b.y;
}

ld norm(const Point &a){
  return dot(a, a);
}

struct Line:vector<Point>{
  Line(Point a = Point(0, 0), Point b = Point(0, 0)){
    this->push_back(a);
    this->push_back(b);
  }
};

typedef vector<Point> Polygon;

int ccw(Point a, Point b, Point c){
  b = b - a;
  c = c - a;
  if(cross(b, c) > EPS) return +1; // 反時計周り
  if(cross(b, c) < -EPS) return -1; // 時計周り
  if(dot(b, c) < 0) return +2; // c -- a -- b がこの順番に一直線上
  if(norm(b) < norm(c)) return -2; // a -- b -- c がこの順番に一直線上
  return 0; // a -- c -- b が一直線上
}

Point next(const Polygon &a, int x){
  return a[(x+1)%a.size()];
}

Point prev(const Polygon &a, int x){
  return a[(x-1+a.size()) % a.size()];
}

bool is_convex(const Polygon &poly){
  for(int i = 0 ; i < (int)poly.size() ; i++){
    if(ccw(prev(poly, i), poly[i], next(poly, i)) == -1) return false;
  }
  return true;
}

int main(){  
  int q;
  cin >> q;
  Polygon poly;
  while(q--){
    Point p;
    cin >> p.x >> p.y;
    poly.push_back(p);
  }
  if(is_convex(poly)) cout << 1 << endl;
  else cout << 0 << endl;
  
  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  string s,ans;
  cin >> s;
  rep(i,s.size()){
    if(s[i] == '0'){
      ans.push_back('0'); 
    }
    else if(s[i] == '1'){
      ans.push_back('1'); 
    }
    else{
      if(ans.size() != 0){
      ans.pop_back();
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 3596
def colorful_subsequence(N: int, S: str)->int:
    MOD = (10 ** 9) + 7
    cum = {}
    for c in S:
        cum.setdefault(c, 0)
        cum[c] += 1

    values = list(cum.values())
    count = 0
    for i, v in enumerate(values):
        temp = v
        for v in values[i+1:]:
            temp = (temp * (1 + v)) % MOD
        count = (count + temp) % MOD

    return count


if __name__ == "__main__":
    N = int(input())
    S = input()
    ans = colorful_subsequence(N, S)
    print(ans)


Measured memory_bytes: 3188
#include <stdio.h>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #include <math.h>
    
    
    
        using namespace std;
    
                                    //I imitated Ant Book version 1: P.84.
    
                                    int n,q,com,x,y;
                                int rank1[10000];
                                int parent[10000];
    
    
    
    
                                    int find(int x){
                                        if(x == parent[x])return x;
                                        else{
                                            return parent[x] = find(parent[x]);
                                        }
                                    }
    
                                    bool Same(int x,int y){
                                        return find(x) == find(y);
                                    }
    
                                    void unite(int x,int y){
                                        x = find(x);
                                        y = find(y);
                                        
                                        if(x == y)return;
                                        
                                        if(rank1[x] < rank1[y]){
                                            parent[x] = y;
                                        }else{
                                            parent[y] = x;
                                            if(rank1[x] == rank1[y])rank1[x]++;
                                        }
                                    }
    
            int main(){
                
                scanf("%d %d",&n,&q);
                int i;
                for(i = 0; i < n; i++){
                    rank1[i] = 0;
                    parent[i] = i;
                }
    
                for(i = 0; i < q; i++){
                    scanf("%d %d %d",&com,&x,&y);
                    
                    if(com == 1){
                        if(Same(x,y))printf("1\n");
                        else{
                            printf("0\n");
                        }
                    }else{
                        if(Same(x,y))continue;
                        
                        unite(x,y);
                    }
                }
                
                return 0;
            }



Measured memory_bytes: 2668
n, k = map(int,input().split())
p = list(map(int,input().split()))

s = []
sum = 0
for i in range(k):
    sum += p[i]

s.append(sum)

for i in range(1, n-k+1):
    sum = sum - p[i-1] + p[i+k-1]
    s.append(sum)

m = max(s)/2 + k/2

print(m)


Measured memory_bytes: 25060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for(ll i=2; i*i<=n; i++) {
        if(n % i != 0) continue;
        ll num = 0;
        while(n % i == 0)  {num++; n /= i;}
        res.push_back(make_pair(i, num));
    }
    if(n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    ll n, p; cin >> n >> p;
    vector<pair<ll, ll>> v = prime_factorize(p);
    ll ans = 1;
    for(auto x : v) {
        //cout << x.first << ' ' << x.second << endl;
        if(x.second >= n) rep(i, x.second / n) ans *= x.first;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
# coding: utf-8
n = int(input())
playlist = []
for i in range(n):
    playlist.append(input().split(" "))
    playlist[i][1] = int(playlist[i][1])

# print(playlist)
x = input()
s = 0

for i, p in enumerate(playlist):
    if p[0] == x:
        s = i
        break

sm = 0
for i in range(s+1, n):
    sm += playlist[i][1]

print(sm)

Measured memory_bytes: 3064
#include <stdio.h>

int n, t, c, time, mini=10000;

int main(){
    scanf("%d %d", &n, &t);

    for(int i=0; i<n; i++){
        scanf("%d %d", &c, &time);
        if(time <= t && c < mini)
            mini = c;
    }
    if(mini != 10000){
        printf("%d\n", mini);
    } else {
        printf("TLE\n");
    }
}


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

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

    double sum = 0;

    for (int i = 0; i < N; i++)
    {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY")
        {
            sum += x;
        }
        else
        {
            sum += 380000 * x;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int MOD = 1e9 + 7;
int main()
{
    int N, K; cin >> N >> K;
    vector<int> A, C;
    {
        int t = 1;
        while (t <= N) {
            A.push_back(N / t);
            C.push_back(N / (N / t));
            t = N / (N / t) + 1;
        }
    }
    int M = A.size();
    vector<Int> dp(M, 1), dp2(M), sum(M);
    for (int i = 1; i < K; i++) {
        sum[0] = C[0] * dp[0] % MOD;
        for (int j = 1; j < M; j++) {
            sum[j] = (sum[j-1] + (C[j] - C[j-1]) * dp[j]) % MOD;
        }
        for (int j = 0; j < M; j++) {
            int t = upper_bound(begin(C), end(C), A[j]) - begin(C) - 1;
            dp2[j] = (sum[t] + (A[j] == C[t] ? 0 : (A[j] - C[t]) * dp[t+1])) % MOD;
        }
        swap(dp2, dp);
    }
    Int ans = C[0] * dp[0];
    for (int i = 1; i < M; i++) {
        ans = (ans + (C[i] - C[i-1]) * dp[i]) % MOD;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2428
#include<stdio.h>
int main()
{
int num,j,c;
  c=0;
  scanf("%d",&num);
char a[num];
  scanf("%s",a,num);
  for(j=0;j<num-2;++j)
  {
  if(a[j]=='A' && a[j+1]=='B' && a[j+2]=='C') c++;
  }
  
  printf("%d",c);
  
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000001;
const ll MOD = 1000000007;
 
int dp[1001][1001];
int ways(int h,int w){
    //int dp[1001][1001]={0};
    if(dp[0][0]==-1){
        return 0;
    }
    
    for(int j=0;j<w;j++){
        if(dp[0][j]==-1){
            break;
        }
        dp[0][j]=1;
    }
    for(int i=0;i<h;i++){
        if(dp[i][0]==-1){
            break;
        }
        dp[i][0]=1;
    }
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(dp[i][j]==-1)
            continue;
            dp[i][j]=0;
            if(dp[i][j-1]!=-1)
            dp[i][j]=dp[i][j-1] % 1000000007;
            if(dp[i-1][j]!=-1){
                dp[i][j]=(dp[i][j]+dp[i-1][j])%1000000007;
            }
        }
    }
    if(dp[h-1][w-1]==-1){
      return 0;}
    //for(int i=0;i<h;i++){
        //for(int j=0;j<w;j++){
            //cout<<dp[i][j]<<" ";
        //}
       // cout<<endl;
    

    return dp[h-1][w-1];

    
}
int main() {
    int h,w;
    cin>>h>>w;
    memset(dp,0,sizeof dp);
    char grid[1001][1001];
    //char x;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>grid[i][j];
            //cin>>x;
            if(grid[i][j]=='#'){
                dp[i][j]=-1;
            }
        }
        
    }
   cout<<ways(h,w);

}


Measured memory_bytes: 8532
var
  i,j,n:longint;
  s:array[0..10000] of string;
  t:string;
begin
  readln(n);
  for i:=1 to n do readln(s[i]);
  for i:=1 to n-1 do
    for j:=i+1 to n do
    if s[i]>s[j] then begin t:=s[i];s[i]:=s[j];s[j]:=t;end;
  for i:=1 to n do write(s[i]);
  writeln;
end.

Measured memory_bytes: 256
n,q = map(int,input().split())
s = input()
ls = [0]
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ls.append(ls[i]+1)
    else:
        ls.append(ls[i])
for i in range(q):
    l,r = map(int,input().split())
    print(ls[r-1] - ls[l-1])

Measured memory_bytes: 6100
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
char str[2000010];
int main(){
    scanf("%s",str+1);
    int n = strlen(str+1);
    int now = 0;
    for(int i = 1;i <= n;i++){
        now += (str[i] - '0');
        now %= 9;
    }
    if(now == 0)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int g = 0;
    for (int i = 0; i < n; i++) {
        int a, k;
        cin >> a >> k;
        while (a % k != 0 && a > k) {
            int x = (a / k) + 1;
            int y = (x - 1) * k;
            int lo = 0, hi = 1e9;
            while (hi - lo > 1) {
                int mid = (hi + lo) / 2;
                if ((ll)a - 1LL * mid * x <= y) {
                    hi = mid;
                } else {
                    lo = mid;
                }
            }
            a -= hi * x;
        }
        g ^= a / k;
    }
    cout << (g == 0 ? "Aoki" : "Takahashi") << '\n';
    return 0;
}

Measured memory_bytes: 3612
program streamline
  implicit none
  integer :: n, m, x(100000) = 0, i, d(100000) = 0
  read(*,*) n, m
  if (m <= n) then
    write(*,'(i0)') 0
    stop
  end if
  read(*,*) x(1:m)
  call quick_sort(x(1:m))
  do i = 1, m-1
    d(i) = x(i+1)-x(i)
  end do
  call quick_sort(d(1:m-1))
  write(*,'(i0)') sum(int(d(1:m-n),8))
contains
  recursive subroutine quick_sort(a)
    integer, intent(inout) :: a(:)
    integer :: n, l, r, m
    integer :: p
    n = size(a)
    l = 1
    r = n
    m = (n+1)/2
    p = a(l)+a(m)+a(r)-max(a(l),a(m),a(r))-min(a(l),a(m),a(r))
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      a(l) = xor(a(l),a(r))
      a(r) = xor(a(l),a(r))
      a(l) = xor(a(l),a(r))
      l = l+1
      r = r-1
    end do
    if (l-1 > 1) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end
end program streamline

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	if (N % 2 == 0) {
		for (int i = 0; i < N - 1; i++) {
			res += min((N - i - 1) * 2, (i + 1) * 2) * (A[i + 1] - A[i]);
		}
		res -= A[N / 2] - A[(N / 2) - 1];
	}
	else {
		for (int i = 0; i < N - 1; i++) {
			res += min((N - i - 1) * 2, (i + 1) * 2) * (A[i + 1] - A[i]);
		}
		res -= min(A[N / 2] - A[(N / 2) - 1], A[(N / 2) + 1] - A[(N / 2)]);
	}
	cout << res << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,ans;
int a[101010];
bool cmp(int u,int w)
{
	return u>w;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmp);
	for (int i=1;i<=n;++i)
		if (i+1>a[i+1]) 
		{
			for (int j=i+1;a[j]==i;++j)
				++ans;
			ans%=2;
			ans|=(a[i]-i)%2;
			break;
		}
	if (ans%2) printf("First\n");
	else printf("Second\n");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0);

  int N;
  scanf("%d", &N);
  printf(N >= 1000 ? "ABD\n" : "ABC\n");
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,d,r;
  scanf("%d %d",&a,&b);
  if(1<=a && a<=1000000000 && 1<=b && b<=1000000000){
    d = a/ b;
    r = a% b;
    double x = a;
    double y = b;
    double f = x / y;
    printf("%d %d %.5lf\n",d,r,f);
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

struct state {
  ll v, z, d;
  bool operator<(const state &s) const {
    return d > s.d;
  }
};

int main(void) {
  for (ll N, M, C; cin >> N >> M >> C, N && M && C;) {
    vector<vector<pair<ll, ll>>> E(N);
    REP(i, 0, M) {
      ll f, t, c;
      cin >> f >> t >> c, f--, t--;
      E[f].push_back(make_pair(t, c));
    }

    vector<vector<ll>> dp(N, vector<ll>(M + 1, INF));

    priority_queue<state> q;
    q.push((state) { 0, 0, 0 });

    while (!q.empty()) {
      assert(q.size() > 0);
      ll v = q.top().v, z = q.top().z, d = q.top().d;
      q.pop();

      if (dp[v][z] <= d) continue;
      dp[v][z] = d;

      REP(i, 0, E[v].size()) {
        ll u = E[v][i].first, c = E[v][i].second;
        if (d + c < dp[u][z]) {
          q.push((state) { u, z, d + c });
        }
        if (z + 1 <= M && d < dp[u][z + 1]) {
          q.push((state) { u, z + 1, d });
        }
      }
    }

    ll ans = INF;
    REP(i, 0, M + 1) {
      if (dp[N - 1][i] <= C) {
        ans = min(ans, i);
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 40580
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

int main()
{
    ll a,b,c;
    cin >> a >> b >> c;

    if (a+b >= c) cout << "Yes" <<endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int inf = 1<<30;
typedef pair<int, int> P;

int main() {
  int n; cin >> n;
  vector<vector<int>> to(n), cost(n);
  rep(i, n-1) {
    int a, b, w; cin >> a >> b >> w;
    a--, b--;
    to[a].push_back(b); cost[a].push_back(w);
    to[b].push_back(a); cost[b].push_back(w);
  }

  vector<int> ans(n, -1);
  queue<int> q;
  ans[0] = 0;
  q.push(0);
  while(!q.empty()) {
    int v = q.front();
    q.pop();
    rep(i, to[v].size()) {
      int u = to[v][i];
      int w = cost[v][i];
      if(ans[u] != -1) continue;
      ans[u] = (ans[v] + w) % 2;
      q.push(u);
    }
  }

  rep(i, n) {
    cout << ans[i] << endl;
  }

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  string out = "";
  if(n == 0) out = "0";

  while(n != 0){
    if(n % 2 != 0){
      out = "1" + out;
      n -= 1;
    }else
    {
      out = "0" + out;
    }
    n /= -2;
  }
  cout << out << endl;
  return 0;
  
}

Measured memory_bytes: 256
#!/usr/bin/env python

A=[]
B = []
max = 0
max2 = 0
count = 0
N=int(input())
for i in range(N):
    A.append(int(input()))
for i in range(len(A)):
    if A[i] > max:
        max = A[i]
        B.append(A[i])
for i in range(len(A)):
    if A[i] == max:
        count +=1

    
for i in range(len(A)):
    if count >= 2:
        print(max)
    if count == 1:
        if A[i] > max2 and A[i] != max:
            max2 = A[i]
for i in range(len(A)):
    if count ==1:
        if A[i] == max:
            print(max2)
        else:
            print(max)


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

class Main {
    int n;
    String s;

    Main() {
        Scanner sc = new Scanner(System.in);
        this.n = Integer.parseInt(sc.next());
        this.s = sc.next();
    }

    int cutAndCount(int i) {
        int charsContainedInBoth = 0;

        String x, y;
        x = s.substring(0, i); y = s.substring(i);
        
        HashSet<Character> charSet = new HashSet<>();
        String shorter = x.length() < y.length() ? x : y;
        String longer = x.length() >= y.length() ? x : y;
        for (char c : shorter.toCharArray()) {
            charSet.add(c);
        }

        for (char cShorter : charSet) {
            for (char cLonger : longer.toCharArray()) {
                if (cShorter == cLonger) {
                    charsContainedInBoth++;
                    break;
                }
            }
        }

        return charsContainedInBoth;
    }

    void solve() {
       int max = 0;

       // test all patterns
       for (int i = 1; i < n; ++i) {
           max = Math.max(cutAndCount(i), max);
       } 

       System.out.println(max);
    }

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

Measured memory_bytes: 22608
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=mp()
uf = UnionFind(n)
for i in range(m):
    X,Y,Z=mp()
    uf.union(X-1,Y-1)
print(len(uf.roots()))

Measured memory_bytes: 15000
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"--------------------------"<<endl; 
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin >> n;
    ll A[n];
    rep(i,0,n)	cin >> A[i];
    ll ans = 0;
    sort(A, A+n);
    rep(i,0,n)	rep(j,i+1,n)	rep(k,j+1,n){
    	if(A[i] != A[j] and A[j] != A[k] and A[i] != A[k] and A[k] < A[j] + A[i]){
    		ans++;
    	}
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;

int main(){

  ios_base::sync_with_stdio(0); cin.tie(0);
  string s; cin >> s;
  int ans = 1e9;
  for(int i = 0; i <= s.size() - 3;i++)
  {
    int tmp = (s[i] - '0')*100 + (s[i+1] - '0')*10+(s[i+2] - '0');
    ans = min(ans, abs(tmp - 753));
  }
  cout << ans << nl;







  return 0;
}



Measured memory_bytes: 3612
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;

int n;
bool pp[mxn];

template<class C> int compress(vector<C> &_v) {//{//prefer using unique+function with lower_bound when compressing combined vectors
    int sz = sz(_v);
    vector<pair<C, int> > tmp(sz);
    for (int i = 0; i < sz; i++) {
        tmp[i] = {_v[i], i};
    }
    sort(begin(tmp), end(tmp));
    int cur = 1;
    for (int i = 0; i < sz; i++) {
        cur += i and tmp[i].first!=tmp[i-1].first;
        // ori[cur] = tmp[i].first;
        _v[tmp[i].second] = cur;
    }
    return cur;
}//}

vector<int> v;


signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
    cin >> n;
    v.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    ASSERT(compress(v), ==, n)
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        pp[v[i]] = i&1;
    }
    sort(begin(v), end(v));
    for (int i = 0; i < n; i++) {
        ans += (pp[v[i]]^(i&1));
    }
    cout << ans/2 << '\n';
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
using namespace std;

const int maxn = 5e3;
int n, k, mod, a[maxn + 5], f[maxn + 5];

int main() {
	scanf("%d %d", &n, &mod);
	k = (n - 1) / 2;
	rep(i, 1, k + 1) a[i]++;
	per(i, n, n - k + 1) a[i]--;
	rep(i, 1, n) a[i] += a[i - 1];
	f[0] = 1;
	rep(i, 1, n) {
		int x = a[i];
		rep(j, x, n - 1) f[j] = (f[j] + f[j - x]) % mod;
	}
	int s = 0;
	rep(i, 0, n - 1) s = (s + f[i]) % mod;
	printf("%d\n", s);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.lang.Math;

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

    char c = S.charAt(0);
    int count = 0;
    for (int i = 1; i < n; i++) {
      char _c = S.charAt(i);
      if (_c == c) {
        count++;
      } else {
        c = _c;
      }
    }

    System.out.println(n - count);
  }
}

Measured memory_bytes: 25724
import itertools
# x, y方向独立
# 初手のみ正なことに注意

txt = input()
x,y = map(int,input().split())
d = [len(s) for s in txt.split('T')]
x -= d[0]

d_x = d[2::2]
d_y = d[1::2]

def check(d,x):
  se = set([0])
  for dx in d:
    se = {a+b for a,b in itertools.product(se,[-dx,dx])}
  return (x in se)

bl = check(d_x,x) and check(d_y,y)
print('Yes' if bl else 'No')

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,i;
	cin>>n;
	int v[n+1],c[n+1];
	for(i=0;i<n;i++)
	{
		cin>>v[i];
	}
	int ans=0;
	for(i=0;i<n;i++)
	{
		cin>>c[i];
		if(v[i]>c[i])
			ans+=v[i]-c[i];
	}
	cout<<ans;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = 0;
	if( a <= b ){
		if( n == 1 ){
			if( a == b ) ans = 1 ;
		}
		else if( n == 2 ){
			ans = 2;
		} else {
			ans = (n-2)*b - (n-2)*a + 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>
#include <math.h>           // M_PI, sin(), cos(), atan2()

int
main(int argc, char **argv)
{
	int n;
	int i;

	while (true)
	{
		scanf("%d", &n);
		if (n == -1)
			break;

		double x = 1, y = 0;
		double th = M_PI / 2;
		for (i = 1; i < n; ++i)
		{
			if (th > M_PI)
				th -= 2 * M_PI;

			x += cos(th);
			y += sin(th);
			th = atan2(y, x) + M_PI / 2;
		}

		printf("%.8f\n", x);
		printf("%.8f\n", y);
	}

	return 0;
}

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

int main() {
  int P, Q, R, PQ, QR, RP, min;
  cin >> P >> Q >> R;
  PQ = P + Q;
  QR = Q + R;
  RP = R + P;
  if (PQ <= QR && PQ <= RP)
    cout << PQ;
  else if (PQ >= QR && QR <= RP)
    cout << QR;
  else
    cout << RP;
  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  S[K - 1] = S[K - 1] - 'A' + 'a';
  cout << S << endl;
  return 0;
}

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

int getNext(int n, int m){
  int tmp = n/m*m;
  return tmp;
}

signed main() {
  int k;cin>>k;
  vector<int> a(k);
  for(int i=k-1;i>=0;--i) cin>>a[i];
  // aは逆に保存している

  int lb=2,ub=2;
  for(int i=0;i<k;++i){
    int tmp = getNext(ub,a[i]);
    if (tmp < lb) {
      cout<<-1<<endl;
      return 0;
    }
    ub = tmp+a[i]-1;

    tmp = getNext(lb,a[i]);
    if(tmp<lb) tmp += a[i];
    lb = tmp;
  }

  cout<<lb<<" "<<ub<<endl;
  
  return 0;
}


Measured memory_bytes: 1152
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1.01e9;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

void add(int & x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int sum(int x, int y) {
  add(x, y);
  return x;
}

int mult(int x, int y) {
  return (ll) x * y % mod;
}

int power(int x, ll p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}

int inv(int x) {
  return power(x, mod - 2);
}

void precalc() {
}

int n, m;
vector<vector<int> > g;

bool read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return false;
  }
  g.clear();
  g.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  return true;
}

const int maxn = 1e5 + 100;
int used[maxn];

void dfs(int v, vector<int> & ans) {
  ans.pb(v);
  used[v] = 1;
  for (auto to : g[v]) {
    if (used[to]) {
      continue;
    }
    dfs(to, ans);
    break;
  }
}

void solve() {
  memset(used, 0, sizeof(used));
  int from = 0;
  for (int i = 0; i < n; i++) {
    if (sz(g[i]) > 1) {
      from = i;
      break;
    }
  }
  vector<int> ans1, ans2;
  dfs(from, ans1);
  for (auto to : g[from]) {
    if (used[to]) {
      continue;
    }
    dfs(to, ans2);
    break;
  }
  reverse(ans2.begin(), ans2.end());
  for (auto i : ans1) {
    ans2.pb(i);
  }
  printf("%d\n", sz(ans2));
  for (int i = 0; i < sz(ans2); i++) {
    printf("%d%c", ans2[i] + 1, " \n"[i == sz(ans2) - 1]);
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.3f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}



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

int main()
{
    int n, i, j=0, k=0;
    cin >> n;
    char a[n], b[n];
    cin >> a >> b;

    for(i=0; i<2*n; i++)
    {
        if(i%2==0)
        {
            cout << a[j];
            j++;
        }
        else if(i%2==1)
        {
            cout << b[k];
            k++;
        }
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n;
  scanf("%d", &n);
  char s[n + 1];
  scanf("%s", s);
  int r = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') r++;
  }
  int ans = 0;
  for (int i = 0; i < r; i++) {
    if (s[i] == 'W') ans++;
  }
  printf("%d\n", ans);
}


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

int main(){
  double W,H,x,y;
  cin >> W >> H >> x >> y;
  int ans =(x*2==W && y*2==H)? 1:0;
  
  cout << W*H/2 << " " << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 public class Main{

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       while(true){
           int H = sc.nextInt();
           int W= sc.nextInt();
        for( int i = 0; i<H; i++ ){
            for( int n = 0; n<W; n++ ){
                if((n+i)%2==1){
                 System.out.print(".");
                }else{
                 System.out.print("#");
                }
            }
        System.out.println();
       }
        if(H==0&&W==0)break;   
         System.out.println();

       }
	}
 }


Measured memory_bytes: 35000
#include <cstdio>
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>
#include <set>
#include <unordered_map>
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
#define mod         1000000007
using namespace std;
typedef pair<int,int> ii;
typedef pair<pair<int,int>,int> iii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;

bool criterio(ii a,ii b){
    if(a.f<b.f) return true;
    if(b.f>a.f) return false;
    return a.f+a.s<b.f+b.s;
}

int main(){
    ofstream out("output.txt");

    ios::sync_with_stdio(0);cin.tie(0);
    

    int n,m;
    cin>>n>>m;
    int l = 1,r = n,total = 0,  li,ri;
    bool todaviaSePuede = true;

    for(int i = 0; i<m; i++){

        cin>>li>>ri;
        if(todaviaSePuede){
            if(li>r || ri<l) todaviaSePuede = false;
            else if(li>l && ri<r){
                l = li;
                r = ri;
            }
            else if(li>l /*&& ri>r*/){
                l = li;
            }
            else if(ri < r /*&& li < l*/){
                r = ri;
            }
        }
    }
    if(todaviaSePuede){
        cout<<r-l+1<<endl;
    }
    else{
        cout<<0<<endl;
    }

    /*vii pares;
    int n,m;
    cin>>n>>m;
    int a,b;
    for(int i =0; i<m; i++){
        cin>>a>>b;

        pares.pb({a,b});
    }

    sort(pares.begin(),pares.end(),criterio);

    if(m<=2){
        cout<<"YES\n";
    }
    else{

        int x,xAux,y,yAux;
        x = -1;
        xAux = -1;

        int veces = 0;
        for(int i = 0; i<m; i++){
            if(x != pares[0].f && x != pares[0].s && xAux!=pares[0].f && xAux!= pares[0].s){

            }
        }
    }*/



    return 0;
}







Measured memory_bytes: 256
import cmath

def koch(n, p1, p2):
  if not n:
    return None
  s = (2*p1 + p2) / 3
  t = (p1 + 2*p2) / 3
  u = s + cmath.rect(1, cmath.pi/3) * (t - s)
  koch(n-1, p1, s)
  print(s.real, s.imag)
  koch(n-1, s, u)
  print(u.real, u.imag)
  koch(n-1, u, t)
  print(t.real, t.imag)
  koch(n-1, t, p2)

p1, p2 = 0j, 100+0j
print(p1.real, p1.imag)    
koch(int(input()), p1, p2)
print(p2.real, p2.imag)


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


int main() {
  string S ; 
  cin >> S ; 
  int N = S.size() ;
  int M = 1000  ;
  
  for(int i = 0 ; i < N-2 ; i++){
    int right = 0 ; 
    int cnt = 0 ; 
    
    for(int j = i ; j < i+3 ; j++){
      char A = S.at(j) ; 
      if(j == i ) right = 100*(A - '0') ; 
      if(j == i+1) right = 10*(A - '0') ; 
      if(j == i+2) right = A - '0' ; 
      cnt += right ; 
    }
    right = abs(cnt - 753) ; 
    M = min(M , right) ;  
  }
  
  
  cout << M << endl ;  
  
}

Measured memory_bytes: 3428
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
X = LIST()

ans = INF
for i in range(N-K+1):
    a, b = X[i], X[i+K-1]
    # if a <= 0 and 0 < b:
    if b <= 0:
        ans = min(abs(a), ans)
    elif 0 <= a:
        ans = min(abs(b), ans)
    else:
        tmp = min(abs(a), abs(b)) + (b - a)
        ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 15012
#include <stdio.h>

int main(void){
	int i,j;
	int h,w;
	scanf("%d %d",&h,&w);

	while(h!=0 && w != 0){
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if((i+j)%2 == 0){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		scanf("%d %d",&h,&w);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        char[] a = s.toCharArray();

        int flag = 0;
        if(a[0] != 'A'){
            flag++;
        }
        int flag2 = 0;
        for(int i = 1;i<a.length;i++){
            if(Character.isUpperCase(a[i])){
                flag2++;
            }
        }
        if(s.indexOf("C") != s.lastIndexOf("C") || s.indexOf("C") == 0 || s.indexOf("C") == 1 || s.lastIndexOf("C")+1 == s.length()){
            flag++;
        }

        if(flag == 0 && flag2 == 1){
            System.out.println("AC");
        }else{
            System.out.println("WA");
        }
    }
}

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


int main(void){
    
   string S;
   cin >> S;
   int cont = 0;
   for(int i = 0; i < S.size();i++){
       if(S[i]=='2')cont++;
   }
   
   cout << cont <<endl;
    
    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define ll long long

int A,B,C;
int main(){
    cin >> A >> B >> C;
    int tmp;
    tmp = A;
    A = B;
    B = tmp;
    tmp = A;
    A = C;
    C = tmp;
    cout << A << " " << B << " " << C << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

ll gcd(ll a,ll b){
	if(a%b==0) return b;
	else{
		a%=b;
		return gcd(b,a);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a.at(i);
	vector<ll> b(n),c(n);
	ll g=a.at(0);
	rep(i,n){
		b.at(i)=g=gcd(g,a.at(i));
	}
	g=a.at(n-1);
	rep(i,n){
		c.at(n-1-i)=g=gcd(g,a.at(n-1-i));
	}
	ll ans=0;
	rep(i,n){
		if(i==0){
			ans=max(ans,c.at(1));
		}
		else if(i==n-1){
			ans=max(ans,b.at(n-2));
		}
		else{
			ans=max(ans,gcd(b.at(i-1),c.at(i+1)));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

class BitSum:
    def __init__(self, n):
        self.n = n + 3
        self.table = [0] * (self.n + 1)

    def update(self, i, x):
        i += 1
        while i <= self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    bit=BitSum(105)
    swap_n=0
    for i,a in enumerate(aa):
        swap_n+=i-bit.sum(a)
        bit.update(a,1)
    aa.sort()
    print(*aa)
    print(swap_n)

main()



Measured memory_bytes: 5624