akhauriyash/Code-Regression huggingface dataset:
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;
  vector<ll> a(n+2,0),r(n+2,0);
  rep(i,n) cin >> a[i+1];

  rep(i,n+1)
  {
    r[i+1] = r[i] + abs(a[i+1] - a[i]);
  }

  rep(i,n)
  {
    ll no = i + 1;
    cout << r[no - 1] + r[n+1] - r[no + 1] + abs(a[no+1] - a[no-1]) << endl; 
  }



  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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


int main(void) {
    
    int n;
    cin >> n;
    
    int t[110000], x[110000], y[110000];
    t[0] = x[0] = y[0] = 0;
    rep(i,n){
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }

    bool flag = true;
    rep(i,n){
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        
        if(dist > dt) flag = false;
        if(dt%2 != dist%2) flag = false;
    }

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

Measured memory_bytes: 1408
from collections import deque
q=deque()
K=int(input())
a=q.append
a((1,1))
m={}
while len(q):
 n,s=q.popleft()
 if n in m:continue
 m[n]=s
 q.appendleft((n*10%K,s))
 a(((n+1)%K,s+1))
print(m[0])

Measured memory_bytes: 24300
n=int(input())
num = 8*n+1
import math
a=int(math.sqrt(num))
ok=False
for i in [a-2,a-1,a,a+1,a+2]:
    if i**2 == num:
        ok=True
if not ok:
    print("No")
    exit()
print("Yes")
k=1+(a-1)//2
print(k)

from collections import defaultdict
ans=defaultdict(list)

i=0
j=1
for now in range(1,n+1):
    ans[i].append(now)
    ans[j].append(now)
    j+=1
    if j==k:
        i+=1
        j=i+1
        if i==k:
            break

for lis in ans.values():
    print(k-1,end=" ")
    print(*lis)

Measured memory_bytes: 47836
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    ll n, q;
    cin >> n;
    map<ll, ll> mp;
    ll sum = 0;
    rep(i,n) {
        int tmp;
        cin >> tmp;
        mp[tmp]++;
        sum += tmp;
    }
    cin >> q;
    rep(i,q) {
        ll b, c;
        cin >> b >> c;

        if (mp[b] == 0) {
            cout << sum << endl;
            continue;
        }
        if (mp[c] == 0) {
            sum = sum + (c - b) * (mp[b]);
            mp[c] += mp[b];
        } else {
            if (c - b > 0) {
                mp[c] += mp[b];
                sum = sum + (c - b) * mp[b];
            } else {
                sum = sum - (b - c) * mp[b];
                mp[c] += mp[b];
            }
        }
        mp[b] = 0;
        cout<< sum << endl;
    }

    return 0;
}


Measured memory_bytes: 9164
#include <stdio.h>
int main(int argc, char const *argv[]) 
{
  int n,i,j;
  scanf("%d",&n );
  int a[n],b[n],c=0,l=0;
  for( i=1,j=1; i<=n,j<=n; i++,j++)
     {
         scanf("%d %d",&a[i],&b[j]);
        if (a[i]==b[j])
        {
           c++;
           if (c>=3)
           {
              l++;
           }
           
        }
        else
        {
            c=0;
        }
        
        
     }
     if (l>0)
     {
         printf("Yes\n");
     }
     else
     {
        printf("No\n");
     }
     
/*          MD OMOR FARUK
            Daffodil International University(CSE)
            Contact:farukprimate@gmail.com
*/     



return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    cout<<((n+999)/1000)*1000-n<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define forr(x,n) for(int x = 0; x < n; ++x)
#define pr pair<int,int>
#define ll long long int
const int mod=998244353;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int len=sqrt(n);
    int nob=ceil(n/(len*1.0));
    int b[nob];
    forr(i,nob)
    b[i]=0;
    vector<vector<int> > v(nob,vector<int> (26,0));
    forr(i,nob)
    {
        for(int j=i*len;j<(i+1)*len&&j<n;j++)
        {
            if(v[i][s[j]-'a']==0)
            b[i]++;
            v[i][s[j]-'a']++;
        }
    }
    int q,t,i,b_no,l,r,ans;
    char c;
    cin>>q;
    while(q--)
    {
        cin>>t;
        if(t==1)
        {
            cin>>i>>c;
            i--;
            b_no=i/len;
            v[b_no][s[i]-'a']--;
            if(v[b_no][s[i]-'a']==0)
            b[b_no]--;
            s[i]=c;
            v[b_no][s[i]-'a']++;
            if(v[b_no][s[i]-'a']==1)
            b[b_no]++;

        }
        else
        {
            cin>>l>>r;
            l--;
            r--;
            ans=0;
            vector<int> al(26,0);
            for(int i=l;i<=r;)
            {
                if(i%len==0&&i+len-1<=r)
                {
                //    ans+=b[i/len];
                    forr(j,26)
                    {
                        if(al[j]==0&&v[i/len][j]>0)
                        ans++;
                        al[j]+=v[i/len][j];
                    }
                    i+=len;
                }
                else
                {
                    if(al[s[i]-'a']==0)
                    ans++;
                    al[s[i]-'a']++;
                    i++;
                }

            }
            cout<<ans<<endl;
        }
    }
}


