akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main(){
    int n,x;
    cin >> n >> x;
    int sum = 0;
    int ans = 1;
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        sum += t;
        if(sum > x) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import collections

N, K, Q = map(int, input().split())
A = [int(input()) - 1 for i in range(Q)]
A_count = collections.Counter(A)
A_sum = sum(A_count.values())
for i in range(N):
    if K - (A_sum - A_count[i]) <= 0:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 16712
#include <bits/stdc++.h>
using namespace std;
int n;
long long l[110];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",l+i);
	}
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(l[i]!=l[j])
			{
				for(int k=j+1;k<n;k++)
				{
					if(l[j]!=l[k]&&l[i]!=l[k])
					{
						long long tmp=l[i]+l[j]+l[k];
						if(tmp-max(l[i],max(l[j],l[k]))>max(l[i],max(l[j],l[k])))
						{
							cnt++;
						}
					}
				}
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 3828
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    if A[0]==1:
        print(1)
        sys.exit()
    cur_a=1
    cunt=0
    visited=[False]*n
    visited[0]=True
    route=[1]
    for _ in range(k):
        next_a=A[cur_a-1]
        if visited[next_a-1]:
            loop=len(route)-route.index(next_a)
            cunt-=loop-1
            break
        cur_a=next_a
        cunt+=1
        route.append(cur_a)
        visited[cur_a-1]=True
    else:
        print(next_a)
        sys.exit()
    #print(route)
    #rint(cunt,loop)
    k-=cunt
    k=k%loop
    #print(k)
    print(route[cunt+k])
    

if __name__=='__main__':
    main()

Measured memory_bytes: 32280
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,h,z,t, x, y,e;
	cin >> n;
	h = n;
	x = n % 500;
	e = x;
	y = (h - x) / 500;
	z= x % 5;
	t = (e - z) / 5;
	cout << (y * 1000) + (t * 5);
	return 0;
}

Measured memory_bytes: 256
K, N = map(int, input().split(' '))
A_ls = list(map(int, input().split(' ')))
max_l = 0
for i in range(N):
    l = A_ls[(i + 1) % N] - A_ls[i]
    if l < 0:
        l = K - A_ls[i] + A_ls[(i + 1) % N]
    max_l = max(max_l, l)
print(K - max_l)

