akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
r = range

s = input()
ret = 0
tmp = 0
for c in s:
    tmp += 1 if c == 'S' else -1
    ret = min(ret, tmp)

print(-ret*2)

Measured memory_bytes: 14436
s=input()
x="KIHBR"
no=[0]
for i in x:
    if not(i in s[no[-1]:]):
        print("NO")
        exit()
    else:
        no.append(s[no[-1]:].index(i)+no[-1])
no.append(len(s))
if no[1]>=2 or no[1]==1 and s[0]!="A" or no[2]-no[1]>=2 or no[3]-no[2]>=2 or no[4]-no[3]>=3 or no[4]-no[3]==2 and s[no[3]+1]!="A" or no[5]-no[4]>=3 or no[5]-no[4]==2 and s[no[4]+1]!="A" or no[6]-no[5]>=3 or no[6]-no[5]==2 and s[no[5]+1]!="A":
    print("NO")
else:
    print("YES")

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

int main() {
	ll N, X, T;
	cin >> N >> X >> T;
	if ((N % X) == 0) {
		cout << ((N / X))*T << endl;
	}
	else {
		cout << ((N / X) + 1)*T << endl;
	}
	return(0);
}


Measured memory_bytes: 3548
#include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;

// 番兵を利用した線形探索アルゴリズム
int binarySearch(vector<int> & A, const int n, const int key) {
	int left = 0; // 探索配列の左端
	int right = n; // 探索配列の右端
	int mid; // 探索配列の中央
	while (left < right) {
		mid = (left + right) / 2;
		if (A[mid] == key) return 1; // key値を発見した
		else if (A[mid] < key) left = mid + 1;
		else if (A[mid] > key) right = mid;
	}
	return 0; // key値が見つからなかった
}

int main(void) {
	int n; cin >> n;
	vector<int> S(n);
	for (int i = 0; i < n; i++) scanf("%d", &S[i]);

	int q; cin >> q;
	int key; // 探索対象となるキー値
	int res = 0; // 探索キーが見つかった回数
	for (int i = 0; i < q; i++) {
		scanf("%d", &key);
		// 二分探索してキー値が見つかればカウント
		if (binarySearch(S, n, key)) res++;
	}
	cout << res << endl;
}


Measured memory_bytes: 3172
n = gets.chomp.to_i
abs = n.times.map { gets.chomp.split.map(&:to_i) }

sorted = abs.sort_by { |a, b| b }

time = 0
sorted.each do |a, b|
    time = time + a
    if time > b
        puts 'No'
        exit
    end
end

puts 'Yes'


Measured memory_bytes: 24312
S = str(input())
N = len(S)
#print(N)
flag = True
if S == S[::-1]:
    n1 = int((N-1)/2)
    S1 = S[:n1]
    #print(S1)
    if S1 == S1[::-1]:
        n2 = int((N+3)/2)
        S2 = S[n2-1:]
        #print(S2)
        if S2 == S2[::-1]:
            print("Yes")
            flag = False
if flag:
    print("No")

Measured memory_bytes: 38384
n = int(input())
for i in range(n):
    a, b, c = map(int,input().split())
    if a**2 + b**2 == c**2 or a**2 + c**2 == b**2 or b**2 + c**2 == a**2:
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 5596
#include<cstdio>
#include<cstring>
#define MAXN 100000
#define MAXM 200000
struct node
{
	int fa,dist;
}poi[MAXN+5];
int FindSet(int x,int &dist)
{
	if(poi[poi[x].fa].fa==poi[x].fa)
	{
		dist=poi[x].dist;
		return poi[x].fa;
	}
	int d;
	int newfa=FindSet(poi[x].fa,d);
	poi[x].fa=newfa;
	dist=d+poi[x].dist;
	poi[x].dist+=d;
	return newfa;
}
bool SameSet(int x,int y)
{
	int dx,dy;
	return FindSet(x,dx)==FindSet(y,dy);
}
void UniteSet(int x,int y,int dist)
{
	int dx;
	int fx=FindSet(x,dx);
	int dy;
	int fy=FindSet(y,dy);
	poi[fx].fa=fy;
	poi[fx].dist=poi[y].dist+dist-poi[x].dist;
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
		poi[i].fa=i;
	for(int i=1;i<=m;i++)
	{
		int x,y,d;
		scanf("%d %d %d",&x,&y,&d);
		if(SameSet(x,y)==true)
		{
			if(poi[x].dist-poi[y].dist!=d)
			{
				printf("No\n");
				return 0;
			}
		}
		else
			UniteSet(x,y,d);
	}
	printf("Yes\n");
	return 0;
}
/*
3 4
1 3 2
4 2 5
1 2 1
4 1 4
*/

