akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 300000 + 10;
int gi () {
    int ret = 0; char ch = getchar();
    while(ch<'0' || ch>'9') ch = getchar();
    while(ch>='0' && ch<='9') ret = ret * 10 + ch - '0', ch = getchar();
    return ret;
}
int n,Q,a[N];
LL s[N],f[N],g[N],w[N],cw[N];
struct line {
    LL k,b;
} q[N];
LL calc (line z,LL x) {
    return z.k * x + z.b;
}
void dp (LL *f) {
    for(int i=1;i<=n;i+=1) s[i] = s[i-1] + a[i];
    int tp = 0;
    q[++tp] = (line){0,0};
    for(int i=1;i<=n;i+=1) {
        while(tp>1 && calc(q[tp],-i) <= calc(q[tp-1],-i)) --tp;
        LL ext = -s[i] + i*(i+1ll) / 2;
        f[i] = max(f[i-1], calc(q[tp],-i)+ext);
        line r = (line){i,f[i]+s[i]+i*(i-1ll)/2};
        while(tp>1 && (q[tp].b-r.b)*(r.k-q[tp-1].k) < (q[tp-1].b-r.b)*(r.k-q[tp].k)) --tp;
        q[++tp] = r;
    }
}
void solve (int l,int r) {
    if(l==r) return;
    int mid = (l+r) >> 1, tp = 0;
    for(int i=l-1;i<=r+1;i+=1) cw[i] = -1e9;
    if(l==1) q[++tp] = (line){0,0};
    for(int i=l;i<=mid;i+=1) {
        line r = (line){i,f[i]+s[i]+i*(i-1ll)/2};
        while(tp>1 && (q[tp].b-r.b)*(r.k-q[tp-1].k) < (q[tp-1].b-r.b)*(r.k-q[tp].k)) --tp;
        q[++tp] = r;
    }
    for(int i=mid+1;i<=r;i+=1) {
        while(tp>1 && calc(q[tp],-i) <= calc(q[tp-1],-i)) --tp;
        LL ext = -s[i] + i*(i+1ll)/2 + g[i+1];
        cw[i] = calc(q[tp],-i)+ext;
    }
    for(int i=r-1;i>mid;i-=1) cw[i] = max(cw[i],cw[i+1]);
    tp = 0;
    for(int i=mid+1;i<=r;i+=1) {
        line r = (line){i,g[i+1]-s[i]+i*(i+1ll)/2};
        while(tp>1 && (q[tp].b-r.b)*(r.k-q[tp-1].k) < (q[tp-1].b-r.b)*(r.k-q[tp].k)) --tp;
        q[++tp] = r;
    }
    for(int i=l-1;i<mid;i+=1) {
        while(tp>1 && calc(q[tp],-i) <= calc(q[tp-1],-i)) --tp;
        LL ext = s[i] + i*(i-1ll)/2 + f[i];
        cw[i+1] = calc(q[tp],-i)+ext;
    }
    for(int i=l+1;i<=mid;i+=1) cw[i] = max(cw[i],cw[i-1]);
    for(int i=l;i<=r;i+=1) w[i] = max(w[i], cw[i]);
    solve(l,mid); solve(mid+1,r);
}
int main () {
    n = gi();
    for(int i=1;i<=n;i+=1) a[i] = gi();
    dp(f);
    reverse(a+1,a+n+1);
    dp(g);
    reverse(a+1,a+n+1); reverse(g+1,g+n+1);
    for(int i=1;i<=n;i+=1) s[i] = s[i-1] + a[i], w[i] = -1e9;
    solve(1,n);
    Q = gi();
    int p,v;
    for(int i=1;i<=Q;i+=1) {
        p = gi(); v = gi();
        printf("%lld\n",max(f[p-1]+g[p+1],w[p]+a[p]-v));
    }
    return 0;
}

Measured memory_bytes: 16128
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std ;
int main()
{
	int n;
	cin >> n ;
	int a[100005],b[100005],c[100005];
	for(int i=0;i<n;i++)
		cin >> a[i] ;
	memset(b,0,sizeof(b)) ;
	memset(c,0,sizeof(c)) ;
	for(int i=0;i<n;i+=2) b[a[i]]++;
	for(int i=1;i<n;i+=2) c[a[i]]++;
	
	int max1=0,x1;
	for(int i=0;i<100005;i++)
		if(b[i]>max1) {
			x1=i;max1=b[i] ;	
		}
	int max2=0,x2;
	for(int i=0;i<100005;i++)
		if(c[i]>max2) {
			x2=i;max2=c[i] ;	
		}
	int M1=max1,M2=max2;
	if(x1!=x2) cout << n-max1-max2;
	else {
		
			c[x2]=0;max2=0;
			for(int i=0;i<100005;i++)
				if(c[i]>max2) {
					x2=i;max2=c[i] ;	
				}
		
		
			b[x1]=0;max1=0;
			for(int i=0;i<100005;i++)
				if(b[i]>max1) {
					x1=i;max1=b[i] ;	
				}
		
		cout << min(n-max1-M2,n-max2-M1); 
	}
	//cout <<max1<<endl <<max2;
	return 0;
}

