akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP1(i, N) for(int i=1; i<=N; i++)
#define P(x) cout << (x)
typedef long long ll;
using namespace std;
ll a[234234], ans;
int b[2434], n;
char s[2434];


int main() {
    int i, j;
    cin >> n;
    REP1(i, n) {
        scanf("%s", s+1);
        REP1(j, 10) b[j] = s[j] - 'a'; // 0-25
        sort(b+1, b+1+10);
        REP1(j, 10) a[i] = a[i]*26 + b[j]; // alphabet > number
    }
    sort(a+1, a+1+n);
    a[n+1] = -1;
    REP1(i, n) {
        j = i+1;
        while(a[i] == a[j]) j++;
        ans += (ll)(j-i)*(j-i-1)/2;
        i = j-1;
    }
    P(ans);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

const double eps = 1.0e-10;
int N,A,B;

ll COM_list[51][51];
void COM_init(){REP(i,51)REP(j,51)COM_list[i][j]=-1;}
ll COM(int n,int k){
	if(n<0||k<0||k>n)return 0;
	if(COM_list[n][k]!=-1)return COM_list[n][k];
	else if(n==k || k==0){
		COM_list[n][k]=1;
      	return 1;
    }
	else{
    	COM_list[n][k]=COM(n-1,k-1)+COM(n-1,k);
		return COM_list[n][k];
    }
}

// A個以上B個以下選んで平均をK以上にできるか調べる
bool check(double K ,int N,const vector<double> & v){
    vector<double> w(N,0.0);
    REP(i,N)w[i]=v[i]-K;
    vector<double> sw(N+1,0.0);
    REP(i,N)sw[i+1]=sw[i]+w[i];
    bool res=false;
    FOR(i,A,B+1){
        if(sw[i]>-eps){
            res=true;break;
        }
    }
    return res;
}



int main(){
    cin>>N>>A>>B;
    vector<double> v(N);
    REP(i,N)cin>>v[i];
    sort(all(v),greater<double>());
    double ub=1.0e16;
    double lb=0.0;
    double mid;
    for(int cnt=0;cnt<150;cnt++){
        mid=(ub+lb)/2;
        if(check(mid,N,v))lb=mid;
        else ub=mid;
    }
    // 平均の最大は lb
    REP(i,N)v[i]-=lb;
    int cnt1=0;
    int cnt2=0;
	int cnt3=0;
    double sum=0.0;
    REP(i,N){
        sum+=v[i];
        if(sum>eps)cnt1++;
    }
	REP(i,N){if(v[i]==v[cnt1])cnt2++;}
  	REP(i,N){if(v[i]>v[cnt1])cnt3++;}
    // 積まれる荷物の中で価値が最小よりも真に大きい荷物は常に cnt3 個.
    // このとき, 積まれるもののなかで価値最小の荷物を最小で A-cnt3 個, 最大で B-cnt3 個選べる.
    // ただし価値最小の荷物は cnt2 個存在している.
	COM_init();
    ll ans = 0;
    FOR(i,A-cnt3,B-cnt3+1){
        ans += COM(cnt2,i); 
    }
    cout<<fixed<<setprecision(15)<<lb<<endl;
    cout<<(v[cnt1]<1e-7&&v[cnt1]>-(1e-7)?ans:COM(cnt2,A-cnt3))<<endl;
    return 0;
}

Measured memory_bytes: 256
import math

a,b,h,m = [int(x) for x in input().split(' ')]

rad_hour = math.pi * 2 * (h/12 + (m/60)/12)
rad_min = math.pi * 2 * (m/60)

rad = max(rad_hour, rad_min) - min(rad_hour, rad_min)

x = (math.pow(a,2) + math.pow(b,2) - (2*a*b*math.cos(rad)))
print(math.sqrt(x))

Measured memory_bytes: 9528
import java.util.*;

class Main {

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

        int N = sc.nextInt();

        if(N < 1200){
            System.out.println("ABC");
        }else if(N < 2800){
            System.out.println("ARC");
        }else{
            System.out.println("AGC");
        }
    }
}

Measured memory_bytes: 23252
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

struct Point { int x, y; };

