akhauriyash/Code-Regression huggingface dataset:
#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 cur = nil -> next;
  while(cur != nil && cur -> key != key) {
    cur = cur -> next;
  }
  return cur;
}

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(){
  deleteNode(nil -> next);
}

void deleteLast(){
  deleteNode(nil -> prev);
}

void delete(int key){
  deleteNode(listSearch(key));
}


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++ ){
    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--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 32948
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]

direction = [(1, 0), (0, 1), (-1, 0), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1)]

for y in range(h):
    for x in range(w):
        if s[y][x] != '.':
            continue
        p_sum = 0
        for z in direction:
            if 0 <= y + z[0] < h and 0 <= x + z[1] < w:
                if s[y + z[0]][x + z[1]] == '#':
                    p_sum += 1
        s[y][x] = p_sum

for y in range(h):
    for x in range(w):
        print(s[y][x], end='')
    print()


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

int main()
{
    int x,y,i,flag;
    cin>>x>>y;
    flag=0;
    for (i = 0; i <= x; i++)
    {
        if (2*i+4*(x-i)==y)
        {
            flag=1;
            break;
        }
    }
    if (flag==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;
const int MAX=500;
const long long INF =  long (1e15);
long long  a[MAX], dp[MAX][MAX],n,ps[MAX];

long long calc(int a , int b) {
    return ps[b] - ps[a-1];
}


long long solve(int start, int end) {
    if( start == end || start > end) {
        return 0;
    }
    if( start + 1 == end) {
        return a[start] + a[end];
    }
    if(dp[start][end] != -1) {
        return dp[start][end];
    }
    long long res = INF;
    for(int split = start; split < end; split++) {
        res = min( res , solve(start, split) + solve(split + 1, end) + ps[end] - ps[start - 1]);
    }
    return dp[start][end]=res;
}



int main() {
    ios::sync_with_stdio(false);
   
    cin >> n;

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

    for(int i = 0; i < MAX ; i++) {
        for(int j = 0; j < MAX; j++) {
            dp[i][j] = -1;
        }
    }

    cout << solve(1,n) << endl;
    return 0;
}

Measured memory_bytes: 2304
N = int(input())
p = input().split()
p = [int(x) for x in p]

q = sorted(p)
c = 0
for i in range(N):
  if p[i] != q[i]:
    c +=1
if c == 0 or c == 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
#define all(x) x.begin(),x.end()
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
    fast;
    ll h = 1;
    //scanf("%lld", &h);
    while(h--){
        string s;
        ll n;
        cin >> n >> s;
        ll out = 0;
        for(int  i = 1; i <= n - 2; i++){
            ll dist = min((ll)i, (ll)n - (ll)i - (ll)1);
            for(int l = 1; l <= dist; l++){
                if(s[i] != s[i - l] && s[i - l] != s[i + l] && s[i] != s[i + l]){
                    out ++;
                }
            }
        }
        ll r = 0, g = 0, b = 0;
        for(auto x : s){
            if(x == 'R'){
                r++;
            }
            if(x == 'G'){
                g++;
            }
            if(x == 'B'){
                b++;
            }
        }
        cout << r * g * b - out << endl;
}
}

Measured memory_bytes: 3660
fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    let c = read::<usize>();
    let d = read::<usize>();
    let e = read::<usize>();
    let v = [a, b, c, d, e];
    let k = read::<usize>();
    for i in 0..4 {
        for j in (i+1)..5 {
            if v[j] - v[i] > k {
                println!(":(");
                return;
            }
        }
    }
    println!("Yay!");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int n,c[510],s[510],f[510],t=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n-1;i++){
		cin>>c[i]>>s[i]>>f[i];
	}
	for(int j=1;j<=n-1;j++){
		t=0;
		for(int i=j;i<=n-1;i++){
			if(s[i]>t){
				t=s[i];
			}
			while(t%f[i]!=0){
				t++;
			}
			t+=c[i];
		}
		cout<<t<<endl;	
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int r,d,x;
    cin>r>d>x;
    REP(i,10){
        x=r*x-d;
        cout<x<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define pb push_back

int main(){
	int h, w;
	cin>>h>>w;
	int pos;
	char let;
	string alf="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	forn(i, h){
		forn(j, w){
			string s;
			cin>>s;
			if(s=="snuke"){
				pos=i+1;
				let=alf[j];
			}
		}
	}
	cout<<let<<pos<<endl;
}


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

typedef long long int ll;
const ll INF = 1LL << 28;

ll N;
vector<ll> num;
map<ll,ll> memo;
queue<ll> q;
function<ll(ll)> seki;

int main() {
    cin >> N;
    q.push(2LL); q.push(8LL);
    while (q.size()) {
        ll n = q.front(); q.pop();
        num.push_back(n);
        if (n <= 1e18) {
            q.push(n * 10LL + 8LL);
            q.push(n * 10LL + 2LL);
        }
    }


    sort(num.begin(), num.end());
    
    seki = [&](ll n) -> ll {
        if (memo.find(n) != memo.end()) return memo[n];

        int i = (int)(lower_bound(num.begin(), num.end(), n) - num.begin());
        memo[n] = -INF;
        if (num[i] == n) memo[n] = 1;
        for (; i > -1; i--) {
            if (n % num[i] == 0 ) {
                memo[n] = max(memo[n], seki(n / num[i]) + seki(num[i]));
            }
        }


        return memo[n];
    };

    int ans = seki(N);
    if (ans > 0) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 15404
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int main(){
  int a,b;
  cin>>a;
  vector<int>n(a);
  for(int i=0;i<a;++i){cin>>n[i];}
  cin>>b;
  vector<int>m(b);
  for(int i=0;i<b;++i){cin>>m[i];}
  
  cout<<includes(all(n),all(m))<<endl;
}


Measured memory_bytes: 4428
#include <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 0; i < 2; i++)
	{
		if (N % 10 == 9)
		{
			printf("Yes\n");
			return 0;
		}
		N /= 10;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
int main()
{
   int x,y;
   int a[]={0,1,3,1,2,1,2,1,1,2,1,2,1,1};
   cin>>x>>y;
 if(a[x]==a[y])
        cout<<"Yes";
    else
        cout<<"No";
    cout<<nl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
ll M = 1e9 + 7;
ll fp(ll b, ll p)
{
	ll ans = 1;
	while (p)
	{
		if (p & 1)
			ans = ans * b % M;
		p /= 2;
		b = b * b % M;
	}
	return ans % M;
}
ll inv(ll x)
{
	return fp(x, M - 2);
}
void solve()
{
	ll n, k;
	cin >> n >> k;
	k = k % M;
	std::vector<int> v(n);
	for (auto &i : v)
		cin >> i;
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		ll l = 0, r = 0;
		for (int j = 0; j < n; j++)
		{
			if (v[j] < v[i])
			{
				if (j < i)
					l++;
				else
					r++;
			}

		}
		l %= M;
		r %= M;
		ans += (l * k % M * (k - 1) % M * inv(2)) % M;
		ans %= M;
		ans += (r * k % M * (k + 1) % M * inv(2)) % M;
		ans %= M;
		// cout << v[i] << ' ' << l << r << endl;

	}
	cout << (ans % M);


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



	int t;
	// cin >> t;
	t = 1;
	while (t--) solve();


	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
 
public class Program
{
    public void Proc() {
        // T の末尾に dream dreamer erase eraser のいずれかを追加する。
        Reader.IsDebug = false;
        string inpt = Reader.ReadLine();
        string[] words = new string[]{"dreamer","eraser", "erase", "dream"};
        int idx = inpt.Length;
        while(idx > 0) {
            bool isMatch = false;
            foreach(string word in words) {
                if(idx < word.Length) {
                    continue;
                }
                if(inpt.Substring(idx-word.Length, word.Length).Equals(word)) {
                    isMatch = true;
                    idx -= word.Length;
                    break; 
                }
            }
            if(!isMatch) {
                break;
            }
        }
        Console.WriteLine(idx == 0?"YES":"NO");

    }

    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"

 erasedream

";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 4696
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use std::cmp::max;

fn main() {
    input! {
    h: usize,
    w: usize,
    mut g: [Chars; h]
    }
    for i in 0..h {
        g[i].push('#')
    }
    g.push(vec!['#'; w + 1]);
    let (mut s, mut t) = (0, 0);
    let mut gc = vec![vec![0; w]; h];
    for i in 0..h {
        s = 0;
        t = 0;
        let mut c = 0;
        while t <= w {
            if g[i][t] == '.' {
                c += 1;
            } else {
                for j in s..t {
                    gc[i][j] += c;
                }
                s = t + 1;
                c = 0;
            }
            t += 1;
        }
    }
    for i in 0..w {
        s = 0;
        t = 0;
        let mut c = 0;
        while t <= h {
            if g[t][i] == '.' {
                c += 1;
            } else {
                for j in s..t {
                    gc[j][i] += c;
                }
                s = t + 1;
                c = 0;
            }
            t += 1;
        }
    }
    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            ans = max(gc[i][j], ans);
        }
    }
    println!("{}", ans - 1);
}


Measured memory_bytes: 37356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  if (N.at(0) == N.at(1) || N.at(1) == N.at(2) || N.at(2) == N.at(3)) {
    cout << "Bad" << endl;
  }
  else {
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
    ll n, a, b;cin >> n >> a >> b;
    if ((a + b) % 2 == 0) cout << (b - a) / 2 << endl;
    else cout << min(a - 1,n - b) + 1 + (b - a - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
typedef long long int ll;
#define pb         push_back
#define mp         make_pair
#define F          first
#define S          second
#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define pll        pair<ll,ll>
#define pii        pair<int,int>
#define all(v)     v.begin(),v.end()
#define M          1000000321

using namespace std;
bool isPrime(ll n)
{
    if(n<=1)
        return false;
    if(n<=3)
        return true;
    if(n%2==0 || n%3==0)
        return false;

    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0|| n%(i+2)==0)
            return false;

    return true;
}

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

}

bool sortbydesc(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    if(a.S < b.S)
        return true;
    else
        return false;
}



int main()
{
 ios::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 ll n;
 cin >> n;
 vector<ll> a,b,c;
 a.pb(0);
 b.pb(0);
 c.pb(0);
 ll x,y,z;
 fl(i,0,n)
 {
    cin>>x>>y>>z;
    a.pb(x);
    b.pb(y);
    c.pb(z);
 }
 ll dp[n+1][3];
 dp[1][0]=a[1];dp[1][1]=b[1];dp[1][2]=c[1];
 fl(i,2,n+1)
 {
    dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
    dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
    dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
 }
 cout << max(max(dp[n][0],dp[n][1]),dp[n][2]);
}

Measured memory_bytes: 5216
#include <iostream>
#include <string>

using namespace std;

main(){
  string in;
  while(cin >> in){
    int joi=0, ioi=0;
    for(int i=2;i<in.size();i++){
      if(in[i]=='I' && in[i-1]=='O'){
	if(in[i-2]=='J'){
	  joi++;
	}else if(in[i-2]=='I'){
	  ioi++;
	}
      }
    }
    cout << joi << endl;
    cout << ioi << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
  
using namespace std;
  
const int N = 1e5;
  
int n, m, s[N], t[N], p[N], sum[2][N];
  
main(){
  cin >> n >> m;
  for(int i=0;i<n;i++) cin >> s[i] >> t[i];
  for(int i=0;i<m;i++) cin >> p[i];
  sort(p, p+m);
  fill(sum[0], sum[2], 0);
  for(int i=0;i<m-1;i++){
    for(int j=0;j<2;j++) sum[j][i+1] = sum[j][i];
    sum[i%2][i+1] += p[i+1] - p[i];
  }
  long long ans = 0;
  for(int i=0;i<n;i++){
    bool f = false;
    if(s[i] > t[i]){
      swap(s[i], t[i]);
      f = true;
    }
    int l = upper_bound(p, p+m, s[i]) - p;
    int r = upper_bound(p, p+m, t[i]) - p - 1;
    if(l > r) ans += t[i] - s[i];
    else{
      if(f){
        ans += t[i] - p[r];
        if((r - l) % 2) ans += p[l] - s[i];
        ans += sum[r%2][r] - sum[r%2][l];
      }else{
        ans += p[l] - s[i];
        if((r - l) % 2) ans += t[i] - p[r];
        ans += sum[1-l%2][r] - sum[1-l%2][l];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3132
from itertools import accumulate

def f(n,k):
    lim = int((n + 0.1) ** 0.5) + 1
    ws = []
    s = 0
    for i in range(1, lim):
        w = n // i - n // (i + 1)
        ws.append(w)
        s += w
    ws += [1] * (n - s)
    dp=ws
    m = len(ws)
    for _ in range(k - 1):
        dp=[s*w%md for s,w in zip(accumulate(dp[::-1]),ws)]
    print(sum(dp) % md)
md=10**9+7
n,k=map(int,input().split())
f(n,k)


Measured memory_bytes: 11032
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
ll n,m,i,j,k,l,t,arr[sz];
int main()
{
    scanf("%lld %lld",&n,&m);
    n=(n*(n-1))/2;
    m=(m*(m-1))/2;
    printf("%lld\n",m+n);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    int y, x;
    vector<vector<int>> tizu(21, vector<int>(21, 0));
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      tizu[y][x] = 1;
    }
    y = x = 10;
    int m;
    cin >> m;
    char d;
    int l, dir, gem_count = 0;
    int dirX[] = {0, 1, 0, -1};
    int dirY[] = {1, 0, -1, 0};
    for (int i = 0; i < m; i++) {
      cin >> d >> l;
      switch(d) {
        case 'N':
          dir = 0;
          break;
        case 'E':
          dir = 1;
          break;
        case 'S':
          dir = 2;
          break;
        case 'W':
          dir = 3;
          break;
      }
      for (int j = 0; j < l;j++){
        y = y + dirY[dir];
        x = x + dirX[dir];
        //cout << "y=" << y << " x=" << x << endl;
        if(tizu[y][x]==1){
          gem_count++;
          tizu[y][x] = 0;
          //cout << "hello" << endl;
        }
      }
    }
    cout << (gem_count == n ? "Yes" : "No") << endl;
  }
  return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef string str;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






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


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  vll num(n) ;
  REP(i,n){
    cin >> num[i] ;
  }
  ll ans = num[0] ;
  REP(i,n-1){
    ans = lcm(ans,num[i+1]) ;
  }
  cout << ans <<endl ;
  
  
  
  return 0 ;
}




Measured memory_bytes: 256
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt

import numpy as np

import bisect
import re
import heapq


from copy import deepcopy
import itertools


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




from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,m = mi()
    a = li()
    atmp = deepcopy(a)
    cnt = [0 for i in range(n)]

    flag = True
    while flag:
        for i in range(n):
            if not a[i] % 2:
                a[i] //=2
                cnt[i]+=1
            else:
                flag = False
    cnttmp = cnt[0]
    for i in range(n):
        if not cnttmp == cnt[i]:
            print(0)
            exit()
    

    k = 1
    for i in range(n):
        atmp[i] //= 2
    for i in range(n):
        k = lcm(atmp[i],k)
        if m < k:
            print(0)
            exit()
    # print(k)
    anstmp = m//k
    print(anstmp//2+anstmp%2)

    
main()


Measured memory_bytes: 24168
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var ss=Console.ReadLine().Split(' ');
			int n=int.Parse(ss[0]);
			int p=int.Parse(ss[1]);
			int q=int.Parse(ss[2]);
			if(n==0 && p==0 && q==0)break;
			Sol mySol=new Sol(n,p,q);
			Console.WriteLine(mySol.Ans);
		}
	}
}

class HrsInterval{
	public int Start{get;set;}
	public int End{get;set;}
	public int Range_Minute{
		get{
			int h0=this.Start/100;
			int h1=this.End/100;
			int m0=this.Start%100;
			int m1=this.End%100;
			if(m1<m0){
				h1--;
				m1+=60;
			}
			return (h1-h0)*60+m1-m0;
		}
	}
	public HrsInterval(int start,int end){
		this.Start=start;
		this.End=end;
	}
	
	public static HrsInterval createIntersection(HrsInterval I1,HrsInterval I2){
		//共通部分を生成。ない場合はnullを返す
		HrsInterval Ret=null;
		if(I1.Start<I2.Start){
			if(I1.End<=I2.Start)Ret=null;
			if(I1.End>I2.Start){
				if(I2.End<I1.End)Ret=new HrsInterval(I2.Start,I2.End);
				if(I2.End>=I1.End)Ret=new HrsInterval(I2.Start,I1.End);
			}
		}
		if(I1.Start>=I2.Start){
			if(I2.End<=I1.Start)Ret=null;
			if(I2.End>I1.Start){
				if(I1.End<I2.End)Ret=new HrsInterval(I1.Start,I1.End);
				if(I1.End>=I2.End)Ret=new HrsInterval(I1.Start,I2.End);
			}
		}
		return Ret;
	}
}


class Sol{
	int ans;
	public int Ans{
		get{return ans;}
	}
	int watchstart;
	int watchend;
	
	public Sol(int n,int p,int q){
		
		watchstart=p;
		watchend=q;
		
		List<HrsInterval> L1=new List<HrsInterval>();
		List<HrsInterval> L2=new List<HrsInterval>();
		
		for(int i=0;i<n;i++){
			var d =int.Parse(Console.ReadLine());
			var s =Console.ReadLine().Split(' ');
			var arr =Array.ConvertAll(s,elem=>int.Parse(elem));
			if(i==0){
				for(int j=0;j<d;j++){
					L2.Add(new HrsInterval(arr[2*j],arr[2*j+1]));
				}
			}
			if(i>0){
				L2.Clear();
				for(int j=0;j<d;j++){
					HrsInterval I;
					HrsInterval P=new HrsInterval(arr[2*j],arr[2*j+1]);
					foreach(HrsInterval Q in L1){
						I=HrsInterval.createIntersection(Q,P);
						if(I!=null)L2.Add(I);
					}
				}
			}
			L1.Clear();
			foreach(HrsInterval R in L2){
				L1.Add(R);
			}
		}
		
		//最終的にL2を使う。
		ans=CalAns(L2);
	}
	
	int CalAns(List<HrsInterval> L){
		L.Sort( delegate ( HrsInterval P,HrsInterval Q){if(P.Start-Q.Start!=0)return P.Start-Q.Start;return P.End-Q.End;});
		
		List<HrsInterval> Complement=new List<HrsInterval>();
		if(L.Count==0){
			Complement.Add(new HrsInterval(watchstart,watchend));
		}
		if(L.Count>0){
			Complement.Add(new HrsInterval(watchstart,L[0].Start));
			int k;
			for(k=1;k<L.Count;k++){
				Complement.Add(new HrsInterval(L[k-1].End,L[k].Start));
			}
			Complement.Add(new HrsInterval(L[k-1].End,watchend));
		}
	
		int max=0;
		foreach(HrsInterval S in Complement){
			if(S.Range_Minute >=max)max=S.Range_Minute;
		}
		return max;
	}
	
}

Measured memory_bytes: 5740
#include <bits/stdc++.h>
using namespace std;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int W, H, N;
int mas[11][11];
bool isin(int y, int x)
{
    return (y >= 0 && x >= 0 && y < H && x < W);
}
int dfs(int y, int x, int bit)
{
    int ret = 0;
    if(bit == 0) return (1);
    for(int i = 0; i < 4; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        while(isin(ny, nx) && (mas[ny][nx] < 0 || (bit != (1 << N) && mas[ny][nx] == N) || (bit & ~(1 << mas[ny][nx])) == bit)) ny += dy[i], nx += dx[i];
        if(isin(ny, nx)) ret += dfs(ny, nx, bit & ~(1 << mas[ny][nx]));
    }
    return (ret);
}

int main()
{
    int px, py;
    while(cin >> W >> H, W || H) {
        N = 0;
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                cin >> mas[i][j];
                if(mas[i][j] == 0) mas[i][j] = -1;
                else if(mas[i][j] == 1) mas[i][j] = N, N++;
                else py = i, px = j;
            }
        }
        mas[py][px] = N;
        cout << dfs(py, px, (1 << (N + 1)) - 1) << endl;
    }
    return (0);
}



Measured memory_bytes: 3092
#include <iostream>

using namespace std;

int n;
int x, y, z;

void no() {
    cout << "No\n";
    exit(0);
}

void yes() {
    cout << "Yes\n";
    exit(0);
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (a % 4 == 0) x++;
        else if (a % 2 == 0) y++;
        else z++;
    }

    if (x < z - 1 || (z > 0 && x == 0)) no();
    if (x >= z) yes();
    if (y > 0) no();
    yes();
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//a??¨b?????§?????????

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//a??¨b????°??????????

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//a??¨b???????????¶??????

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//p????´???°,a???b??????p??§?????£?????????

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//p????´???°,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//?????§??¬?´???°

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//????°???¬?????°

int main() {
	
	int a, b, c, count = 0;

	cin >> a >> b >> c;

	for (int i = a; i <= b; i++) {

		if (c%i == 0)count++;

	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3092
#include<stdio.h>
int main(){
  char c;
  int a[26]={0};
  int i,j;
  while( scanf("%c",&c)!=EOF){
      if(c>='A' && c<='Z') c+='a'-'A';
      if(c>='a' && c<='z') a[c-'a']++;
  }
    
    for(i=0;i<26;i++){
      printf("%c : %d\n",'a'+i,a[i]);
    }
    return 0;
}

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

int main() {
  int n, m, a, b;
  static int g[1010][1010];
  scanf("%d%d%d%d", &n, &m, &a, &b);
  for (int i = 1; i <= n - b; ++i){
    for (int j = 1; j <= a; ++j) {
      g[i][j] = 1;
    }
  }
  for (int i = n - b + 1; i <= n; ++i){
    for (int j = a + 1; j <= m; ++j) {
      g[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; ++i, puts("")) for (int j = 1; j <= m; ++j) printf("%d", g[i][j]);
  return 0;
}

Measured memory_bytes: 5120
n = int(input())
name_base = []
dog_name = ''
while n > 0:
  ch_mod = (n-1)%26
  n = (n-1)//26
  name_base.append(ch_mod)
for i in name_base:
  dog_name = dog_name + chr(i+97)
print(dog_name[::-1])

Measured memory_bytes: 8952
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

struct Mod {
	static ll gcd(ll x, ll y, ll* out_cx, ll* out_cy) {
		if (x < 0) {
			ll d = gcd(-x, y, out_cx, out_cy);
			if (out_cx) {
				*out_cx *= -1;
			}
			return d;
		}
		if (y < 0) {
			ll d = gcd(x, -y, out_cx, out_cy);
			if (out_cy) {
				*out_cy *= -1;
			}
			return d;
		}
		if (x > y) {
			return gcd(y, x, out_cy, out_cx);
		}
		if (x == 0) {
			if (out_cx && out_cy) {
				*out_cx = 0;
				*out_cy = 1;
			}
			return y;
		}
		ll q = y / x;
		ll r = y % x;
		ll d = gcd(r, x, out_cy, out_cx);
		if (out_cx) {
			*out_cx -= q * *out_cy;
		}
		return d;
	}
	static ll BASE;
	ll value = 0;
	static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
	Mod()
	: value(0) {}
	Mod(ll value)
	: value(residue(value)) {}
	Mod operator+(const Mod& rhs) const { return Mod(value + rhs.value); }
	void operator+=(const Mod& rhs) { *this = *this + rhs; }
	Mod operator-(const Mod& rhs) const { return Mod(value - rhs.value); }
	void operator-=(const Mod& rhs) { *this = *this - rhs; }
	Mod operator*(const Mod& rhs) const { return Mod(value * rhs.value); }
	void operator*=(const Mod& rhs) { *this = *this * rhs; }
	Mod operator/(const Mod& rhs) const { return *this * rhs.inv(); }
	void operator/=(const Mod& rhs) { *this = *this / rhs; }
	Mod inv() const {
		if (value == 0) {
			assert(false);
			throw "[Mod::inv] div by zero";
		}
		ll ans, sub;
		ll d = Mod::gcd(value, BASE, &ans, &sub);
		if (d != 1) {
			assert(false);
			throw "[Mod::inv] not invertible";
		}
		return ans;
	}
};
ll Mod::BASE = 1000000007;

int main() {
	ll N;
	cin >> N;
	vector<ll> Cs(N);
	rep(i,0,N) {
		cin >> Cs[i];
	}
	sort(Cs.begin(), Cs.end());
	Mod pow = 1;
	rep(i,0,2*N-2) {
		pow *= 2;
	}
	Mod ans = 0;
	rep(i,0,N) {
		ans += Mod(N-i+1) * pow * Cs[i];
	}
	cout << ans.value << endl;
}


Measured memory_bytes: 1792
import sys
def amida(A,x):
  for e in A:
    if e[x]=="1":x+=1
    elif e[x-1]=="1":x-=1
  return x
def f():
  for i in D:
    for j in range(1,n):
      if A[i][j-1:j+2]=="000":
        B=[e[:] for e in A]
        B[i]=B[i][:j]+"1"+B[i][j+1:]
        if amida(B,m)==p:
          print i+1,j
          return
  print 1
  return

while 1:
  n=input()
  if n==0:break
  m=input()
  p=input()
  D=range(input())
  A=["0"+raw_input()+"0" for i in D]
  if amida(A,m)==p:print 0
  else:f()

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

int main(){
    long long N;
    cin >> N;
    long long kotae = N - 1;
    for (long long i = 2; i <= sqrt(N); i++)
    {
        long long a = N / i;
        long long amari = N % i;
        if (amari == 0)
            kotae = min(kotae, i + a - 2);
    }
    cout << kotae << endl;
    return 0;
}

Measured memory_bytes: 256
n,*s=open(0)
d={i:int(j)for i,j in zip('笑ABC',n.split())}
r=[]
for(i,j,_),(k,l,_)in zip(s,s[1:]):
    if d[i]<1>d[j]:exit(print('No'))
    if d[i]<1:
        d[i]+=1
        d[j]-=1
        r+=i,
    elif d[j]<1:
        d[i]-=1
        d[j]+=1
        r+=j,
    else:
        t={i,j}&{k,l}
        if t:
            t,*_=t
            u,*_={i,j}-{t}
        else:t,u=i,j
        d[t]+=1
        d[u]-=1
        r+=t,
i,j,_=s[-1]
if d[i]<1>d[j]:exit(print('No'))
if d[i]<1:
    d[i]+=1
    d[j]-=1
    r+=i,
else:
    d[i]-=1
    d[j]+=1
    r+=j,
print('Yes',*r)

Measured memory_bytes: 94472
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int N,K;
vi vec;
bool check(int x){
    bool dp[5010][5010]={};
    dp[0][0]=true;
    REP(i,N){
        REP(j,K){
            if(dp[i][j]){
                dp[i+1][j]=true;
                if(i!=x&&j+vec[i]<K){
                    dp[i+1][j+vec[i]]=true;
                }
            }
        }
    }
    FOR(i,max(0,K-vec[x]),K){
        if(dp[N][i]){
            return false;
        }
    }
    return true;
}
int main(){
    cin>>N>>K;
    vec=vi(N);
    REP(i,N){
        cin>>vec[i];
    }
    sort(all(vec));
    int ok=-1,ng=N;
    while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;
        if(check(mid)){
            ok=mid;
        }else{
            ng=mid;
        }
    }
    cout<<ng<<endl;
    return 0;
}

Measured memory_bytes: 24832
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(long long i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(long long i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1LL<<50);

void solve(long long K){
  vi ans(9);
  iota(ALL(ans), 1LL);
  Int cur = 0;
  while(ans.size() < K){
    Int a = ans[cur++];
    Int b = a % 10;
    for(Int c = b-1; c <= b+1; c++){
      if(c < 0 || c > 9) continue;
      ans.pb(a * 10LL + c);
    }
  }
  dump(ans);
  cout << ans[K-1] << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long K;
  scanf("%lld",&K);
  solve(K);
  return 0;
}


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


const long long MAXVAL = (long long) 1e18 + 1;
const long long MOD = 1000000007;
const int INF = 1000000000 + 1;

long long poww(int x, long long pow) {
  if (pow == 0ll ) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x ) % MOD;
  }
  return ans % MOD;
}

void dfs(int v, vector<int>& cols, vector<int> & p, vector<int> & bp, int curcol) {
  cols[v] = curcol;
  for (int next : {p[v], bp[v]}) {
    if (next < 0) continue;
    if (cols[next] > 0) {
      assert (curcol == cols[next]);
      dfs(next, cols, p, bp, curcol);
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << setprecision(20);
  int q = 1;
  //cin >> q;

  while (q-- > 0) {
    ll n;
    cin >> n;
    vector<ll> primes;
    vector<int> pows;
    for (int z = 2; z * 1ll * z <= n; ++z) {
      if (!(n % z)) {
        int curp = 0;
        while (!(n % z)) {
          n /= z;
          curp++;
        }
        primes.push_back(z);
        pows.push_back(curp);
      }
    }
    if (n > 1) {
      primes.push_back(n);
      pows.push_back(1);
    }
    int ans = 0;
    for (int pow : pows) {
      int cursum = 0;
      for (int i = 1; i <= pow; ++i) {
        cursum += i;
        if (cursum > pow) {
          ans += (i - 1);
          break;
        } else if (cursum == pow) {
          ans += i;
          break;
        }
      }
    }
    cout << ans << endl;

  }
  return 0;
}



Measured memory_bytes: 3652
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
SP = [(x.split()[0].decode('utf-8'),int(x.split()[1])) for x in readlines()]

SP = sorted((name,-pt,i+1) for i,(name,pt) in enumerate(SP))

answer = '\n'.join(str(x[2]) for x in SP)
print(answer)


Measured memory_bytes: 3064
import java.util.Scanner;
   
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    while(true){
      int H = sc.nextInt();
      int W = sc.nextInt();
      if(H == 0 && W == 0){
        break;
      }
      for(int x = 0; x < H; x++){
        for(int y = 0; y < W; y++){
          System.out.print("#");
        }
      System.out.println("");
      }
    System.out.println("");
    }
  }
}


Measured memory_bytes: 33376
#include <iostream>

int max(int a, int b)
{
    return (a > b) ? a : b;
}

int max(int a, int b, int c)
{
    return max(a, max(b, c));
}

int main()
{
    int A, B;
    scanf("%d %d", &A, &B);
    std::cout << max(A+B, A-B, A*B) << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int k,n,i,ans=0,l,j;
    cin >> k >> n;
    long long int a[n],b[n];
    for(i=0;i<n;i++)
    cin >> a[i];
    for(i=0;i<n-1;i++)
    b[i]=abs(a[i]-a[i+1]);
    b[n-1]=abs(0-a[0]);
    // for(i=0;i<n;i++)
    // cout << b[i] << " ";
    j=(k-a[n-1])+a[0];
    //cout << j;
    sort(b, b+n, greater<int>());
    //cout << b[0];
    l=max(b[0],j);
    ans=k-l;
    cout << ans;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    for(int i=0; i<S.size(); i++){
        int a = S[i] - 'A';
        a = (a+N) % 26;
        S[i] = 'A' + a;
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 768
#include<stdio.h>

int main(){
    long long int n,m;
    scanf("%lld%lld",&n,&m);

    long long int sum;
    if(m==1){
        sum=0;
    }else if((m/2-n)<0){
        sum=m/2;
    }else if((m/2-n)<2){
        sum=n;
    }else{
        sum=n+(m/2-n)/2;
    }
    printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 1700
n=int(input())
a=list(map(int,input().split()))
a.sort()
num=a[0]
count=0
cnt=1
for i in range(1,n):
    if a[i]==num:
        cnt+=1
    else:
        if num>cnt:
            count+=cnt
        else:
            count+=cnt-num
        num=a[i]
        cnt=1
if num>cnt:
    count+=cnt
else:
    count+=cnt-num
print(count)

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
const int dc[4] = {1, -1, 0,  0};
const int dr[4] = {0,  0, 1, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T, typename U, typename V> inline
ostream& operator<<(ostream &o, tuple<T,U,V> &p)
{
    return o << "{" << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n;
    cin >> n;

    vector<pii> v;
    irep(i, n) {
        int x, y;
        cin >> x >> y;
        v.push_back(pii(x,y));
    }
    sort(v.begin(), v.end());

    map<pii, int> mp;
    
    irep(i, n) {
        irep2(j, i+1, n-1) {
            int x1 = v[i].fi, y1 = v[i].se;
            int x2 = v[j].fi, y2 = v[j].se;
            mp[pii(x2-x1, y2-y1)]++;     
        }
    }
    int ans = 0;
    for(auto xy : mp) {
        chmax(ans, xy.se);
    }
    cout << n-ans << endl; 
    return 0;
}

/*atcoder*/


Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N;
std::vector<LL>A;

LL f(LL b)
{
	LL res = 0;
	rep(i, N) res += abs(A[i] - b);
	return res;
}

int main()
{
	in >> N;
	A.resize(N);
	rep(i, N)
	{
		in >> A[i];
		A[i] -= i;
	}
	LL l = -1123456789, r = 1123456789;
	while (r - l > 1)
	{
		LL m = (l + r) / 2;
		if (f(m - 1) < f(m + 1)) r = m;
		else l = m;
	}
	out << f(l) << std::endl;
	return 0;
}


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

int main(){
	long n = 0;
	while (cin >> n){
		if (n == 0) break;
		vector<long> s(n, 0);
		for (long i = 0; i < n; i++){
			cin >> s[i];
		}
		long t = 0;
		for (long i = 0; i < n; i++){
			t += s[i];
		}
		double ave = 0;
		ave = (double)t / n;
		double sum = 0;
		for (long i = 0; i < n; i++){
			sum += (s[i] - ave) * (s[i] - ave);
		}
		cout << fixed << sqrt(sum / n) << endl;
	}
	return 0;
}

Measured memory_bytes: 1268
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = INT_MAX;
const ll MOD = 1e9+7;

/*
75=3*5^2
p^74,p^24*q^2,p^14*q^4,p^4*q^4*r^2
*/

bool isnotprime[110];
vint prime;
void init(){
  isnotprime[0]=isnotprime[1]=true;
  for(int i=2;i<=100;i++){
    if(!isnotprime[i]){
      for(int j=2*i;j<=100;j+=i){
        isnotprime[j]=true;
      }
      prime.push_back(i);
    }
  }
}


int cnt[5];//74,24,14,4,2
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  init();
  ll N;cin>>N;
  for(int p:prime){
    int e=0;
    ll ppow=p;
    while(ppow<=N){
      e+=N/ppow;
      ppow*=p;
    }
    if(e>=2){
      cnt[4]++;
    }
    if(e>=4){
      cnt[3]++;
    }
    if(e>=14){
      cnt[2]++;
    }
    if(e>=24){
      cnt[1]++;
    }
    if(e>=74){
      cnt[0]++;
    }
  }
  //debugArray(cnt,5);
  cout<<cnt[0]+cnt[1]*(cnt[4]-1)+cnt[2]*(cnt[3]-1)+cnt[3]*(cnt[3]-1)/2*(cnt[4]-2)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c;
    cin >>a>>b>>c;
    
    if(a == 1 && b == 0 && c == 0){
        cout <<"Close"<<endl;
    }else if(a == 1 && b == 1 && c == 0){
        cout <<"Open"<<endl;
    }else if(a == 0 && b == 1 && c == 0){
        cout <<"Close"<<endl;
    }else if(a == 0 && b == 0 && c == 1){
        cout <<"Open"<<endl;
    }else{
        cout <<"Close"<<endl;
    }
    
}



Measured memory_bytes: 3100