Measured memory_bytes: 1408
const { count } = require("console");

function main(lines) {
  const [N, M] = na();

  const ans = N*(N-1)/2 + M*(M-1)/2;
  
  return ans;
}



const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);

const ans = main(lines);
console.log( ans );

Measured memory_bytes: 30520
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int M, D, ans;

int main() {
	cin >> M >> D;
	
	inc1(m, M) {
	inc1(d, D) {
		if(d < 10) { continue; }
		int d1 = d / 10;
		int d2 = d % 10;
		if(d1 >= 2 && d2 >= 2 && d1 * d2 == m) { ans++; }
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    int n, k;

    cin >> n >> k;

    vi v(n);

    for(auto &z : v)cin >> z;

    sort(all(v));

    ll zbir = 0;

    for(int i = 0; i < n - k; i++)
    {
        zbir += (ll)v[i];
    }

    cout << zbir << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define sf(n) scanf("%f",&n)
#define pf(n) printf("%.12f",n)
#define psp printf(" ")
#define endc printf("\n")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int maxn = 1e3 + 6;
const ll md = 1e9 + 7;

ll C[maxn][maxn];
ll dp[maxn][maxn];
ll f[maxn][maxn];
ll fact[maxn];

ll inv(ll x) {
	ll ex = md-2; ll ans = 1;
	while (ex > 0) {
		if (ex & 1 == 1) ans = (ans * x)%md;
		x = (x*x)%md; ex >>= 1;
	}
	return ans;
}

int main() {
	int n,a,b,c,d; sd(n); sd(a); sd(b); sd(c); sd(d);
	for (int i = 0; i < maxn; i++) {
		for (int j = 0; j < maxn; j++) {
			if (j > i) { C[i][j] = 0; continue; }
			if (j == 0) { C[i][j] = 1; continue; }
			C[i][j] = (C[i-1][j-1] + C[i-1][j])%md;
		}
		dp[a-1][i] = 0;
	}
	fact[0] = 1;
	for (int s = 1; s <= n; s++) {
		fact[s] = (fact[s-1] * s)%md;
		int curi = 0; f[s][0] = 1;
		for (int g = 1; g*s <= n; g++) {
			f[s][g] = f[s][g-1];
			for (int k = 1; k <= s; k++) {
				curi++;
				f[s][g] = (f[s][g]*curi)%md;
				f[s][g] = (f[s][g]*inv(k))%md;
			}
		}
	}
	dp[a-1][0] = 1;
	for (int s = a; s <= b; s++) {
		dp[s][0] = 1;
		for (int g = 1; g * s <= n; g++) {
			f[s][g] = (f[s][g] * inv(fact[g]))%md;
		}
		for (int m = 1; m <= n; m++) {
			dp[s][m] = 0;
			for (int g = c; g <= d; g++) {
				int y = g*s;
				if (y > m) break;
				ll cur = (C[m][y] * f[s][g])%md;
				dp[s][m] = (dp[s][m] + cur*dp[s-1][m - y])%md;
			}
			dp[s][m] = (dp[s][m] + dp[s-1][m])%md;
		}
	}
	
	pl(dp[b][n]); endc;	
}


Measured memory_bytes: 23040
import java.util.*;

public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  
	  long M = 0;
	  for(long i = 1; i < N; i++) {
		  M += i;
	  }
	  System.out.println(M);
	  
	  sc.close();
	  
  }
}


Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Split(bufio.ScanWords)
	var N, K int
	var H []int

	N = nextInt()
	K = nextInt()
	for i := 0; i < N; i++ {
		H = append(H, nextInt())
	}
	// fmt.Println(N, K)
	// fmt.Println(H)

	fmt.Println(skillJudge(N, K, H))
}

func skillJudge(N int, K int, H []int) int {
	if N <= K {
		return 0
	} else {
		sort.Ints(H)
		sum := 0
		for i := 0; i < N-K; i++ {
			sum += H[i]
		}
		return sum
	}
}