int main() {
	Point s, t;
	cin >> s.x >> s.y >> t.x >> t.y;

	char c;

	int deltax = t.x - s.x;
	int deltay = t.y - s.y;

	if (deltax > 0) c = 'R';
	else c = 'L';
	for (int i = 0;i < deltax;i++) {
		cout << c;
	}

	if (deltay > 0) c = 'U';
	else c = 'D';
	for (int i = 0;i < deltay;i++) {
		cout << c;
	}

	if (deltax > 0) c = 'L';
	else c = 'R';
	for (int i = 0;i < deltax;i++) {
		cout << c;
	}

	if (deltay > 0) c = 'D';
	else c = 'U';
	for (int i = 0;i < deltay;i++) {
		cout << c;
	}


	if (deltay > 0) cout << "D";
	else if (deltay < 0) cout << "U";

	if (deltax > 0) c = 'R';
	else c = 'L';
	for (int i = 0;i < deltax + 1;i++) {
		cout << c;
	}

	if (deltay > 0) c = 'U';
	else c = 'D';
	for (int i = 0;i < deltay + 1;i++) {
		cout << c;
	}

	if (deltax > 0) cout << "L";
	else if (deltay < 0) cout << "R";



	if (deltay > 0) cout << "U";
	else if (deltay < 0) cout << "D";

	if (deltax > 0) c = 'L';
	else c = 'R';
	for (int i = 0;i < deltax + 1;i++) {
		cout << c;
	}

	if (deltay > 0) c = 'D';
	else c = 'U';
	for (int i = 0;i < deltay + 1;i++) {
		cout << c;
	}

	if (deltax > 0) cout << "R";
	else if (deltay < 0) cout << "L";

	return 0;
}

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

int main()
{
    int a,b;
    cin >> a >> b;
    cout << (a<10 && b<10 ? a*b : -1) << endl;
    return 0;
}

Measured memory_bytes: 256
x,n=map(int,input().split())
p=list(map(int, input().split()))
youso=[]
for i in range(-300,1000):
    if not i in p:
        youso+=[i]
hikaku=[]
for i in youso:
    hikaku+=[(i,abs(x-i))]
hikaku1=sorted(hikaku,key=lambda x:x[1])
res=hikaku1[0][0]
print(res)

Measured memory_bytes: 9200
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k; string s;
char maze[60][60];
int dis[101][101];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int gcd(int x, int y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
int main() {
	cin >> n >> k;
	vector<int> a(n);
	int m = 0;
	int res = 0;
	rep(i, n) {
		cin >> a[i];
	}
	if ((n-1) % (k - 1) != 0) {
		res = (n-1) / (k - 1) + 1;
	}
	else {
		res = (n-1) / (k - 1);
	}
	cout << res << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(ll i = 0; i<n; i++)
#define rep_s(i, start, n) for(ll i= start;  i<n; i++)
#define rep_down(i, n) for(ll i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(ll i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()
#define print(ans) cout << ans << endl;
#define MOD 1000000007
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
 
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;
 
}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];
 
void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}
 
ll keta_num(ll num){
  ll total = 0;
  while(num){
    num /= 10;
    total++;
  }
}
 
 
ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}
 
bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}
 
ll gcd(ll a, ll 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;
  }
  return b;
}
 
ll fibonacchi(ll num){
  ll f0 = 0, f1 = 1, f2;
  ll count = 0;
  while(count<num){
    f2 = f0+f1;
    f0 = f1;
    f1 = f2;
    count++;
  }
  return f2;
}
 
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
 
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
 
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
 
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
 
int main(void){
  ll N, M, A, B, C, D, E, F, G, K,L, W, H, P, Q, R, V, X, Y;
  string S, T;
  cin >> S;
  rep(i, 3) cout<< S[i];
 
 
}

Measured memory_bytes: 3724
n = int(input())  # 人数の入力
a = [0] * n  # 証言のリスト
x = [[0] * n for _ in range(n)]  # 人
y = [[0] * n for _ in range(n)]  # 判定

for i in range(n):
    a[i] = int(input())  # 証言数の入力
    for j in range(a[i]):
        # 人とその人の判定を入力
        x[i][j], y[i][j] = map(int, input().split())
        x[i][j] -= 1  # 人のインデックスは1から始まるように設定する


def check(honest):  # 矛盾の有無を判定する関数
    for i in range(n):
        if not honest[i]: continue  # Trueでないなら次のloopを回す
        for j in range(a[i]):
            # 判定がTrueで証言者がunkindならFalseを返す
            if y[i][j] == 1 and not honest[x[i][j]]: return False
            # 判定がFalseで証言者がhonestならTrueを返す
            if y[i][j] == 0 and honest[x[i][j]]: return False
    # 以上の条件に当てはまらなったらTrueを返す
    return True


def dfs(honest):  # 深さ優先探索の実装
    if len(honest) == n:  # 全て確認し終わったら
        if check(honest):  # 矛盾がなければ
            return sum(honest)  # Trueの数を合計して出力
        else:  # 矛盾があれば
            return 0
    # まだ全て確認していなければ，再帰を使って全探索を続ける
    return max(dfs(honest + [True]), dfs(honest + [False]))