Measured memory_bytes: 1172
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
using namespace std;
int main(){
   string str1,str2;
   cin>>str1>>str2;
   int a,b;
   cin>>a>>b;
   string str3;
   cin>>str3;
   if(!str3.compare(str1))
    a--;
   else b--;
   cout<<a<<" "<<b;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
	
	for(;;){
		char ban[3][3];
		char result = 'N';
		
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				cin >> ban[i][j];
				if(ban[i][j] == '0'){
					goto FIN;
				}
			}
		}
		
		for(int i = 0; i < 3; i++){
			if(ban[i][0] == ban[i][1] && ban[i][1] == ban[i][2]){	//ツ可。ツ板サツ津ィ
				if(ban[i][0] == 'b'){
					result = 'b';
				}
				else if(ban[i][0] == 'w'){
					result = 'w';
				}
			}
		}
		for(int i = 0; i < 3; i++){
			if(ban[0][i] == ban[1][i] && ban[1][i] == ban[2][i]){	//ツ可。ツ板サツ津ィ
				if(ban[0][i] == 'b'){
					result = 'b';
				}
				else if(ban[0][i] == 'w'){
					result = 'w';
				}
			}
		}
		
		if(ban[0][0] == ban[1][1] && ban[1][1] == ban[2][2]){	//ツづ按づ按づ淞板サツ津ィ
			if(ban[0][0] == 'b'){
				result = 'b';
			}
			else if(ban[0][0] == 'w'){
				result = 'w';
			}
		}
		if(ban[0][2] == ban[1][1] && ban[1][1] == ban[2][0]){	//ツづ按づ按づ淞板サツ津ィ
			if(ban[0][2] == 'b'){
				result = 'b';
			}
			else if(ban[0][2] == 'w'){
				result = 'w';
			}
		}
		
		if(result == 'N'){
			cout << "NA" << endl;
		}
		else{
			cout << result << endl;
		}
	}
	FIN:;
	getchar();
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    int n,m,a[100];
    cin>>n>>m;
    
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int k = 1; k <= m ; k++){
        for(int i = 0 ; i < n - 1 ; i++){
            if(a[i] % k > a[i+1] % k){
                swap(a[i],a[i+1]);
                     
            }
        }
    }
    
                     for(int i = 0 ;i < n;i++)
                     cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 3112
# 169A
# A × B を整数として出力せよ

# 1.入力をプログラムで扱えるように受け取ること
a, b = map(int, input().split())
# print(a, b)

# 2.受け取った入力値を使って、適切に処理(計算)すること
answer = a * b

# 3.計算した結果を出力すること
print(answer)


Measured memory_bytes: 9088
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

int arr[4];
int N;

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

	int i = 0;
	for(int i = 0; i < 4; i++)
	{
		arr[i] = N % 10;
		N = N / 10;
		
	}
	if((arr[1] == arr[2] && arr[0] == arr[1]) || (arr[1] == arr[2] && arr[2] == arr[3]))
	{
		printf("Yes\n");
	}	
	else
	{
		printf("No\n");
	}
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/
	

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

int main(void) 
{
   int n;
   cin >> n;
    map<string,int> mp;
    rep(i,n) {
        string key;
        cin >> key;
        mp[key]++;
    }

    cout << mp.size() << endl;

}

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

int main(){
    int D;
    long long G;
    cin>>D>>G;
    vector<int> data;
    vector<long long> score;
    int ans=0;
    for(int i=1;i<=D;i++){
        int p;
        long long c;
        cin>>p>>c;
        ans+=p;
        data.push_back(p);
        score.push_back(100*i*p+c);
        //cout<<100*i*p+c<<endl;
    }

    //cout<<ans<<endl;

    for(int bit=0;bit<(1<<D);bit++){
        int x=0,l=-1;
        long long g=0;
        for(int i=D-1;i>=0;i--){
            if(bit & 1<<i) {
                g+=score.at(i);
                x+=data.at(i);
            }
            else if(l==-1) l=i;
        }

        if(x<ans && g>=G) ans=x;
        else if(x<ans && g+(data.at(l)-1)*100*(l+1)>=G){
            int k=(G-g-1)/(100*(l+1));
            x+=k+1;
            if (x<ans) ans=x;
        }
    }

    cout<<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);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (b - a == c - b) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21972
#include <stdio.h>


int main(){

  int i,j,n,m;
  long min = 100000000000,ans = -100000000000;
  scanf("%d",&n);

  for(i = 0;i < n;i++){
      scanf("%d",&m);
      if(m - min > ans ) ans = m - min;
      if(m < min) min = m;
  }

  printf("%ld\n",ans);

  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

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

    int ret;
    ret = (t / a) * b;
    printf("%d\n", ret);

    /* --------------------------------- */
    return 0;
}

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