func nextInt() int {
	stdin.Scan()
	i, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	return i
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 1005
ll mod=1e9+7;
int n,m,a,b;
vector<int> G[MAX],g[MAX];
int p[MAX],flg[MAX];
 
int update(int x){
  flg[x]=1;
  if(p[x]==x)return x;
  return p[x]=update(p[x]);
}
 
int find(int x){
  if(p[x]==x)return x;
  return find(p[x]);
}
 
ll dfs(int pos){
  ll res=1;
  for(int i=0;i<(int)g[pos].size();i++)
    res=res*dfs(g[pos][i])%mod;
  return res+1;
}
 
int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++)p[i]=i;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    G[b].push_back(a);
    if(find(b)==a)update(b);
    else p[a]=b;
  }
  for(int i=1;i<=n;i++){
    for(int j=0;j<(int)G[i].size();j++){
      int w=G[i][j];
      if(flg[w])continue;
      if(flg[i])g[p[i]].push_back(w);
      else g[i].push_back(w);
    }
  }
  ll ans=1;
  for(int i=1;i<=n;i++)if(p[i]==i)ans=ans*dfs(i)%mod;
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pp;
#define MAXN 300005
#define MAXM 1005
#define MAXP 50
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;
map <ll, int> cnt;
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N;
	ll sum = 0; ll x;
	cin >> N;
	ll ans = 0;
	for(int i=0; i<N; i++) {
		cin >> x;
		sum += x;
		if(sum == 0) ans++;
		ans += cnt[sum];
		
		cnt[sum]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 12800
def myAnswer(W:int,H:int,N:int,X:list,Y:list,A:list) -> int:
   startX = 0
   endX = W
   startY = 0
   endY = H
   for x,y,a in zip(X,Y,A):
      if(a == 1):
         startX = max(startX,x)
      elif(a == 2):
         endX = min(endX,x)
      elif(a == 3):
         startY = max(startY,y)
      elif(a == 4):
         endY = min(endY,y)
   # print(startX,endX,startY,endY)
   return 0 if(startX > endX or startY > endY) else (endX - startX) * (endY - startY)

def modelAnswer():
   return
def main():
   W,H,N = map(int,input().split())
   X = []
   Y = []
   A = []
   for _ in range(N):
      x,y,a = map(int,input().split())
      X.append(x)
      Y.append(y)
      A.append(a)
   print(myAnswer(W,H,N,X,Y,A))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  cout << (A + B) % 24 << endl;
}

Measured memory_bytes: 3604
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
#define M 1000000007

  
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vector<ll>v(n+1);
    for(ll i=1;i<=n;i++)
    cin>>v[i];
    
    vector<bool>a(n+1,false);
    ll ans=0;
    ll p=1;
   
    while(1)
    {
        if(a[p]==true)
        break;
        a[p]=true;
        p=v[p];
        ans++;
    }
    for(auto i:a)
    i=false;
    
    ll ans1=0;
    while(1)
    {
        if(a[p]==true)
        break;
        a[p]=true;
        p=v[p];
        ans1++;
    }
    //cout<<ans<<" "<<ans1<<endl;
    
    //ans=ans+1;
    //cout<<p<<" ";
    if(k<=ans - ans1)
    {
    //k=k%ans;
        p=1;
        while(k--)
        {
         p=v[p];
        }
        cout<<p<<endl;
    }
    else
    {
        k=k-(ans-ans1);
        k=k%ans1;
        while(k--)
        {
        p=v[p];
        }
        cout<<p<<endl;
    }
    
   
    
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

long dp[1010][1010] = {0};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  string s[1010];
  for(int i = 0; i < n; i++) {
    cin >> s[i];
  }
  
  dp[0][0] = 1;
  for(int i = 1; i < n; i++) {
  	if(s[i][0] == '.') {
      dp[i][0] = dp[i-1][0];
    }
  }
  for(int j = 1; j < m; j++) {
  	if(s[0][j] == '.') {
      dp[0][j] = dp[0][j-1];
    }
  }
  
  for(int i = 1; i < n; i++) {
    for(int j = 1; j < m; j++) {
      if(s[i][j] == '.') {
        dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
      }
    }  
  }
  cout << dp[n-1][m-1] << "\n";
  return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define int long long
