akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <vector>
#include <cstdlib>
#include<algorithm>
#include<string>
#include<cmath>
#include<math.h>
#include <list>
#define ll long long 
using namespace std;
ll md=1000000007;




int main()
{
 ll n;
 cin>>n;
 vector <ll> arr;
 ll sum=0;
 for(ll i=0;i<n;i++)
 {
   ll temp;
   cin>>temp;
   sum+=temp;
   arr.push_back(temp);
 }
 ll ans=0;
 for(ll i=n-1;i>=0;i--)
 {
   sum-=arr[i];
  // ans+=(sum*arr[i]);
   ans=(ans%md + ((sum%md)*(arr[i]%md))%md)%md;


 }
 cout<<ans%md;
 return 0;
}

Measured memory_bytes: 5288
#include <iostream>
#include <algorithm>
#include <string>

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

using namespace std;

int main() {
	int a,b;
	cin>>a>>b;
	a=a+b;
	if(a<10){
		cout<<a<<endl;
	}
	else{
		cout<<"error"<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination

int x[11][11];

int cal(int a,int b,int c){
    int t=0;
    rep(i,10){
        t+=(x[a][i]-x[b][i])*(x[a][i]-x[b][i]);
    }
    rep2(i,150){
        if(t==i*i){
            return 1;
        }
    }
    return 0;
}

int main(){
    rep(i,10){
        rep(j,10){
            x[i][j]=0;
        }
    }
    int n,d;
    int ans=0;
    cin >> n>> d;
    rep(i,n){
        rep(j,d){
            cin >> x[i][j];
        }
    }
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            if(cal(i,j,ans)){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main ( void )
{
	string str;
	
	string hyo[] = { "abcde", "fghij", "klmno", "pqrst", "uvwxy", "z.?! " };
	
	while (cin >> str)
	{
		if (str.size() % 2)
		{
			cout << "NA" << endl;
			continue;
		}
		
		string out = "";
		
		for (int i = 0, len = str.size(); i < len; i+=2)
		{
			int x, y;
			
			y = str[i] - '1';
			x = str[i+1] - '1';
			
			if (0 > x || x > 4 || 0 > y || y > 5)
			{
				out = "NA";
				break;
			}
			
			out += hyo[y][x];
		}
		
		cout << out << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>

using namespace std;

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i,j,tt=1;
    //cin>>tt;
    while(tt--)
    {
        lli a;
        cin>>a;
        lli ans=a+a*a+a*a*a;
        cout<<ans<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>


using namespace std;

int main()
{
	int hoge[5];
	for (int i = 0; i < 5; ++i)
		scanf("%d", hoge+i);
	sort(hoge, hoge+5, greater<int>());
	for (int i = 0; i < 4; ++i)
		printf("%d ", hoge[i]);
	printf("%d\n", hoge[4]);

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N=100000;
int a[N];
string s1,s2,s3;
int main()
{
	cin >> s1>>s2>>s3;
	cout <<s1[0];
	cout <<s2[1];
	cout <<s3[2];
	return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx")
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL vector<LL>
#define VP vector<pair<LL,LL>>
#define VVL vector<vector<LL>>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define EB emplace_back
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;i++)
#define FORR(i,a,n) for(i=n-1;i>=a;i--)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FOR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define LB(a,n) *lower_bound(ALL(a),n)
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
//#define ERR 0.00000000000001
#define NUM 200010
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL LBn(VL &v,LL a){LL mx=v.size(),mn=-1,md;while(mx-mn>1){md=(mx+mn)/2;if(v[md]<a)mn=md;else mx=md;}return mx;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a%m<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(m,d);x-=k*y;swap(x,y);}return mod(a*mod(x,MOD),MOD);}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(pair<LL,LL> a,pair<LL,LL> b){if(a.second!=b.second)return a.second<b.second;return a.first<b.first;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  FAST;
  LL i,ans=0,R;
  cin>>R;
  printf("%.12f",R*2.0*PI);
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =99999999999;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




//10億7。　　　100000007
//2*2行列 H*W
//vector<vector<int>> vec(H,vector<int>(W));
//for(int i=0;i<H;i++){
//for(int j=0;j<W;j++){
//cin>>vec[i][j];
//  }
//}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//ソート　sort(vec.begin(),vec.end());



int main(){
cout<<fixed<<setprecision(10);

  int N;cin>>N;
  vector<int> vec(N);
  vector<ll> dp(100010);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  
  for(int i=0;i<100010;i++){
    dp[i]=INF;
  }
  dp[0]=0;
  for(int i=1;i<N;i++){
    dp[i]=min(dp[i],dp[i-1]+abs(vec[i]-vec[i-1]));
    if(i>1){
      dp[i]=min(dp[i],dp[i-2]+abs(vec[i]-vec[i-2]));
    }
  }
  
  cout<<dp[N-1]<<endl;
  
}


Measured memory_bytes: 1408
// Contest: AtCoder Beginner Contest 158 (https://atcoder.jp/contests/abc158)
// Problem: A: Station and Bus (https://atcoder.jp/contests/abc158/tasks/abc158_a)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

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

    string s; cin >> s;
    cout << (s != "BBB" && s != "AAA" ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        long a = sc.nextLong(); // always 0
        long b = 0;
        long c = 0;
        for (int i = 1; i < n; i++) {
            b = sc.nextLong();
            c += Math.min(t, b-a);
            a = b;
        }

        System.out.println(c+t);
    }

}

Measured memory_bytes: 62364
package main

import (
	"fmt"
	"math"
	"math/cmplx"
)

func main() {
	var n int
	fmt.Scan(&n)
	z := make([]complex128, n, n)

	answer := math.MaxFloat64

	for i := 0; i < n; i++ {
		var x, y float64
		fmt.Scan(&x)
		fmt.Scan(&y)
		z[i] = complex(x, y)
	}

	for i1 := 0; i1 < n; i1++ {
		for i2 := i1 + 1; i2 < n; i2++ {
			z0 := (z[i1] + z[i2]) / 2.0
			r := cmplx.Abs(z[i1]-z[i2]) / 2.0

			flag := true
			for j := 0; j < n; j++ {
				if j == i1 || j == i2 {
					continue
				}
				if cmplx.Abs(z[j]-z0) > r {
					flag = false
				}
			}
			if flag && r < answer {
				answer = r
			}
		}
	}

	for i1 := 0; i1 < n; i1++ {
		for i2 := i1 + 1; i2 < n; i2++ {
			for i3 := i2 + 1; i3 < n; i3++ {
				z1, z2, z3 := z[i1], z[i2], z[i3]
				if math.Abs(imag((z1-z2)/(z1-z3))) < math.SmallestNonzeroFloat64 {
					continue
				}

				z0 := ((z2-z3)*z1*cmplx.Conj(z1) + (z3-z1)*z2*cmplx.Conj(z2) + (z1-z2)*z3*cmplx.Conj(z3)) /
					((z2-z3)*cmplx.Conj(z1) + (z3-z1)*cmplx.Conj(z2) + (z1-z2)*cmplx.Conj(z3))
				r := cmplx.Abs(z1 - z0)

				flag := true
				for j := 0; j < n; j++ {
					if j == i1 || j == i2 || j == i3 {
						continue
					}
					if cmplx.Abs(z[j]-z0) > r {
						flag = false
					}
				}
				if flag && r < answer {
					answer = r
				}
			}
		}
	}
	fmt.Println(answer)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int mi = INF, id = -1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a < mi) {
            mi = a;
            id = i;
        }
    }
    cout << id + 1 << endl;
}


Measured memory_bytes: 3216
import copy

class Card():
    def __init__(self, suit, value):
        self.suit = suit
        self.value = value

def bubblesort(n,a):
    flag = 1
    while flag:
        flag = False
        for i in reversed(range(1,n)):
            if a[i-1].value > a[i].value:
                a[i], a[i-1] = a[i-1], a[i]
                flag = True
    return a

def selectionsort(n,a):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if a[j].value < a[minj].value:
                minj = j
        a[i], a[minj] = a[minj], a[i]
    return a

def is_stable(before, after):
    n = 9
    lb = [[] for _ in range(n)]
    la = [[] for _ in range(n)]
    for i in range(len(before)):
        lb[before[i].value-1].append(before[i].suit)
        la[after[i].value-1].append(after[i].suit)
    if la == lb:
        print('Stable')
    else:
        print('Not stable')


if __name__ == '__main__':
    n = int(input())
    cards = [Card(x[0], int(x[1])) for x in input().split()]

    bubble_cards = bubblesort(n, copy.deepcopy(cards))
    selection_cards = selectionsort(n, copy.deepcopy(cards))

    print(' '.join(map(lambda x: x.suit+str(x.value), bubble_cards)))
    is_stable(cards, bubble_cards)

    print(' '.join(map(lambda x: x.suit+str(x.value), selection_cards)))
    is_stable(cards, selection_cards)










Measured memory_bytes: 6352
w,h,i,j,f[52][52],d[8]={0,1,1,1,0,-1,-1,-1};rec(x,y,k){if(!f[x][y])return 0;for(f[x][y]=0;k<8;k++)rec(x+d[k],y+d[(k+6)%8],0);return 1;}main(n){while(scanf("%d%d",&w,&h),w|h){for(j=1;j<=h;f[w+1][j++]=0)for(i=1;i<=w;f[i++][h+1]=n=0)scanf("%d",&f[i][j]);for(j=1;j<=h;j++) for(i=1;i<=w;)n+=rec(i++,j,0);printf("%d\n",n);}}

Measured memory_bytes: 0
n,m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
c = [-1 for i in range(n)]
visited = [False for i in range(n)]
x = 0
for i in range(n):
    if visited[i]:
        continue
    visited[i] = True
    q = [i]
    temp = [i]
    while q:
        idx = q.pop(0)
        adj = g[idx]
        for j in adj:
            if visited[j]:
                continue
            visited[j] = True
            q.append(j)
            temp.append(j)
    for j in temp:
        c[j] = x
    x += 1
print(x-1)

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

int main(void){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> light(m,vector<int>()); //各電球につながるスイッチ
    for(int i=0;i<m;i++){
        int sn;
        cin >> sn;
        for(int j=0;j<sn;j++){
            int sw;
            cin >> sw;
            light[i].push_back(sw-1);
        }
    }
    vector<int> surplus(m);
    for(int i=0;i<m;i++) cin >> surplus[i];

    int ans = 0;
    for(int k=0;k<(1<<n);k++){
        bitset<10> bit(k);
        bitset<10> lighton(0);  //ライト点いてるor点いてない

        for(int i=0;i<m;i++){
            int onnum = 0;
            for(int j=0;j<light[i].size();j++){
                if(bit.test(light[i][j])) onnum++;
            }
            if(onnum%2==surplus[i]) lighton.set(i);
        }
        int num1 = lighton.count();
        if(num1==m) ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
N = int(input())
A = [i for i in map(int, input().split())]

height = []
for i in range(N-1):
    if A[i] >= A[i+1]:
        height.append(A[i] - A[i+1])
        A[i+1] = A[i]
    else:
        pass

print(sum(height))


Measured memory_bytes: 32276
x = int(input())
i = 1
while True:
    for j in range(i):
        if i**5 == x + j**5:
            print(str(i) + " " + str(j))
            exit()
        elif i**5 == x - j**5:
            print(str(i) + " " + str(-j))
            exit()
    i += 1

Measured memory_bytes: 9192
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
using namespace std;

int main() {
  long long N,Q,l[100009],r[100009];
  string s;
  cin >> N >> Q >> s;
  std::vector<ll> v,t(N,0);
  for (size_t i = 0; i < Q; i++) {
    cin >> l[i] >> r[i];
  }
  for (size_t i = 1; i < N; i++) {
    if(s[i-1] == 'A' && s[i] == 'C') {
      t[i] = t[i-1] + 1;
    } else {
      t[i] = t[i-1];
    }
    // cout << "t[" << i << "] = " << t[i] << endl;
  }
  for (size_t i = 0; i < Q; i++) {
    cout << t[r[i]-1] - t[l[i]-1] << endl;
  }
}


Measured memory_bytes: 3456
#include <stdio.h>

// note saya masih blom ngerti ini but i will try to figure it out
int main() {
  int lines;
  scanf("%d", &lines);
  long long int arr[lines]; 
  long long int big = 1e18, end = 1, flag = 0, zero = 0;
  
  for (int i = 0; i < lines; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > big) ? 1 : flag;
	// arr[1] > big itu buat tau bakal jadi -1 apa hasil total kali
    end *= arr[i];
    // ini dikaliin2 terus
    (arr[i]) ? big /= arr[i] : zero = 1;
    //^ i dont ge tthis... wtf
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\n", end));
  
  return 0;
}

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

int main() {
  int w,a,b;
  cin >> w >> a >> b;
  if(a+w < b){
    cout << b-(a+w) << endl;
  }
  else if(b+w < a){
    cout << a-(b+w) << endl;
  }
  else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, M; cin >> N >> M;
  bool from_1[N], to_N[N];
  rep(i, N) {from_1[i] = false; to_N[i] = false;}
  rep(i, M) {
    int a, b; cin >> a >> b;
    if (a == 1) from_1[b] = true;
    else if (b == 1) from_1[a] = true;
    if (a == N) to_N[b] = true;
    else if (b == N) to_N[a] = true;
  }

  string result = "IMPOSSIBLE";
  rep(i, N) if (from_1[i]&&to_N[i]) result = "POSSIBLE";
  cout << result << endl;
  return 0;
}

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

void print() { std::cout << std::endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    std::cout << head;
    if(sizeof...(tail) != 0)
        std::cout << " ";
    print(std::forward<Tail>(tail)...);
}
template <class T> void print(std::vector<T> &vec) {
    for(auto &a : vec) {
        std::cout << a;
        if(&a != &vec.back())
            std::cout << " ";
    }
    std::cout << std::endl;
}
template <class T> void print(std::vector<std::vector<T>> &df) {
    for(auto &vec : df) {
        print(vec);
    }
}

int main() {
    string S, T;
    cin >> S >> T;

    int count = 0;
    for(int i = 0; i < 3; i++) {
        if(S[i] == T[i]) {
            count++;
        }
    }
    print(count);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[55][30];
string s,ans;
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> s;
		for(int j = 0; j < s.size(); j++)
			a[i][s[j] - 97]++;
	}
	for(int i = 0; i < 26; i++) {
		int num = 2147483647;
		for(int j = 1; j <= n; j++)
			num = min(num,a[j][i]);
		for(int j = 0; j < num; j++)
			ans += char(i + 97);
	}
	cout << ans << endl;
	return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int A, B;
    string S;

    cin >> A >> B >> S;

    bool flag = true;
    rep(i, A + B + 1) {
        if (i == A) {
            if (S[i] != '-') {
                flag = false;
                break;
            }
        }
        else {
            if (S[i] < '0' || S[i] > '9') {
                flag = false;
                break;
            }
        }
    }

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

Measured memory_bytes: 256
while True:
    n,m=map(int,raw_input().split())
    if n==m==0:break
    taro=[input() for i in range(n)]
    hana=[input() for i in range(m)]
    L=[]
    sumta=sum(taro)
    sumha=sum(hana)
    for i in range(n):
        temp1=sumta-taro[i]
        temp2=sumha+taro[i]
        for j in range(m):
            if temp1+hana[j]==temp2-hana[j]:
                L.append((taro[i]+hana[j],taro[i],hana[j]))
    if L<>[]:
        L.sort()
        print L[0][1],L[0][2]
    else:
        print -1

Measured memory_bytes: 5016
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (h, w) = listOfInt()
    val grid = mutableListOf<MutableList<Char>>()

    repeat(h) {
        val row = next().toMutableList()
        if (row.count { it == '#' } > 0) grid.add(row)
    }

    repeat(w) {
        var blackFound = false
        for (i in grid) {
            if (i[it] == '#') {
                blackFound = true
                break
            }
        }

        if (!blackFound) {
            for (i in grid) {
                i[it] = '\u0000'
            }
        }
    }

    grid.forEach { row ->
        println(row.filter { it != '\u0000' }.joinToString(separator = ""))
    }
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 38604
function Main(input) {
  input = input.split("\n");
  var X = parseInt(input[0].split(" ")[0]);
  var ans="NO";
  if(X==3||X==5||X==7){
    ans="YES";
  }
  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

class Program {

    static void Main (string[] args) {
        int N = int.Parse (Console.ReadLine ());
        var Stemp = Console.ReadLine ().Split (' ');
        var A_i = new long[N];
        var log_i = new double[N];
        bool zero = false;
        double logsum = 0;
        bool fail = false;
        for (int i = 0; i < N; i++) {
            A_i[i] = long.Parse (Stemp[i]);
            if (A_i[i] == 0) {
                zero = true;
                break;
            } else {
                log_i[i] = Math.Log10 (A_i[i]);
                logsum += log_i[i];
                if (logsum > 18) {
                    fail = true;
                }
            }
        }
        long ans = 1;
        if (!zero) {
            if (!fail) {
                for (int i = 0; i < N; i++) {
                    ans *= A_i[i];
                    if (ans > 1000000000000000000 || ans < 0) {
                        fail = true;
                        break;
                    }
                }
                if (fail) {
                    ans = -1;
                }
            } else {
                ans = -1;
            }
        } else {
            ans = 0;
        }

        Console.WriteLine (ans);
    }
}
//dotnet run --project test

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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if((a+b)>(c+d))cout<<"Left"<<endl;
  else if((a+b)<(c+d))cout<<"Right"<<endl;
  else cout<<"Balanced"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  vector<vector<int>> A(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>A[i][j];
    }
  }
  
  int N;cin>>N;
  
  vector<int> B(N);
  for(int i=0;i<N;i++){
    cin>>B[i];
  }
  
  int check[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      check[i][j]=i+j*3;
    }
  }
  
  
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<N;k++){
        if(A[i][j]==B[k]){
          check[i][j]=10;
        }
      }
    }
  }
  
  string ans="No";
  
  for(int i=0;i<3;i++){
    if(check[i][0]==check[i][1]&&check[i][2]==check[i][0]&&check[i][0]==10){
      ans="Yes";
    }
  }
  for(int j=0;j<3;j++){
    if(check[0][j]==check[1][j]&&check[1][j]==check[2][j]&&check[0][j]==10){
      ans="Yes";
    }
  }
  if(check[0][0]==check[1][1]&&check[2][2]==check[0][0]&&check[0][0]==10){
    ans="Yes";
  }
  else if(check[0][2]==check[1][1]&&check[2][0]==check[1][1]&&check[1][1]==10){
    ans="Yes";
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            int[] A = new int[N];

            for (int i = 0; i < N; i++) {
                A[i] = int.Parse(Console.ReadLine());
            }

            int maxValue = A.Max();


            //配列Aを降順にソートする
            var work = A.OrderBy(a => -a);

            int secondValue = work.ToArray()[1];

            //二番目に大きな値を求める
            //for (int i = 0; i < N; i++) {
            //    if (work.ToArray()[i] == maxValue) {

            //    } else {
            //        secondMaxValue = maxValue;
            //        break;
            //    }
            //}

            for (int i = 0; i < N; i++) {
                if (A[i] == maxValue) {
                    Console.WriteLine(secondValue);
                } else {
                    Console.WriteLine(maxValue);
                }
            }

        }
    }
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }


void Dijkstra(int s, const vector<vector<P>> &g, vector<int> &dis) {
  priority_queue<P, vector<P>, greater<P>> que; // pair = (cost, v);
  dis[s] = 0;
  que.emplace(0,s);
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int now = p.second;
    if(dis[now] < p.first) continue;
    for(P np : g[now]) {
      int next = np.second;
      if(dis[next] > dis[now] + np.first) {
        dis[next] = dis[now] + np.first;
        que.emplace(dis[next], next);
      }
    }
  }
}


