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

using namespace std;

typedef long long ll;

struct seg
{
	ll l, r, s;
	inline int operator<(const seg &a) const {return s > a.s;}
} s[10010];

const ll inf = (1ll<<62) - 1;
int n, m;
ll f[10010][2];

int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> s[i].l >> s[i].r;
		s[i].s = s[i].l + s[i].r;
	}
	sort(s+1, s+n+1);
	
	for (int i = 1; i <= n; ++i)
		f[i][0] = f[i][1] = inf;
	f[0][0] = 0;
	
	int x = 1, y = 0;
	m = n / 2;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j <= n; ++j)
			f[j][x] = inf;
		for (int j = 0; j<i && j<=m; ++j)
		{
			const int k = i-j-1;
			if (j < m)
				f[j+1][x] = min(f[j+1][x], f[j][y] + s[i].r + s[i].s * j);
			if (k < m)
				f[j][x] = min(f[j][x], f[j][y] + s[i].l + s[i].s * k);
			if (n & 1)
				f[j][x] = min(f[j][x], f[j][y] + (n-1)/2 * s[i].s);
		}
		swap(x, y);
	}
	
	cout << f[m][y] << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll d,t,s;
    cin>>d>>t>>s;
    if(s*t>=d)
    cout<<"Yes";
    else
    cout<<"No";}

Measured memory_bytes: 3648
n = int(input())

ans = 0
cnt = [[0] * 9 for i in range(9)]

for i in range(1, n + 1):
    if i % 10 == 0:
        continue
    a = str(i)[0]
    b = str(i)[-1]
    cnt[int(a) - 1][int(b) - 1] += 1

for i in range(9):
    for j in range(9):
        ans += cnt[i][j] * cnt[j][i]
print(ans)

Measured memory_bytes: 41708
#include <stdio.h>
#define S_len 100000
#define T_len 50000
#define TRUE 1
#define FALSE 0

int isMatched(int S[],int n, int Ti){
  int rgh = n;
  int lft = 0;
  int mid = n / 2;

  while(rgh > lft){
    mid = (rgh + lft)/2;
    if(Ti == S[mid]){
      return TRUE;
    }else if(S[mid] < Ti){
      lft = mid + 1;
    }else if(S[mid] > Ti){
      rgh = mid;
    }
  }

  return FALSE;
}

int main(){
  int n,q,i, match=0;
  int S[S_len];
  int T[T_len];

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

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

  for(i=0; i<q; i++){
    match += isMatched(S,n,T[i]);
  }
  
  printf("%d\n",match);
  return 0;
}



Measured memory_bytes: 2280
using System;
using System.Linq;
class c
{
    static void Main()
    {
        Console.ReadLine();
        var s = Console.ReadLine();
        int min = s.Where((f, g) => g > 0).Count(f => f == 'E');
        int now = min;
        for (int i = 1; i < s.Length; i++)
        {
            if (s[i - 1] == 'W') now++;
            if (s[i] == 'E') now--;
            min = Math.Min(now, min);
        }
        Console.WriteLine(min);
    }
}

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

void Constraints(int H,int W)
{
  if(!(1<=H&&H<=300&&1<=W&&W<=300))
  {
    printf("条件を満たす入力をしてください。\n");
    exit(0);
  }
}

void PrintRectangle(int H,int W)
{
  for(int i=0;i<H;i++)
  {
      for(int j=0;j<W;j++)
      {
        printf("#");
      }
      printf("\n");
  }
  printf("\n");
}

int main(void)
{
  int H=1;
  int W=1;
  while(H!=0&&W!=0)
  {
    scanf("%d %d",&H,&W);
    if(H!=0&&W!=0)
    {
      Constraints(H,W);
      PrintRectangle(H,W);
    }
  }
  return 0;
}



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  
  if(L > R){
    cout << "Left" << endl;
  }
  else if(L == R){
    cout << "Balanced" << endl;
  }
  else if(L < R){
  	cout << "Right" << endl;
  }
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <ctime>

using namespace std;

#define LOCAL 0
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1& arg1){
    cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1& arg1, Args&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " /";
    __f(comma + 1, args...);
}

template <class T> bool mini(T& a, T b) { return a > b ? (a = b, 0) : 1; }
template <class T> bool maxi(T& a, T b) { return a < b ? (a = b, 0) : 1; }

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 7;