string s[10];
set<int> si,us,cu;
vector<int> v;
int x,y;
int calc(const int a[5][5]){
  int res=0;
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++)
      res+=(1LL<<(i*5+j))*a[i][j];
  return res;
}
int calc2(const int a[5][5]){
  int res=0;
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++)
      res+=(1LL<<(i*5+j))*a[i][4-j];
  return res;
}
string t[5];
bool check(){
  map<string,int> ms;
  for(int i=0;i<10;i++){
    if(cu.count(i)) continue;
    string tmp=s[i];
    ms[tmp]++;
    reverse(tmp.begin(),tmp.end());
    ms[tmp]++;
  }
  for(int i=0;i<5;i++){
    string tmp=t[i];
    ms[tmp]--;
    reverse(tmp.begin(),tmp.end());
    ms[tmp]--;
    if(ms[t[i]]<0) return false;
  }
  return true;
}
set<int> memo[6];
void dfs(int d){
  if(memo[d].count(x)) return;
  memo[d].insert(x);
  if(d==5){
    if(si.count(x)) return;
    if(!check()) return;
    si.insert(x);
    return;
  }
  for(int i=0;i<20;i++){
    if(cu.count(i%10)) continue;
    cu.insert(i%10);
    if(i>=10) reverse(s[i%10].begin(),s[i%10].end());
    v.push_back(i%10);
    for(int j=0;j<5;j++){
      t[j]+=(s[i%10][j]=='1'?'0':'1');
      x+=(1LL<<(d*5+j))*(s[i%10][j]=='1');
    }
    dfs(d+1);
    v.pop_back();
    for(int j=0;j<5;j++){
      t[j].pop_back();
      x-=(1LL<<(d*5+j))*(s[i%10][j]=='1');
    }
    if(i>=10) reverse(s[i%10].begin(),s[i%10].end());
    cu.erase(i%10);
  }
}
signed main(){
  while(cin>>s[0],s[0]!="END"){
    for(int i=1;i<10;i++) cin>>s[i];
    si.clear();
    us.clear();
    for(int i=0;i<6;i++) memo[i].clear();
    x=y=0;
    dfs(0);
    int a[5][5];
    int c[5][5];
    int ans=0;
    for(int b:si){
      if(us.count(b)) continue;
      for(int i=0;i<5;i++)
	for(int j=0;j<5;j++)
	  a[i][j]=(b>>(i*5+j))&1;
      us.insert(calc(a));
      us.insert(calc2(a));
      for(int i=0;i<5;i++)
	for(int j=0;j<5;j++)
	  c[i][j]=a[4-j][i];
      us.insert(calc(c));
      us.insert(calc2(c));
      for(int i=0;i<5;i++)
	for(int j=0;j<5;j++)
	  c[i][j]=a[j][4-i];
      us.insert(calc(c));
      us.insert(calc2(c));
      for(int i=0;i<5;i++)
	for(int j=0;j<5;j++)
	  c[i][j]=a[4-i][4-j];
      us.insert(calc(c));
      us.insert(calc2(c));
      ans++;
    }
    //cout<<si.size()<<endl<<us.size()<<endl;
    cout<<ans/2<<endl;
  }
  return 0;
}

Measured memory_bytes: 30904
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

#define INF 100000000