print(dfs([]))

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end());

    int ans = 0;
    int ptr = 0;
    while (ptr < N) {
        int val = A[ptr], cnt = 0;
        while (ptr < N && val == A[ptr]) ptr++, cnt++;
        ans += cnt % 2;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
a,b,c=map(int,input().split())
if(a==b and b==c):
    print(1)
else:
    if(a==b and b!=c):
        print(2)
    elif(b==c and c!=a):
        print(2)
    elif(c==a and a!=b):
        print(2)
    else:
        print(3)






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

int main(void) {
    string S = "";
    cin >> S;

    // 奇数か
    auto isOdd = (S.length() & 1) == 1;

    auto index = S.length() / 2;
    auto lstr = S.substr(0, index);
    auto rstr = isOdd ? S.substr(index + 1) : S.substr(index);
    reverse(rstr.begin(), rstr.end());
    
    auto count = 0;
    for (auto i = 0; i < lstr.length(); i++) {
        if (lstr[i] != rstr[i]) 
            count++;
    }

    cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

string s,s2;

int main() {
    cin >> s;
    ll cnta = 0,ans = 0;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i] == 'A') cnta++;
        else if(s[i] == 'B' && s[i+1] == 'C'){
            ans += cnta;
            i++;
        }else cnta = 0;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<int> s(N), d(M);
        for(int i=0; i<N; ++i) {
            cin >> s[i];
        }
        for(int j=0; j<M; ++j) {
            cin >> d[j];
        }
        sort(d.begin(), d.end());
        vector<vector<int>> dp(M+1, vector<int>(1 << N, 1e9));
        vector<int> sum(1 << N);
        for(int S=0; S<1<<N; ++S) {
            for(int i=0; i<N; ++i) {
                if((S >> i) & 1) {
                    sum[S] += s[i];
                }
            }
        }
        dp[0][0] = 0;
        for(int i=1; i<=M; ++i) {
            for(int S=0; S<1<<N; ++S) {
                for(int j=0; j<N; ++j) {
                    dp[i-1][S | (1 << j)] = min(dp[i-1][S | (1 << j)], dp[i-1][S]);
                }
            }
            for(int S=0; S<1<<N; ++S) {
                dp[i][S] = min(dp[i][S], dp[i-1][S] + abs(d[i-1] - sum[S]));
            }
        }
        cout << *min_element(dp[M].begin(), dp[M].end()) << endl;
    }
}


Measured memory_bytes: 16276
n,q=map(int, input().split())
S=input()
lr=[list(map(int, input().split())) for _ in range(q)]
t=[0]*(n+1)
for i in range(n):
    #i桁目までに登場するACを計算する
    t[i+1]=t[i]+(1 if S[i:i+2] == "AC" else 0)
for i in range(q):
    l,r=lr[i][0]-1,lr[i][1]-1
    print(t[r]-t[l])

Measured memory_bytes: 32220
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N,temp;
    int count = 0;
    cin>>N;
    vector<int> rt;
    while(cin>>temp){
        rt.push_back(temp);
    }
    for(int i =0;i<N;i++){
        int mini = i;
        for(int j = i;j<N;j++){
            if(rt[j]<rt[mini]){
                mini = j;
            }
        }
        if (i!=mini) {
            count++;
            temp = rt[i];
            rt[i] = rt[mini];
            rt[mini] = temp;
        }
        if(i!=N-1)
           cout<<rt[i]<<" ";
        else
            cout<<rt[i]<<endl;
    }
    cout<<count<<endl;
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;cin>>N;
	string S[N];
	int count=0;int a=0,b=0,c=0;
	for(int i=0;i<N;i++){
		cin>>S[i];
		for(int j=0;j<S[i].size()-1;j++){
			if(S[i].at(j)=='A'&&S[i].at(j+1)=='B'){
				count++;
			}
		}if(S[i].at(0)=='B'&&S[i].back()=='A'){
			c++;
		}else if(S[i].back()=='A'){
			a++;
		}else if(S[i].at(0)=='B'){
			b++;
		}
    }
    if(c==0){
        cout<<count+min(a,b)<<endl;
    }else if(a==0&&b==0){
        cout<<count+c-1<<endl;
    }else if(a==0||b==0){
        cout<<count+c<<endl;
    }else{
        cout<<count+c+1+min(a-1,b-1)<<endl;
    }
}

Measured memory_bytes: 768
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  print $ 3*n*n

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n, m; cin >> n >> m;
	vector<int> check(n, 0);
	vector<int> chWA(n, 0);
	int AC = 0;
	int WA = 0;
	for (int i=0; i<m; i++){
		int p; cin >> p;
		string s; cin >> s;
		if (check[p-1]==1) continue;
		if (s=="AC") {
			AC++;
			check[p-1] = 1;
		} else {
			chWA[p-1]++;
		}
	}
	for (int i=0; i<n; i++) {
		if (check[i]==1) WA += chWA[i];
	}
	cout << AC << " " << WA << endl;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