int main() {
#if LOCAL
    freopen("CP.inp", "r", stdin);
//    freopen("CP.out", "w", stdout);
#endif // LOCAL
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k, h, cnt = 0; cin >> n >> k;
    while (n--) {
        cin >> h;
        if (h >= k) ++cnt;
    }
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

string str;

bool is_left(int a) {
    if(a==1) return true;
    if(a==4) return true;
    if(a==7) return true;
    return false;
}
bool is_center(int a) {
    if(a==8) return true;
    if(a==2) return true;
    return false;
}
bool is_right(int a) {
    if(a==3) return true;
    if(a==6) return true;
    if(a==9) return true;
    return false;
}

bool ok(int l,int r) {
    if(is_left(l)) return true;
    if(is_right(r)) return true;
    if(is_right(r) && is_right(l)) return true;
    if(is_left(r) && is_left(l)) return true;
    if(is_center(r) && is_center(l)) return true;
    if(is_center(l) && is_right(r)) return true;
    if(is_center(r) && is_left(l)) return true;
    // cout<<"ok : "<<l<<","<<r<<endl;
    return false;

}

int solve1(int a) {
    int ans = 0;
    int r,l;
    r=l=0;
    rep(i,str.size()) {
        int step = str[i] - '0';
        if(i==0) {
            if(a==1) l=step;
            else r=step;
            a^=1;
            continue;
        }
        if(a==1) {
            if(ok(step,r)) {
                l=step;
                a^=1;
            }
            else {
                r=step;
                ans++;
            }
        }
        else {
            if(ok(l,step)) {
                r = step;
                a^=1;
            }
            else {
                l=step;
                ans++;
            }
        }
    }
    // cout<<"ans = "<<ans<<endl;
    return ans;

}

void solve() {
    int l = str[0]-'0';
    int r = str[1]-'0';
    int ans = min(solve1(0),solve1(1));
    cout<<ans<<endl;
}

int main() {
    // cout<<ok(4,2)<<endl;
    // cout<<ok(7,1)<<endl;
    // cout<<ok(6,2)<<endl;
    while(cin>>str) {
        if(str=="#") break;
        solve();

    }
    return 0;
}

Measured memory_bytes: 1316
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		String s = sc.nextLine();
		sc.close();
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<s.length();i++) {
		String  t = s.substring(i, i+1);	
		if(t.matches("[a-z]")) {
				sb.append(t.toUpperCase());
			}else if(t.matches("[A-Z]")) {
				sb.append(t.toLowerCase());
			}else {
				sb.append(t);
			}
		}
		System.out.println(sb.toString());
	}
}



Measured memory_bytes: 30608
import sys

def main():
    N = int(input())
    P = list(map(int, input().split()))
    min_so_far = sys.maxsize
    ans = 0
    for p in P:
        if p <= min_so_far:
            ans += 1
            min_so_far = p
    print(ans)


if __name__ == '__main__':
    main()


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

typedef std::pair<int, int> point;
const int N = 2005;

std::string a, b;
int n, ans = 0x3f3f3f3f;
int left[N], right[N];
point p[N];


void solve() {
	for (int j = 0; j < n; ++j) {
		int ret = j;
		for (int i = 0; i < n; ++i)
			if (a[i] == b[(i + j) % n] || (++ret, right[i] <= j))
				p[i] = point(0, 0);
			else p[i] = point(left[i], right[i] - j);
		std::sort(p, p + n);
		int max = 0, min = 0x3f3f3f3f;
		for (int i = n - 1; ~i; --i) {
			min = std::min(min, max + p[i].first);
			max = std::max(max, p[i].second);
		}
		ans = std::min(ans, ret + min * 2);
		}
}

bool empty(std::string s) { return std::count(s.begin(), s.end(), '1') == 0; }
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> a >> b, n = a.size();
	if (empty(b)) return std::cout << empty(a) - 1 << '\n', 0;
	for (int i = 0; i < n; ++i) {
		while (b[(i + n - left[i]) % n] == '0') ++left[i];
		while (b[(i + right[i]) % n] == '0') ++right[i];
	}
	solve();
	std::reverse(a.begin(), a.end()), std::reverse(b.begin(), b.end());
	for (int i = 0; i < n; ++i) std::swap(left[i], right[i]);
	std::reverse(left, left + n), std::reverse(right, right + n);
	std::cout << (solve(), ans) << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#define MN 500005
#define mod 998244353
using namespace std;
int pro[MN],npr[MN];
int n,m,ans;

inline int read()
{
	int n=0,f=1; char c=getchar();
	while (c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}
	while (c>='0' && c<='9') {n=n*10+c-'0'; c=getchar();}
	return n*f;
}

inline int mi(int x,int y)
{
	register int z=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) z=1LL*z*x%mod;
	return z;
}
inline int ni(int x) {return mi(x,mod-2);}
inline int C(int x,int y) {return 1LL*pro[x]*npr[y]%mod*npr[x-y]%mod;}
inline void rw(int& x,int y) {x+=y; if(x>=mod)x-=mod;}
inline void rd(int& x,int y) {x-=y; if(x< 0  )x+=mod;}

int main()
{
	register int i;
	for (pro[0]=i=1;i<MN;++i) pro[i]=1LL*pro[i-1]*i%mod;
	for (npr[MN-1]=ni(pro[MN-1]),i=MN-2;i>=0;--i)
		npr[i]=1LL*npr[i+1]*(i+1)%mod;
	n=read(); m=read();
	for (i=1;i<=m;++i)
	{
		if (i<n) continue;
		if (i>=m-i+n) rw(ans,C(m,i));
		else if (i>m-i) rw(ans,C(m,i)),rd(ans,C(m,i+i-n+1)); //y-x>=i-n+1
		else if (i==m-i) rw(ans,C(m-1,i)),rd(ans,C(m-1,i+i-n+1));
	}
	printf("%d",ans);
}

Measured memory_bytes: 4096
using System;
using System.Linq;