int main(){
  
  string S, T;
  cin >> S >> T;
  
  int N = (int)S.size();
  
  for(int i = 0; i < N; ++i){
    
    string U;
    U += S.at(N-1);
    S.pop_back();
    U += S;
    
    if(U == T){
      cout << "Yes" << endl;
      return 0;
    }
    
    S = U;
  }
  
  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3608
def multiple_of_n(x, y, n=3):
    return (x - y) % n == 0

def combination(g1, g2, inverse, n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min([r, n - r])
    return g1[n] * g2[r] * g2[n - r] % mod

def make_inv(mod, N):
    g1 = [1, 1]
    g2 = [1, 1]
    inverse = [0, 1]
    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((- inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)
    return g1, g2, inverse

mod = 10 ** 9 + 7

x, y = map(int, input().split())
if multiple_of_n(2 * x, y) and multiple_of_n(2 * y, x):
    vertical = (2 * y - x) // 3
    horizontal = (2 * x - y) // 3
    total = vertical + horizontal
    g1, g2, inverse = make_inv(mod, total)
    print(combination(g1, g2, inverse, total, horizontal, mod))
else:
    print(0)

Measured memory_bytes: 82464
#define USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 998244353ll
#define INF 1000000000000000000ll
#define EPS 1e-9

#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll N, M, L, Q, dist[305][305], tank[305][305];
vector <ll> acc[305];
queue <ll> proc;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> M >> L;
	
	for (ll i = 1; i <= N; i++)
		for (ll j = 1; j <= N; j++)
			dist[i][j] = (i == j) ? 0 : INF;
	
	for (ll i = 1; i <= M; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		dist[a][b] = min(dist[a][b], c);
		dist[b][a] = min(dist[b][a], c);
	}
	
	for (ll k = 1; k <= N; k++)
		for (ll i = 1; i <= N; i++) 
		    for (ll j = 1; j <= N; j++)
		        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	
	for (ll i = 1; i <= N; i++) {
		for (ll j = 1; j <= N; j++) {
			if (i != j && dist[i][j] <= L) acc[i].push_back(j);
			tank[i][j] = INF;
		}
	}

	for (ll r = 1; r <= N; r++) {
		tank[r][r] = 0;
		proc.push(r);
		while (!proc.empty()) {
			ll cur = proc.front();
			proc.pop();
			for (ll nex : acc[cur]) {
				if (tank[r][nex] == INF) {
					tank[r][nex] = tank[r][cur] + 1;
					proc.push(nex);
				}
			}
		}
	}
	
	cin >> Q;
	for (ll q = 1; q <= Q; q++) {
		ll r, x, ans;
		cin >> r >> x;
		ans = INF;
		for (ll nex : acc[x]) ans = min(ans, tank[r][nex]);
		cout << ((ans == INF) ? -1 : ans) << "\n";
	}
	
    return 0;
}

Measured memory_bytes: 3072
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 1000000000+7;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(s) cout<<s<<endl
#define input(s) cin>>s
ll n, v[100010],x,ans;
int main() {
	input(n>>x);
	rep(i, n) {
		input(v[i]);
		if (i == 0) { if (v[i] > x) { ans += v[i] - x; v[i] -= v[i] - x; } }
		else if (v[i - 1] + v[i] > x)ans += v[i] + v[i - 1] - x, v[i] -= v[i] + v[i - 1] - x;
		//print(ans);
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
struct UnionFind {
public:
  int n;
  std::vector<int> par;
  UnionFind(int n): n(n) {
    par.resize(n, -1);
  }
  int root(int x) {
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if(rx == ry) return;
    if(par[rx] < par[ry]) {
      std::swap(x, y);
      rx = root(x), ry = root(y);
    }
    par[rx] += par[ry];
    par[ry] = rx;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return -par[root(x)];
  }
};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template<typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.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) os << " ";
    os << v[i];
  }
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m;
  cin >> n >> m;
  vvi g(n, vi(n)), compg(n, vi(n));
  for(int i=0;i<(m);++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a][b] = 1;
    g[b][a] = 1;
  }
  UnionFind uf(n);
  for(int i=0;i<(n);++i) {
    for(int j=0;j<(n);++j) {
      if (i != j && !g[i][j]) {
        compg[i][j] = 1;
        uf.unite(i, j);
      }
    }
  }
  vi col(n, -1);
  bool bipartite = true;
  queue<int> que;
  for(int i=0;i<(n);++i) {
    if(col[i] != -1) continue;
    que.push(i);
    col[i] = 0;
    while (!que.empty()) {
      if (!bipartite) break;
      int now = que.front();
      que.pop();
      for(int i=0;i<(n);++i) {
        if (compg[now][i]) {
          if (col[i] == -1) {
            col[i] = !col[now];
            que.push(i);
          } else if (col[now] == col[i]) {
            bipartite = false;
            break;
          }
        }
      }
    }
  }
  if (!bipartite) {
    cout << -1 << endl;
    return 0;
  }
  map<int, P> mp;
  for(int i=0;i<(n);++i) {
    int r = uf.root(i);
    if (col[i]) mp[r].first++;
    else mp[r].second++;
  }
  vector<set<int>> dp((int)(mp.size()) + 1);
  dp[0].insert(0);
  int idx = 0;
  for (auto &e1: mp) {
    for (auto &e2: dp[idx]) {
      dp[idx + 1].insert(e1.second.first + e2);
      dp[idx + 1].insert(e1.second.second + e2);
    }
    idx++;
  }
  ll mi = LINF;
  for (auto &e: dp[idx]) {
    chmin(mi, e * (e - 1) / 2 + (n - e) * (n - e - 1) / 2);
  }
  cout << mi << endl;
}