Measured memory_bytes: 896
#include <stdio.h>
int A[2000000];
int n;
 
int Partition(int,int);

int main(){
  int i,k;
 
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }

  k=Partition(1,n);

  for(i=1;i<=n;i++){
    if(k==i) printf("[%d] ",A[i]);
    else if(i==n) printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }
  return 0;
}
   
int Partition(int p,int r){
  int x,y,i,j;
 
  x = A[r];
  i = p-1;
  for(j = p;j<=r-1;j++){
    if( A[j] <= x){ i = i+1;
    y=A[i];
    A[i]=A[j];
    A[j]=y;
    }
  }
    y=A[i+1];
    A[i+1] =A[r];
    A[r]=y;
    return i+1;
}

Measured memory_bytes: 992
import math
import heapq
import sys
from collections import Counter
import numpy as np
import datetime

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#s = [input() for i in range(3)]

S=input()
try:
    a = datetime.date(int('20'+S[:2]), int(S[2:]), 1)
    try:
        a = datetime.date(int('20'+S[2:]), int(S[:2]), 1)
        print('AMBIGUOUS')
    except ValueError:
        print('YYMM')
except ValueError:
    try:
        a = datetime.date(int('20'+S[2:]), int(S[:2]), 1)
        print('MMYY')
    except ValueError:
        print('NA')

Measured memory_bytes: 12496
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;

vector<int> Point(string s){
  stringstream ss(s);
  int num;
  vector<int> v;

  while(ss >> num){
    v.push_back(num);
  }

  return v;
}

int getScore(string s){
  vector<int> a;
  a = Point(s);
  int len = (int)a.size();
  int score = 0 , sum = 0;
  int p = 0,n = 0;

  for(int i = 0 ; i < len ; i++){
    if(p >= 9){
      p++;
      score += a[i];
    }else{
      if(a[i] == 10 && n == 0){
	score += a[i] + a[i+1] + a[i+2];
	p++;
      }else{
	n++;
	sum += a[i];
	if(n == 2){
	  n = 0;
	  score += sum;
	  if(sum == 10){
	    score += a[i+1];
	  }
	  p++;
	  sum = 0;
	}
      }
    }
  }

  return -score;
}