namespace AtCoder.Abc140
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            // 整数の入力
            int n = int.Parse(Console.ReadLine());
            var aArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i));
            var bArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i));
            var cArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i));

            int result = 0;
            int last = -2;
            foreach(var a in aArray)
            {
                result += bArray.ElementAt(a-1);
                if(a == last + 1)
                {
                    result += cArray.ElementAt(a-2);
                }
                last = a;                      
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    int ork = k;
    for (int i = 0; i < 1000; i++)
    {
        k = ork;
        k *= i;
        if (k >= a && k <= b)
        {
            cout << "OK";
            return 0;
        }
        else
        {
            continue;
        }
    }
    cout << "NG";
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int plusPlus(int n){
	if(n == 1)  return 1;
	else return n + plusPlus(n - 1);
}

int main(int argc, char const *argv[])
{
	int N;
	scanf("%d",&N);
	printf("%d\n", plusPlus(N));
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<queue>
#include<math.h>

int main(){
	int n;
	std::cin>>n;

	std::vector<double> aList(n);
	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	std::sort(aList.begin(), aList.end(), [](double x, double y){return x<y;});

	double ans= aList[0];

	for(int i=1; i<n; i++)
		ans= (ans+aList[i])/2.0;

	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int max = Math.max(a, Math.max(b, c));
        
        int dif = max * 3 -a-b-c;
        
        int ans = 0;
        if (dif % 2 == 1) {
            ans += 2;
        }
        ans += dif / 2;
        
        System.out.println(ans);
    }
}

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

using namespace std;


struct point{int x,y;};

float dist(point a, point b)
{

return sqrt(  (a.x - b.x)*  (a.x - b.x)    +   (a.y - b.y) *   (a.y - b.y)    );


}

int main()
{

int n;
cin >> n;
vector <point> x(n);
for (int i=0; i<n; ++i) cin >> x[i].x >> x[i].y;

float sum = 0;
for (int i=0; i<n; ++i)
    for (int j=0; j<n; ++j)
        if (i!=j) sum += dist(x[i],x[j]);


cout << setprecision(10) << sum/n;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 500
#define ll long long
using namespace std ; 
const ll mod=1e9+7; 
ll n,m;
ll a[N],b[N];
ll sum[N][N],l[N][N];
ll f[N][N];
int main() {
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf( "%lld",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%lld",&b[i]);
	}
	for(int i=1;i<N;i++){
		l[i][0]=1;
		for(int j=1;j<N;j++){
			l[i][j]=l[i][j-1]*i;
			l[i][j]%=mod ;
		}
	}
	for(int i=1;i<N;i++ ){
		for(int j=0;j<N;j++){
			sum[i][j]+=sum[i-1][j]+l[i][j];
			sum[i][j]%=mod;
		}
	} 
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		for( int j=0;j<=m;j++){
			for( int k=0;k<=j;k++){
				f[i][j]=(f[i][j]%mod+(1ll*f[i-1][j-k]*((sum[b[i]][k]-sum[a[i]-1][k])%mod)+mod)%mod+mod)%mod;
			}
		} 
	} 
	printf( "%lld\n",f[n][m]);
	return 0 ;
} 

Measured memory_bytes: 9244
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct uftree{
	int par[200005];
	int rank[200005];
	uftree(){
	}
	void init(int n){
		for(int i=0;i<n;i++){
			par[i]=i;
			rank[i]=0;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		return par[x]=find(par[x]);
	}

	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(rank[x]<rank[y]){
			par[x]=y;
		}else{
			if(rank[x]==rank[y])rank[x]++;
			par[y]=x;
		}
	}

	bool same(int x,int y){
		return find(x)==find(y);
	}
};


uftree uf;
int n,m;
int p[100005];
vector<int> vec[100001];
vector<int> num[100001];
int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
		p[i]--;
	}
	uf.init(n);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		uf.unite(a,b);
	}
	for(int i=0;i<n;i++){
		vec[uf.find(i)].push_back(p[i]);
		num[uf.find(i)].push_back(i);
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(vec[i].size()==0)continue;
		sort(vec[i].begin(),vec[i].end());
		for(int j=0;j<num[i].size();j++){
			int g=lower_bound(vec[i].begin(),vec[i].end(),num[i][j])-vec[i].begin();
			if(g<vec[i].size() && vec[i][g]==num[i][j])ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> v[100001];
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }

    int ans = 0;
    priority_queue<int> pq;
    for (int i = 1; i <= M; i++) {
        for (auto e : v[i]) pq.push(e);
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5632
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  string A,B,C;
  cin >> A >> B >> C;
  if(A.at(A.length()-1)==B.at(0) && B.at(B.length()-1)==C.at(0))cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void A_Duplex_Printing(void) {

	int N;
	cin >> N;
	cout << int((N + 1) / 2);
	return;
}

int main(void) {

	A_Duplex_Printing();
	return 0;
}

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

using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t[3],n;long long p=0;
  cin >> t[0] >> t[1] >> t[2] ;
  swap(t[0],t[1]);
  swap(t[0], t[2]);
  cout << t[0] << ' ' << t[1] << ' ' << t[2];
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <numeric>
#include <list> 
#include <cmath>
#include <stdio.h>

using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
#define INF (1e9)

typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> P;

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

int main() {
	string s;
	cin >> s;
    int ans = 0;
    REP(i, s.size()) {
        if(s[i] == '2') {
            ans += 1;
        }
    }
    printf("%d", ans);
}

Measured memory_bytes: 256
// AOJ 0644 Mizuyokan
// 2018.3.30 bal4u

#include <stdio.h>
#include <string.h>

//#define getchar_unlocked()  getchar()
int in()	/* 整数値の入力 */
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define INF 0x10101010
int  L[53];
int dp[53];

int main()
{
	int N, i, j, k, lo, hi, w, ans;

	N = in();
	for (i = 0; i < N; i++) L[i] = in();

	ans = 1000;
	for (lo = 0; lo < N; lo++) {
		w = 0;
		for (hi = lo; hi < N; hi++) {
			w += L[hi];
			memset(dp, 0, sizeof(dp));
			dp[0] = w;
			for (i = 0; i < N; i++) {
				k = 0;
				dp[i+1] = INF;
				for (j = i; j >= 0; j--) {
					k += L[j];
					if (i == N-1 && j == 0) continue;
					if (k >= w) {
						int x = dp[j]; if (x < k) x = k;
						if (dp[i+1] > x) dp[i+1] = x;
					}
				}
			}
			if (dp[N]-w < ans) ans = dp[N]-w;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2104
typedef long long ll;
/*
id: sadykhzadeh -> @Azer_Sadykhzadeh
Programming Language: (C++)
*/
using namespace std;
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <iterator>
#define pb push_back
int main(){
    ll N; cin >> N; ll k = N;
    vector <ll> a, b;
    ll cnt(0);
    for(ll i = 0; i< N; i++){
        ll temp; cin >> temp; a.pb(temp); b.pb(temp);
    }
    if(is_sorted(a.begin(), a.end())) return cout << "YES" << endl, 0;
  //  if(is_sorted())
    for(ll i = 0; i < N - 1; i++){
        for(ll j = i + 1; j < N; j++){
            if(a[i] > a[j]){
                swap(a[i], a[j]);
                //cnt++;
            }
        }
    }
    for(ll i = 0; i < N; i++){
        if(a[i] != b[i]) cnt++;
    }
    if(cnt == 2) return cout << "YES" << endl, 0;
    else cout << "NO" << endl, 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  vector<ll> a(3);
  rep(i, 3)cin>>a[i];
  sort(a.begin(), a.end());

  if( a[0]%2 && a[1]%2 && a[2]%2 ) cout<<a[0]*a[1];
  else cout<<0;

  return 0;
}

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

int main(){
    int a,b,c,n;
    while(cin>>a>>b>>c&&a&&b&&c){
        int d[300];
        int e[1000],f[1000],g[1000],h;
        for(int i=0; i<300; i++) d[i] = 2;
        cin >> n;
        int k=0;
        for(int i=0; i<n; i++){
            cin>>e[k]>>f[k]>>g[k]>>h; e[k]--;f[k]--;g[k]--;
            if(h==1) d[e[k]]=d[f[k]]=d[g[k]]=1;
            else k++;
        }
        for(int i=0; i<k; i++){
            int x=e[i],y=f[i],z=g[i];
            if(d[x]==1&&d[y]==1) d[z]=0;
            else if(d[y]==1&&d[z]==1) d[x]=0;
            else if(d[z]==1&&d[x]==1) d[y]=0;
        }
        for(int i=0; i<a+b+c;i++){
            cout <<d[i]<<endl;
        }
    }
}

Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>

using lli = long long int;
int inf = 1000000007;
using namespace std;

int n;

int main()
{
	cin >> n;
	vector<int> p(20);
	for (int i = 0; i < n; i++)cin >> p[i];
	int ans = 0;
	for (int i = 0; i < n - 2; i++) {
		if (p[i] < p[i+1] && p[i+1] < p[i+2])ans++;
		if (p[i+2] < p[i+1] && p[i+1] < p[i])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())


def gcd(v1, v2):
    v3 = v1 % v2
    if v3 == 0:
        return v2
    return gcd(v2, v3)


cnt = 0
for i in range(gcd(A, B), 0, -1):
    if A % i == 0 and B % i == 0:
        cnt += 1
        if cnt == K:
            print(i)
            exit()


Measured memory_bytes: 3060
import std.stdio;
import std.conv;
import std.string;
import std.math;
import std.random;
import std.range;
import std.algorithm;
import std.functional;
import core.bitop;
import std.bigint;
import std.typecons;
import std.container;
 
void main()
{
    auto input = readln.split.to!(int[]);
    auto A = input[0], B = input[1], C = input[2], D = input[3];
 
    ((A + B) > (C + D)
        ? "Left"
        : (A + B) < (C + D)
            ? "Right"
            : "Balanced").writeln;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

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

const double EPS = 1e-8;
const double INF = 1e12;

// ½ÊãÌ_ExNg
typedef complex<double> P;
namespace std{
	bool operator< (const P& a, const P& b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}

// OÏ
double cross(const P& a, const P& b){
	return imag(conj(a)*b);
}

// àÏ
double dot(const P& a, const P& b){
	return real(conj(a)*b);
}

// ¼ü
struct L : public vector<P> {
	L(const P &a, const P &b){
		push_back(a);
		push_back(b);
	}
};

// ½p`
typedef vector<P> G;

// ~
struct C{
	P p;
	double r;
	C(const P& p, double r) : p(p), r(r) {}
};

int ccw(P a, P b, P c)
{
	b -= a;
	c -= a;
	if(cross(b, c) > 0)   return +1; // ½vñè
	if(cross(b, c) < 0)   return -1; // vñè
	if(dot(b, c) < 0)     return +2; // c--a--b
	if(norm(b) < norm(c)) return -2; // a--b--c
	return 0;
}

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		P p[5];
		rep(j, 5)
			scanf("%lf%lf", &p[j].real(), &p[j].imag());
		
		bool ok = true;
		rep(j, 2){
			int ans;
			rep(k, 3){
				int tmp = ccw(p[k], p[(k+1)%3], p[3+j]);
				if(!k)
					ans = tmp;
				else if(ans*tmp < 0){
					ok = !ok;
					break;
				}
			}
		}
		
		puts(ok ? "NG" : "OK");
	}
	
	return 0;
}

Measured memory_bytes: 0
///
// File:  1232.cpp
// Author: ymiyamoto
//
// Created on Sat Nov 25 19:23:48 2017
//

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

bool is_prime(uint32_t n)
{
  for (uint32_t i = 2; i <= (uint32_t)sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

vector<uint32_t> primes_up_to(uint32_t n)
{
  vector<uint32_t> primes;
  for (uint32_t i = 2; i <= n; i++) {
    if (is_prime(i)) {
      primes.push_back(i);
    }
  }

  return primes;
}

int32_t main()
{
  vector<uint32_t> primes = primes_up_to(100000);

  while (true) {
    uint32_t m, a, b;
    cin >> m >> a >> b;
    if (m == 0 && a == 0 && b == 0) break;

    uint32_t max_p = 0;
    uint32_t max_q = 0;
    for (uint32_t i = 0; i < primes.size(); i++) {
      uint32_t q = primes[i];
      if (q > m) break;
      auto start = lower_bound(primes.begin(), primes.end(), ceil((double)a * q / b));
      auto end = upper_bound(primes.begin(), primes.end(), min(q, m / q));
      for (auto iter = start; iter < end; iter++) {
        uint32_t p = *iter;
        if (max_p * max_q < p * q) {
          max_p = p;
          max_q = q;
        }
      }
    }
    cout << max_p << " " << max_q << endl;
  }

  return 0;
}

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

int main (void){
  long long int a = 0,b = 0,n = 0,x = 0,y = 0,z = 0,max = 0;
  cin >> a >> b >> n;


if(n >= b-1){
    y = (b-1) / b;
    y = a * y;
    x = a*(b-1)/b;
    z = x - y;
    if(max < z){
      max = z;
    }
    z = 0;
}else{
    y = n / b;
    y = a * y;
    x = a*n/b;
    z = x - y;
    max = z;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 3556
#include<stdio.h>
int main(void){
    int wid, hei, t, p;
    while(1){
        scanf("%d%d%d%d",&wid,&hei,&t,&p);
        if(wid==0) break;
        int mat[500][500];//mat[wid][hei]
        for(int i=0;i<500;i++){
            for(int j=0;j<500;j++){
                if(i<wid&&j<hei) mat[i][j]=1;
                else mat[i][j]=0;
            }
        }
        int nw=0, nh=0;
        /*for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                printf("%d ",mat[i][j]);
            }puts("");
        }*/
        for(int i=0;i<t;i++){
            int d, c;
            scanf("%d%d",&d,&c);
            if(d==1){
                nw+=c;
                for(int j=0;j<c;j++){
                    for(int k=0;k<hei;k++){
                        mat[nw+j][nh+k] += mat[nw-j-1][nh+k];
                    }
                }
                wid = (c>wid-c)?c:wid-c;
            }else{
                nh+=c;
                for(int j=0;j<c;j++){
                    for(int k=0;k<wid;k++){
                        mat[nw+k][nh+j] += mat[nw+k][nh-j-1];
                    }
                }
                hei = (c>hei-c)?c:hei-c;
            }
        }
        for(int i=0;i<p;i++){
            int x, y;
            scanf("%d%d",&x,&y);
            printf("%d\n",mat[nw+x][nh+y]);
        }
    }
}



Measured memory_bytes: 2712
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    x, y, z = map(str, input().split())
    temp = x
    x = y
    y = temp
    temp = x
    x = z
    z = temp
    print(x+' '+y+' '+z)


main()


Measured memory_bytes: 38384
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}


int main(){
    init();

    ll H,W;cin>>H>>W;
    ll c[10][10];
    vector<vector<ll>>dp(10,vector<ll>(10,INF));
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            ll c;cin>>c;
            dp[i][j]=c;
        }
    }
    //ワーシャルフロイド
    for(int i=0;i<10;i++)dp[i][i]=0;
    
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }

    ll ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            ll A;cin>>A;
            if(A==-1)continue;
            ans+=dp[A][1];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BS
import           Data.List             (sortOn, transpose)
import           Data.Maybe            (fromJust)
import           Data.Ord              (Down (Down))

main :: IO ()
main = do
  [n, h] <- readInts <$> BS.getLine
  abs' <- map readInts . BS.lines <$>  BS.getContents
  print $ solve n h abs'

solve :: Int -> Int -> [[Int]] -> Int
solve _ h abs' = c + d where
  [as, bs] = transpose abs'
  maxA = maximum as
  (c, h') = throwSword (0, h) . sortOn Down $ filter (maxA <) bs
  d = (h' + maxA - 1) `div` maxA

throwSword :: (Int, Int) -> [Int] -> (Int, Int)
throwSword ch [] = ch
throwSword (c, h) (b:bs)
  | h <= 0 = (c, 0)
  | otherwise = throwSword (c + 1, h - b) bs

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

readInts :: BS.ByteString -> [Int]
readInts = map readInt . BS.words


Measured memory_bytes: 47484
n = int(input())
num_dict = {}
numbers = map(int,input().split())
last_sum = 0;
for val in numbers: 
    last_sum+=val
    if val in num_dict:
        num_dict[val]+=1
    else:
        num_dict[val]=1

q = int(input())
for i in range(0,q):
    b,c=map(int,input().split())
    if b in num_dict:
        last_sum += (c-b)*num_dict[b]
        if c in num_dict:
            num_dict[c]+=num_dict[b]
        else:
            num_dict[c]=num_dict[b]
        num_dict.pop(b,'ignore')

    
    print(last_sum)

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

using namespace std;

int main(void) {
	string S,T;
	cin >> S >> T;
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i]) {
			ans++;
		}
	}
		cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static ArrayList<Node> nodes = new ArrayList<Node>();
    static int count = 0;
    public static void main( String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int e = in.nextInt();
        for( int i = 0; i < n; i++ ) nodes.add(new Node(i));
        while(e-->0) {
            int u = in.nextInt()-1;
            int v = in.nextInt()-1;
            nodes.get(u).adj.add(nodes.get(v));
            nodes.get(v).adj.add(nodes.get(u));
        }
        boolean[] visited = new boolean[n];
        visited[0] = true;
        dfs(n, 0, visited, 1);
        System.out.println(count);
    }
    public static void dfs(int n, int start, boolean[] visited, int size ) {
        if( size == n ) count++;
        // System.out.println(nodes.get(start).i);
        for( Node nd : nodes.get(start).adj ) {
            if(!visited[nd.i]) {
                visited[nd.i] = true;
                dfs(n, nd.i, visited, size+1);
                visited[nd.i] = false;
            }
        }
    }
    public static class Node {
        int i;
        ArrayList<Node> adj = new ArrayList<Node>();
        public Node(int i) {
            this.i = i;
        }
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int x;
    cin >> x;
    if (x == 3 || x == 5 || x == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}



Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int main()
{
    int x, y;
    scanf("%d %d", &x, &y);

    if (x % y == 0)
    {
        printf("-1\n");
        return 0;
    }

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

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	char ch;
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
	a = 0;b = 0;
	c = 0;d = 0;
	e = 0;f = 0;
	g = 0;h = 0;
	i = 0;j = 0;
	k = 0;l = 0;
	m = 0;n = 0;
	o = 0;p = 0;
	q = 0;r = 0;
	s = 0;t = 0;
	u = 0;v = 0;
	w = 0;x = 0;
	y = 0;z = 0;
	while (cin.get(ch)){
		if (ch == 'a' || ch == 'A')a++;
		else if (ch == 'b' || ch == 'B')b++;
		else if (ch == 'c' || ch == 'C')c++;
		else if (ch == 'd' || ch == 'D')d++;
		else if (ch == 'e' || ch == 'E')e++;
		else if (ch == 'f' || ch == 'F')f++;
		else if (ch == 'g' || ch == 'G')g++;
		else if (ch == 'h' || ch == 'H')h++;
		else if (ch == 'i' || ch == 'I')i++;
		else if (ch == 'j' || ch == 'J')j++;
		else if (ch == 'k' || ch == 'K')k++;
		else if (ch == 'l' || ch == 'L')l++;
		else if (ch == 'm' || ch == 'M')m++;
		else if (ch == 'n' || ch == 'N')n++;
		else if (ch == 'o' || ch == 'O')o++;
		else if (ch == 'p' || ch == 'P')p++;
		else if (ch == 'q' || ch == 'Q')q++;
		else if (ch == 'r' || ch == 'R')r++;
		else if (ch == 's' || ch == 'S')s++;
		else if (ch == 't' || ch == 'T')t++;
		else if (ch == 'u' || ch == 'U')u++;
		else if (ch == 'v' || ch == 'V')v++;
		else if (ch == 'w' || ch == 'W')w++;
		else if (ch == 'x' || ch == 'X')x++;
		else if (ch == 'y' || ch == 'Y')y++;
		else if (ch == 'z' || ch == 'Z')z++;
	}
	cout << "a : " << a << endl;
	cout << "b : " << b << endl;
	cout << "c : " << c << endl;
	cout << "d : " << d << endl; 
	cout << "e : " << e << endl;
	cout << "f : " << f << endl; 
	cout << "g : " << g << endl;
	cout << "h : " << h << endl; 
	cout << "i : " << i << endl;
	cout << "j : " << j << endl; 
	cout << "k : " << k << endl;
	cout << "l : " << l << endl;
	cout << "m : " << m << endl;
	cout << "n : " << n << endl;
	cout << "o : " << o << endl;
	cout << "p : " << p << endl;
	cout << "q : " << q << endl;
	cout << "r : " << r << endl;
	cout << "s : " << s << endl;
	cout << "t : " << t << endl;
	cout << "u : " << u << endl;
	cout << "v : " << v << endl;
	cout << "w : " << w << endl;
	cout << "x : " << x << endl;
	cout << "y : " << y << endl;
	cout << "z : " << z << endl;
}

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

main() {
  int N,A;
  int b;
  cin >> N;  // 払う金額
  cin >> A;  // 所有 1円玉
  if (N - 500 * ( N / 500) > A) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque
N = int(input())

s = 'a'
queue = deque()
queue.append(s)
while True:
    a = queue.popleft()
    if len(a) == N:
        queue.append(a)
        break
    origin = a
    a = max(a)
    s = 'a'
    end = chr(ord(a)+2)
    while s != end:
        queue.append(origin+s)
        s = chr(ord(s)+1)
ans = []
while queue:
    ans.append(queue.popleft())
for s in sorted(ans):
    print(s)

Measured memory_bytes: 14872
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

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

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int h,w;
	cin>>h>>w;
	vector<string> mp(h);
	rep(i,h) cin>>mp[i];
	vv<int> ds(h,vector<int>(w,MOD));
	ds[0][0]=(mp[0][0]=='#');
	rep(i,h)rep(j,w){
		if(i+1<h) MN(ds[i+1][j],ds[i][j]+(mp[i][j]!=mp[i+1][j]));
		if(j+1<w) MN(ds[i][j+1],ds[i][j]+(mp[i][j]!=mp[i][j+1]));
	}
	// using TP=tuple<int,int,int>;
	// priority_queue<TP,vector<TP>,greater<TP>> pq; pq.emplace(ds[0][0],0,0);
	// while(pq.size()){
	// 	int d,x,y;
	// 	tie(d,x,y)=pq.top(); pq.pop();
	// 	if(d!=ds[y][x]) continue;
	// 	rep(d,4){
	// 		int nx=x+dx[d];
	// 		int ny=y+dy[d];
	// 		if(nx<0 || ny<0 || nx>=w || ny>=h) continue;
	// 		int nd=d+(mp[y][x]!=mp[ny][nx]);
	// 		if(MN(ds[ny][nx],nd)) pq.emplace(nd,nx,ny);
	// 	}
	// }
	out(ds,mp,1);
	int re=ds[h-1][w-1];
	if(mp[h-1][w-1]=='#') ++re;
	cout<<re/2 NL;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=405;
ll dp[N][N],a[N],prfx[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(ll i=1;i<=n;i++)cin>>a[i];
    for(ll i=1;i<=n;i++)prfx[i]=prfx[i-1]+a[i];
    for(ll len=2;len<=n;len++){
        for(ll s=1,e=len;e<=n;s++,e++){
            dp[s][e]=(1e16);
            for(ll k=s;k<e;k++){
                ll val = dp[s][k] + dp[k+1][e] + prfx[e]-prfx[s-1];
                dp[s][e]=min(dp[s][e],val);
            }
        }
    }
    cout<<dp[1][n];
}

Measured memory_bytes: 1536
n = int(input())
h = list(map(int, input().split()))

ans = 0
while sum(h) != 0:
    sakki = 1
    for i in range(n):
        if h[i] != 0:
            h[i] -= 1
            sakki = 1
        else:
            if sakki == 0:
                continue
            else:
                if i != 0:
                    ans += 1
                    sakki = 0
                else:
                    sakki = 0
    if sakki == 1:
        ans += 1

print(ans)

Measured memory_bytes: 38896
using System;

namespace _1172
{
    class Program
    {
        static void Main(string[] args)
        {
            bool[] prime = new bool[300000];
            for (int i = 2; i < 300000; i++) prime[i] = true;
            for (int i = 2; i < Math.Sqrt(300000); i++)
            {
                if (prime[i])
                {
                    for (long j = i * i; 0 < j && j < 300000; j += i)
                    {
                        prime[j] = false;
                    }
                }
            }
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                int ret = 0;
                for (int i = n + 1; i <= n * 2; i++)
                {
                    if (prime[i]) ret++;
                }
                Console.WriteLine(ret);
            }
        }
    }
}

Measured memory_bytes: 9240
# 最小公倍数(mathは3.5以降) fractions
from functools import reduce
import fractions #(2020-0405  fractions→math)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
lcm         =lcm_list(A)
harf_lcm     =lcm//2             # 最小公倍数の半分
harf_lcm_num =M//harf_lcm          # Mの中の半公倍数の個数
harf_lcm_num =(harf_lcm_num +1)//2 # 偶数を除く

#半公倍数がaiで割り切れるときは✖
import numpy as np 
A_np =np.array(A)
if np.any(harf_lcm % A_np ==0):
    harf_lcm_num =0
"""    
for a in A:
    if harf_lcm % a ==0:
        harf_lcm_num =0
        break
"""
print(harf_lcm_num)

Measured memory_bytes: 20956
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    int cnt = 0;
    for(auto itr = n.begin(); itr != n.end(); itr++) if(*itr == '2') cnt++;

    cout << cnt << endl;
}

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

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

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

template <typename T>

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

signed main(void) {
	int n;
	cin >> n;
	vector<int>a(n,2);
	a[1]=1;
	FOR(i, 2, n+1) {
		for (int j = 2 * i; j <= n; j += i) {
			a[j]++;
		}
	}
	int ret=0;
	rep1(i,n){
		ret+=a[n-i];
	}
	print(ret);
}

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

using pii = pair<int, int>;

struct edge {
    int to, cost;
};

using edges = vector<edge>;
using graph = vector<edges>;

constexpr int INF = 1e9;

vector<int> dijkstra(graph& g, int s) {
    vector<int> d(g.size(), INF);
    priority_queue<pii, vector<pii>, greater<pii>> que;
    que.push(make_pair(0, s));
    d[s] = 0;
    while(!que.empty()) {
        pii p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) {
            continue;
        }
        for(auto& e : g[v]) {
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main() {
    int N, M, cap;
    while(cin >> N >> M >> cap, N) {
        unordered_map<string, int> idx;
        string src, dest;
        cin >> src >> dest;
        graph g(6001);
        idx[src] = 0; idx[dest] = 1;
        cap *= 10;
        for(int i=0; i<N; ++i) {
            string c1, c2;
            int d;
            cin >> c1 >> c2 >> d;
            if(idx.count(c1) == 0) {
                idx[c1] = idx.size();
            }
            if(idx.count(c2) == 0) {
                idx[c2] = idx.size();
            }
            g[idx[c1]].push_back(edge{idx[c2], d});
            g[idx[c2]].push_back(edge{idx[c1], d});
        }
        vector<int> S = {0, 1};
        for(int i=0; i<M; ++i) {
            string s;
            cin >> s;
            S.push_back(idx[s]);
        }
        graph g2(S.size());
        for(int i=0; i<S.size(); ++i) {
            auto d = dijkstra(g, S[i]);
            for(int j=0; j<S.size(); ++j) {
                if(d[S[j]] <= cap) {
                    g2[i].push_back(edge{j, d[S[j]]});
                }
            }
        }
        auto res = dijkstra(g2, 0);
        cout << (res[1] == INF ? -1 : res[1]) << endl;
    }
}


Measured memory_bytes: 4744
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int _=2e5+5;
int n,k,f[_];
int main()
{
    scanf("%d%d0",&n,&k);
    for(int i=1;i<=n;++i)f[i%k]++;
    long long ans=0;
    ans=1ll*f[0]*f[0]*f[0];
    if(!(k&1))
    {
        int t=k/2;
        ans+=1ll*f[t]*f[t]*f[t];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 640
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let a: usize = scan(tokens);
    let b: usize = scan(tokens);
    if a <= 2 * b {
        println!("0");
    } else {
        println!("{}", a - 2 * b);
    }
}


Measured memory_bytes: 4352
A, B, C, D = input().split(" ")
count = 0
while (count == 0):
    C = int(C) - int(B)
    if (int(C) <= 0):
        print("Yes")
        count = count + 1
        break
    elif (int(C) >= 0):
        A = int(A) - int(D)
        if (int(A)<= 0):
            print("No")
            count = count + 1
            break
    else:
        continue

Measured memory_bytes: 9196
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int dp[1000006];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, W;
  cin >> N >> W;
  int v[N], w[N];
  FOR(i,0,N) cin >> v[i] >> w[i];
  FOR(i,0,N){
    FOR(j,0,W+1) {
      // 入れる
      if(j+w[i] <= W) dp[j+w[i]] = max(dp[j+w[i]], dp[j] + v[i]);
    }
  }
  int ans = 0;
  FOR(i,0,W+1) ans = max(ans, dp[i]);
  cout << ans << endl;
}


Measured memory_bytes: 3272
h, w = gets.split.map(&:to_i)
cm = Array.new(h + 2){Array.new(w + 2, 0)}
que = []
1.upto(h) do |i|
  s = gets.chomp
  1.upto(w) do |j|
    if s[j - 1] == '.'
      cm[i][j] = -1
    else
      que.push(i)
      que.push(j)
      cm[i][j] = 0
    end
  end
end
ans = 0
while que.size > 0
  y = que.shift
  x = que.shift
  ans = cm[y][x] + 1
  if cm[y + 1][x] == -1
    cm[y + 1][x] = ans
    que.push(y + 1)
    que.push(x)
  end
  if cm[y - 1][x] == -1
    cm[y - 1][x] = ans
    que.push(y - 1)
    que.push(x)
  end
  if cm[y][x + 1] == -1
    cm[y][x + 1] = ans
    que.push(y)
    que.push(x + 1)
  end
  if cm[y][x - 1] == -1
    cm[y][x - 1] = ans
    que.push(y)
    que.push(x - 1)
  end
end
puts ans - 1

Measured memory_bytes: 27132