int main() {
	long long n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	cout << max({ (n - 1) / a, (n - 1) / b, (n - 1) / c, (n - 1) / d, (n - 1) / e }) + 5 << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, t;
    cin >> n >> t;
    string s;
    cin >> s;
    vi v;
    v.pb(0);
    int ans = 0;
    for(int i = 0; i < s.size()-1; i++){
        if(s[i] == 'A' && s[i+1] == 'C'){
            ans++;
        }
        v.pb(ans);
    }
    while(t--){
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        cout << v[r] - v[l] << endl;
    }
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long
#define endl '\n'

int32_t main()
{
    int h,w,m;
    cin>>h>>w>>m;
    int r[h+1],c[w+1];
    memset(r,0,sizeof(r));
    memset(c,0,sizeof(c));
    int x[m],y[m];
    for(int i=0;i<m;i++)
    {
    	cin>>x[i]>>y[i];
    	r[x[i]]++;
    	c[y[i]]++;
    }
    int mx=-1;
    int count=0;
    for(int i=1;i<=w;i++)
    	mx=max(mx,c[i]);
    for(int i=1;i<=w;i++)
    	count+=(mx==c[i]);
    int ch[h+1];
    memset(ch,0,sizeof(ch));
    for(int i=0;i<m;i++)
    {
    	if(mx==c[y[i]])
    		ch[x[i]]++;
    }
    int ans=0;
    for(int i=1;i<=h;i++)
    {
    	if(ch[i]==count)
    		ans=max(ans,r[i]+mx-1);
    	else
    		ans=max(ans,r[i]+mx);
    }
    cout<<ans;
}   

Measured memory_bytes: 15332
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def gcd(a, b):
    if a < b:
        a,b = b,a
    while b > 0:
        r = a % b
        a,b = b,r
    return a

def arrgcd(a):
    alen = len(a)
    if alen == 3:
        return gcd(a[0], gcd(a[1], a[2]))
    elif alen == 2:
        return gcd(a[0], a[1])
    elif alen == 1:
        return a[0] # 最初から1つ
    elif alen == 0:
        return 0
    else:
        return gcd(arrgcd(a[:alen//2]), arrgcd(a[alen//2:]))

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    print(arrgcd(al))

if __name__=="__main__":
    solve()


Measured memory_bytes: 74520
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K,X,Y;
int a,b,c,d;
string S,T;
vector<int> A,B;
//=============================
void input()
{
    cin>>S;
}
//=============================
void func(){}
/*
 - 樹形図をかく
*/
//=============================
void solve()
{
    int ans = 0;
    for(auto x : S){
        if (x == '1')ans++;
    }
    cout<<ans<<endl;


}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

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

using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[100002] = {};
	int b[100002] = {};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		b[i]=a[i];
	}
	//偶数回目の合計が正
	long eve = 0,sum=0, odd = 0;;
	for (int j = 0; j < n; j++) {
		if (j % 2 == 0 && sum + a[j] <=0) {
			eve += abs(a[j]+ sum)  + 1;
			a[j] = abs(sum) + 1;
		}
		if (j % 2 == 1 && sum +a[j] >=0) {
			eve += a[j] + sum + 1;
			a[j] = -abs(sum)-1;
		}
		sum += a[j];
		
		//cout << a[j] << " " <<eve << " " <<sum << endl;
	}
	//cout << endl;
	//奇数回目が正
	sum = 0;
	for (int k = 0; k < n; k++) {
		if (k % 2 == 0 && sum + b[k] >= 0) {
			odd += abs(b[k] + sum) + 1;
			b[k] = -abs(sum) - 1;
			
		}
		if (k % 2 == 1 && sum + b[k] <= 0) {
			odd += abs(sum + b[k]) + 1;
			b[k] = abs(sum) + 1;
		}
		sum += b[k];
		//cout << b[k] << " " <<odd << " " << sum<<endl;
	}
	//cout << endl;
	cout << min(odd, eve) << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

double toRadian(int degree)
{
    return (degree / (180 / M_PI));
}

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

    double S, L, h;
    S = (double)(a * b * sin(toRadian(C)) / 2);
    double c = sqrt(pow(a, 2) - 2*a*b*cos(toRadian(C)) + pow(b, 2));
    L = (double)(a + b + c);
    h = (double)(2 * S / a);
    printf("%lf\n%lf\n%lf\n", S, L, h);

    return 0;
}



Measured memory_bytes: 2056
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] val = new int[n];
        boolean[] b = new boolean[k + 1];
        for (int i = 0; i < n; i++) {
            val[i] = in.nextInt();
            b[val[i]] = true;
        }
        for (int i = 0; i <= k; i++) {
            if (!b[i]) {
                boolean t = true;
                for (int j = 0; j < n; j++) {
                    if ((i - val[j] >= 0)) {
                        t = t && b[i - val[j]];
                    }
                }
                b[i] = !t;
            }
        }
        if (b[k]) {
            out.println("First");
        } else {
            out.println("Second");
        }
        out.close();
    }

    private static void dfs(Vertex v, Set<Vertex> visited, Stack<Vertex> st) {
        visited.add(v);
        for (Vertex n : v.adj) {
            if (!visited.contains(n))
                dfs(n, visited, st);
        }
        st.add(v);
    }

    static class Vertex {
        int i;

        public Vertex(int i) {
            this.i = i;
        }

        List<Vertex> adj = new ArrayList<>();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }
}


Measured memory_bytes: 24276
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
#define int long long