int main(){
  int m;
  while(cin >> m ,m){
    vector<P> v;
    string pin;
    for(int i = 0 ; i < m ; i++){
      int score,num;
      cin >> num;

      getline(cin,pin);
      score = getScore(pin);
  
      v.push_back(P(score,num));
    }
    sort(v.begin(),v.end());
    for(int i = 0 ; i < m ; i++){
      cout << v[i].second << " " << -v[i].first << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1244
/* _________________________________________________________________________________________________
  |                                                                                                 |
  |                             Author      : Aditya Ahuja                                          |
  |                             Date        : Thu, 20th Jun 2019                                    |
  |_________________________________________________________________________________________________|
*/
 
#include<bits/stdc++.h>
using namespace std;

// #define int long long

#define pb          push_back
#define F           first
#define S           second
#define rep(i,a,b)  for(int i=a; i<b; i++)
#define all(a)      (a).begin(),(a).end()
#define ret(x)      {cout << (x) << endl; return;}
#define sz(x)       (int)x.size()
#define type(x)     typeid(x).name()

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

#define wa(x)       cout << (#x) << " -------- " << (x) << endl
#define pvi(v)      {for(auto it:v) cout << it << " "; cout << endl;}
#define line1	    printf("---------------------------\n")

// #define wa //
// #define line1 //
// #define pvi //
// #define printf //

void solve();
signed main() {
	//ios_base::sync_with_stdio(false); cin.tie(NULL);
	////cout << fixed << setprecision(10);

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

//___________________________________________________________________________________________________

void solve() {

	int n;
	cin>>n;

	vi a(n);
	rep(i,0,n) cin>>a[i];

	vi dp(n, 1e9+5);
	dp[0]=0;

	for(int i=0; i<n; ++i) {
		for(int j:{i+1,i+2}) {
			if(j<n) {
				dp[j] = min(dp[j], dp[i] + abs(a[j] - a[i]));
			}
		}
	}
	
	ret(dp[n-1]);
}


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

using ll = long long;

constexpr int mod = 1e9+7;
constexpr ll inf = 4e18;

struct edge
{
    int t,w;
    edge(int t, int w) : t(t), w(w) {}
};

int sq(long long x)
{
    return x*x%mod;
}

vector<edge> g[100005];
ll dist[2][100005], cnt[2][100005];

void dijk(int st, ll* d, ll* cn)
{
    priority_queue<pair<ll,int>> pq;
    pq.emplace(0,st);
    while(!pq.empty())
    {
        ll w = -pq.top().first;
        int c = pq.top().second;
        pq.pop();
        if(w > d[c]) continue;
        for(auto e : g[c])
        {
            ll ww = w + e.w;
            if(ww>d[e.t]) continue;
            if(ww == d[e.t])
            {
                cn[e.t] += cn[c];
                cn[e.t] %= mod;
                continue;
            }
            d[e.t] = ww;
            cn[e.t] = cn[c];
            pq.emplace(-ww,e.t);
        }
    }
}

int main()
{
    int n,m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    while(m--)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        g[a].push_back(edge(b,c));
        g[b].push_back(edge(a,c));
    }
    for(int i=0;i<=n;i++) dist[0][i] = dist[1][i] = inf;
    dist[0][s] = dist[1][t] = 0;
    cnt[0][s] = cnt[1][t] = 1;
    dijk(s,dist[0],cnt[0]);
    dijk(t,dist[1],cnt[1]);
    ll len = dist[0][t];
    ll ans = cnt[0][t]*cnt[1][s]%mod;
    for(int i=1;i<=n;i++)
    {
        if(dist[0][i] == dist[1][i] && dist[0][i]*2 == len)
        {
            ans = (ans + mod - sq(cnt[0][i]*cnt[1][i]%mod))%mod;
        }
        else
        {
            if(dist[0][i] + dist[1][i] > len || dist[0][i]*2 > len) continue;

            for(auto e : g[i])
            {
                ll ww = dist[0][i] + e.w;
                if(ww + dist[1][e.t] > len || ww*2 <= len) continue;;
                ans = (ans + mod - sq(cnt[0][i]*cnt[1][e.t]%mod))%mod;
            }
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 15060
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		out.println(Math.max(Math.max(A+A-1, A+B), (B+B-1)));

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#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 vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	FAST;
	ll n, i, j;
	cin >> n;
	ll a[n+1];
	ll b[n];
	fr(i,0,n+1)
		cin >> a[i];
	fr(i,0,n)
		cin >> b[i];
	ll c = 0, ans = 0;
	fr(i,0,n+1)
	{
		if(i == n)
		{
			ans += min(c, a[i]);
			continue;
		}
		if(c >= a[i])
		{
			c = b[i];
			ans += a[i];
		}
		else
		{
			if(c + b[i] >= a[i])
			{
				ans += a[i];
				c = c + b[i] - a[i];
			}
			else
			{
				ans += c + b[i];
				c = 0;
			}
		}
	}
	cout << ans;
}


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

#define MOD 1e9+7;
#define INF 1e17+9;

using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	
	if(n==1 && m==0){
		cout << "0" << endl;
		return 0;
	}
	
	vector<int> a(50,-1);

	for(int i=0;i<m;i++){
		int s,c;
		cin >> s >> c;
		if(a[s]==-1){
			a[s]=c;
		}else{
			if(a[s]==c){
				continue;
			}else{
				cout << "-1" << endl;
				return 0;
			}
		}
	}
	
	if(n>=2 && a[1]==0){
		cout << "-1" << endl;
		return 0;
	}
	
	int ans=0;		
	for(int i=1;i<=n;i++){
		if(a[1]==-1){
			a[i]=1;
		}
		if(a[i]==-1){
			a[i]=0;
		}
		ans+=a[i]*pow(10,n-i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    try(Scanner sc = new Scanner(System.in)){
      int w = sc.nextInt();
      int n = sc.nextInt();
      int[] values = new int[w];
      for(int i=0;i<values.length;i++){
        values[i] = i+1;
      }
      for(int i=0;i<n;i++){
        String str = sc.next();
        String[] ab = str.split(",");
        int a = Integer.parseInt(ab[0])-1;
        int b = Integer.parseInt(ab[1])-1;

        int temp = values[a];
        values[a]=values[b];
        values[b]=temp;
      }
      for(int i=0;i<values.length;i++){
        System.out.println(values[i]);
      }
    }
  }
}



Measured memory_bytes: 26040
N, K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0

for a in range(min(N,K)+1):
    for b in range(min(N,K)-a+1):
        cur = V[:a] + V[N-b:]
        cur.sort()

        idx = 0
        while idx < min(K-a-b, len(cur)):
            if cur[idx] > 0: break
            else: idx += 1
        
        ans = max(ans, sum(cur[idx:]))
    
print(ans)

Measured memory_bytes: 9160
#include <stdio.h>

int main(void)
{
    int H,W;
    int i,j,k,count;

    int a[100][2];

    for(count=0;;count++){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0){
            break;
        }

        a[count][0]=H;
        a[count][1]=W;
    }

    for(i=0;i<count;i++){
        /* 長方形 */
        for(j=0;j<a[i][0];j++){

            if(j==0||j==(a[i][0]-1)){
                for(k=0;k<a[i][1];k++){
                    printf("#");
                 }
            }
            else{
                /* 横一列 */
                for(k=0;k<a[i][1];k++){
                    if(k==0 || k ==(a[i][1]-1)){
                        printf("#");
                    }
                    else{
                        printf(".");
                    }
                }
            }

            printf("\n");
        }
        printf("\n");
    }
    return 0;
}





Measured memory_bytes: 2596
n = gets.to_i
a = n.times.map{|i| gets.split.map(&:to_i)}
101.times do |x|
  101.times do |y|
    i, j, k = a.find{|i, j, k| k != 0}
    h = (i - x).abs + (j - y).abs + k
    next if h < 1
    if a.all?{|i, j, k| [h - (i - x).abs - (j - y).abs, 0].max == k }
      puts [x, y, h].join(' ')
      exit
    end
  end
end


Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;

char s[30010];
int n;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(6);
	cout << fixed;
	
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < 1000; ++i) {
		int c[3];
		int temp = i;
		for (int j = 0; j < 3; ++j) {
			c[j] = temp % 10;
			temp /= 10;
		}
		int pos = 0;
		for (int i = 0; i < n; ++i) {
			if (s[i] == c[pos] + '0')
				++pos;
			if (pos == 3)
				break;
		}
		if (pos == 3)
			++ans;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main()
{
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);

  if(a==b+c||b==a+c||c==a+b)
  {
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if ( A + B == 10 ){
    if ( C == 7 ){
      cout << "YES" << endl;
    }
  }
  else if ( A + C == 10 ){
    if ( B == 7 ){
      cout << "YES" << endl;
    }
  }
  else if ( B + C == 10 ){
    if ( A == 7 ){
      cout << "YES" << endl;
    }
  }
  else {
    cout << "NO" << endl;
  }
}


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



int main(){
	cin.tie(0)->sync_with_stdio(0);
	long long x, k, d;
	cin >> x >> k >> d, x = abs(x);
	if(x / d >= k){
		cout << x - d * k << "\n";
	}
	else{
		k - x / d & 1 ? cout << abs(x - d * (x / d + 1)) << "\n" : cout << x - x / d * d << "\n";
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    map<pair<int,int>,int> mp;

    for(int i = 0; i < m; i++) {
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        mp[make_pair(a,b)]++;
        mp[make_pair(b,a)]++;
    }

    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        a[i]=i;
    }
    int cnt=0;
    while(a[0]==0) {
        bool flag=true;
        for(int i = 1; i < n; i++) {
            if(mp.count(make_pair(a[i-1],a[i]))==0) flag=false;
        }
        if(flag) cnt++;
        next_permutation(a.begin(),a.end());
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define ALL(a) (a).begin(), (a).end()
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
#define INF 1e18
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
  return s.find(v) != std::string::npos;
}
ULL mod = 1e9 + 7;

int main()
{
  string s, before = "", after = "";
  bool flag = false;
  cin >> s;
  for (int i = 0; i <= s.size(); i += 2)
  {
    flag = true;
    for (int j = 0; j < (s.size() - i) / 2; j++)
    {
      before += s[j];
      after += s[(s.size() - i) / 2 + j];
    }

    if (before == after && i != 0)
    {
      cout << before.size() + after.size() << endl;
      return 0;
    }
    before = "";
    after = "";
  }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, bool>> box(N, make_pair(1, false));
  box[0].second = true;
  rep(i, M){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    box[y].first++;
    box[y].second |= box[x].second;
    box[x].first--;
    if(box[x].first == 0){
      box[x].second = false;
    }
  }
  int count = 0;
  rep(i, N){
    if(box[i].second){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

int main(){
    long long  n;
    long long  ans=1;
    cin >> n;
    for(long long  i=2;i<=n;i++){
        for(long long k =2;k<=i;k++){
            if(k == i){
                long long sum  =0;
                for(long long j=1;(long long)pow(i,j) <= n;j++){        
                    long long  count = 1;
                    long long num = (long long)pow(i,j);
                    long long tmp = num; 
                    while(tmp<=n){
                        count ++;
                        tmp = num * count;
                    }
                    sum += count -1;   
                }
                ans = (ans*(long long)(sum +1))%(long long )(1000000007);
               // cout <<"i=" << i <<  "ans=" << ans<<endl;
            }
            else if(i%k == 0){
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int Maxn = 100010;
int x,y,z,cnt,ans,maxn;
int main()
{
    cin>>x>>y>>z;
    cnt = x/y;
    maxn = 0;
    for (int i = 1; i <= cnt; i++)
    {
        ans = i * y + z * ( i - 1 ) + 2 * z;
        if(ans <= x && i > maxn)
            maxn = i;
    }
    printf("%d\n",maxn);
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;



int main() {
    ll n; cin>>n;
    ll n1=n-1, ans=0, tmp=1;
    for(ll i=2; i*i<=n1; ++i) {
        if(n1%i==0) {
            int j=0;
            while(n1%i==0) n1/=i, j++;
            tmp*=j+1;
        }
    }
    if(n1>1) tmp*=2;
    ans=tmp;
    vector<ll> d;
    for(ll i=2; i*i<=n; ++i) {
        if(n%i==0) {
            d.push_back(i);
            if(i*i!=n) d.push_back(n/i);
        }
    }
    for(ll c: d) {
        ll x=n;
        while(x%c==0) x/=c;
        if(x%c==1) ans++;
    }
    cout<<ans<<endl;
}

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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define RPT1(i, n) RPT(i, 1, n)
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

void resolve()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,i;
	cin >> n;
	vector<vector<int>> v(10, vector<int>(10));
	for (int i = 1; i <= n; ++i) {
		int a = i % 10;
		int b = i;
		while (b >= 10) b /= 10;
		v[a][b]++;
	}
	int ans = 0;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			ans+=v[i][j]*v[j][i];
		}
	}
	cout << ans << endl;
 	return 0;
}

Measured memory_bytes: 256
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
a = Is()
#a = sorted(a)
ans = 10**10
for i,e in enumerate(a):
    l,r = a[:i],a[i:]
    ans = min(abs(sum(l)-sum(r)),ans)
print(ans)

Measured memory_bytes: 4712
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
long long s(long long x){
    if(x>0) return x;
    return -x;
}

int main(){
   long long a,v,b,w,t;
   cin>>a>>v>>b>>w>>t;;
   if(s(b-a)<=t*(v-w)) cout<<"YES";
   else cout<<"NO";
}


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

using namespace std;

const int N = 100010;

int a[N];
int parent[N];
int where[N];

int find(int x) {
  if (x == parent[x]) {
    return x;
  }
  return parent[x] = find(parent[x]);
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    a[i]--;
    where[a[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    parent[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--; b--;
    int x = find(a), y = find(b);
    if (x != y) {
      parent[y] = x;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x = find(i), y = find(where[i]);
    if (x == y) {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
struct UnionFind {
    vector<int> d;
    UnionFind(int n):d(n,-1){}
    int root(int x){
        if(d[x] <0) return x;
        return d[x] = root(d[x]);

    }
    bool unite(int x,int y){
        x = root(x),y = root(y);
        if(x == y) return false;
        if(d[x] < d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    int size(int x) {return -d[root(x)];}
};

int main()
{
    int n,m,k;
    cin >> n >> m >> k;
    vector<int> friends(n);
    UnionFind uf(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--;b--;
        friends[a]++;
        friends[b]++;
        uf.unite(a,b);
    }
    vector<vector<int>> block(n);

    rep(i,k){
        int c,d;
        cin >> c >> d;
        c--;d--;
        block[c].push_back(d);
        block[d].push_back(c);

    }
    rep(i,n){
        
        int ans = uf.size(i) - 1- friends[i];
        for ( int x : block[i]){
            if(uf.root(x) == uf.root(i))ans--;

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

Measured memory_bytes: 7424
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

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

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	string s; cin >> s;
	set<char> st;
	for (int i = 0; i < 3; i++)st.insert(s[i]);
	if (st.size() == 3) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3612
using System;

    class Program
    {

        static void Main(string[] args)
        {
            //文字列受け取り
            string str = Console.ReadLine();

            //文字列→char配列
            char[] array = str.ToCharArray();

            //文字数取得
            int len = str.Length;

            for (int i = 0; i < len; i++)
            {

                if (char.IsLower(array[i]))
                {
                    //小文字→大文字
                    array[i] = char.ToUpper(array[i]);
                    Console.Write(array[i]);
                }
                else if (char.IsUpper(array[i]))
                {
                    //大文字→小文字
                    array[i] = char.ToLower(array[i]);
                    Console.Write(array[i]);
                }
                else
                {
                    Console.Write(array[i]);
                }
            }
            Console.WriteLine("");
        }
    }



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

using namespace std;

int main ()
{
    int n, x, i = 0, arr[105];
    scanf("%d", &n);
    while (n--) {
        scanf("%d", &x);
        arr[i] = x;
        i++;
    }
    sort(arr, arr + i);
    n = i;
    int ans = 0;
    for (int i = arr[0] + 1; i <= arr[n - 1]; i++) {
        int sum = 0;
        for (int j = 0; j < n; j++) {
            sum += abs((arr[j] - i) * (arr[j] - i));
        }
        if (ans == 0 || ans > sum) {
            ans = sum;
        }
    }
    printf("%d\n", ans);

    return 0;
}


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

using namespace std;

class job{
public:
	job(){}
	job(string n, int t){
		name = n;
		time = t;
	}
	job(const job& a){
		name = a.name;
		time = a.time;
	}
	void operator=(const job& a){
		name = a.name;
		time = a.time;
	}
	string name;
	int  time;
};

class queue{
public:
	queue(int q, int n):_head(0),_tail(0){
		_num = n+1;
		_queue = new job[_num];
	}
	~queue(){delete[] _queue;}
	job deq(){
		int head = _head;
		_head = ++_head >= _num ? 0:_head;
		return _queue[head];
	}
	void enq(job a){
		_queue[_tail++] = a;
		_tail = _tail >= _num ? 0: _tail;
	}
	bool check(){
		return _tail == _head;
	}

private:
	job* _queue;
	int _head;
	int _tail;
	int _num;
};

int main()
{
	int num, quantum, time;
	char buf[11];
	scanf("%d %d",&num,&quantum);
	queue qqq(quantum, num);

	for(int i=0; i<num; ++i){
		scanf("%s %d",buf,&time);
		job a((string)buf, time);
		qqq.enq(a);
	}

	int clock=0;

	while(!qqq.check()){
		job t = qqq.deq();
		t.time -= quantum;
		if(t.time <= 0){
			clock += quantum + t.time;
			cout << t.name << " " << clock << endl;
		}
		else{
			clock += quantum;
			qqq.enq(t);
		}
	}
	return 0;
}


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

using namespace std;

#define ll long long


/*
    重さw[i],価値v[i]の品物n個があるとき、
        max_value[j] : 重さj以内で選べる価値の最大値
                            (j = 0,1,2,...,wmax)
    なる配列max_valueを計算して返す.
 */
ll* knapsack(ll* w,ll* v,int n,ll wmax){
    /*
        dp[i][j] : possible max value you can get when 
                you select some items from item 1,2,...,n
                and put them into a bag of strength j.
     */
    // initialize the dp table
    ll** dp = new ll*[n + 1];
    for (int i = 0;i <= n;++i){
        dp[i] = new ll[wmax + 1];
    }
    for (int i = 0;i <= n;++i)
        for (int j = 0;j <= wmax;++j)
            dp[i][j] = 0;
    // fill the dp table
    for (int i = 1;i <= n;++i){
        ll wi = w[i - 1];
        ll vi = v[i - 1];
        for (int j = 0;j <= wmax;++j){
            if (j >= wi){
                dp[i][j] = max({
                    dp[i - 1][j],
                    dp[i - 1][j - wi] + vi
                });
            }
            else
                dp[i][j] = dp[i - 1][j];
        }
    }
    // free unnecessary memory
    for (int i = 0;i < n;++i)
        delete[] dp[i];

    return dp[n];
}

signed main(){
    int n,w;
    cin >> n >> w;
    ll* weight = new ll[n];
    ll* value = new ll[n];
    for (int i = 0;i < n;++i)
        cin >> weight[i] >> value[i];

    auto knap = knapsack(weight,value,n,w);

    cout << knap[w] << endl;
    return 0;
}

Measured memory_bytes: 79360
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
using namespace std;
typedef long long ll;
int main() {
    int x;
    cin >> x;
    cout << x*x*x << endl;

    return 0;
}

Measured memory_bytes: 1160
$stdin.read.split(?\n).tap do |hw, *map|
  h, w = hw.split.map(&:to_i)

  map
    .map { |line| line.split // }
    .select { |line| line.include? "#" }
    .transpose
    .select { |line| line.include? "#" }
    .transpose
    .each do |line| puts line * "" end
end

Measured memory_bytes: 2300
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int MOD = 1e9+7;
const int MAX = 1e6+10;
const int INF = 0x3fffffff;

int a,b,c;

int main(){
	while(scanf("%d%d%d",&a,&b,&c)!=EOF){
		if((a+b==c)||(b+c==a)||(a+c==b))	printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
    long long n,m,l,a[100][100],b[100][100],c[100][100]={0};
    cin >> n >> m >> l;
    for(int i=0;n>i;i++)
        for(int j=0;m>j;j++) cin >> a[i][j];
    for(int i=0;m>i;i++)
        for(int j=0;l>j;j++) cin >> b[i][j];
    for(int i=0;n>i;i++)
        for(int j=0;l>j;j++)
            for(int k=0;m>k;k++)
                c[i][j]+=a[i][k]*b[k][j];
    for(int i=0;n>i;i++){
        for(int j=0;l>j;j++){
            cout << c[i][j];
            if((l-1)!=j) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3324
n, k = (int(x) for x in input().split())
h_list = list(map(int, input().split()))

# 体力の多い順に並べ替え
h_list.sort(reverse = True)

temp_k = k
sum_normal_attack = 0

while temp_k < n:
    sum_normal_attack = sum_normal_attack + h_list[temp_k]
    temp_k = temp_k + 1

print(sum_normal_attack)

Measured memory_bytes: 26180
/*
中間試験、期末試験のいずれかを欠席した場合成績は F。
中間試験と期末試験の合計点数が 80 以上ならば成績は A 。
中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B。
中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C。
中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D。 ただし、再試験の点数が 50 以上ならば成績は C。
中間試験と期末試験の合計点数が 30 未満ならば成績は F。
*/

#include<iostream>
using namespace std;

struct Student{
    int m, f, r;
};

int main(){
    int m, f, r;
    struct Student s[50];
    
    cin >> m >> f >> r;
    s[0].m = m; s[0].f = f; s[0].r = r;
    
    int i=1;
    while(m+f+r>-3){
        cin >> m >> f >> r;
        s[i].m = m; s[i].f = f; s[i].r = r;
        i++;
    }
    
    int num_student = i-1; //学生数
    i=0; //カウンターリセット
    while(i<num_student){
        if(s[i].m==-1 || s[i].f==-1) cout << "F" << endl;
        else if(s[i].m + s[i].f >= 80) cout << "A" << endl;
        else if(s[i].m + s[i].f < 80 && s[i].m + s[i].f >= 65) cout << "B" << endl;
        else if(s[i].m + s[i].f < 65 && s[i].m + s[i].f >= 50) cout << "C" << endl;
        else if(s[i].m + s[i].f < 50 && s[i].m + s[i].f >= 30){
            if(s[i].r >= 50) cout << "C" << endl;
            else cout << "D" << endl;
        }else cout << "F" << endl;
        i++;
    }
    
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int H, W;
char route[110][110];
int main() {
    cin >> H >> W;
    vector<int> checkerH(H);
    vector<int> checkerW(W);

    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            cin >> route[i][j];
            if(route[i][j] == '#') {
                checkerH.at(i) = 1;
                checkerW.at(j) = 1;
            }
        }
    }

    for(int i = 0; i < H; ++i) {
        if(checkerH.at(i) == 1) {
            for(int j = 0; j < W; ++j) {
                if(checkerW.at(j) == 1) {
                    cout << route[i][j];
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int b;
int n[405];
long long bio[405][405], pref[405];
long long r(int p, int k)
{
	if(bio[p][k] != -1)
	{
		return bio[p][k];
	}
	if(p == k)
	{
		return bio[p][k] = 0;
	}
	long long u = (long long)1e18;	
	for(int j = p; j < k; j++)
	{
		if(p != 0)
		{
		    u = min(u, pref[k] - pref[p-1] + r(p, j) + r(j+1, k));
		}
		else
		{
			u = min(u, pref[k] + r(p, j) + r(j+1, k));
		}
	}	
	return bio[p][k] = u;
}
int main()
{
    cin >> b;
    for(int i = 0; i < b; i++)
    {
    	cin >> n[i];
	}
	for(int i = 0; i < 405; i++)
	{
		for(int j = 0; j < 405; j++)
		{
			bio[i][j] = -1;
		}
	}
	pref[0] = n[0];
    for(int i = 1; i < b; i++)
    {
    	pref[i] = pref[i-1] + n[i];
	}
	cout << r(0, b-1) << endl;
}



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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> vec;
  for(int i=0; i<n; i++){
    int num;
    cin >> num;
    vec.push_back(num);
  }
  int smallest = 1000000000;
  for(int i=0; i+k-1<n; i++){
    int left = vec[i];
    int right = vec[i+k-1];
    if(right-left+min(abs(left), abs(right)) < smallest){
      smallest = right-left+min(abs(left), abs(right));
    }
  }
  cout << smallest << endl;
  return 0;
}
      
      
      
      

Measured memory_bytes: 892
#include <iostream>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    string s;
    cin >> s;
    map<string, int> m;
    m["SUN"] = 7;
    m["MON"] = 6;
    m["TUE"] = 5;
    m["WED"] = 4;
    m["THU"] = 3;
    m["FRI"] = 2;
    m["SAT"] = 1;
    cout << m[s] << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N;
int d[MAX];

int main(void) {
    cin >> N;
    REP(i, N) cin >> d[i];
    sort(d, d + N);
    int ans = 0;
    FOR(i, 1, MAX) {
        auto dist = lower_bound(d, d + N, i) - d;
        if (dist == N / 2) ans ++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
//constexpr ll MOD = 1e9+7;
constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

Vec2<ll> graph;

set<ll> st;

ll dfs(ll v, ll p, ll s, ll t){
	if (v == s) return 1;
	else if(v == t) return 0;
	
	for(ll i : graph[v]){
		if (i != p) return dfs(i, v, s, t);
	}
	return 0;
}

int main(void){
	ll n, m;
	cin >> n >> m;
	graph.resize(n);
	rep(i, m){
		ll a, b;
		cin >> a >> b;
		--a, --b;
		graph[a].pb(b);
		graph[b].pb(a);
	}

	bool flg = true;
	rep(i, n) if(graph[i].size() & 1){
		puts("No");
		return 0;
	}

	Vec e4;
	rep(i, n){
		if(graph[i].size() >= 6){
			puts("Yes");
			return 0;
		}else if(graph[i].size() == 4)
			e4.pb(i);
	}

	if(e4.size() >= 3){
		puts("Yes");
		return 0;
	}else if(e4.size() == 2){
		ll cnt = 0;
		for(ll i : graph[e4[0]]){
			cnt += dfs(i, e4[0], e4[0], e4[1]);
		}

		if (cnt) {
			puts("Yes");
			return 0;
		}
	}

	puts("No");

	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FOR(i,j,n,m) for(int i=j;i<n;i+=m)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=3e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=(ll)1e18;

ll d[MAXn];
int main(){
  IOS();
  ll n;
  string s;
  cin>>n>>s;
  REP(i,n){
    d[i+1]+=(s[i]=='W' ?1:0);
    d[i+1]+=d[i];
  }
  pary(d,d+n);
  ll tmp;
  ll ans=INF;
  REP(i,n){
    tmp=0;
    ll x=n-i-1-(d[n]-d[i+1]),y=d[i];
    tmp=x+y;
    debug(x,y,tmp);
    chkmin(ans,tmp);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2964
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s;
    int n = s.size();
    int cnt[3] = {-n/3, -n/3, -n/3};
    rep(i, 0, n) cnt[s[i] - 'a']++;
    bool flag = true;
    rep(i, 0, 3) {
      if (cnt[i] != 0 && cnt[i] != 1) {
        flag = false;
      }
    }
    cout << (flag ? "YES" : "NO") << endl;
    return 0;
}



Measured memory_bytes: 512
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <sstream>
#include <bitset>
using namespace std;
#define MP(a, b) make_pair(a, b)
#define VT vector
#define FI first
#define SE second
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
typedef long long ll;
typedef unsigned long long ull;

bool can[110][110];

int a[110];
int dp[110];
int sum[110][110];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), can[i][i] = 1, sum[i][i] = a[i];

    for (int l = 2; l <= n; l++) {
        for (int i = 1; i + l - 1 <= n; i++) {
            for (int j = i; j < i + l; j++) {
                sum[i][i+l-1] = sum[i][j] + sum[j+1][i+l-1];
                if (sum[i][j] == sum[j+1][i+l-1])
                    can[i][i+l-1] = can[i][j] & can[j+1][i+l-1];
                // printf("can[%d][%d] = %d\n", i, i + l - 1, can[i][i+l-1]);
            }
        }
    }

    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        dp[i] = 1000;
        for (int j = 0; j < i; j++) {
            if (can[j+1][i]) {
                dp[i] = min(dp[i], dp[j] + 1);
            }
        }
    }
    printf("%d\n", dp[n]);



    return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define int long long
signed  main(){
  int N,K;
  str S;
  cin>>N>>K;
  cout<<N-K+1<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPP(i,j,n) for(int i=(int)(j);i<(int)(n);i++)

using namespace std;
using ll=long long;
ll lcd(ll a,ll b){
  if(b>a)swap(a,b);
  if(a%b==0)return b;
  return lcd(b, a%b);
}
ll t[1010],a[1010];
int main(){ _;
  int n;cin>>n;
  REP(i,n)cin>>t[i]>>a[i];
  ll tmin=t[0],amin=a[0];
  REPP(i,1,n){
    if(tmin%t[i])tmin=(tmin/t[i]+1)*t[i];
    if(amin%a[i])amin=(amin/a[i]+1)*a[i];
    ll t0=amin/a[i]*t[i];
    ll a0=tmin/t[i]*a[i];
    if(t0<tmin){
      amin=a0;
    }else if(a0<amin){
      tmin=t0;
    }
  }
  cout<<tmin+amin<<endl;
}


Measured memory_bytes: 384