Measured memory_bytes: 15744
#include <iostream>

using namespace std;

int main()
{
    string s , t , u;
    int a , b;
    cin >> s >> t >> a >> b >> u;
    if (u == s){
        a--;
    }else if (u == t){
        b--;
    }
    cout << a << ' ' << b;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a,b,c,N, Ya,Y,x,y,z;
	int i = 0;
	c = 0;
	cin >> N, cin >> Ya;
	Y = Ya / 1000;
	a = Y - N;
	b = 2 * (N - Y);
	while (i * 4 <= a) {
		if (a - i * 4 >= 0 && b + 9 * i >= 0) {
			c = 1;
			x = a - i * 4;
			y = b + 9 * i;
			z = N - x - y;
			break;
		}
		i++;
	}
	if (c == 1 && z >= 0) {
		cout << x << " " << y << " " << z << endl;
	}
	else {
		cout << "-1 -1 -1" << endl;
	}
	return 0;
}

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

int main(){
	int m=0, s=0;
	int n;
	for(int i=0; i < 4; i++){
		cin >> n;
		s += n;
	}
	m = s / 60;
	s %= 60;
	cout << m << endl << s << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    int ans = 100000000;
    rep(i, N) {
        int A;
        cin >> A;
        int tmp = 0;
        while(A%2==0){
            if(ans <= tmp) break;
            ++tmp;
            A/=2;
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
}

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

int main() {
	long long N, K;
	cin >> N >> K;
	if (2 * K > N + 1) {
		cout << -1 << endl;
		return 0;
	}
	vector<pair<long long, pair<long long, long long> > > ANS;
	for (int i = K; i <= N; i++) {
		ANS.push_back({ K + N + i * 2 - 1, { i, K + N + i - 1 } });
	}
	for (int i = N + 1; i < N + K; i++) {
		ANS.push_back({ i * 2 + K - 1 , { i, i + K - 1 } });
	}
	sort(ANS.begin(), ANS.end());
	for (int i = 0; i < N; i++) {
		cout << ANS[i].second.first << " " << ANS[i].second.second << " " << N * 2 + K + i << endl;
	}
}

Measured memory_bytes: 5360
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.next());
		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;
		for(int i = 0; i < n; i++) {
			String cur = in.next();
			if(cur.equals("AC")) ac += 1;
			else if(cur.equals("WA")) wa += 1;
			else if(cur.equals("TLE")) tle += 1;
			else re += 1;
		}
		System.out.println("AC x " + ac);
		System.out.println("WA x " + wa);
		System.out.println("TLE x " + tle);
		System.out.println("RE x " + re);
	}
}

Measured memory_bytes: 58116
def selectionSort( nums )
	cnt = 0
	0.upto( nums.length-1 ) { |i|
		mini = i
		( i+1 ).upto( nums.length-1 ) { |j|
			if nums[j] < nums[ mini ]
				mini = j
			end
		}
		if mini != i	
			cnt += 1
			nums[i], nums[ mini ] = nums[ mini ], nums[i]
		end
	}
	puts( nums.join( " " ) )
	puts( cnt )
end

n = gets.to_i
nums = gets.split( " " ).map { |val| val.to_i }
selectionSort( nums )

Measured memory_bytes: 6108
import random, time
start = time.time()
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
#貪欲初期解
t = []
memo = [0 for _ in range(26)]
for i in range(d):
    scores = []
    for j in range(26):
        delta_score = 0
        delta_score += s[i][j]
        for k in range(26):
            if j == k:
                continue
            delta_score -= c[k] * (i+1 - memo[k])
        scores.append((delta_score, j))

    scores.sort(key=lambda x: -x[0])
    choice = scores[0][1]
    t.append(choice)
    memo[choice] = i+1

#局所探索
def delta_scoring(t, x, y):
    delta_score = 0
    before_ti, after_ti = 0, d+1
    before_y, after_y = 0, d+1

    for i in range(x):
        if t[i] == t[x]:
            before_ti = i+1
        if t[i] == y:
            before_y = i+1

    for i in range(x+1, d):
        if t[i] == t[x]:
            after_ti = i+1
            break
    for i in range(x+1, d):
        if t[i] == y:
            after_y = i+1
            break

    delta_score -= s[x][t[x]]
    delta_score += s[x][y]
    delta_score -= c[t[x]] * (x + 1 - before_ti) * (after_ti - x - 1)
    delta_score += c[y] * (x + 1 - before_y) * (after_y - x - 1)

    return delta_score