p = list(map(int,input().split()))
all = 0
for i in range(n-2):
    if p[i] < p[i+1] < p[i+2] :
        all = all + 1
    elif p[i] > p[i+1] > p[i+2] :
        all = all + 1
print(all)

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

const int inf = 1001001001;

int n, s, g, d;
bool b[50][10];

int main() {
  while (cin >> n, n) {
    cin >> s >> g >> d;

    s--;
    g--;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) v[i] = i;

    for (int i = 0; i < d; ++i) {
      for (int j = 0; j < n - 1; ++j) {
        int f;
        scanf("%1d", &f);
        b[i][j] = f;
        if (b[i][j]) swap(v[j], v[j + 1]);
      }
    }

    int G = v[g];
    if (G == s) {
      cout << 0 << endl;
      continue;
    }

    bool f = false;
    for (int i = 0; i < n; ++i) v[i] = i;

    for (int i = 0; i < d; ++i) {
      if (f) continue;
      for (int j = 0; j < n - 1; ++j) {
        if (b[i][j]) swap(v[j], v[j + 1]);
      }

      for (int j = 0; j < n; ++j) {
        if (f) continue;

        if (v[j] == s) {

          if (j != 0 && v[j - 1] == G) {
            bool c = true;
            for (int k = j - 2; k <= j; ++k)
              if (0 <= k && k < n && b[i][k]) c = false;
            if (c) {
              cout << i + 1 << " " << j << endl;
              f = true;
            }
          }

          if (j != n - 1 && v[j + 1] == G && !b[i][j]) {
            bool c = true;
            for (int k = j - 1; k <= j + 1; ++k)
              if (0 <= k && k < n && b[i][k]) c = false;
            if (c) {
              cout << i + 1 << " " << j + 1 << endl;
              f = true;
            }
          }
        }
      }
    }
    if (f) continue;

    cout << 1 << endl;
  }
}

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

int main(){
           int n;
           cin>>n;
           int a[4][13] = {};
           for(int x=0;x<n;x++){
           string str;
           int number;
           cin>>str>>number;
    
           if(str=="S") a[0][number-1] = 1;
           if(str=="H") a[1][number-1] = 1;
           if(str=="C") a[2][number-1] = 1;
           if(str=="D") a[3][number-1] = 1;
           }
        
           string str2[4] = {"S","H","C","D"};
           for(int i=0;i<4;i++){
                for(int j=0;j<13;j++){
                    if(a[i][j] == 1) continue;
                    cout<<str2[i]<<" "<<j+1<<endl;
                }
           }
     return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


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


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n, x, i, j, k;
    while(1){
    int Combination = 0;
    scanf("%d %d", &n, &x);
    if(n == 0 && x == 0){
        break;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            for(k=j+1;k<=n;k++){
                if(i + j + k == x){
                    Combination++;
                    //printf("%d %d %d\n", i, j, k);
                }
            }
        }
    }
    printf("%d\n", Combination);
    }
    return 0;
}


Measured memory_bytes: 2020
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        int ma = 0;
        int res = 0;
        for (int i = 0; i < n; i ++) {
                int a, b;
                scanf("%d %d", &a, &b);
                if (a > ma) {
                        ma = a;
                        res = b;
                }
        }
        printf("%d\n", ma + res);
        return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> edges(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            v--;
            edges[u][v] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j > 0) {
                cout << " ";
            }
            cout << edges[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer i;
  for(i=nil->next; i!=nil && i->key!=key ;i=i->next) {
  }return i;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if(t == nil) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t;
    t = listSearch(key);
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  //番兵の次に要素を追加
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
 
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    //printf("aiueo1\n");
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) {deleteFirst();}
	else if ( com[6] == 'L' ) {deleteLast();}
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }
  //printf("aiueo6\n");
  printList();
  return 0;
}




Measured memory_bytes: 32952
#include <iostream>

using namespace std;

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

    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
        cout << "Possible\n";
    else
        cout << "Impossible\n";
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;

int a, b, c, d;


char re(int x){
	if(x == 1) return '+';
	else if(x == 2) return '-';
}