Measured memory_bytes: 32356
#include<iostream>
#include<queue>
using namespace std;
long long k,dist[222222];
priority_queue<pair<int,int> > pq;
int main()
{
	cin>>k;
	for (int i=0;i<=k;i++) dist[i]=1e18;
	for (int i=1;i<=9;i++) 
	{
		if (dist[i%k]==1e18)
		{
			dist[i%k]=i;
			pq.push(make_pair(-i,i%k));
		}
	}
	while(!pq.empty())
	{
		int x=pq.top().second;
		pq.pop();
		for (int i=0;i<=9;i++)
		{
			int y=(x*10+i)%k;
			if (dist[y]>dist[x]+i)
			{
				dist[y]=dist[x]+i;
				pq.push(make_pair(-dist[y],y)); 
			}
		}
	}
	cout<<dist[0]<<endl;
	return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;

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

int main(){
  ll a,b,c,d;
  cin >>a>>b>>c>>d;
  ll total=b-a+1;
  ll cd=c*d/gcd(c,d);
  ll tmp1=b/c-(a-1)/c;
  ll tmp2=b/d-(a-1)/d;
  ll tmp3=b/cd-(a-1)/cd;
  cout <<total-tmp1-tmp2+tmp3<<endl;
}

Measured memory_bytes: 3592
let aa = Int(readLine()!)!
let arr=readLine()!.split{$0==" "}.map{Int(String($0))!}
var a=arr[0]
var b=arr[1]
var i = 0
while a <= b {
    if a%aa == 0 {
        print("OK")
        i = 1
        break
    }
    a+=1
}
if i == 0 {
    print("NG")
}

Measured memory_bytes: 7800
#include <stdio.h>
#include <algorithm>
int map[100][100];
char a[100][100];
void mine(int x,int y)
{
	map[x][y-1]++;
	map[x][y+1]++;
	map[x+1][y]++;
	map[x-1][y]++;
	map[x+1][y+1]++;
	map[x+1][y-1]++;
	map[x-1][y-1]++;
	map[x-1][y+1]++;
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",a[i]+1);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]=='#') mine(i,j);
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]=='#') printf("#");
			else printf("%d",map[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

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

int main()
{
  int N, X;
  int a[110000];
  int res=0;
  cin >> N>> X;

  FOR(i,0,N-1) {
    int aa;
    cin >> aa;
    a[i] = abs(aa-X);
    res = gcd(res, a[i]);
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace  std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const long double pi=3.1415926535897932384626433832;
const long long mod=1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
		
	res = res * res;
	
	if (b % 2 == 1)
		res = res * a;
	
	return res;
}

long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;

	return res;
}
int dp[1001][1001];
int a[1001][1001];
ll Findpaths(int h, int w)
{
	if(h== 1 && w==1 )
	{
		dp[1][1]=1;
		return dp[1][1];
	}

	if(dp[h][w]>-1)
		return dp[h][w];
	else 
	{
		int x=0,y=0;
		if(h-1>=1 && a[h-1][w]==1)
			x=Findpaths(h-1,w);
		if(w-1 >= 1 && a[h][w-1]==1)
			y=Findpaths(h,w-1);

		dp[h][w]=(x+y)%mod;
		return dp[h][w];

	}
}
int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	for(int i=1 ;i<1001;i++)
	for(int j=1 ; j<1001 ;j++ )
	{
		dp[i][j]=-1;
	}
	int h,w;
	cin>>h>>w;
	for(int i=1; i<=h ;i++)
	{
		for(int j=1 ; j<=w ;j++)
		{
			char p;
			cin>>p;
			if(p == '.')
			a[i][j]=1;
			else
			a[i][j]=0;	
		}
	}

	
	cout<<Findpaths(h,w);

	//cout<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 8192
#include <algorithm>
#include <iostream>
#include <utility>
#define int long long
using namespace std;
int N, M;
pair<int,int> D_P[10000];
bool com(pair<int,int> a, pair<int,int> b){ //Pの値で降順ソート
    return a.second > b.second;
}
int solve(){
    sort(D_P,D_P+N,com);
    int r = 0;
    for(int i=0; i<N; i++){
        if(M>D_P[i].first) M -= D_P[i].first;
        else if(M>0){
            r += (D_P[i].first - M)*D_P[i].second;
            M = 0;
        }else{
            r += D_P[i].first * D_P[i].second;
        }
    }
    return r;
}
void get(){
    for(int i=0; i<N; i++){
        cin >> D_P[i].first >> D_P[i].second;
    }
}
signed main(){
    while(cin >> N >> M && N > 0){
        get();
        cout << solve() << endl;
    }
}


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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;

//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//def function
//------------------------------------------


//main
//------------------------------------------

int main(){
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  VVI ls(Q, VI(2));
  REP(i, Q){
    cin >> ls.at(i).at(0) >> ls.at(i).at(1);
  }


  VI counts(N+1);
  counts.at(0)=0;
  int count=0;
  FOR(i, 1, N+1){
    if(i<N&&S.at(i-1)=='A'&&S.at(i)=='C'){
      count++;
    }
    counts.at(i)=count;
  }

  REP(i, Q){
    cout << counts.at(ls.at(i).at(1)-1)-counts.at(ls.at(i).at(0)-1) << endl;
  }

  return 0;
}


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

int main(int argc, const char * argv[]) {

    int a,b,c;
    cin >> a >> b >> c;
    
    if((b-a) == (c-b)){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
   ll a,b,c,d,k;
   cin>>a>>b>>k;
   if(k<a){
     a-=k;
     cout<<a<<spc<<b<<endl;
   }
   else{
    k-=a;
    if(b>k){
        b-=k;
        cout<<0<<spc<<b<<endl;
    }
    else cout<<0<<spc<<0<<endl;
   }
return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

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

    vector<long> counts(n, 0);

    long input;
    for (long i = 0; i < n - 1; i++)
    {
        cin >> input;
        counts[input - 1]++;
    }

    for (long i = 0; i < counts.size(); i++)
    {
        cout << counts[i] << '\n';
    }
}


Measured memory_bytes: 4840
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
int n;
int a[11111];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	int cnt = 0;
	rep(i, n)cnt += a[i];
	cout << a[0] << " " << a[n - 1] << " " << cnt << endl;
	ggr
}



Measured memory_bytes: 3228
A, B, C, X, Y = map(int, input().split())

print(min(
          A * X + B * Y,
          C * 2 * min(X, Y) + A * max(0, (X - min(X, Y))) + B * max(0, (Y - min(X, Y))),
          C * 2 * max(X, Y) + A * max(0, (X - max(X, Y))) + B * max(0, (Y - max(X, Y)))))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

int main(void) {
	string s;
	getline(cin, s);

	for (int i = 0; i + 5 <= (int)s.size(); i++) {
		if (s.substr(i, 5) == "apple") {
			s.replace(i, 5, "peach");
		} else if(s.substr(i, 5) == "peach") {
			s.replace(i, 5, "apple");
		}
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 1188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<str.length();i++){
            if(Character.isUpperCase(str.charAt(i))){
                sb.append(str.substring(i,i+1).toLowerCase());
            }else{
                sb.append(str.substring(i,i+1).toUpperCase());
            }
        }
        sb.append("\n");
        System.out.print(sb);
    }
}

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

int main (void){
  long int l,r,d,ans = 0;
  cin >> l >> r >> d;

  for(int i = l; i <= r;i++){
    if(i % d == 0){
      ans++;
    }
  }

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
const db pi = acos(-1.0);
inline LL gcd(LL a, LL b) {return a % b == 0 ? b : gcd(b, a % b);}
inline LL read() {
    LL x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-')f = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}

LL l, r;
inline LL calc(LL x) {
    LL ans = 0;
    for (int i = 0; i < 64; ++i) {
        LL cur = 1LL << (i + 1), haf = 1LL << i, p;
        if (x < haf) break;
        p = (x - haf + 1) % cur;
        //printf("i = %d cur = %lld p = %lld\n", i, cur, p);
        if (i == 0) {
            p = (x - haf + 2) / cur;
            if (p == 0 || p & 1) ans++;
            continue;
        }
        if (p > haf) continue;
        ans += (p & 1LL) ? haf : 0;
    }

    return ans;
}
int main() {
    l = read(); r = read();
    //printf("%lld ", calc(r));
    //printf("%lld ", calc(l - 1));
    printf("%lld\n", calc(r) ^ calc(l - 1));
    return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInt :: IO Int
readInt = fst . fromJust . C.readInt <$> C.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  _n <- readInt
  as <- readInts
  bs <- readInts
  cs <- readInts
  print $ f as bs cs

f :: [Int] -> [Int] -> [Int] -> Int
f as bs cs = h 0 as bs cs

h acc [a1] bs _
  = acc + (bs!!(a1-1)) -- +(bs!!a2) +(if a2==a1+1 then (cs !! a1) else 0)
h acc (a1:as@(a2:as')) bs cs
  = h acc' as bs cs
  where
    acc' = acc + (bs!!(a1-1)) + (if a2==a1+1 then (cs !! (a1-1)) else 0) 

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  vector<string> months = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
  string first = S.substr(0, 2);
  string last = S.substr(2, 2);
  bool first_month = false;
  bool last_month = false;
  for (int i; i < 12; i++) {
    if (first == months.at(i)) { first_month = true; }
    if (last == months.at(i)) { last_month = true; }
  }
  if (first_month && last_month) { cout << "AMBIGUOUS" << endl; }
  else if (first_month && last_month == false) { cout << "MMYY" << endl; }
  else if (first_month == false && last_month) { cout << "YYMM" << endl; }
  else { cout << "NA" << endl; }
}

Measured memory_bytes: 256
def solve(ns):
    d = 0
    for s in ns:
        d += int(s)
        d %= 9
    if d == 0:
        return 'Yes'
    else:
        return 'No'


def main():
    ns = input()
    res = solve(ns)
    print(res)


def test():
    assert solve("123456789") == 'Yes'
    assert solve("0") == 'Yes'
    assert solve("31415926535897932384626433832795028841971693993751058209749445923078164062862089986280") == 'No'


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 9404
#include<iostream>
#include<algorithm>

using namespace std;

int gcd(int h,int l){
  if(h<l){
    swap(h,l);
  }
  while(h%l){
    h%=l;
    swap(h,l);
  }
  return l;
}

int main(){
  for(int a,b;cin>>a>>b;){
    cout<<gcd(a,b)<<' '<<a/gcd(a,b)*b<<endl;
  }
  return 0;
}



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

int main(){

	int A, B, C, X,total = 0;
	cin >> A >> B >> C >> X;

	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= B; j++) {
			for (int k = 0; k <= C; k++)
				if (500 * i + 100 * j + 50 * k == X) total++;
		}
	}

	cout << total;

	return 0;
}

Measured memory_bytes: 256
import math
while True:
    a, op, b= input().split()
    a=int(a)
    b=int(b)
    if op=="?":
        break
    elif op=="+":
        print(a + b)
    elif op=="-":
        print(a - b)
    elif op=="*":
        print(a * b)
    else:
        x=a%b
        y=a//b
        if x==0:
            print(int(y))
        else:
            print(format(y, '.0f'))
    
print('', end='')



Measured memory_bytes: 5668
#include <iostream>

template< typename Type >
Type input() {
	Type value;
	std::cin >> value;
	return value;
}

template< typename Type >
Type gcd(Type x, Type y) {

	// x >= y ????????????
	if( x < y ) std::swap(x, y);

	while(0 < y) {
		Type r = x % y;
		x = y;
		y = r;
	}

	return x;
}

int main() {
	// 1 <= x,y <= 10^9 ?????????????????´??°
	int x = input<int>();
	int y = input<int>();

	std::cout << gcd(x,y) << std::endl;

	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main()
{
	int r, g, b;
	scanf("%d %d %d", &r, &g, &b);
	if ((g * 10 + b) % 4 == 0) printf("YES\n");
	else printf("NO\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1620
N, *_XYH = map(int, open(0).read().split())
XYH = list(zip(*[iter(_XYH)]*3))

C = [(x, y) for x in range(101) for y in range(101)]

for c in C:
    for i, xyh in enumerate(sorted(XYH, key=lambda x: x[2], reverse=True)):
        if i==0:
            H = xyh[2] + abs(xyh[0] - c[0]) + abs(xyh[1] - c[1])
        elif max(H - abs(xyh[0] - c[0]) - abs(xyh[1] - c[1]), 0) == xyh[2]:
            is_ans = True
        else:
            is_ans = False
            break
        
    if is_ans:
        break

print(*c, H)

Measured memory_bytes: 9468
class UnionFind:
    def __init__(self, size):
        self.parent = [-1]*size #非負なら親ノード，負ならグループの要素数

    def root(self, x): #root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        elif self.parent[self.parent[x]] < 0:
            return self.parent[x]
        else:
            self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]
        
        
n,m = [int(i) for i in input().split()]

T=UnionFind(n)
c=0
for _ in [0]*m:
    x,y,z=[int(i) for i in input().split()]
    if not T.issame(x-1,y-1):
        T.merge(x-1,y-1)
        c+=1

print(n-c)



Measured memory_bytes: 6232
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()
template<class T> inline bool chmax(T &a, T b){if(a<b){a=b; return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a>b){a=b; return true;}return false;}


int main(){
  double r;
  cin >> r;

  cout << fixed << setprecision(10) << 2*M_PI*r;

}


Measured memory_bytes: 3788
N,K = gets.split.map(&:to_i)
h = {}
gets.split.map(&:to_i).each{ |a| h[a] = (h[a] || 0) + 1 }
p N - h.keys.sort_by{ |k| -h[k] }[0...K].map{ |k| h[k] }.inject(:+)


Measured memory_bytes: 33896
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int N = sc.nextInt();
      int[] a = new int[110];
      int ans = 0;
        for(int i = 0; i < N; i++) a[i] = sc.nextInt();
      for(int i = 0; i < N; i++){
      if(i % 2 ==0 && a[i] % 2 == 1) ans++;
      }
      System.out.println(ans);
    } 
}

Measured memory_bytes: 27144
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;


int a[200010];
int b[200010];
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n; cin >> n;
    REP(i, n) cin >> a[i];
    
    int q; cin >> q;
    REP(i, q){
        int k; cin >> k;
        cout << lower_bound(a, a+n, k)-a << " " << upper_bound(a, a+n, k)-a << endl;
    }
	return 0;
}


Measured memory_bytes: 3536
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import qualified Data.IntMap as IMap
import qualified Data.Vector as V
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt

sqleft :: Seq a -> a
sqleft q = sqleft_(Sq.viewl q)
sqleft_ :: ViewL a -> a
sqleft_ (x :< xs) = x
sqright :: Seq a -> a
sqright q = sqright_(Sq.viewr q)
sqright_ :: ViewR a -> a
sqright_ (xs :> x) = x
-------------------------------------------------------------
eat :: Int -> Int -> [Int]
eat d ai = [1 + j * ai | j <- [0..100] , 1 + j * ai <= d]

main = do
    n <- readLn :: IO Int
    [d,x] <- map bsreadInt . BC.words <$> BC.getLine
    an <- (map bsreadInt) <$> replicateM n BC.getLine
    let cn = map (eat d) an
    print $ x + (length (concat cn))
    

Measured memory_bytes: 636
#include<stdio.h>
int main(){
  int a,b,c,d,i,j=0,dt[1000],ls[1000],max,min,l,sum;
  while(1){
    scanf("%d",&a);
    if(a==0)break;
    sum=0;
    max=0;
    min=10000;
    for(i=0;i<a;i++){
      scanf("%d",&b);
      dt[i]=b;
    }
    for(i=0;i<a;i++){
      if(dt[i] > max) max=dt[i];
      if(dt[i] < min) min=dt[i]; 
    } 
    for(i=0;i<a;i++){
      if(dt[i]==max) 
	max=0;
      else if(dt[i]==min)
	min=0;
      else sum+=dt[i];
    }
    ls[j]=sum/(a-2);
    j++;
  }
  for(l=0;l<j;l++)
    printf("%d\n",ls[l]);
  return 0;
}

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

int main(){
  int X, Y, Z, K;cin>>X>>Y>>Z>>K;
  vll A, B, C;
  for (int i=0;i<X;++i){ll a;cin>>a;A.push_back(a);} 
  for (int i=0;i<Y;++i){ll b;cin>>b;B.push_back(b);} 
  for (int i=0;i<Z;++i){ll c;cin>>c;C.push_back(c);}

  sort(A.begin(), A.end(), greater<ll>());
  sort(B.begin(), B.end(), greater<ll>());
  sort(C.begin(), C.end(), greater<ll>()); 
  vll D;

  for (int i=0;i<X;++i){
    for (int j=0;j<Y;++j){
      D.push_back(A[i]+B[j]);
    }
  }

  sort(D.begin(), D.end(), greater<ll>());
  vll E;

  int K_=min(K, X*Y);

  for (int i=0;i<K_;++i){
    for (int j=0;j<Z;++j){
      E.push_back(D[i]+C[j]);
    }
  }

  sort(E.begin(), E.end(), greater<ll>());

  for (int i=0;i<K;++i){
    cout << E[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 43000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__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.X<<","<<_p.Y<<")";}
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; }

const ll MAXn=505,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

char s[MAXn][MAXn];
char r[MAXn][MAXn],b[MAXn][MAXn];
int main(){
    IOS();
    int n,m;
    cin >> n >> m;
    for (int i=0;i<n;++i) for (int j=0;j<m;++j) {
        cin >> s[i][j];
    }

    for (int i=0;i<m;++i) {
        r[0][i] = '#';
        b[n-1][i] = '#';
    }
    for (int i=0;i<m;++i) {
        if (i&1) {
            for (int j=1;j<n;++j) {
                b[j][i] = '#';
            }
        }
        else {
            for (int j=0;j<n-1;++j) {
                r[j][i] = '#';
            }
        }
    }
    for (int i=0;i<n;++i) for (int j=0;j<m;++j) {
        if (s[i][j] == '#') {
            if (j&1) r[i][j] = '#';
            else b[i][j] = '#';
        }
        if (b[i][j] != '#') b[i][j] = '.';
        if (r[i][j] != '#') r[i][j] = '.';
    }
    for (int i=0;i<n;++i) {
        for (int j=0;j<m;++j) {
            cout << r[i][j];
        }
        cout << endl;
    }
    cout << endl;
    for (int i=0;i<n;++i) {
        for (int j=0;j<m;++j) {
            cout << b[i][j];
        }
        cout << endl;
    }
#ifdef cold66
    for (int i=0;i<n;++i) {
        for (int j=0;j<m;++j) {
            if (b[i][j] == r[i][j] && b[i][j] == '#') cout << '#';
            else cout << '.';
        }
        cout << endl;
    }
#endif
}


Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int M;
  cin >>N>>M;
  vector<long long>data1(M);
  vector<long long>data2(M);
  for (int i=0;i<M;i++){
  cin >>data1.at(i)>>data2.at(i);
  }
  sort(data1.begin(),data1.end());
  sort(data2.begin(),data2.end());
  if (data2.at(0)-data1.at(M-1)+1>0){
  cout <<data2.at(0)-data1.at(M-1)+1<<endl;
  }
  else {
  cout <<0<<endl;
  }
}

  
  
  
  
  

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 2000005
using namespace std;
int n,m,mp[35],fr[N],r[N],ans; char a[N],b[N];
void GG(){ printf("-1"); exit(0);}
int main()
{
	int i,p;
	scanf("%d\n",&n);
	scanf("%s",a+1);
	scanf("%s",b+1);
	for(i=1;i<=n;i++)
		if(a[i]!=b[i]) break;
	if(i>n){ printf("0"); return 0;}
	for(i=1;i<=n;i++)
		if(b[i]!=b[i-1]) r[m]=i-1,++m;
	r[m]=n,p=n+1;
	for(i=m;i>=1;i--){
		p=min(p,r[i-1]+1);
		while(a[p]!=b[r[i]]&&p) p--;
		if(!p) GG();
		fr[i]=p;
	  }
	fr[m+1]=n+1;
	for(i=p=1;i<=m;i++){
		for(;p<m&&fr[p+1]-p+i-1<r[i];p++);
		ans=max(ans,p-i+1);
	  }
	cout<<ans;
	return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int main ( ) {
	string s;
	cin >> s;
	ll now = 0;
	ll ans = 0;
	for (int i = 0; i < s.size ( ); i++) {
		if (s[i] == 'W') {
			ans += (ll)i - now;
			now++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <numeric>
using namespace std;
int main() {
	string str;
	int sum = 0;
	cin >> str;
	for (int i = 0; i < 3; ++i) {
		if (str[i] == '1')++sum;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    cnt = {1: 0, 2: 0, 3: 0, 4: 0}
    for _ in range(3):
        a, b = map(int, input().split())
        cnt[a] += 1
        cnt[b] += 1

    ans = 'YES'
    for k, v in cnt.items():
        if v > 2:
            ans = 'NO'
            break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
int A,B,C,D;
int main()
{
	scanf("%1d%1d%1d%1d",&A,&B,&C,&D);
	for(int i=1;i>(-2);i-=2)
		for(int j=1;j>(-2);j-=2)
			for(int k=1;k>(-2);k-=2)
				if(i*B+j*C+k*D+A==7)
				{
					printf("%d%c%d%c%d%c%d=7\n",A,(i==1?'+':'-'),B,(j==1?'+':'-'),C,(k==1?'+':'-'),D);
					return 0;
				}
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define for1(i,n) for(int i = 1;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define REP(a,i,b) for (int i = a;i<b;i++);

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}


ll gcd(ll a, ll b)
{
	while (b)
	{
		a %= b;
		swap(a, b);
	}
	return a;
}

void solve()
{
	ll a, b;
	cin >> a >> b;
	cout << a * b / gcd(a, b);
}


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


#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	//freopen("journey.in", "r", stdin);
	//freopen("journey.out", "w", stdout);


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


}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 100
#define INFTY (1<<21)
#define rep(i, n) for ( int i = 0; i < n; i++)
int N, M, L, D[MAX][MAX], E[MAX][MAX];

int dijkstra(){
    int cost[MAX][MAX+1];
    bool visited[MAX][MAX+1];
    rep(i, N) rep(j, L+1){
	cost[i][j] = INFTY;
	visited[i][j] = false;
    }
    cost[0][L] = 0;
    
    while(1){
	pair<int, int> u;
	int minv = INFTY;
	rep(i, N) rep(j, L+1){
	    if ( !visited[i][j] && minv > cost[i][j] ){
		u = make_pair(i, j);
		minv = cost[i][j];
	    }
	}
	if ( minv == INFTY ) break;
	visited[u.first][u.second] = true;
	if ( u.first == N-1 ) return cost[u.first][u.second];
	for ( int v = 0; v < N; v++ ){
	    if ( D[u.first][v] == INFTY ) continue;
	    if ( !visited[v][u.second] ){
		cost[v][u.second] = min(cost[v][u.second], cost[u.first][u.second] + E[u.first][v]);
	    }
	    if ( u.second < D[u.first][v] ) continue;
	    int l = u.second - D[u.first][v];
	    if ( visited[v][l] ) continue;
	    cost[v][l] = min(cost[v][l], cost[u.first][u.second]);
	}
    }
}

main(){
    int s, t, d, e;
    while( cin >> N >> M >> L && N ){
	rep(i, N) rep(j, N){ D[i][j] = INFTY; E[i][j] = 0; }
	rep(i, M){
	    cin >> s >> t >> d >> e; s--; t--;
	    D[s][t] = D[t][s] = d;
	    E[s][t] = E[t][s] = e;
	}
	cout << dijkstra() << endl;
    }
}

Measured memory_bytes: 988
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int n,x;
  cin>>n>>x;
  int m[n];
  rep(i,n) cin>>m[i];
  rep(i,n) x -= m[i];
  sort(m, m + n);
  cout << n + x / m[0] << endl;

  return 0;
}


Measured memory_bytes: 256
a, b, c, x, y = list(map(int, input().split()))

ans = x*a + y*b # normal

ans = min(ans, 2*c*max(x, y)) # all from c


if max(x, y) == x: 
    A = True
else:
    A = False
left = (max(x, y) - min(x, y))*(a if A else b)
ans = min(ans, 2*c*min(x, y) + left)

print(ans)

Measured memory_bytes: 61172
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <math.h>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repp(i, m, n) for(int i = m; i < (int)n; i++)
#define reps(i, n) for(int i = 1; i <= (int)n; i++)
#define pb push_back
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;

int main()
{
	string s;
	cin >> s;
	if(s=="zyxwvutsrqponmlkjihgfedcba") cout << "-1" << endl;
	else if(s.size()!=26)
	{
		int a[26]={};
		rep(i, 26) a[(int)s[i]-(int)'a']++;
		rep(i, 26) if(a[i]==0)
		{
			a[0]=i;
			break;
		}
		cout << s << (char)(a[0]+(int)'a') << endl;
	}
	else
	{
		for(int i=25; i>=1; i--)
		{
			if(s[i]>s[i-1])
			{
				int ans=25;
				rep(j, 25-i)
				{
					if(s[i+j]<s[i-1])
					{
						ans=i+j-1;
						break;
					}
				}
				s[i-1]=s[ans];
				rep(k, i) cout << s[k];
				break;
			}
		}
		cout << endl;
	}
	return 0;
}

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

int N, M, Q;
vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;
int A[10];
long long maxv;

void dfs(int aa, int num)
{
#if 0
        for (int i = 0; i < N; ++i) {
                cout << A[i] << " ";
        }
        cout << endl;
#endif
        if (num > 1) {
                if (aa < A[num-2]) return;
        }
        A[num-1] = aa;
        if (num == N) {
                long long ans = 0;
                for (int i = 0; i < Q; ++i) {
                        if ((A[b[i]-1] - A[a[i]-1]) == c[i]) {
                                ans += d[i];
                        }
                }
                if (maxv < ans) maxv = ans;
                return;
        }

        for (int i = 1; i <= M; ++i) {
                dfs(i, num+1);
        }

}

int main()
{
        cin >> N >> M >> Q;
        for (int i = 0; i < Q; ++i) {
                int t1, t2, t3, t4;
                cin >> t1 >> t2 >> t3 >> t4;
                a.push_back(t1);
                b.push_back(t2);
                c.push_back(t3);
                d.push_back(t4);
        }

        for (int i = 0; i < N; ++i) {
                A[i] = 0;
        }
        maxv = -1;
        dfs(1, 1);
        cout << maxv << endl;


}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using std::cerr;using std::max;using std::min;
#define N 100005
#define ll long long
#define db double
#define dbg1(x) cerr<<#x<<"="<<x<<" "
#define dbg2(x) cerr<<#x<<"="<<x<<"\n"
int n,m,A[N],pos,ans;
int main()
{
	scanf("%d%d",&n,&m),ans=n;
	for(int i=1;i<=n;i++) scanf("%d",&A[i]);
	for(int i=1;i<=n;i++) if(A[i]==1) pos=i;
	for(int i=1;i<=m;i++)
	{
		ans=min(ans,(int)ceil((pos-i)*1./(m-1)+(int)ceil((n-(pos+m-i))*1./(m-1))));
//		dbg1(i),dbg1(pos-i),dbg2(n-(pos+m-1));
	}
	printf("%d\n",ans+1);
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
typedef long long ll;

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  vector<ll> a(3*n);
  REP(i,3*n) a[i] = getInt();

  sort(a.rbegin(), a.rend());
  ll ans = 0;
  REP(i,n) ans += a[2 * i + 1];
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

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

   int cntl = 0;
   int cntr = 0;
   int addl = 0;
   int addr = 0;
   for (int i = 0; i < N; i++) {
      if (S[i] == '(') cntl++;
      else if (cntl > 0) cntl--;
      else addl++;
   }
   for (int i = N - 1; i >= 0; i--) {
      if (S[i] == ')') cntr++;
      else if (cntr > 0) cntr--;
      else addr++;
   }
   
   for (int i = 0; i < addl; i++) cout << "(";
   cout << S;
   for (int i = 0; i < addr; i++) cout << ")";
   cout << endl;
   return 0;
}


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

struct Card {
    char suit;
    char value;
};

void swap(struct Card *v, struct Card *u){
    struct Card temp = *v;
    *v = *u;
    *u = temp;
}

void bubbleSort(struct Card a[], int n){
    for(int i = 0; i < n; i++){
        //上からバブル
        for(int j = n-1; j > i;j--){
            if(a[j].value < a[j-1].value){
                swap(&a[j], &a[j-1]);
            }
        }
    }
}

void selectionSort(struct Card a[], int n){
    for(int i = 0; i < n;i++){
        int minj = i;
        for(int j = i; j < n; j++){
            if(a[j].value < a[minj].value){
                minj = j;
            }
        }
        swap(&a[i], &a[minj]);
    }
}

void stable(struct Card bubble[], struct Card test[], int n){
    bool flag = true;
    for(int i = 0 ; i < n ; i++){
        if(bubble[i].suit != test[i].suit){
            flag = false;
            break;
        }
    }
    if(flag){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
}

void showAllay(const struct Card a[], int n){
    for(int i=0;i<n;i++){
        if(i)   cout << " ";
        cout << a[i].suit << a[i].value;
    }
    cout << endl;
}

int main(void){
    int n;
    cin >> n;
    Card C1[n], C2[n];
    for(int i=0;i<n;i++){
        cin >> C1[i].suit >> C1[i].value;
    }
    for(int i = 0 ; i < n; i++)
        C2[i] = C1[i];

    bubbleSort(C1, n);
    showAllay(C1,n);
    stable(C1,C1,n);

    selectionSort(C2, n);
    showAllay(C2,n);
    stable(C1,C2,n);
    return 0;
}


Measured memory_bytes: 3104
n = list(input())
a = [0,0,0,0]
for i in range(len(n)):
  if n[i] =="W":
    a[0] += 1
  elif n[i] == "E":
    a[1] += 1
  elif n[i] == "N":
    a[2] += 1
  elif n[i] == "S":
    a[3] += 1
if a[0]*a[1] * a[2]*a[3] != 0 or (a[0]+a[1] == 0 and (a[2]*a[3]) != 0)or(a[2]+a[3] == 0 and (a[0]*a[1]) != 0):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3188
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int S[2000][2000];
int cycle[2000][2000]={};
int main(){
	int K=38;//Kはそすうぽよ+1でないといけない
	int N=((K*2-1)*(K*2-1)+3)/4;
	int count=2;
	rep(i,K){
		S[i][0]=1;
		rep1(j,K-1){
			S[i][j]=count;
			count++;
		}
	}
	vint permu;
	rep(i,K-1) permu.push_back(i);
	rep1(block,K-1){
		rep1(gyo,K-1){
			S[block*(K-1)+gyo][0]=block+1;
			rep1(retu,K-1){
				S[block*(K-1)+gyo][retu]=S[retu][((block-1)*(retu-1)+gyo-1)%(K-1)+1];
			}
		}
		next_permutation(permu.begin(),permu.end());
	}
	printf("%d %d\n",N,K);
	rep(i,N){
		rep(j,K){
			printf("%d ",S[i][j]);
		}
		kaigyo;
	}
	return 0;
}


Measured memory_bytes: 12800
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};


#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


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


ll dp[110][100010];


void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,W;
    cin >> N >> W;
    memset(dp, 0, sizeof(dp));
    int w[110];
    int v[110];
    
    rep(i,N) cin >> w[i] >> v[i];
    
    for (int i = 0; i < N; i++) {
        for (int sumw = 0; sumw <= W; sumw++) {
            if (sumw - w[i] >= 0) {
                dp[i+1][sumw] = max(dp[i][sumw],dp[i][sumw-w[i]]+v[i]);
            }else{
                dp[i+1][sumw] = dp[i][sumw];
            }
        }
    }
    
    cout << dp[N][W] << endl;
    
    
    
}



signed main() {
    
    
    solve();
    return 0;
}



Measured memory_bytes: 86272