while time.time() - start < 1.7:
    x = random.randint(0, d-1)
    y = random.randint(0, 25)
    if delta_scoring(t, x, y) > 0:
        t[x] = y


for i in range(d):
    print(t[i] + 1)

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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

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

	int a, b;
	cin >> a >> b;
	if (a > 9 || b > 9)
		cout << "-1\n";
	else
		cout << a * b << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int main()
{
    int n;
    int color[100100];
    vector<pair<int,int> > d[100100];
    for(int i=0;i<100100;i++)color[i]=-1;

    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int u,v,w;
        cin>>u>>v>>w;
        u--;v--;
        d[u].push_back(make_pair(v,w%2));
        d[v].push_back(make_pair(u,w%2));
    }

    queue<int> Q;
    Q.push(0);
    color[0]=0;
    while(Q.size())
    {
        int i = Q.front();Q.pop();
        if (color[i] == -1) continue;
        for(int j=0;j<d[i].size();j++)
        {
            int to = d[i][j].first;
            if(color[to]!=-1)continue;

            Q.push(to);
            if(d[i][j].second==0)
            {
                color[to] = color[i];
            }else
            {
                color[to] = color[i] ^ 1;
            }
        }
    }

    for(int i=0;i<n;i++)
    {
        cout << color[i] << endl;
    }
}

Measured memory_bytes: 6784
#include <iostream>
#include <string>
#include <cmath>

int digits( long long n ) {
	int cnt = 0;
	while( n > 0 ) {
		n = n / 10;
		cnt += 1;
	}

	return cnt;
}

int main()
{
	long long n;
	std::cin >> n;

	long long min = digits( n );
	for( long long i = 1; i <= sqrt( n ); i++ ) {
		long long a, b;
		a = i;
		b = n / a;
		if( a * b != n ) {
			continue;
		}
		//std::cout << a << " " << b << std::endl;

		int t = digits( std::max( a, b ) );
		if( i == 1 ) {
			continue;
		}
		if( t < min ) {
			min = t;
		}
	}
	std::cout << min << std::endl;

	return 0;
}



Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input=Console.ReadLine().Split(' ');
        char a = char.Parse(input[0]);
        char b = char.Parse(input[1]);
        char topCoder;

        if (a == 'H')
            topCoder = b;
        else
        {
            topCoder = (b == 'H') ? 'D' : 'H';
        }
        Console.WriteLine(topCoder);

    }
}

Measured memory_bytes: 11092
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
      String ans="";
      	if(s.equals("a")){ans="a";}
      	if(s.equals("b")){ans="a";}
      	if(s.equals("c")){ans="a";}
      	if(s.equals("d")){ans="a";}
      	if(s.equals("e")){ans="a";}
      	if(s.equals("f")){ans="a";}
      	if(s.equals("g")){ans="a";}
      	if(s.equals("h")){ans="a";}
      	if(s.equals("i")){ans="a";}
      	if(s.equals("j")){ans="a";}
      	if(s.equals("k")){ans="a";}
      	if(s.equals("l")){ans="a";}
      	if(s.equals("m")){ans="a";}
      	if(s.equals("n")){ans="a";}
      	if(s.equals("o")){ans="a";}
      	if(s.equals("q")){ans="a";}
      	if(s.equals("r")){ans="a";}
      	if(s.equals("s")){ans="a";}
      	if(s.equals("t")){ans="a";}
      	if(s.equals("u")){ans="a";}
      	if(s.equals("v")){ans="a";}
      	if(s.equals("w")){ans="a";}
      	if(s.equals("x")){ans="a";}
      	if(s.equals("y")){ans="a";}
      	if(s.equals("z")){ans="a";}
      	if(s.equals("A")){ans="A";}
      	if(s.equals("B")){ans="A";}
      	if(s.equals("C")){ans="A";}
      	if(s.equals("D")){ans="A";}
      	if(s.equals("E")){ans="A";}
      	if(s.equals("F")){ans="A";}
      	if(s.equals("G")){ans="A";}
      	if(s.equals("H")){ans="A";}
      	if(s.equals("I")){ans="A";}
      	if(s.equals("J")){ans="A";}
      	if(s.equals("K")){ans="A";}
      	if(s.equals("L")){ans="A";}
      	if(s.equals("M")){ans="A";}
      	if(s.equals("N")){ans="A";}
      	if(s.equals("O")){ans="A";}
      	if(s.equals("P")){ans="A";}
      	if(s.equals("Q")){ans="A";}
      	if(s.equals("R")){ans="A";}
      	if(s.equals("S")){ans="A";}
      	if(s.equals("T")){ans="A";}
      	if(s.equals("U")){ans="A";}
      	if(s.equals("V")){ans="A";}
      	if(s.equals("W")){ans="A";}
      	if(s.equals("X")){ans="A";}
      	if(s.equals("Y")){ans="A";}
      	if(s.equals("Z")){ans="A";}
		System.out.println(ans);
	}
}

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