int main(){
	scanf("%1d %1d %1d %1d", &a, &b, &c, &d);
	int ans = 0;
	for(int i = 1; i <= 2; i++){
		for(int j = 1; j <= 2; j++){
			for(int k = 1; k <= 2; k++){
				ans = a;
				if(i == 1) ans += b;
				else if(i == 2) ans -= b;
				if(j == 1) ans += c;
				else if(j == 2) ans -= c;
				if(k == 1) ans += d;
				else if(k == 2) ans -= d;
				if(ans == 7){
					printf("%d%c%d%c%d%c%d=7\n", a, re(i), b, re(j), c, re(k), d);
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128
def pow_with_mod(x, n, m):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
            K %= m
        x *= x
        x %= m
        n //= 2

    return (K * x) % m

def main():
    import sys
    S=sys.stdin.readline().strip()
    N=len(S)
    L=[0]*2019
    now=0
    for i in range(N):
        now+=int(S[-i-1])*pow_with_mod(10, i, 2019)
        now%=2019
        L[now]+=1  
    print(L[0]+sum([x*(x-1)//2 for x in L]))
main()


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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  
  string S;
  cin >> S;
  
  vector<bool> ans(N, false);
  int Apass = 0, Bpass = 0;
  for (int i = 0; i < N; i++){
    if (S.at(i) == 'a'){
      if (Apass + Bpass < A + B){
        ans.at(i) = true;
        Apass++;
      }
    }
    else if (S.at(i) == 'b'){
      if (Apass + Bpass < A + B && Bpass < B){
        ans.at(i) = true;
        Bpass++;
      }
    }
  }
  
  for (int i = 0; i < N; i++){
    if (ans.at(i) == true){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

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

    int D;
    cin >> D;
    ll c[26], a[D][26];
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26) cin >> a[i][j];
    }

    int N = 2000;
    pii pre[D+1][N];
    vector<int> state[D+1][N];
    ll sum[D+1][N];
    fill(sum[0], sum[D+1], -INF);
    sum[0][0] = 0;
    state[0][0].assign(26, -1);

    rep(i, D){
        vector<pair<ll, pii>> next;
        rep(j, N){
            if(sum[i][j] == -INF) break;
            ll pena = 0;
            rep(k, 26){
                pena += c[k]*(i-state[i][j][k]);
            }
            rep(k, 26){
                ll tmp = sum[i][j]+a[i][k]-pena;
                tmp += c[k]*(i-state[i][j][k]);
                next.eb(tmp, pii(j, k));
            }
        }
        sort(all(next), greater<pair<ll, pii>>());
        rep(j, min(N, sz(next))){
            sum[i+1][j] = next[j].first;
            pre[i+1][j] = next[j].second;
            state[i+1][j] = state[i][pre[i+1][j].first];
            state[i+1][j][pre[i+1][j].second] = i;
        }
    }

    ll M = -INF;
    int ptr = 0;
    rep(i, N){
        if(chmax(M, sum[D][i])) ptr = i;
    }

    vector<int> ans(D);
    rep3(i, D, 1){
        ans[i-1] = pre[i][ptr].second;
        ptr = pre[i][ptr].first;
    }
    
    for(auto &e: ans) cout << e+1 << endl;
}

Measured memory_bytes: 113396
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
typedef pair<ll, ll> P;
ll inf = 1e18;

ll total_cost[100005];
ll yen_cost[100005];
ll snk_cost[100005];
vector<P> yen_edge[100005];
vector<P> snk_edge[100005];

// Dijkstra
void dijkstra(ll *D, vector<P> *G, ll s){
    // max priority queue ordered by first element
    // priority_queue < P > q;

    // min priority queue ordered by first element
    priority_queue < P, vector<P>, greater<P> > q;
    for (int i = 0; i < 100005; i++) D[i] = inf;
    D[s]=0;
    q.push(P(0,s));
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        ll y = p.second; // p.second means current node position
        if (D[y] != p.first) continue;
        for (int i = 0; i < G[y].size(); i++) {
            int node = G[y].at(i).first; // edge y->node
            ll cost = G[y].at(i).second; // cost of y->node
            if (D[node] > D[y] + cost) {
                D[node] = D[y] + cost;
                q.push(P(D[node], node)); // P(total cost, current node)
            }
        }
    }
}

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

    ll n, m, s, t, u, v, a, b;
    cin >> n >> m >> s >> t;
    for (int i = 0; i < m; i++) {
        cin >> u >> v >> a >> b;
        yen_edge[u].push_back(P(v, a));
        yen_edge[v].push_back(P(u, a));
        snk_edge[u].push_back(P(v, b));
        snk_edge[v].push_back(P(u, b));
    }

    dijkstra(yen_cost, yen_edge, s);
    dijkstra(snk_cost, snk_edge, t);

    total_cost[n] = yen_cost[n] + snk_cost[n];
    for (int i = n-1; i > 0; i--) {
        total_cost[i] = min(total_cost[i+1], yen_cost[i] + snk_cost[i]);
    }

    for (int i = 1; i <= n; i++) {
        cout << 1000000000000000 - total_cost[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 19196
#include <iostream>
using namespace std;
int main(void) {
  int a, b;
  cin >> a >> b;
  if (a == 1) a += 13;
  if (b == 1) b += 13;
  if (a > b) cout << "Alice" << endl;
  else if (a < b) cout << "Bob" << endl;
  else cout << "Draw" << endl;
  return 0;
}

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

int main(){
  int n;
  string a,b;
  cin>>n;
  string s[n];
  cin>>s[0];
  bool ans=true;
  for(int i=1;i<n;++i){
    cin>>s[i];
    b=s[i];
    a=s[i-1];

    if(a[a.size()-1]!=b[0])
        ans=false;
    for(int j=0;j<i;++j){
        if(s[i]==s[j])
            ans=false;
    }
  }

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


Measured memory_bytes: 256
n=int(input())
A=sorted((map(int,input().split())))
G=sorted([2*(i+1) for i in range(n//2)]*2+[0])
K=sorted([(2*i+1) for i in range(n//2)]*2)
if n%2:
	if A!=G:
		print(0)
		exit()
else:
	if A!=K:
		print(0)
		exit()
print(2**(n//2)%(10**9+7))

Measured memory_bytes: 14008
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll K, N;
  cin >> K >> N;
  vl A(N);
  REP(i, N) cin >> A[i];
  ll ans = 0;
  REP(i, N - 1) { ans = max(ans, A[i + 1] - A[i]); }
  ans = max(ans, A[0] + K - A[N - 1]);
  cout << K - ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>



int main()
{
	long long n;

	std::cin >> n;

	std::vector<long long> a(n), b(n), c(n);

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> a[i];
	}

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> b[i];
	}

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> c[i];
	}

	std::sort(a.begin(), a.end());
	std::sort(b.begin(), b.end());
	std::sort(c.begin(), c.end());

	std::vector<long long> count0(n);
	long long sum = 0;

	for (size_t i = 0; i < n; i++)
	{
		count0[i] = std::lower_bound(a.begin(), a.end(), b[i]) - a.begin();
	}

	std::vector<long long> acc(n + 1);

	for (size_t i = 0; i < n; i++)
	{
		acc[i + 1] = acc[i] + count0[i];
	}

	for (size_t i = 0; i < n; i++)
	{
		sum += acc[std::lower_bound(b.begin(), b.end(), c[i]) - b.begin()];
	}

	std::cout << sum << std::endl;



	return 0;
}


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

long long ju(long long h){
  if(h==1){
    return 1;
  }
  long long s=ju(h/2);
  return 1+2*s;
}
  

int main(){
  long long H;
  cin >> H;
  
 
  cout << ju(H) << endl;
}
  
  

Measured memory_bytes: 256
n = raw_input()
t = raw_input()
t, a = int(t.split(" ")[0]),int(t.split(" ")[1])
h = raw_input()
h = [int(i) for i in h.split(" ")]

min_diff = 999999
min_i = 1
for i in range(len(h)):
	temp = t-h[i]*0.006
	diff = abs(temp-a)
	if diff<min_diff:
		min_diff = diff 
		min_i = i+1
print(min_i)

Measured memory_bytes: 2692
N = gets.chomp.to_i

ts = [0] * 12
name = []
count = 0
m = N
eigo = [*"a".."z"]
eigo.unshift("z")

(1..11).each do |i|
  ts[i] = (26 ** i)
end

while m > ts[count]
  m -= ts[count]
  count += 1
end

mozisu = count
# mozisu桁のm番目

while count > 0
  count -= 1
  if count > 0
    name[mozisu - count - 1] = (m / ts[count])
    m %= ts[count]
    if m != 0
      name[mozisu - count - 1] += 1
    end
  else
    name[mozisu - 1] = m
  end
end

(0...mozisu).each do |j|
  v = name[j]
  name[j] = eigo[v]
end

puts name.join

Measured memory_bytes: 14368
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main(){
  prep();
  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  long long csum[n] = {0};
  long long msum[n] = {0};
  for (int i=0; i<n; i++){
      if (s[i] == 'C'){
          csum[i]++;
      }else if (s[i] == 'M'){
          msum[i]++;
      }
  }
  for (int i=1; i<n; i++){
      csum[i] += csum[i-1];
      msum[i] += msum[i-1];
  }
  long long sums[n] = {0};
  for (int i=0; i<n; i++){
      if (s[i] == 'C'){
          sums[i] = msum[i];
      }
  }
  for (int i=1; i<n; i++){
      sums[i] += sums[i-1];
  }
  for (int i=0; i<q; i++){
      int k;
      cin >> k;
      long long res = 0;
      for (int j=0; j<n-2; j++){
          if (s[j] == 'D'){
              long long myval = sums[min(j+k-1, n-1)]-sums[j];
              long long cs = csum[min(j+k-1, n-1)];
              cs -= csum[j];
              if (j > 0){
                  myval += -msum[j-1]*cs;
              }
              res += myval;
          }
      }
      cout << res << '\n';
  }
  return 0; 
}

Measured memory_bytes: 24860
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

divisors = make_divisors(N)

count = 0
for divisor in divisors:
    m = divisor-1
    if m and (N//m == N%m):
        count += m
print(count)

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

int main(){
    int n, t, a;
    cin >> n >> t >> a;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int out = 0;
    double min = INT_MAX;
    rep(i, n){
        double temp = abs(t - h[i] * 0.006 - a);
        if(min > temp){
            min = temp;
            out = i + 1;
        }
    }
    cout << out << endl;
}

Measured memory_bytes: 3608
from sys import stdin

N, M = map(int, stdin.readline().split())
light = [None] * M
for i in range(M):
    light[i] = list(map(int, stdin.readline().split()))[1:]
P = list(map(int, stdin.readline().split()))

ans = 0
for i in range(2 ** N):
    on_switch = [0] * N
    for j in range(N):
        if int(format(i, 'b').zfill(N)[j]) == 1:
            on_switch[j] = 1

    on_bulb = 0
    for j in range(M):
        num_of_on_switch = 0
        for index in light[j]:
            num_of_on_switch += on_switch[index - 1]
        if num_of_on_switch % 2 == P[j]:
            on_bulb += 1
    if on_bulb == M:
        ans += 1

print(ans)


Measured memory_bytes: 43376
def main():
    n = input()
    digit = len(n)
    
    k = int(input())
    dp0 = [[0]*k for _ in range(digit)]
    dp0[0][0] = int(n[0])-1
    
    dp1 = [[0]*k for _ in range(digit)]
    dp1[0][0] = 1
    
    c = 1
    flag1 = True
    flag2 = True
    flag3 = False
    flag4 = False
    flag5 = True
    for i in range(1, digit):
        if n[i] != "0":
            c += 1
        for j in range(k):
            if j > i or j > k:
                continue
            if j == 0:
                dp0[i][j] = 9+dp0[i-1][j]
                if c == 1:
                    dp1[i][j] = 1
                else:
                    if flag1:
                        dp0[i][j] += 1
                        flag1 = False
            if j == 1:
                dp0[i][j] = dp0[i-1][j-1]*9+dp0[i-1][j]
                if flag3:
                    dp0[i][j] += dp1[i-1][j-1]*9
                else:
                    dp0[i][j] += dp1[i-1][j-1]*max([(int(n[i])-1), 0])
                    if c >= 2:
                        flag3 = True
                
                if c == 2:
                    dp1[i][j] = 1
                if flag2 and c == 3:
                    dp0[i][j] += 1
                    flag2 = False
                
            if j == 2:
                dp0[i][j] = dp0[i-1][j-1]*9+dp0[i-1][j]
                
                if flag4:
                    dp0[i][j] += dp1[i-1][j-1]*9
                else:
                    dp0[i][j] += dp1[i-1][j-1]*max([(int(n[i])-1), 0])
                    if c >= 3:
                        flag4 = True

                if c == 3:
                    dp1[i][j] = 1
                if flag5 and c == 4:
                    dp0[i][j] += 1
                    flag5 = False
                    
    print(dp0[digit-1][k-1]+dp1[digit-1][k-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    string s;
    cin >> s;
    string t = "NWSE";
    int m = 0;
    for (char c: s) {
        int i = 0;
        while (t[i] != c) ++i;
        m |= 1 << i;
    }
    cout << (m == 5 || m == 10 || m == 15 ? "Yes" : "No") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 764
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b)
    a-=b;
    else
    {
        cout<<a<<endl;
        return 0;
    }
    while(a>=c)
        a-=c;
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 614656
#define MAX_SQRT_N 784
#define MAX_P 50205
#define N_PRIME 50000

bool f[MAX_N + 1];
int primes[MAX_P];
int p;

bool
search(int x, int ub)
{
	int lb = -1;
	while (ub - lb > 1)
	{
		int mid = (lb + ub) / 2;
		if (primes[mid] == x)
			return true;

		else if (primes[mid] < x)
			lb = mid;

		else
			ub = mid;
	}

	return false;
}


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

	for (i = 0; i <= MAX_N; ++i)
		f[i] = true;

	p = 0;
	for (i = 2; i <= MAX_N; ++i)
	{
		if (f[i])
		{
			primes[p++] = i;
			if (i <= MAX_SQRT_N)
			{
				for (j = i + i; j <= MAX_N; j += i)
					f[j] = false;
			}
		}
	}

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

		int u = -1;
		int v;
		for (v = 0; v < N_PRIME; ++v)
		{
			if (u == -1 && primes[v] > n / 2)
				u = v - 1;

			if (primes[v] > n)
				break;
		}

		int count = 0;
		for (i = 0; i <= u; ++i)
		{
			if (search(n - primes[i], v))
				count++;
		}

		printf("%d\n", count);
	}

	return 0;
}

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

const int MAX_N = 1e5;
ll N;
ll a[MAX_N+5];

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

    bool flg = true;

    ll sum = 0, p = N * (N+1) / 2, sy = 0, m;
    for(int i=0;i<N;i++) sum += a[i];

    if (sum%p) flg = false;

    m = sum / p;
    for(int i=1;i<=N;i++){
        ll d = a[i%N] - a[i-1];

        if((m-d)%N || m < d) flg = false;
        sy += (m-d) / N;
    }

    if(flg && sy==m) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main(){
  int K, n;
  cin >> K >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  a.push_back(a[0]+K);
  int l = 0;
  rep(i,n){
    l = max(l, a[i+1]-a[i]);
  }
  int ans = K-l;
  cout << ans << endl;
}

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

int main()
{
	int n;
	int c = 0, maxim=0;
	int a[2][100];
	cin >> n;
	int s, t;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}

	s = 0;
	for (int i = 0; i < n; i++) {
		s = 0;
		c = 0;
		for (int j = 0; j < n; j++) {
			c += a[s][j];
			if (j == i) {
				s++;
				c += a[s][j];
			}
		}
		maxim = max(maxim, c);
	}
	cout << maxim << endl;
}

Measured memory_bytes: 256
from fractions import gcd
from functools import reduce

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]

    print(lcm_list(num_list))

if __name__ == '__main__':
    main()

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

int main(){
  int n,array[50][26]={},minal[26];
  string s[50];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s[i];
    for(int j=0;j<s[i].size();j++){
      for(char c='a';c<='z';c++){
        if(c==s[i][j]){
          array[i][c-'a']++;
          break;
        }
      }
    }
  }
  for(char c='a';c<='z';c++){
    minal[c-'a']=1e9;
    for(int i=0;i<n;i++){
      minal[c-'a']=min(array[i][c-'a'],minal[c-'a']);
    }
    for(int i=0;i<minal[c-'a'];i++){
      cout<<c;
    }
  }
  cout<<endl;
}

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

int main(){
  unsigned long long int *a;
  unsigned long long int n;
  unsigned long long int x = 1;
  unsigned long long int i,j,k;
  unsigned long long int a2, x2;
  cin >> n;
  a = (unsigned long long int*)malloc(n*sizeof(unsigned long long int));

  for(i=0;i<n;i++){
    cin >> a[i];
    if(a[i]==0){
      cout << 0 << endl;
      return 0;
    }   
  }
  for(i=0;i<n;i++){
    j=0;
    k=0;
    a2=a[i];
    x2=x;
    while(a2>=10){
      a2 /= 10;
      j++;
    }
    while(x2>=10){
      x2 /= 10;
      k++;
    }
    if(j+k>=18 && a2*x2>1){
      cout << -1 << endl;
      free(a);
      return 0;
    }
    x *= a[i];
  }
  if(x>1000000000000000000){
  cout << -1 << endl;
  free(a);
  return 0;
  } 
  free(a);
  

  cout << x << endl;

  return 0;
}

Measured memory_bytes: 3996
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

M = 998244353
n,k = ip()
seg = [ip() for i in range(k)]
dp = [0]*(n+1)
pre = [0]*(n+1)

dp[1] = 1
pre[1] = 1
for i in range(2,n+1):
    for l,r in seg:
        a,b = max(i-r,1),i-l
        dp[i] += (pre[b] - pre[a-1])%M
    pre[i] += (pre[i-1]+dp[i])%M
print(dp[n]%M)


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

typedef long long ll;

int main ()
{
	int n, m;
  	cin >> n >> m;
  	ll dp[100010];
  	vector<ll> broken(100010,true);
  	for(int i = 0; i < m; i++)
    {
    	int a;
      	cin >> a;
      	broken[a] = false;
    }
  	for(int i = 0; i < 100010; i++)
    {
    	dp[i] = 0;
    }
  	dp[0] = 1;
  	for(int i = 0; i < n; i++)
    {
    	for(int j = i + 1; j <=min(n, i+2); j++)
        {
        	if(broken[j])
            {
            	dp[j] += dp[i];
              	dp[j] %= 1000000007;
            }
        } 
    }
  	cout << dp[n] << endl;
  	return 0;
}


Measured memory_bytes: 1792