signed main(){
    int N;
    cin >> N;
    int A1[N],A2[N],ue[N+1],shita[N+1];
    shita[N] = 0;
    for(int i=0;i<N;i++){
        cin >> A1[i];
    }
    ue[0] = A1[0];
    for(int i=0;i<N;i++){
        ue[i+1] = ue[i]+A1[i+1];
    }
    for(int i=0;i<N;i++){
        cin >> A2[i];
    }
    for(int i=N;i>=0;i--){
        shita[i-1] = shita[i]+A2[i-1];
        
    }
    int ans = 0;
    for(int i=0;i<N;i++){
        ans = max(ans,ue[i]+shita[i]);
    }
    
    cout << ans << endl;
    return 0;
}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const ll max_co = 3234600000;
vl ans;
int mod =1000000007;
int main(){
    int n;
    cin>>n;
    vector<P>ab;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        ab.push_back({b,a});
    }
    sort(been(ab));
    int now=0;
    bool f = true;
    rep(i,n){
        if(now+ab[i].second>ab[i].first){
            f = false;
            break;
        }
        else {
            now += ab[i].second;
        }
    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
int solve1(int x){
  if(x%2==0) return x/2;
  return 3*x+1;
}
void  solve(){
  int s;
  cin>>s;
  map<int,int> m;
  int last=s,ans=1;
  while(m.find(last)==m.end()){
    m[last]++;
    last=solve1(last);
    // cout<<last<<endl;
    ans++;

  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3656
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    string s;
    cin>>s;
    stack<char> st;
    int cnt=0;
    for(int i=0;i<s.length();i++){
        if(!st.empty() && s[i]!=st.top()){
            cnt+=2;
            st.pop();
        }
        else{
            st.push(s[i]);
        }
    }
    cout<<cnt<<endl;
    /*
    int cnt1=0, cnt0=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='0')   cnt0++;
        else            cnt1++;
    }
    cout<<2*min(cnt0,cnt1)<<endl;
    */
    return 0;
}



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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N;
	cin >> N;
	double ans = 0;
	for (int i = 0; i < N; i++) {
		double tmp;
		cin >> tmp;
		ans += 1.0 / tmp;
	}
	cout << 1.0 / ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
// 82

using namespace std;

const int MAXN = (int) 1e5;

vector < pair <int, int> > g[MAXN + 1];
bool viz[MAXN + 1];

int sol[MAXN + 1];

void dfs(int nod) {
    viz[nod] = 1;
    for(auto it : g[nod]) {
        if(viz[it.first] == 0) {
            sol[it.first] = sol[nod] + it.second;
            dfs(it.first);
        }
        else if(sol[it.first] != sol[nod] + it.second) {
            cout << "No";
            exit(0);
        }
    }
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, m, l, r, d;
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(i = 1; i <= m; i++) {
        cin >> l >> r >> d;
        g[l].push_back({r, d});
        g[r].push_back({l, -d});
    }
    for(i = 1; i <= n; i++) {
        if(viz[i] == 0) {
            dfs(i);
        }
    }
    cout << "Yes";
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 11136
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline

mod=998244353

def main():
    n,*a=map(int,open(0).read().split())
    if a[0]!=0:
        print(0)
        exit()
    for i in a[1:]:
        if i==0:
            print(0)
            exit()
    
    ans=1
    a=Counter(a)
    for i in range(len(a)-1):
        ans*=pow(a[i],a[i+1],mod)%mod
    print(ans%mod)

    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 19644
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//a???????????????
		int a = sc.nextInt();
		//b???????????????
		int b = sc.nextInt();

		//??´??°d???
		int d = a / b;
		System.out.println(d);
		//??????
		int Amari = a % b;
		System.out.println(Amari);

		//???????°???°?????°
		double f =  (double) a / (double) b;
		System.out.printf("%.5f",f);

	}
}

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

int main(){
    int n;
    cin>>n;
    long long r=1,a[100005];
    for(int i=0;i<n;i++){
    	cin>>a[i];
	}
	sort(a,a+n);
	if(a[0]==0){
		cout<<0;
		return 0;
	}
	for(int i=n-1;i>=0;i--){
		if(1000000000000000000/a[i]>=r) r*=a[i];
		else{
			cout<<-1;
			return 0;
		}
	}
	cout<<r;
    return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

////const long long MOD = 2;
//



#define binary_search_vector t
vec(t,1);

bool binary_search_solve(ll index, ll key){
  if(binary_search_vector[index] >= key) return true;
  else return false;
}

bool isOK(ll index, ll key) {
    if (binary_search_vector[index] >= key) return true;
    else return false;
}

int binary_search(ll key) {
    int ok = -1; 
    int ng = (int) binary_search_vector.size(); 

    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}


void solve(long long N, std::vector<long long> a){
    
    t[0]=a[0];
    repf(i,1,N){
      ll tmp=binary_search(a[i]);
      //op(tmp);
      if(tmp==t.size()-1)t.push_back(a[i]);
      else t[tmp+1]=a[i];
    }
    op(t.size());
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 2168
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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 (b<a) { a=b; return 1; } return 0; }

int N,ans;

int main(){
    while(cin>>N){
        ans=0;
        rep(i,10){
            rep(j,10){
                rep(k,10){
                    rep(l,10){
                        if(i+j+k+l==N)ans++;
                    }
                }
            }
        }
        out(ans);
    }
}



Measured memory_bytes: 3020
#include <stdio.h>

int main()
{
  int i, j, n, m;
  int a[100][100];
  int b[100];
  int c[100] = {0};

  scanf("%d %d", &n, &m);

  for( i = 0 ; i < n ; i++ )
  {
    for( j = 0 ; j < m ; j++ )
    {
      scanf("%d", &a[i][j]);
    }
  }

  for( i = 0 ; i < m ; i++ )
  {
    scanf("%d", &b[i]);
  }

  for( i = 0 ; i < n ; i++ )
  {
    for( j = 0 ; j < m ; j++ )
    {
      c[i] = c[i] + a[i][j] * b[j];
    }
    printf("%d\n", c[i]);
  }
}



Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;

int main() {
	VI a(3);
	REP(i, 3) { cin >> a[i]; }
	
	cout << *max_element(ALL(a)) - *min_element(ALL(a)) << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#if !defined(M_PI)
#define M_E 2.71828182845904523536
#define M_LOG2E 1.44269504088896340736
#define M_LOG10E 0.434294481903251827651
#define M_LN2 0.693147180559945309417
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.785398163397448309616
#define M_1_PI 0.318309886183790671538
#define M_2_PI 0.636619772367581343076
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.707106781186547524401
#endif

class UnionFind {
public:
    vector<int> id;
    vector<int> sz;

    UnionFind(int n) {
        id = vector<int>(n, 0);

        for (int i = 0; i < n; i++) {
            id[i] = i;
        }
        sz = vector<int>(n, 1);
    }

    void unite(int p, int q) {
        int p_root = get_root(p);
        int q_root = get_root(q);

        if (p_root != q_root) {
            if (sz[p_root] < sz[q_root])
                swap(p_root, q_root);

            id[q_root] = p_root;
            sz[p_root] += sz[q_root];
        }
    }

    int get_root(int p) {
        while (p != id[p]) {
            id[p] = id[id[p]];
            p = id[p];
        }
        return p;
    }
};

ll solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    return max(max(a*c, a*d), max(b*c, b*d));
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int tt = 1;
    // cin >> tt;

    for (int tc = 1; tc <= tt; tc++) {
        cout << solve() << "\n";
    }
}


Measured memory_bytes: 3648
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m : usize,
        x : usize,
    }

    let mut ans = x;

    for _ in 0..10{
        ans = n*ans - m;
        println!("{}",ans);
    }
    
}


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