const int N = 2005;
int vet[N];

int main(){
	int n;
	scanf("%d", &n);
	for (int i=0; i<n; i++){
		scanf("%d", &vet[i]);
	}
	sort(vet, vet+n);
	long long ans = 0LL;
	for (int i=0; i<n; i++){
		for (int j=i+1; j<n; j++){
			int lo = j+1, hi = n-1, idx = j;
			while (lo <= hi){
				int mid = (lo + hi) >> 1;
				if(vet[mid] < vet[i] + vet[j]){
					idx = mid;
					lo = mid+1;
				}
				else hi = mid-1;
			}
			ans += (long long)(idx - (j+1) +1);
		}
	}
	printf("%lld\n", ans);
}



Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	string s; cin >> s;
	bool same = false;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < s.size(); j++) {
			if(i == j ) continue;
			if (s[i] == s[j]) {
				same = true;
				break;
			}
		}
		if (same) {
			break;
		}
	}

	cout << (same ? "no" : "yes" ) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
 
 
using namespace std;

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

    priority_queue<long long> pq;
    int n, m;
    cin >> n >> m;

    long long t;
    
    for (int i = 0; i < n; i++) {
        cin >> t;
        pq.push(t);
    }

    for (int i = 0; i < m; i++) {
        t = pq.top();
        t /= 2;
        pq.pop();
        pq.push(t);
    }

    long long result = 0;
    while (!pq.empty()) {
        result += pq.top();
        pq.pop();
    }

    cout << result << endl;

}

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

int main(){
  string s,t,u;
  int a,b;
  cin >> s >>t ;
  cin >> a >> b;
  cin >> u;
  if(u==s){
    a--;
  }else{
    b--;
  }
   cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()

{
    int n;
    scanf("%d",&n);
    switch(n){
        case 22:
        printf("Christmas Eve Eve Eve\n");
        break;
        case 23:
        printf("Christmas Eve Eve\n");
        break;
        case 24:
        printf("Christmas Eve\n");
        break;
        default:
        printf("Christmas\n");



    }



return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

#define roop(i, n) for(int i=0;i<n;i++)

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	ll a, b;
	cin >> a >> b;
	ull x = a * b;
	ll tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}
	ll r = a % b;
	while(r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	cout << x / b << endl;
	return 0;
}

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

# nの足場までいく最小コストを a_n とする。
# a_1のコストは0,  a_2のコストは(h_1からの１通りなので)\h_1-h_2\
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))

print(dp[-1]) 

Measured memory_bytes: 52208
N=int(input())
arr=[list(map(int,input().split())) for i in range(N)]

za,wa=-10**10,-10**10
zi,wi=10**10,10**10
for i in range(N):
    z=arr[i][0]+arr[i][1]
    w=arr[i][0]-arr[i][1]
    
    za=max(z,za)
    zi=min(z,zi)
    
    wa=max(w,wa)
    wi=min(w,wi)

print(max(za-zi,wa-wi))

