akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

int count(std::vector<int> vec, int k) {
    int ans = 0;
    int band = 2*k + 1;
    int n = vec.size();
    for (int i=0; i < vec.size(); i+=2) {
        int tmp = 0;
        for (int j=i; j<i+band; ++j) {
            if (j >= n) break;
            tmp += vec[j];
        }
        // std::cout  << tmp << ' ';
        ans = std::max(tmp, ans);
        // ans = std::max(ans, std::accumulate(vec.begin()+idx, vec.begin()+idx + band, 0));
    }
    // std::cout << '\n';
    return ans;
}

int solve(std::string s, int k, int n) {
    int ans = 0, tmp = 0, idx;
    std::vector<int> vec;
    char cur = '1';
    for (int i=0; i<n; ++i) {
        if (s[i] != cur) {
            vec.push_back(tmp);
            cur = (cur == '1') ? '0' : '1';
            tmp = 0;
        }
        ++tmp;
    }
    vec.push_back(tmp);
    if(vec.size() == 1) return vec[0];
    // for (auto v :  vec) {
    //     std::cout << v << ' ';
    // }
    // std::cout << '\n';

    ans = count(vec, k);
    return ans;
}

int main() {
    int n, k;
    std::string s;
    std::cin >> n >> k >> s;
    std::cout << solve(s, k, n) << '\n';
    return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

/**
 *  http://abc069.contest.atcoder.jp/tasks/abc069_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		final String s = sc.next();
		sc.close();
		
		String ans = ""+ s.charAt(0) + (s.length()-2) + s.charAt(s.length()-1);
		
		System.out.println(ans);

	}

}


Measured memory_bytes: 24276
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;cin>>s>>t;
    int cnt=0;
    for(int i=0;i<s.size();++i){
        if(s[i]!=t[i]){
            ++cnt;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3848
#include <stdio.h>
#include <stdlib.h>

int mas[3][3];
int cpy[3][3];

void input() {
  int i, j;
  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++)
      scanf("%d", &mas[i][j]);
}

void output() {
  int i, j;
  for(i = 0; i < 3; i++) {
    for(j = 0; j < 3; j++) printf("%3d", mas[i][j]);
    puts("");
  }
}

void copy(int m[3][3], int t[3][3]) {
  int i, j;

  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++) m[i][j] = t[i][j];
}

int calc() {
  int i, sum = 0;
  for(i = 0; i < 9; i++) {
    int v = mas[i/3][i%3];
    if(v) {
      v--;
      sum += abs(i/3-v/3)+abs(i%3-v%3);
    }
  }
  return sum;
}

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

void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int is_in(int x, int y) {
  return 0<=x&&x<3&&0<=y&&y<3;
}

int dfs(int x, int y, int p, int dep, const int lim) {
  int i, h = calc();
  if(h == 0) return dep;
  if(dep+h > lim) return -1;

  for(i = 0; i < 4; i++) {
    int nx = x+dx[i], ny = y+dy[i], res;
    if(~p && i == (p+2)%4) continue;
    if(!is_in(nx, ny)) continue;
    swap(&mas[y][x], &mas[ny][nx]);
    res = dfs(nx, ny, i, dep+1, lim);
    if(~res) return res;
    swap(&mas[y][x], &mas[ny][nx]);
  }

  return -1;
}

void get_empty(int *x, int *y) {
  int i, j;
  for(i = 0; i < 3; i++) {
    for(j = 0; j < 3; j++) {
      if(!mas[i][j]) {
    *x = j;
    *y = i;
    return;
      }
    }
  }
}

int solve() {
  int x, y, lim, ans;
  get_empty(&x, &y);
  for(lim = 0; lim < 50; lim++) {
    copy(cpy, mas);
    if((ans = dfs(x, y, -1, 0, lim)) != -1) return ans;
    copy(mas, cpy);
  }
  return -1;
}

int main() {
  input();
  printf("%d\n", solve());
  return 0;
}



Measured memory_bytes: 2148
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
int main()
{
	int n, a, b;
	scanf("%d", &n);
	int chk = 0;
	int occur = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &a, &b);
		if (a == b) chk++;
		else chk = 0;
		if (chk >= 3) occur = 1;
	}
	if (occur) printf("Yes");
	else printf("No");
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template<signed MOD = 1000000007>
struct Mint{
  signed v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(int k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }
  
  Mint inv(){return pow(MOD-2);}
  
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}
  
  Mint operator+(Mint a){return Mint(v)+=a;};
  Mint operator-(Mint a){return Mint(v)-=a;};
  Mint operator*(Mint a){return Mint(v)*=a;};
  Mint operator/(Mint a){return Mint(v)/=a;};

  Mint operator-(){return v?MOD-v:v;}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  
  vector<Mint> fact(int n){
    vector<Mint> res(n+1,1);
    for(int i=1;i<=n;i++) res[i]=res[i-1]*Mint(i);
    return res;
  }
  
  vector<Mint> finv(int n){
    vector<Mint> res(n+1,1);
    for(int i=1;i<=n;i++) res[i]=res[i-1]*Mint(i);
    res[n]=Mint(1)/res[n];
    for(int i=n;i>=1;i--) res[i-1]=res[i]*Mint(i);
    return res;
  }

  vector<Mint> invs(vector<Mint> &a,vector<Mint> &b){
    int n=a.size()-1;
    vector<Mint> res(n+1,0);
    for(int i=1;i<=n;i++) res[i]=b[i]*a[i-1];
    return res;
  }
};
//END CUT HERE

template<typename T> 
map<T, int> factorize(T x){
  map<T, int> res;
  for(int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}

//INSERT ABOVE HERE
signed main(){
  int n;
  Mint<> m;
  cin>>n>>m.v;
  
  auto fact=m.fact(n+100);
  auto finv=m.finv(n+100);
  
  auto C=[&](int n,int k){
	   if(n<k||k<0) return Mint<>(0);
	   return fact[n]*finv[n-k]*finv[k];
	 };
  auto H=[&](int n,int k){return C(n+k-1,n);};

  Mint<> ans(1);
  auto x=factorize(m.v);
  for(auto p:x) ans*=H(p.second,n);
  
  cout<<ans.v<<endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    if(n>=64){
      System.out.println(64);
    }else if(n>=32){
      System.out.println(32);
    }else if(n>=16){
      System.out.println(16);
    }else if(n>=8){
      System.out.println(8);
    }else if(n>=4){
      System.out.println(4);
    }else if(n>=2){
      System.out.println(2);
    }else{
      System.out.println(1);
    }
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int a, b;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> a >> b;
	if(a <= 9 && b <= 9) cout << a * b << "\n";
	else cout << -1 << "\n";
}

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

int main(){
  int n;
  cin >> n;
  double ans;
  if(n%2==0){
    int tmp;
    tmp = n/2;
    ans = (double)tmp /(double)n;
    cout << ans << endl;
  }else{
    int tmp;
    tmp = n/2 +1;
    ans = (double)tmp /(double)n;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,C[110]={},ans=0;
int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> C[i];
  }
  sort(C,C+N);//小さい順
  reverse(C,C+N);
  //cout << C[0] << endl;
  for(int i=0;i<N;i+=2){
    ans+=C[i]-C[i+1];
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

double pi = acos(-1);
int N;
struct point
{
	int x,y;
	void read(){scanf("%d%d",&x,&y);}
}p1,p2;
vector<point>p;
bool between(int a,int l,int r)
{
	if (l > r) swap(l,r);
	return (a >= l && a <= r);
}
bool bet(point a,point l,point r)
{
	return between(a.x,l.x,r.x) && between(a.y,l.y,r.y);
}
bool cmp(point a,point b)
{
	return a.x < b.x;
}
bool cmp2(point a,point b)
{
	return abs(a.y - p1.y) < abs(b.y - p1.y);
}
int stk[200010];
int f[200010];

int main()
{
	p1.read();p2.read();
	scanf("%d",&N);
	for (int i=1;i<=N;i++)stk[i] = -1;
	point tmp;
	for (int i=1;i<=N;i++)
	{
		tmp.read();
		if (bet(tmp,p1,p2)) p.push_back(tmp);
	}
	if (p1.x > p2.x) swap(p1,p2);
	sort(p.begin(),p.end(),cmp);
	int ma = 0;
	for (int i=0;i<p.size();i++)
	{
		//printf("!!!!!%d %d\n",p[i].x,p[i].y);
		int l = 0, r = ma;
		if (ma == 0) f[i] = 1;
		else
		{
			if (cmp2(p[stk[ma]],p[i])) 
			{
				//puts("ahahah");
				f[i] = ma + 1;
			}
			else
			{
				while(l != r-1)
				{
					int mid = (l + r) >> 1;
					//printf("%d\n",mid);
					assert(mid); 
					if (cmp2(p[stk[mid]],p[i]))
						l = mid;
					else r = mid;
				}
				if (l==0) f[i] = 1;
				else f[i] = f[stk[l]] + 1; 
			}
		}
		ma = max(ma,f[i]);
		
		if (stk[f[i]] == -1 || cmp2(p[i],p[stk[f[i]]]))
			stk[f[i]] = i;
			
		//printf("%d\n",f[i]);
		//for (int i=1;i<=ma;i++)printf("%d ",stk[i]);puts("");
	}
	//printf("%d\n",ma);
	double ans = 100.00*(abs(p1.x-p2.x) + abs(p1.y-p2.y));
	//printf("%.10lf %.10lf\n",pi,ans);
	ans += ma * (5 * pi - 20);
	if (ma == min(abs(p1.x-p2.x),abs(p1.y-p2.y)) + 1) ans += (5 * pi);
	printf("%.15lf\n",ans); 
}

Measured memory_bytes: 4212
//#############################################################################
//----------------------------Karma is Real------------------------------------
#include "bits/stdc++.h"
//#############################################################################
//Macros 
#define MOD 1000000007
#define eb emplace_back
#define mp make_pair
#define fr first
#define sc second
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
//Type Defs
typedef long long ll;
typedef unsigned long long ull;
//#############################################################################
using namespace std;
//#############################################################################
//Helpers
void io_handler()
{
#ifdef LOCAL_TESTING
    freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void print_matrix(vector<vector<ll>> mat){
    for(auto row: mat){
        for(auto e : row){cout << e << " ";}
        cout << endl;
    }
}
void print_vector(vector<ll> vec){
    for(auto e : vec){cout<< e <<" ";}
    cout<<endl;
}
map<int,int> get_count(vector<ll> vec){
    map<int,int> count;
    for(auto e: vec){
        if(count.find(e)!=count.end()){count[e]++;}
        else{count[e] = 1;}}
    return count;
}
//#############################################################################
//Solution
void solve(){
    ll n,w;
    cin>>n>>w;
    vector<ll> val(n),wt(n);
    for(ll i = 0; i<n; i++){
        cin>>wt[i]>>val[i];
    }
    ll mxN = accumulate(all(val),1LL);
    vector<ll> dp(mxN,1e11); dp[0] = 0;
    vector<ll> tmp(mxN,1e11); 
    for(ll i = 0; i<n; i++){
        for(ll j = 0; j<mxN; j++){
            if(val[i]>=j){
                tmp[j] = min(dp[j],wt[i]);
            } else {
                tmp[j] = min(dp[j],wt[i]+dp[j-val[i]]);
            }
        }
        swap(tmp,dp);
    }
    ll ans  = mxN;
    for(ll j = 0; j<mxN; j++){
        if(dp[j]>w){break;}
        ans = j;
    }
    cout<<ans<<endl;
}
//#############################################################################
//Driver
int main()
{
    io_handler();
    int t = 1;
    //cin>>t;
    for (int i = 0; i < t; i++){
        solve();
    }
#ifdef LOCAL_TESTING
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
//#############################################################################

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

typedef unsigned long long ll;
using namespace std;

int main()
{
    vector<vector<int>> a(3,vector<int>(3));
    vector<vector<int>> sheet(3,vector<int>(3));
    int n;
    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 3; ++j){
            cin >> a[i][j];
        }
    }
    sheet.assign(3, vector<int>(3, 0));

    cin >> n;
    bool bingo_check = false;
    for (int i = 0; i < n; ++i)
    {
        int b;
        cin >> b;
        for (int i = 0; i < 3; ++i)
        {
            for (int j = 0; j < 3; ++j)
            {
                if(a[i][j] ==b){
                    sheet[i][j] = 1;
                }
            }
        }
        for (int i = 0; i < 3; ++ i){
            int row_check = sheet[i][0] + sheet[i][1] + sheet[i][2];
            int colmn_check = sheet[0][i] + sheet[1][i] + sheet[2][i];
            if (row_check == 3)
                bingo_check = true;
            if (colmn_check == 3)
                bingo_check = true;
        }
        int x_check = sheet[0][0] + sheet[1][1] + sheet[2][2];
        if ( x_check == 3)
            bingo_check = true;
         x_check = sheet[2][0] + sheet[1][1] + sheet[0][2];
        if ( x_check == 3)
            bingo_check = true;
    }
    if ( bingo_check == true){
        cout << "Yes" << endl;
    }
        else{
            cout << "No" << endl;
        }
}

Measured memory_bytes: 256
from collections import deque


def main():
    n, m = map(int, input().split())
    adj = [[] for _ in range(n)]

    for _ in range(m):
        l, r, d = map(int, input().split())
        adj[l - 1].append((r - 1, d))
        adj[r - 1].append((l - 1, -d))

    x = [None] * n

    for i in range(n):
        if x[i] is not None:
            continue
        x[i] = 0
        q = deque()
        q.append(i)

        while q:
            u = q.popleft()
            for v, d in adj[u]:
                if x[v] is None:
                    q.append(v)
                    x[v] = x[u] + d
                elif x[v] != x[u] + d:
                    print("No")
                    exit()
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 107868
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

	int count = 0;

	for(int i = a; i <= b; i++){
		if(c % i == 0)
			count++;
	}

	cout << count << endl;

	return 0;
}




Measured memory_bytes: 3120
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli n, T;
	cin >> n >> T;
	lli ans = T;
	vector<lli> t(n);
	cin >> t[0];
	loop(i, 1, n){
		cin >> t[i];
		ans += Min(T, t[i]-t[i-1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;



int main() {
	int n;
	cin >> n;
	int count = 0;
	for (int i = 1; i <= n; i++) {
		if (i < 10)count++;
		if (i >= 100 && i < 1000)count++;
		if (i >= 10000 && i < 100000)count++;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
s = input()

dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


while s != "":
    if s.endswith(dreamer):
        s = s[:-7]
    elif s.endswith(eraser):
        s = s[:-6]
    elif s.endswith(dream):
        s = s[:-5]
    elif s.endswith(erase):
        s = s[:-5]
    else:
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 135256
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  
  val xn = inputs(0).split(" ").map(_.toInt)
  val x = xn(0)
  val n = xn(1)

  if (n == 0) {
    println(x)
  } else {
    val nums = inputs(1).split(" ").map(_.toInt)
    println(solve(x, nums))
  }

  def solve(x: Int, nums: Seq[Int]): Int = {
    val sortedNums = nums.sorted
    (0 to n).foreach { i =>
      if (!nums.contains(x - i)) {
        return x - i
      } else if(!nums.contains(x + i)){
        return x + i
      }
    }
    return -1
  }
}

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

typedef long long ll;

ll s;
ll ans=0;

void check(ll x){
    if(x<=s){
        string str=to_string(x);
        if(str.find('3')!=-1&&str.find('5')!=-1&&str.find('7')!=-1){
            ans++;
        }
    }
    return;
}

void dfs(ll x){
    check(x);
    if(x<=s){
        dfs(10*x+3);
        dfs(10*x+5);
        dfs(10*x+7);
    }
    return;
}

int main(void){
    cin>>s;
    dfs(0);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,c,k,ans=0;cin>>a>>b>>c>>k;
  ans+=min(a,k);
  if(a<k) {
    k-=a;
    if(b<k) {
      k-=b;
      ans-=k;
    }
  }
  print(ans);
  return 0;
}

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

const int N = 2e4 + 5;
int H, n;
int dp[N];

int main() {
	scanf("%d %d", &H, &n);
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	for (int i = 0; i < n; ++ i) {
		int A, B;
		scanf("%d %d", &A, &B);
		for (int j = 0; j + A < N; ++ j)
			dp[j + A] = min(dp[j + A], dp[j] + B);
	}
	int ans = 0x3f3f3f3f;
	for (int i = H; i < N; ++ i)
		ans = min(ans, dp[i]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
def median(a, n):
    if n % 2:
        return a[n // 2]
    return (a[n // 2 - 1] + a[n // 2]) / 2
n = int(input())
l,r = [], []
for _ in range(n):
    a,b = map(int, input().split())
    l.append(a)
    r.append(b)
l = sorted(l)
r = sorted(r)
left,right = median(l, n), median(r, n)
if n % 2:
    print(right - left + 1)
else:
    print(int(2 * (right - left) + 1))

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll SQ = 100000;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    vector<ll> ans;
    for(ll i=SQ;i>=1;i--){
        if(m %i == 0){
            ll a = i;
            ll b = m / i;
            if(m / a >= n){
                ans.push_back(a);
            }
            if(m / b >= n){
                ans.push_back(b);
            }
        }
    }
    sort(ans.rbegin(), ans.rend());
    cout << ans[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A, A+3);
  int K;
  cin >> K;
  for(int i=0;i<K;i++){
    A[2] *= 2;
  }
  cout << A[0] + A[1] + A[2] << endl;
}

Measured memory_bytes: 256
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod = 998244353;
ll dp[3030];
ll arr[3030];
int main()
{
    int n,i,j,k,x,y,ans,temp,curr,m;
    cin >> n >> k;
    for(i=1;i<=n;i++)
    {
        cin >> arr[i];
    }
    ll chaeng = 0;
    for(i=1;i<=n;i++)
    {
        dp[0] += 1;
        for(j=k;j>=0;j--)
        {
            if(j + arr[i] <= k) dp[j+arr[i]] = (dp[j+arr[i]] + dp[j]) % mod;
        }
        chaeng += dp[k];
        chaeng %= mod;
    }
    cout << chaeng << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;






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

	int num;

	set<int> st;
	for (int i = 0; i < N; i++)
	{
		cin >> num;
		st.insert(num);
	}

	cout << st.size();
}



Measured memory_bytes: 3608
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,num[2],a[100005],Num=0;
int main()
{
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	sort(a+1,a+n+1,greater<int>());
	for(int i=1,j;i<=n+1;++i) if(i-1>=a[i])
	{
		int ans1=a[i-1]-(i-2);
		for(j=i;a[j]==i-1;++j);
		int ans2=j-(i-2)-1;
		puts((ans1&1)&&(ans2&1)?"Second":"First");
		return 0;
	}	
}



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

int s[509][509];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m, q; cin >> n >> m >> q;
	for (int i = 1; i <= m; i++) {
		int l, r; cin >> l >> r;
		s[l][r]++;
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
	for (int i = 1; i <= q; i++) {
		int p, q; cin >> p >> q; p--;
		cout << s[q][q] - s[p][q] - s[q][p] + s[p][p] << '\n';
	}
	return 0;
}


Measured memory_bytes: 1920
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    K = int(input())

    ans = INF
    for i in range(N + 1):
        ans = min(ans, 2 ** i + (N - i) * K)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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; }

int main() {
  ll x;
  cin >> x;
  int ans = 0;
  ll now = 100;
  while (now<x) {
    now = now + now/100;
    ans++; 
  }
  cout << ans << endl;

  return 0;
}

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

int dp[101][4][4][4];

//ACGT->0123

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

  // 長さ0の文字列は1
  // 0,1,2の制約しかない
  // S = 333SとしてOK
  dp[0][3][3][3] = 1;

  int mod = 1000000007;
  for (int len = 0; len < N; len++) {
    for (int c1 = 0; c1 < 4; c1++) {
      for (int c2 = 0; c2 < 4; c2++) {
        for (int c3 = 0; c3 < 4; c3++) {
          if (dp[len][c1][c2][c3] == 0) continue;
          for (int a = 0; a < 4; a++) {
            if (a == 2 && c1 == 1 && c2 == 0) continue;
            if (a == 2 && c1 == 0 && c2 == 1) continue;
            if (a == 1 && c1 == 2 && c2 == 0) continue;
            if (a == 2 && c1 == 1 && c3 == 0) continue;
            if (a == 2 && c2 == 1 && c3 == 0) continue;

            // S = ..... c3 c2 c1
            // nextS = ...... c2 c1 a
            dp[len+1][a][c1][c2] += dp[len][c1][c2][c3];
            dp[len+1][a][c1][c2] %= mod;
          }
        }
      }
    }
  }
  int ans = 0;
  for (int c1 = 0; c1 < 4; c1++) {
    for (int c2 = 0; c2 < 4; c2++) {
      for (int c3 = 0; c3 < 4; c3++) {
        ans += dp[N][c1][c2][c3];
        ans %= mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int n, m, i;

int main (void)
{
	scanf("%d%d",&n,&m);
	if (m&1) {
		for (i=1; i<=m>>1; i++) printf("%d %d\n",i,m-i+1);
		for (i=1; i<=(m+1)>>1; i++) printf("%d %d\n",i+m,2*m+2-i);
	}
	else {
		for (i=1; i<=m>>1; i++) printf("%d %d\n",i,m+2-i);
		for (i=1; i<=m>>1; i++) printf("%d %d\n",i+m+1,2*m+2-i);
	}
	return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
typedef long long ll;
const int p=1e9+7;
int n,t,ans=1;
int main()
{
    scanf("%d",&n);
    for(int i=1,x;i<=n;++i)
    {
        scanf("%d",&x),++t;
        if(x<2*t-1)ans=(ll)ans*t--%p;
    }
    while(t)ans=(ll)ans*t--%p;
    printf("%d\n",ans);
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n, m;
    cin >> n >> m;
    double sum = 0;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if(a[i] >= 1.0 * sum / (4.0 * (double)m)) cnt++;
    }
    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N_MAX=100000;
int gcd(int m, int n)
{
  while (m>0&&n>0){
    n = n % m;
    if (n>0)
      m = m % n;
  }
  if (n==0)
    return m;
  else
    return n;
}
int main()
{
  int n,m,i,res=1;
  int a[N_MAX],b[N_MAX],c[N_MAX];
  cin >> n;
  for(i=0;i<n;i++)
    cin >> a[i];
  b[0]=a[1];
  m=a[0];
  for(i=1;i<n;i++){
    b[i]=m;
    m=gcd(a[i],m);
  }
  c[n-1]=a[n-2];
  m=a[n-1];
  for(i=n-2;i>=0;i--){
    c[i]=m;
    m=gcd(a[i],m);
  }
  for(i=0;i<n;i++){
    m=gcd(b[i],c[i]);
    if(m>res) res=m;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1408
import java.math.BigInteger;
import java.util.Scanner;
    class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        for (int i =0;i < a;i++){
            BigInteger big = sc.nextBigInteger().add(sc.nextBigInteger());
            System.out.println(big.toString().length()>80?"overflow":big.toString());

        }
    }
}

Measured memory_bytes: 18424
#include <stdio.h>

int main(void){
  int i;

  char s[4], t[4];
  scanf(" %s", s);
  scanf(" %s", t);

  int ans=0;
  for(i=0; i<3; i++){
    if(s[i]==t[i]){
      ans++;
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
typedef long long int ll;
long v[3000][3000];
long dp[3001][3001][4];
int main() {
    int r,c,k;
    scanf("%d %d %d",&r,&c,&k);
    for (int i=0;i<k;i++) {
        int rn,cn;
        long vn;
        scanf("%d %d %ld",&rn,&cn,&vn);
        v[rn-1][cn-1]=vn;
    }
    for (int i=0;i<r;i++) {
        for (int j=0;j<c;j++) {
            for (int l=2;l>=0;l--) {
                dp[i][j][l+1]=max(dp[i][j][l+1],dp[i][j][l]+v[i][j]);
            }
            for (int l=0;l<4;l++) {
                dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][l]);
                dp[i][j+1][l]=max(dp[i][j+1][l],dp[i][j][l]);
            }
        }
    }
    long ans=0;
    for (int l=0;l<4;l++) ans=max(ans,dp[r-1][c-1][l]);
    printf("%ld",ans);
    return 0;
}

Measured memory_bytes: 353424
import java.util.*;
public class Main{

    public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int W = scan.nextInt();
int H = scan.nextInt();
int x = scan.nextInt();
int y = scan.nextInt();
int r = scan.nextInt();

if((x-r <0 || x + r > W) || (y - r < 0 || y + r > H)){
    System.out.println("No");

} else if((x - r >= 0 && x + r <= W) || (y -r >=0 && y + r <= H)){
    System.out.println("Yes");

} 
    }
}



Measured memory_bytes: 26368
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int grid[100][100];
int cost[2][100][100];
int back_dist[100][100];
int ans = 0;
int dist[100][100];

int h, w, m;

int dfs(pair<int, int> now, pair<int, int> back, pair<int, int> target) {
    int reflect = 0;
    if (now == target) {
        reflect = 1;
    }
    else {
        int dx[4] = { 1,-1,0,0 };
        REP(t, 4) {
            int x = now.first + dx[t];
            int y = now.second + dx[3 - t];
            if (x >= 0 && x < h && y >= 0 && y < w) {
                if (mp(x, y) == back) continue;
                if (grid[x][y] == 1) continue;
                dist[x][y] = dist[now.first][now.second] + 1;
                if (dfs(mp(x, y), now, target) == 1) {
                    reflect = 1;
                    break;
                }
            }
        }
    }
    if (reflect == 1) {
        if (back_dist[now.first][now.second] == -1e9) {
            ans += cost[1][now.first][now.second];
        }else
        ans += min(cost[1][now.first][now.second], cost[0][now.first][now.second] * (dist[now.first][now.second] - back_dist[now.first][now.second]));
        back_dist[now.first][now.second] = dist[now.first][now.second];
        return 1;
    }
    return 0;
}

void solve() {
    cin >> h >> w >> m;
    REP(i, h) {
        string s;
        cin >> s;
        REP(q, w) {
            if (s[q] == '#') {
                grid[i][q] = 1;
            }
        }
    }
    REP(i, 3) {
        REP(q, h) {
            REP(j, w) {
                int hogge;
                cin >> hogge;
                cost[min(1LL, i)][q][j] += hogge;
            }
        }
    }
    REP(i, h) {
        REP(q, w) {
            back_dist[i][q] = -1e9;
        }
    }
    pair<int, int> now;
    cin >> now.first >> now.second;
    REP(i, m-1) {
        pair<int, int> target;
        cin >> target.first >> target.second;
        dfs(now, mp(-1,-1), target);
        now = target;
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}



Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;

bool passed[101][101];
vector<pair<int,int> > d;
int cnt=0;

void dfs(int x,int y,int left){
  if(left==0)
    cnt++;
  else{
    if(passed[y][x]){
      int ny=y;
      int nx=x-1;
      if(nx<0){
	ny--;nx=3;
	if(ny<0)
	  return;
      }
      dfs(nx,ny,left);
    }
    else{
      passed[y][x]=true;
      for(int i = 0; i < d.size(); i++){
	int ny=d[i].first+y;
	int nx=d[i].second+x;
	if(ny>=0&&nx>=0&&ny<4&&nx<4&&!passed[ny][nx]){
	  passed[ny][nx]=true;
	  int nny=y;int nnx=x-1;
	  if(nnx<0){
	    nny--;nnx=3;
	  }
	  dfs(nnx,nny,left-2);
	  passed[ny][nx]=false;
	}
      }
      passed[y][x]=false;
    }
  }
}

int main(){
  while(1){
    memset(passed,0,sizeof(passed));
    d.clear();cnt=0;
    for(int i = 0; i < 4; i++){
      int x,y;
      cin>>x;
      if(x>4)
	return 0;
      cin>>y;
      d.push_back(make_pair(-y,-x));
    }
    dfs(3,3,16);
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	int x; cin >> x;
	int count500 = 0;
	int count5 = 0;

	while (x >= 500) {
		x -= 500;
		count500++;
	}
	while (x >= 5) {
		x -= 5;
		count5++;
	}

	int ans = 1000 * count500 + 5 * count5;
	dunk(ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>

using namespace std;

long long n;

struct edge{
    int a, b, c;
};

vector<edge> edges;

bool comp(edge a, edge b)
{
    return a.c > b.c;
}

int h[500000];
int root[500000];
int ce[500000];
int cv[500000];

int Root(int x)
{
    if (x == root[x])
        return x;
    return root[x] = Root(root[x]);
}

void Merge(int a, int b)
{
    a = Root(a);
    b = Root(b);
    if (a == b) return;
    if (h[a] == h[b])
        h[a]++;
    if (h[a] > h[b])
    {
        root[b] = a;
        ce[a] += ce[b] + 1;
        cv[a] += cv[b];
    }
    else
    {
        root[a] = b;
        ce[b] += ce[a] + 1;
        cv[b] += cv[a];
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> n >> x >> x;
    for (int i = 0; i < 500000; i++)
    {
        root[i] = i;
        cv[i] = 1;
    }
    for (int i = 0; i < n; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        edges.push_back({a, b + 100500, c});
    }
    sort(edges.begin(), edges.end(), comp);
    long long ans = 0;
    for (int i = 0; i < edges.size(); i++)
    {
        int a = edges[i].a;
        int b = edges[i].b;
        int c = edges[i].c;
        a = Root(a);
        b = Root(b);
        if (a == b)
        {
            if (ce[a] + 1 <= cv[a])
            {
                ans += c;
                ce[a]++;
            }
        }
        else
        {
            int total_edges = ce[a] + ce[b] + 1;
            int total_vertex = cv[a] + cv[b];
            if (total_edges <= total_vertex)
            {
                ans += c;
                Merge(a, b);
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 7928
<?php
// 縦h x 横w の迷路を木構造に変換（壁=# 道=.）
define('BLACK', '#');
define('WHITE', '.');
fscanf(STDIN, '%d %d', $h, $w);
for ($i  = 0; $i < $h; $i++) {
    $s[] = trim(fgets(STDIN));
}
$g = array_fill(0, $h * $w, []);
$cnt_w = 0;
for ($i  = 0; $i < $h * $w; $i++) {
    $l = intval(floor($i / $w));
    $m = $i % $w;

    if ($s[$l][$m] === BLACK) continue;

    $cnt_w++;
    if ($m < $w - 1 && $s[$l][$m + 1] === WHITE) {
        $g[$i][] = $i + 1;
        $g[$i + 1][] = $i;
    }

    if ($l < $h - 1 && $s[$l + 1][$m] === WHITE) {
        $g[$i][] = $i + $w;
        $g[$i + $w][] = $i;
    }
}

// BFS（幅優先探索）：最短経路アルゴリズムとして活用
$n = $h * $w;
$q = new SplQueue(); // キューを用意
$dist = array_fill(0, $n, -1); // 距離を格納する配列（-1の場合はその頂点が未発見）

$dist[0] = 0; // 頂点0からの距離格納配列
$q->enqueue(0); // キューに0を追加

while (!$q->isEmpty()) {
    $v = $q->dequeue();

    foreach ($g[$v] as $next_v) {
        if ($dist[$next_v] !== -1) continue; // 発見済み

        $dist[$next_v] = $dist[$v] + 1;
        $q->enqueue($next_v);
    }
}
if ($dist[$h * $w - 1] === -1) exit('-1');
echo $cnt_w - 2 - ($dist[$h * $w - 1] - 1);


Measured memory_bytes: 5240
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = getLine >> solve <$> f >>= print
  where
    f = readil B.readInteger <$> B.getLine

solve :: [Integer] -> Integer
solve xs = minimum . map (\x -> abs (w - 2 * x)) . scanl' (+) 0 $ xs
  where
    w = sum xs

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')


Measured memory_bytes: 22908
import numpy as np
S = input()
T = input()
SA = np.array([0]+[s == 'A' for s in S]).cumsum()
SB = np.array([0]+[s == 'B' for s in S]).cumsum()
TA = np.array([0]+[s == 'A' for s in T]).cumsum()
TB = np.array([0]+[s == 'B' for s in T]).cumsum()

q = int(input())
res_list = []

for _ in range(q):
    a, b, c, d = map(int, input().split())
    a_cnt = ((SA[b] - SA[a-1]) - (TA[d] - TA[c-1])) % 3
    b_cnt = ((SB[b] - SB[a-1]) - (TB[d] - TB[c-1])) % 3
    if a_cnt == b_cnt:
        res_list.append('YES')
    else:
        res_list.append('NO')
    
for i in range(q):
    print(res_list[i])

Measured memory_bytes: 21504
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 1000005;
int n,a[MAXN];
char str[MAXN];
inline int c(int n, int m)
    { return (n&m)==m; }
inline int calc()
{
	int res = 0;
	for(int i = 1; i<=n; i++)
	    if(c(n-1,i-1))
	        res ^= a[i]&1;
	return res; 
}

int main()
{
    scanf("%d",&n);
    scanf("%s",str+1);
    for(int i = 1; i<=n; i++)
    	a[i] = str[i]-'1';
    bool flag = false;
	for(int i = 1; i<=n; i++)
        flag |= a[i]==1;
	if(flag) 
	    cout << calc() << endl;
	else
	{
        for(int i = 1; i<=n; i++)
            a[i] >>= 1;
        cout << 2*calc() << endl;
	}
	return 0;
}


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

using namespace std;

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

  int x;
  cin >> x;

  int ans = 1;
  if ((x / 100) * 5 < (x % 100)) {
    ans = 0;
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	vector<int>a(3);
	rep(i, 3) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	if (a[0] + a[1] == a[2])print("Yes");
	else print("No");
}

Measured memory_bytes: 3628
import java.util.*;
import java.io.*;
public class Main{
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      String s = st.nextToken();
      st = new StringTokenizer(br.readLine());
      String t = st.nextToken();
     int count = 0;
     for(int i = 0; i < s.length(); i++)
       if(s.charAt(i) != t.charAt(i))
         count++;
     out.println(count);
      out.close();
   }
}

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

int main(){
    int n,a,b;
   cin >> n;
    cout << (1+n)*n/2<< endl;
    
  return 0;
}


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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    string st[n];
    for(int i=0;i<n;i++){
    	cin >> st[i];
    	reverse(st[i].begin(),st[i].end());
    	st[i]='#'+st[i];
    }
    sort(st,st+n,[&](auto a,auto b){
    	return a.size()>b.size();
    });
    vector <vector <int> > f[n];
    for(int i=0;i<n;i++){
    	f[i]=vector <vector <int> > (st[i].size(),vector <int> (26,0));
    	for(int j=1;j<st[i].size();j++){
    		for(int k=0;k<26;k++)
    			f[i][j][k]=f[i][j-1][k];
    		f[i][j][st[i][j]-'a']++;
    	}
    }
    const int N=1e6+9;
    int trie[N][26],cnt[N][26],sz=0;
    ll ans=0;
    memset(trie,-1,sizeof trie);
    memset(cnt,0,sizeof cnt);
    for(int i=0;i<n;i++){
    	int cur=0,len=st[i].size();
    	for(int j=1;j<len;j++){
    		for(int k=0;k<26;k++){
    			if(f[i][len-1][k]>f[i][j-1][k])
    				cnt[cur][k]++;
    		}
    		int x=st[i][j]-'a';
    		if(j==len-1){
    			ans+=cnt[cur][x]-1;
    		}
    		if(trie[cur][x]==-1)
    			trie[cur][x]=++sz;
    		cur=trie[cur][x];
    	}
    }
    cout << ans;
}

Measured memory_bytes: 375236
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


n = ni()
a = na()

a.sort(reverse=True)
l = list()
for key, gr in groupby(a):
    if len(l) == 2:
        break
    num = len(list(gr))
    if num >= 2:
        l.append(key)
    if num >= 4:
        l.append(key)
print(l[0] * l[1] if len(l) >= 2 else 0)


Measured memory_bytes: 14616
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long sum=0,cou[100005]={0};
	for(int i=0;i<n;i++)
	{
		long long x;
		cin>>x;
		cou[x]++;
		sum=sum+x;
	}
	long long q;
	cin>>q;
	for(int i=0;i<q;i++)
	{
		long long b,c;
		cin>>b>>c;
		sum=sum-cou[b]*b+cou[b]*c;
		cou[c]+=cou[b];
		cou[b]=0;
		cout<<sum<<endl;
	}
	return 0;
}
		



Measured memory_bytes: 3956
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  string s; cin >> s;
  if (s.size() == 1) {
    cout << s << CRLF;
    return;
  }
  bool flg = false;
  for (int i = s.size()-1; i > 0; --i) {
    if (s[i]-'0' != 9) {
      flg = true;
    }
  }
  if (flg) {
    s[0] -= 1;
    std::fill(s.begin()+1, s.end(), '9');
  }
  auto ans = boost::accumulate(s, 0, [](int r, char c){ return r + (c - '0'); });
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

int main() {
  int A, B, max_number;
  cin >> A >> B;
  max_number = A + B;
  if (A * B > max_number){
    max_number = A * B;
  }
  if (A - B > max_number) {
    max_number = A - B;
  }
  cout << max_number;
}


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

int main(){
    string S;
    cin >> S;
    //cout << S.back() << '\n';

    if(S.back() == 's'){
        cout << S << "es" << '\n';
    }else{
        cout << S << "s" << '\n';
    }
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <cstdio>
using namespace std;

#define INF 1e9

int min(int a, int b){ return a < b ? a : b; }

int main(void){
  while(true){
    int n, m, p, a, b;
    cin >> n >> m >> p >> a >> b;
    if(n == 0 && m == 0 && p == 0 && a == 0 && b == 0){ break; }
    --a; --b;

    // ??¬??????????????±???????????????
    vector<int> t(n);
    for(int i = 0; i < n; i++){ cin >> t[i]; }

    // ???????????±???????????????
    int x, y, z;
    vector<vector<pair<int, int> > > adjlist(m);
    for(int i = 0; i < p; i++){
      cin >> x >> y >> z;
      --x; --y;
      adjlist[x].push_back(make_pair(z, y));
      adjlist[y].push_back(make_pair(z, x));
    }

    // ????????????????????????
    vector<vector<double> > result(m, vector<double>(1 << n, INF));
    priority_queue<pair<double, pair<int, int> > > wait;

    wait.push(make_pair(0, make_pair(0, a)));
    for(int i = 0; i < (1 << n); i++){ result[a][i] = 0; }

    while(!wait.empty()){
      double nowcost = -wait.top().first;
      int nowticket = wait.top().second.first;
      int nowpoint = wait.top().second.second;
      wait.pop();
      if(nowcost > result[nowpoint][nowticket]){ continue; }

      for(int i = 0; i < adjlist[nowpoint].size(); i++){
        int nextpoint = adjlist[nowpoint][i].second;
        for(int j = 0; j < n; j++){
          if((nowticket & (1 << j)) == 0){
            int nextticket = nowticket | (1 << j);
            double nextcost = nowcost + ((double)adjlist[nowpoint][i].first / t[j]);
            if(result[nextpoint][nextticket] > nextcost){
              result[nextpoint][nextticket] = nextcost;
              wait.push(make_pair(-nextcost, make_pair(nextticket, nextpoint)));
            }
          }
        }
      }
    }

    // ??????????¨????????????????
    double mincost = INF;
    for(int i = 0; i < (1 << n); i++){
      if(mincost > result[b][i]){ mincost = result[b][i]; }
    }
    if(mincost == INF){ cout << "Impossible" << endl; }
    else{ printf("%.4f\n", mincost); }
  }

  return 0;
}

Measured memory_bytes: 2768