using namespace std;
typedef long long ll;
vector<char> c;
int main()
{
   string a;
   cin>>a;

   if(a.size()==3)
   {

       reverse(a.begin(),a.end());
       cout<<a<<endl;

   }else
   {

       cout<<a<<endl;
   }
    return 0;
}


Measured memory_bytes: 256
import bisect

N = int(input())

def calc(a):
  return max(len(str(a)),len(str(N//a)))

P = set()
for i in range(1,int(N**0.5)+2):
  if N % i == 0:
    P.add(i)
    P.add(N // i)
P = list(P)
P.sort()
#print(P)
r = bisect.bisect_left(P,int(N**0.5))
print(min(calc(P[r-1]),calc(P[r])))

Measured memory_bytes: 38768
s=input()
x='Yes'
if 'N' in s:
  if 'S' not in s:
    x='No'
else:
  if 'S' in s:
    x='No'
if 'E' in s:
  if 'W' not in s:
    x='No'
else:
  if 'W' in s:
    x='No'
print(x)

Measured memory_bytes: 2940
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)

if K > A[-1]:
    print('IMPOSSIBLE')
    exit()

keep = A[0]
for i in range(1, N):
    keep = math.gcd(keep, A[i])
if K % keep == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define FOR(i, a, b) for (int i = a; i <= (int)(b); i++)
#define FORD(i, a, b) for (int i = a; i >= (int)(b); i--)

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
using Lint = long long;
#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define PB push_back
#define MP make_pair
using P=pair<int, int>;
using V=vector<int>;
using M=map<int, int>;
using S=set<int>;

#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "

#define DUMP(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
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 (b < a){a = b;return 1;}return 0;}
/* vector<T>のイテレータはvector<T>::iterator型
vector<int>::iterator it = vc.begin();  // begin()はvectorの最初の要素を指すイテレータを返す。
vector<int>::iterator endIt = vc.end(); // end()はvectorの終端位置を指すイテレータを返す。
while (it != endIt)
{
  cout << *it << '\n'; // イテレータの指す要素は、ポインタのように*演算子でアクセスします。
  it++;                // インクリメントすることで次の要素を指します。
}
}*/
int main()
{
  
  int n,k,sum=0;
  cin >>n>>k;
  V p(n);
  REP(i,n)cin>>p[i];
  sort(p.begin(),p.end());
  REP(i,k)sum+=p[i];
  COUT(sum); 
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <ctype.h>

int main(void) {
  char input;
  int counts[26] = {};
  int i;
  for (i = 0; i < 1200; i++) {
    scanf("%c", &input);
    if (isalpha(input)) {
      if (isupper(input))
	counts[tolower(input) - 'a']++;
      else
	counts[input - 'a']++;
    }
  }
  for (i = 0; i < 26; i++)
    printf("%c : %d\n", i + 'a', counts[i]);
  return 0;
}



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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll n; cin >> n;
  if(n%2==1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  for(int i = 1; (ll)pow(5, i) <= n; ++i) {
    ans += n/(ll)pow(5, i)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
    int n,m,a[50],b[50],c[50],d[50],ans[50];
    cin >>n>>m;
    for (int i=0;i<n;i++)
       cin>>a[i]>>b[i];
    for (int i=0;i<m;i++)
       cin>>c[i]>>d[i];
    for (int i=0;i<n;i++){
       int t,x,y;
       for (int j=0;j<m;j++){
           x=a[i]-c[j];
           y=b[i]-d[j];
           if (x<0)x*=-1;
           if (y<0)y*=-1;
           if (j==0)t=x+y+1;
           if (t>x+y){
              ans[i]=j;
              t=x+y;
           }
       }
       cout<<ans[i]+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
//Name: Curling 2.0
//Level: 3
//Category: 探索
//Note:

/**
 * 障害物が壊れるのが面倒だが、10回までしか石を動かせないので、状態数は4^10=2^20≒100万程度。
 * 1回の移動では1ラインだけ見ればよいので、普通にシミュレーションすれば2000万ループ程度で解ける。
 *
 * オーダーはO((W+H)4^N)。
 * ただしNは石を動かせる回数で、N=10。
 */

#include <iostream>
#include <vector>

using namespace std;

int W, H;
int ans;
const int DR[] = {0, -1, 0, 1};
const int DC[] = {1, 0, -1, 0};
void dfs(vector<vector<int>> &field, const pair<int,int> &p, int turn) {
    if(turn >= ans) return;
    if(turn >= 11) return;
    for(int d = 0; d < 4; ++d) {
        auto cur = p;
        bool first = true;
        while(true) {
            cur.first += DR[d];
            cur.second += DC[d];
            if(cur.first < 0 || cur.first >= H || cur.second < 0 || cur.second >= W) {
                break;
            }
            if(field[cur.first][cur.second] == 3) {
                ans = min(ans, turn);
                break;
            }
            if(field[cur.first][cur.second] == 1) {
                if(!first) {
                    field[cur.first][cur.second] = 0;
                    dfs(field, make_pair(cur.first-DR[d], cur.second-DC[d]), turn+1);
                    field[cur.first][cur.second] = 1;
                }
                break;
            }
            first = false;
        }
    }
}

bool solve() {
    if(!(cin >> W >> H)) return false;
    if(!W && !H) return false;

    vector<vector<int>> field(H, vector<int>(W, 0));
    pair<int,int> start;
    for(int r = 0; r < H; ++r) {
        for(int c = 0; c < W; ++c) {
            cin >> field[r][c];
            if(field[r][c] == 2) {
                start = make_pair(r, c);
            }
        }
    }

    ans = 100;
    dfs(field, start, 1);
    if(ans == 100) ans = -1;
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <stdlib.h>
 
int puzzle[3][3];
int tmp[3][3];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
void empty(int *,int *);
int dfs(int,int,int,int,const int);
int cal();
void swap(int *,int *);
 
int main() {
    int i,j,a,x,y,l;
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) scanf("%d",&puzzle[i][j]);
    }
 
    empty(&x,&y);
    for(l=0; l<100; l++) {
        for(i=0; i<3; i++) {
            for(j=0; j<3; j++) tmp[i][j] = puzzle[i][j];
        }
 
        a = dfs(x,y,-1,0,l);
        if(a!=-1) {
            printf("%d\n",a);
            break;
        }
 
        for(i=0 ; i<3 ; i++) {
            for(j=0 ; j<3 ; j++) puzzle[i][j] = tmp[i][j];
        }
        a = -1;
        if(l==99) printf("%d\n",a);
    } 
    return 0;
}
 
void empty(int *x,int *y) {
    int i,j;
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) {
            if(!puzzle[i][j]) {
                *x = j;
                *y = i;
                return;
            }
        }
    }
}
 
void swap(int *a,int *b) {
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}
 
int cal() {
    int i,a,sum=0;
    for(i=0; i<9; i++) {
        a = puzzle[i/3][i%3];
        if(a) {
            a--;
            sum += abs(i/3 - a/3) + abs(i%3 - a%3);
        }
    }
    return sum;
}
 
int dfs(int x,int y,int p,int dep,const int lim) {
    int i,h,nx,ny,res;
 
    h = cal();
    if(h==0) return dep;
    if(dep+h>lim) return -1;
 
    for(i=0; i<4; i++) {
        nx = x+dx[i];
        ny = y+dy[i];
  
        if(~p && i==(p+2)%4) continue;
        if(!(0<=nx && nx<3 && 0<=ny && ny<3)) continue;
  
        swap(&puzzle[y][x],&puzzle[ny][nx]);
        res = dfs(nx,ny,i,dep+1,lim);
        if(~res) return res;
  
        swap(&puzzle[y][x],&puzzle[ny][nx]);
    }
 
    return -1;
}


Measured memory_bytes: 2044