Measured memory_bytes: 45300
#include<bits/stdc++.h>
# define  _deb(x) { cerr << "\033[94m"<< "[ " << #x << " = " << (x) << " ]\n\033[0m"; }
using namespace std;
#define int long long
signed main(){
	int n,m;
	cin >> n >> m;
	vector<int>v[200000];
	for(int i=0;i<n;i++){
		int x,y;
		cin >> x >> y;
		v[x].push_back(y);
	}
    priority_queue<int>q;
	int ans = 0;
	for(int i=1;i<=m;i++){
		for(int e : v[i]) {
			q.push(e);
		}
		if(!q.empty()){
			int a = q.top();
			q.pop();
			ans += a;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 8064
#include<iostream>
#define MAX_N 55
#define MAX_M 55
#define INF (1 << 30)
using namespace std;
typedef long long ll;

ll a[MAX_N], b[MAX_N], c[MAX_M], d[MAX_M];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < M; i++) cin >> c[i] >> d[i];
    for (int i = 0; i < N; i++) {
        int min_dist = INF, idx = 0;
        for (int j = 0; j < M; j++) {
            int now_dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (now_dist < min_dist) {
                min_dist = now_dist;
                idx = j;
            }
        }
        cout << idx + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
#define f first
#define s second
using namespace std;
const int INF=(int)0x3f3f3f3f;
const int MOD=(int)1e9+7;
const double eps=1e-9;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,d;
    cin>>n>>d;
    cout<<(n+2*d)/(2*d+1);
    return 0;
}


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

using namespace std;

int main(){
	long long n, c, k;
	cin >>n >>c >>k;

	vector<long long> t(n);
	for(int i = 0; i < n; ++i)
		cin >>t[i];
	
	sort(begin(t), end(t));

	long long b = 0, cnt = 0, bt = 0;
	for(int i = 0; i < n; ++i){
		if(t[i] > bt || cnt == c){
			bt = t[i] + k;
			cnt = 1;
			++b;
		}
		else{
			++cnt;
		}
	}
	cout <<b <<'\n';
	return 0;
}


Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    string N;
    cin >> N;
    long long length,i;
    long long cnt = 0;

    length = N.size();
    //cout << length << endl;
    for(i=0; i<length; i++){
      cnt += N[i] - '0';

    }
    //cout << cnt << endl;
    if (cnt % 9 == 0){
      cout << "Yes" << endl;
      return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3752
#include<cstdio>
static const int M_SEC = 60;

int main() {
    int S;

    scanf("%d", &S);
    int h, m, s;
    s = S % M_SEC;
    m = S / M_SEC;
    h = m / M_SEC;
    m %= M_SEC;
    printf("%d:%d:%d\n", h, m, s);

    return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K,x,s=0;
    cin>>N>>K;
    for(int i = 0;i<N;i++){
        cin>>x;
        s+=min(2*x,2*(K-x));

    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int K = Integer.parseInt(sc.get()) - 1;
		String S = sc.get();
		char[] chars = S.toCharArray();
		for (int i = 0; i < chars.length; i++) {
			System.out.print((char) (K != i ? chars[i] : chars[i] - 'A' + 'a'));
		}
		System.out.println();
	}
}

class Main {
	public static void main(String... args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<String>() {
			StringTokenizer line;

			public String get() {
				try {
					return (line = line != null && line.hasMoreTokens() ? line : new StringTokenizer(reader.readLine())).nextToken();
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
		});
	}
}

Measured memory_bytes: 21460
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); //number 
#define ll long long                      //of element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after 
using namespace std;                      // sort use as s.f();
using namespace __gnu_pbds;



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);		
	cout.flush();
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll n,m;
		ll a[100000];
		cin>>n>>m;
		ll st;
		ll sum=0;
		for(ll i=0;i<n;i++)
		{
		cin>>a[i];
		sum+=a[i];	
		}
		sort(a,a+n,greater<ll>() );
		st=a[m-1];
		st=st*4*m;
		
		
	   if(st>=sum)
	   {
		   
		   cout<<"Yes"<<endl;
		   }
		   else
		   {
			   cout<<"No"<<endl;
			   }
	  // cout<<sum<<" "<<p<<" "<<st<<endl;
	   
	   
	}
	
return 0;
}


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

const int MOD = 1e9+7;
void add(int &a,int b) { a = (a + b + MOD) % MOD; }