int main(){
    
    int n;
    cin >> n;
    V<V<P>> g(n); // pair = (cost, to);
    rep(i,n) {
        int a, k;
        cin >> a >> k;
        rep(j,k) {
            int b, v;
            cin >> b >> v;
            g[a].emplace_back(v,b);
        }
    }

    V<int> d(n, inf);
    Dijkstra(0,g,d);
    rep(i,n) {
        printf("%d %d\n", i, d[i]);
    }
}


Measured memory_bytes: 7832
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int n;

int main() {
    fastio();

    cin >> n;
    int ans = 0;
    bool swapped = false;
    forn1(i, n) {
        int p;
        cin >> p;
        if (p == i && !swapped) {
            ans++;
            swapped = true;
        } else {
            swapped = false;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<String, Integer> s = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String str = sc.next();
            if (!s.containsKey(str)) {
                s.put(str, 1);
            } else {
                s.put(str, s.get(str) + 1);
            }
        }
        int m = Integer.parseInt(sc.next());
        Map<String, Integer> t = new HashMap<>();
        for (int i = 0; i < m; i++) {
            String str = sc.next();
            if (!t.containsKey(str)) {
                t.put(str, 1);
            } else {
                t.put(str, t.get(str) + 1);
            }
        }

        // 主処理
        int result = 0;
        for (String key : s.keySet()) {
            int sum = s.get(key);
            if (t.containsKey(key)) {
                sum -= t.get(key);
            }
            result = Math.max(result, sum);
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll k;
cin>>k;
ll a=7%k;
map<int,int> memo;
int cnt=1;
while(1){
    if(a==0){
        cout<<cnt<<endl;
        return -0;
    }
    if(memo.count(a))break;
    memo[a]=1;
    a = (10*a+7)%k;
    cnt++;
}
cout<<-1<<endl;
return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int>a(n);

    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    int cnt = 1;
    int next = a[1];

    if(next == 2){
        cout << "1" << endl;
        return 0;
    }else{
        while(cnt != n){
            int temp = a[next];
            next = temp;
            if(next == 2){
                cout << cnt + 1 << endl;
                return 0;
            }
            cnt++;
        }
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

// BIT (Fenwick Tree) with 0-indexed query
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0) : n(n), d(n+1) {}
  void add(int i, T x=1) {
    i++; // 0-indexed to 1-indexed
    for (; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    i++; // 0-indexed to 1-indexed
    T x = 0;
    for (; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
};

// int main(int argc, char** argv) {
//   int N;
//   cin >> N;
//   vector<int> v(N);
//   rep(i, N) {
//     cin >> v[i];
//   }
//
//   BIT<int> bit(N);
//   rep(i, N) {
//     bit.add(i, v[i]);
//   }
//
//   cout << bit.sum(4) << endl; // 24
//   cout << bit.sum(9) << endl; // 55
// }

int main(int argc, char** argv) {
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i, N) {
    cin >> L[i];
  }
  sort(all(L)); // Now, L is sorted

  // For Debug
  // rep(i, N) {
  //   cout << L[i] << endl;
  // }

  // Here, we want to calculate the count of c < a + b. c is the largest number.
  // This is calculated by BIT.
  // add(a+b, 1).
  // sum(MAXA + MAXB) - sum(c).

  ll ans = 0;
  BIT<int> bit(2010);
  bit.add(L[0] + L[1], 1);
  for (int i = 2; i < N; ++i) {
    int c = L[i];
    // For Debug
    // cout << "L["<<i<<"]: "<< L[i] << endl;
    // cout << bit.sum(2005) - bit.sum(c) << endl;

    ans += bit.sum(2010) - bit.sum(c); // The count of c < a + b
    rep(j, i) { // 0, 1, .. i-1.
      bit.add(L[j] + c, 1);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int K = sc.nextInt();
	int X = sc.nextInt();
	int Y = sc.nextInt();
	if ( N >= K ) {
	    System.out.println(X*K+(N-K)*Y);
	} else {
	    System.out.println(N*X);
	}
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<cstdlib>
//#include<cmath>
//#include<algorithm>
//#include<vector>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
using namespace std;
#define SC scanf
#define PR printf
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define db double
#define ldb long double
#define uint unsigned
#define ll long long
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef map<int,int> mii;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
int inline in(){
	int x=0,c;
	for(;(uint)((c=getchar())-'0')>=10;){
		if(c=='-')return -in();
		if(!~c)throw ~0;
	}
	do{
		x=(x<<3)+(x<<1)+(c-'0');
	}while((uint)((c=getchar())-'0')<10);
	return x;
}
ll a[100005],b[100005];
int main(){
    cin.sync_with_stdio(false);cin.tie(0);
    int n;
	cin>>n;
	rep(i,n+1)cin>>a[i];
	rep(i,n)cin>>b[i];
	ll ans=0;
	int x=0,y=n-1;
	ll tmp;
	while(x<=y){
//		cout<<x<<' '<<y<<endl;
		tmp=min(a[x],b[x]);
		ans+=tmp;
		a[x]-=tmp;
		b[x]-=tmp;
		tmp=min(a[x+1],b[x]);
		ans+=tmp;
		a[x+1]-=tmp;
		b[x]-=tmp;
		if(x==y)break;
		x++;
		tmp=min(a[y+1],b[y]);
		ans+=tmp;
		a[y+1]-=tmp;
		b[y]-=tmp;
		tmp=min(a[y],b[y]);
		ans+=tmp;
		a[y]-=tmp;
		b[y]-=tmp;
		y--;
	}
//	rep(i,n+1)cout<<a[i]<<' ';
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
using namespace std;
 
int main()
{
int n,g=0; cin>>n;
while(n>=3)
{
    g++; n-=3;
}
cout<<g;
return 0;
}

Measured memory_bytes: 3556
s = input()

for i in range(1, len(s) + 1):
    if i % 2:
        if s[i - 1] not in ["R", "U", "D"]:
            print("No")
            exit()
    else:
        if s[i - 1] not in ["L", "U", "D"]:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::Read;
use std::io::{stdout, BufWriter, Write};
 
fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    
    let n: i64 = iter.next().unwrap().parse().unwrap();
    let k: i64 = iter.next().unwrap().parse().unwrap();
    
    if k == 1 {
        println!("{:?}",0); 
    }
    else{
        println!("{:?}",n-k); 
    }
}

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

int main(){
	int n;
  	cin >> n;
  	vector<int> a(n);
  	vector<int> b(n-1);
  	rep(i, n-1) cin >> b[i];
  
  	a[0] = b[0];
  	for(int i = 1; i < n; i++){
      	if(i == n-1){
          	a[i] = b[i-1];
         	break;
        }
    	a[i] = min(b[i-1], b[i]);
    }
  
  	int ans = 0;
  	rep(i, n) ans += a[i];
  	cout << ans << endl;
}

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

int main(){
	long long int h,w,a,b;
	long long int ans,M,m,X,Y,Z;
	cin>>h>>w;
	if(h*w%3==0){
		cout<<0<<endl;
		return 0;
	}
	ans=min(h,w);
	for(int k=0;k<2;++k){
		for(int i=0;i<=2;++i){
			for(int j=0;j<=1;++j){
				a=w/3+i;b=h/2+j;
				X=a*h;
				Y=b*(w-a);
				Z=(w-a)*(h-b);
				//cout<<a<<b<<endl;
				if(X==0||Y==0||Z==0)continue;
				M=max(X,Y);
				M=max(M,Z);
				m=min(X,Y);
				m=min(m,Z);
				ans=min(ans,M-m);
				
			}
		}
		swap(h,w);
	}
	cout<<ans<<endl;
}

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

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

	int count = 0;
	int pos;
	string w, t;
	cin >> w;
	cin >> t;
	while (t != "END_OF_TEXT"){
		transform(t.begin(), t.end(), t.begin(), ::tolower);//make t small
		if (t == w)
			count++;
		cin >> t;
	}
	cout << count << '\n';

	return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    vector<LP> A(N);
    REP(i,N) cin>>A[i].first >> A[i].second;
    ll sum = 0;
    VSORT(A);
    REP(i,N){
        if(A[i].second>=M){
            sum += M * A[i].first;
            break;
        }
        else{
            sum += A[i].first * A[i].second;
            M -= A[i].second;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
import sys

def main():
    N = int(input())
    A = [int(_) for _ in input().split()]

    t = 0
    while True:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] //= 2
            else:
                print(t)
                sys.exit()
        t += 1

main()


Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>
using namespace std;

int gcd(int a, int b);

int main(void){
    int K, tmp;
    int sum=0, sum1=0, sum2=0;


    cin >> K;

    for (int a = 1; a < K+1; a++)
    {
        for (int b = 1; b < a; b++)
        {
            for (int c = 1; c < b; c++)
            {
                tmp=gcd(a,b);
                sum1 += gcd(tmp, c);
                //cout << "gcd=" << gcd(tmp,c) << endl;
            }
        }        
    }
    sum1*=6;

    for (int a = 1; a < K+1; a++)
    {
        for (int b = 1; b < a; b++)
        {
            tmp=gcd(a,b);
            sum2 += gcd(tmp, b);
            sum2 += gcd(tmp,a); 
        }   
    }
    sum2 *= 3;
    for (int i = 1; i < K+1; i++)
    {
        sum += i;
    }
    
    cout << sum+sum1+sum2 << endl;
    

    return 0;
}

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

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

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    if(B>A*N) cout << A*N << endl;
    else cout << B << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define INT_MAX 2147483647
#define INT_MIN -2147483648

typedef long long ll;			//%ld.
typedef long long int lli;		//%lld.
typedef unsigned long long ull;	//%llu.
// int %d, double %lf ,float %f ,string %s.

void swap(int *x,int *y);
int max(int x,int y);
int min(int x,int y);
void sortSeq(int dt[],int l,int r);
void sortIns(int dt[],int l,int r);
void mergeSort(int dt[],int l,int r);
int binser(int nilai,int dt[],int l,int r);
int abs(int x);
double maxD(double x,double y);
double minD(double x,double y);

//main code
int hitung(int x){
	int m = 0;
	while(x>0){
		m+=(x%10);
		x/=10;
	}
	return m;
}

int main(){
	int x = 0;
	int maxn = 0;
	int n;
	char s[105];
	scanf("%d",&n);
	scanf("%s",&s);
	for(int i=0;i<n;i++){
		if(s[i]=='I')
			x+=1;
		else if(s[i]=='D')
			x-=1;
		maxn = max(maxn,x);
	}
	printf("%d\n",maxn);
}

















///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double maxD(double x,double y){
	return x > y ? x : y;
}
double minD(double x,double y){
	return x < y ? x : y;
}
int abs(int x){
	if(x<0)	return -x;
	return x;
}
void merge(int arr[], int aLeft , int aRight , int bLeft , int bRight){ //merge
	int size = bRight - aLeft + 1;
	int temp[size];                
	int tIndex = 0;
	int aIndex = aLeft;
	int bIndex = bLeft;
	while( (aIndex <= aRight)&&(bIndex <= bRight))
	{
		if(arr[aIndex]<=arr[bIndex])
		{
			temp[tIndex] = arr[aIndex];
			aIndex = aIndex +1;
		}
		else
		{
			temp[tIndex] = arr[bIndex];
			bIndex = bIndex + 1;
		}
		tIndex = tIndex + 1;
	}
	while(aIndex <= aRight)
	{
		temp[tIndex] = arr[aIndex];
		aIndex = aIndex + 1;
		tIndex = tIndex + 1;
	}
	while(bIndex <= bRight)
	{
		temp[tIndex] = arr[bIndex];
		bIndex = bIndex + 1;
		tIndex = tIndex + 1;
	}
	for(int i = 0 ; i<= size-1 ; i++)
	{
		arr[aLeft + i] = temp[i];
	}
}

void swap(int *a,int *b){ //swap
	int temp = *a;
	*a = *b;
	*b = temp;
}
int max(int a,int b){ //maksimum
	return a>b ? a : b;
}
int min(int a,int b){ //minimum
	return a<b ? a : b;
}
void sortSeq(int arr[],int l,int r){ //sequencial sort
	for(int i=l;i<=r-1;i++)
		for(int j=i+1;j<=r;j++)
			if(arr[j]<arr[i])
				swap(&arr[i],&arr[j]);
}
void sortIns(int h[],int l,int r){ //insertion sort
	for(int i=l;i<=r;i++){
		int pos=i;
		while((pos>1)&&(h[pos]<h[pos-1])){
			swap(&h[pos],&h[pos-1]);
			pos=pos-1;
		}
	}
}
void mergeSort(int arr[],int left,int right){ //merge sort
	if( left == right )
		return; 
	else{
		int mid = (left+right)/2;    	 
		mergeSort(arr,left,mid);	
		mergeSort(arr,mid+1,right);
		merge(arr,left,mid,mid+1,right); 
	}
}
int binser(int x,int dt[],int kiri,int kanan){ //tidak ada = -1
	int hasil = -1;
	while((kiri<=kanan)&&(hasil==0)){
		int tengah=(kiri+kanan)/2;
		if(x<dt[tengah])
			kanan=tengah-1;
		else if(x>dt[tengah])
			kiri=tengah+1;
		else
			hasil=tengah;
	}
	return hasil;
}

Measured memory_bytes: 1704
import bisect

A,B,Q = map(int,input().split())
S,T = [-10**18],[-10**18]

for i in range(A):
    S.append(int(input()))
S.append(10**18)
for i in range(B):
    T.append(int(input()))
T.append(10**18)

for q in range(Q):
    x = int(input())
    res = 10**18
    s_idx = bisect.bisect_right(S,x)
    t_idx = bisect.bisect_right(T,x)
    for s in [S[s_idx-1],S[s_idx]]:
        for t in [T[t_idx-1],T[t_idx]]:
            d1,d2 = abs(s-x)+abs(t-s),abs(t-x)+abs(s-t)
            res = min(res,d1,d2)
    print(res)

Measured memory_bytes: 12084
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    while (cin >> n) {
        int f = 0;
        string s;
        vector<int> v(n);
        cin >> s;
        for (int i = 0 ; i < n ; i++) {
            v[i] = s[i] - '1';
            if (v[i] == 1) {
                f = 1;
            }
        }
        
        for (auto &i : v) {
            if (!f)
                i /= 2;
            else 
                i %= 2;
        }
        int x = 0;
        //int cur = 0;
        for (int i = 0 ; i < n ; i++) {
            if (((n - 1)&i)==i) {
                x ^= v[i];
            }
        }
        if (f == 0) {
            x <<= 1;
        }
        cout << x << '\n';
    }
}

Measured memory_bytes: 5788