signed main(){

  string L; cin >> L;
  int N = L.size();

  static int dp[101010][2];
  //i桁まで見てL未満か確定している
  dp[0][0] = 1;
  for(int i = 0; i < N; i++){
    add(dp[i+1][1], dp[i][1]*3); //{a,b} = {0,0},{0,1},{1,0}
    if(L[i] == '1'){
      add(dp[i+1][1], dp[i][0]); //{a,b} = {0,0} L未満が確定
      add(dp[i+1][0], dp[i][0]*2); //{a,b} = {0,1},{1,0}
    }
    else {
      add(dp[i+1][0], dp[i][0]);
    }
  }
  cout << (dp[N][0] + dp[N][1]) % MOD << endl;

  return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
const int pi=3.1415926535897932384626433832795;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
#define ll long long
#define inf int(1e9+7)
#define pb push_back
#define mp make_pair
int s[100005],a[100005],n;
char p[100005];
int main()
{
	cin>>n;
	cin>>p;
	for(int i=0;i<n;i++)
	{
		if(p[i]=='o')
			a[i+1]=0;
		else
			a[i+1]=1;
	}
	a[n+1]=a[1];
	for(int i=0;i<8;i++)
	{
		s[0]=i&1;
		s[1]=(i>>1)&1;
		s[2]=(i>>2)&1;
		for(int j=2;j<=n+1;j++)
			s[j+1]=s[j-2]^a[j];
		if(s[0]^s[n]^s[1]^s[n+1]||s[1]^s[n+1]^s[2]^s[n+2])
			continue;
		for(int j=1;j<=n;j++)
			cout<<(s[j]^s[j-1]?"W":"S");
		return 0;
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 1280
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;
#define int long long
const int N = (int) 1e6 + 6, mod = (int) 1e9 + 7;
vector<int> col[N];
int f[N], par[N], sz[N], inv[N];
map<int, int> c[N];
int fpm(int a, int b) { return b != 0 ? (LL) fpm((LL) a * a % mod, b >> 1) * (b & 1 ? a : 1) % mod: 1; }
pair<int, int> a[N];
int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }
void unite(int u, int v) {
	u = find(u);
	v = find(v);
	if (u == v) return;
	sz[u] += sz[v];
	par[v] = u;
}
int32_t main() {
	f[0] = inv[0] = 1;
	for (int j = 1; j < N; ++j) {
		f[j] = f[j - 1] * (LL) j % mod;
		inv[j] = fpm(f[j], mod - 2);
	}
	ios_base::sync_with_stdio(0);
	int n, x, y;
	cin >> n >> x >> y;
	for (int j = 0; j < n; ++j) {
		par[j] = j;
		sz[j] = 1;
		cin >> a[j].second >> a[j].first;
	}
	sort(a, a + n);
	int cnt = 0;
	for (int j = 0; j < n; ++j) {
		col[a[j].second].push_back(j);	
		if ((j == 0 || a[j].second != a[j - 1].second) && cnt <= 100) {
			++cnt;
			for (int k = 0; k < n; ++k) if (k != j) {
				if (a[k].second == a[j].second) {
					if (a[k].first + a[j].first <= x) {
						unite(k, j);
					}
				} else {
					if (a[k].first + a[j].first <= y) {
						unite(k, j);
					}
				}
			}
		}
	}
	for (int j = 0; j < N; ++j) if ((int) col[j].size()) {
		int fst = col[j][0];
		for (int xx : col[j]) {
			if (a[fst].first + a[xx].first <= x) {
				unite(fst, xx);
			}
		}
	}
	for (int j = 0; j < n; ++j)
		c[find(j)][a[j].second]++;
	int res = 1;
	for (int j = 0; j < n; ++j)
		if (par[j] == j) {
			res = (LL) res * f[sz[j]] % mod;
			for (auto x : c[j]) {
				res = (LL) res * inv[x.second] % mod;
			}
		}
	cout << res << endl;
}




Measured memory_bytes: 116608
#include <stdio.h>

int main(void)
{
	int a,b,i,j;
	int Ga[7] = {1,3,5,7,8,10,12};
	int Gb[4] = {4,6,9,11};
	int Gc = 2;
	
	
	scanf("%d %d",&a,&b);
	
	if(a == Gc){
		printf("No\n");
		return 0;
	}
	
	for(i=0;i<4;i++){
		if(a == Gb[i]){
			for(j=i+1;j<4;j++){
				if(b == Gb[j]){
					printf("Yes\n");
					return 0;
				}
			}
		}
	}
	
	for(i=0;i<7;i++){
		if(a == Ga[i]){
			for(j=i+1;j<7;j++){
				if(b == Ga[j] ){
					printf("Yes\n");
					return 0;
				}
			}
		}
	}
	
	printf("No\n");
	
	
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = 0;
		for(int i=1 ; i<=a ; i++) {
			b += i;
		}
		
		System.out.println(b);

	}

}

Measured memory_bytes: 20692
def main():
    N, K = map(int, input().split())
    S = input()
    seq = []
    current = "1"
    cnt = 0
    for c in S:
        if c == current:
            cnt += 1
        else:
            seq.append(cnt)
            current = c
            cnt = 1
    seq.append(cnt)
    if len(seq) % 2 == 0:
        seq.append(0)
    if len(seq) <= K*2+1:
        print(sum(seq))
        return
    ans = 0
    total = 0
    j = 0
    for i in range(len(seq)-K*2):
        while j < i+K*2+1:
            total += seq[j]
            j += 1
        if i % 2 == 0:
            ans = max(ans, total)
        total -= seq[i]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 45552
n = input()
a = []
b = []
c = []
for i in range(n):
    ai, bi, ci = map(int, raw_input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)

dpa = [0] * (n + 1)
dpb = [0] * (n + 1)
dpc = [0] * (n + 1)
for i in range(n - 1, -1, -1):
    dpa[i] = a[i] + max(dpb[i + 1], dpc[i + 1])
    dpb[i] = b[i] + max(dpa[i + 1], dpc[i + 1])
    dpc[i] = c[i] + max(dpa[i + 1], dpb[i + 1])

print(max([dpa[0], dpb[0], dpc[0]]))


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

int main() {
  int a,b;cin>>a>>b;
  string ans = "Impossible";
  if (a %3 == 0 || b % 3 ==0 || (a+b) % 3 == 0 ) ans = "Possible";
  cout << ans << endl;
}

Measured memory_bytes: 3568
/*#          #  # # # # #  # # # # #  # # # # #  #          #
  #          #  #       #  #       #  #          #          #
  # # # # # ##  # # # # #  ## # # #   # # # # #  # # # # # ##
  #          #  #       #  #    #             #  #          #
  #          #  #       #  #      #   # # # # #  #          #*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define iofile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define ump unordered_map<int,int>
#define st set<int>
#define ust unordered_set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define sumofdigits(sum,num) int sum = 0; while (n != 0) { sum = sum + n % 10; n = n/10; }
#define int2str(str,n) n=boost::lexical_cast<int>(str);
#define float2str(str,n) n=boost::lexical_cast<float>(str);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
int32_t main()
{
    fastio
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int arr[n];
        rep(i,n)cin>>arr[i];
        sort(arr,arr+n);
        cout<<n-(lower_bound(arr,arr+n,k)-arr)<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024