akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iterator>

using namespace std;

#define DT long long
#define forn(i,n)for(i=0;i<n;i++)
#define forc(i,c,n)for(i=c;i<=n;i++)
typedef vector<DT> vec;
typedef list<DT> li;


int main() {
	//ifstream fin("input.txt");
	int i,j,k;
	string st;
	cin>>st;
	k=st.length();
	vec vc(k);
	list<char> lst;
	forn(i,k){
		lst.push_back(st[i]);
	}
	list<char>::iterator it=lst.begin(),it2,itt;
	it2=it;
	it2++;
	while(it2!=lst.end()){
		if((*it)=='S' && (*it2)=='T'){
			it=lst.erase(it);
			it=lst.erase(it);
			if(it==lst.end()){
				it=lst.begin();
				if(it==lst.end()){
					cout<<0<<endl;
					return 0;
				}
				it2=it;
				it2++;
				if(it2==lst.end()){
					cout<<1<<endl;
					return 0;
				}
			}
			else{
				if(it!=lst.begin())
					it--;
				it2=it;
				it2++;
			}
		}
		else{
			it=it2;
			it2++;
		}
	}
	cout<<lst.size()<<endl;
	return 0;
}

Measured memory_bytes: 8196
#include <iostream>

using namespace std;

int main(){
    int x;
    cin >> x;
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    for(int i=0;i<x;i++){
        string str;
        cin >> str;
        if(str=="AC"){
            a+=1;
        }else if(str=="WA"){
            b+=1;
        }else if(str=="TLE"){
            c+=1;
        }else if(str=="RE"){
            d+=1;
        }
    }cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
}

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC120A
{
	class Program
	{
		static void Main(string[] args)
		{
			int a, b, c;
			var word = Console.ReadLine().Split(' ');
			a = int.Parse(word[0]);
			b = int.Parse(word[1]);
			c = int.Parse(word[2]);
			if (b / a < c)
			{
				Console.WriteLine(b / a);
			}
			else
			{
				Console.WriteLine(c);
			}
			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int main()
{
	int n,w;
	cin>>n>>w;
	int v1[n+1][2], v2[n+1][w+1];//v1は荷物の価値と重さ、v2は表
	for(int i=1;i<=n;++i){
		for(int j=0;j<2;++j){
			cin>>v1[i][j];//n種類の荷物の価値と重さを入力
		}
	}
	for(int i=0;i<=w;++i){
		v2[0][i]=0;//表の数０の段を０にする
	}
	for(int i=1;i<=n;++i){//i=0のとき、表は０にしてあるので１から始める
		for(int j=0;j<=w;++j){
			if(j < v1[i][1]){
				v2[i][j] = v2[i-1][j];
			}else{
				if(v2[i-1][j] < (v2[i-1][j-v1[i][1]] + v1[i][0])){
					v2[i][j] = (v2[i-1][j-v1[i][1]] + v1[i][0]);
				}else v2[i][j] = v2[i-1][j];
			}
		}
	}
	cout<<v2[n][w]<<endl;
	return 0;
}



Measured memory_bytes: 7028
#include<iostream>
using namespace std;
int main(){
  int n,a[1000000],cnt=0,m=0,g[1000000];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=1;i<=n;i=3*i+1)g[m]=i,m++;
  for(int i=m-1;i>=0;i--){
    for(int j=g[i];j<n;j++){
      int v=a[j],k=j-g[i];
      while(k>=0&&a[k]>v){
    a[k+g[i]]=a[k];
    k=k-g[i];
    cnt++;
      }
      a[k+g[i]]=v;
    }
  }
  cout<<m<<endl;
  for(int i=m-1;i>=0;i--){
    cout<<g[i];
    i==0?cout<<endl:cout<<" ";
  }
  cout<<cnt<<endl;
  for(int i=0;i<n;i++)cout<<a[i]<<endl;
  return 0;
}


Measured memory_bytes: 7020
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <iomanip>
#include <sstream>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum, cnt;


int main(){
	ll n,d;
	cin>>n>>d;
	for(ll i=1; i<=n; i++){
		if(cnt==d*2){
			ans++;
			cnt=0;
		}
		else cnt++;
	}
	if(cnt>0) ans++;
	cout<<ans<<endl;
}


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

int main(void) {
    int K,X;cin>>K>>X;
    string result = "";
    for (int i = X - K + 1; i <= X + K - 1; i++) {
        if (i >= -1000000 && i <= 1000000) result += " " + to_string(i);
    }
    cout << result.substr(1, result.size() - 1) << endl;
    return 0;
}

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

void Main()
{
  int sx, sy, tx,ty; cin >> sx >> sy >> tx >> ty;
  string path = "";
  int x = sx;
  while (x < tx) {path += "R"; x++;}
  int y = sy;
  while (y < ty) {path += "U"; y++;}
  while (x > sx) {path += "L"; x--;}
  while (y > sy) {path += "D"; y--;}
  path += "D"; y--;
  while (x < tx+1) {path += "R"; x++;}
  while (y < ty) {path += "U"; y++;}
  path += "L"; x--;
  path += "U"; y++;
  while (x > sx-1) {path += "L"; x--;}
  while (y > sy) {path += "D"; y--;}
  path += "R"; x++;
  cout << path << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define llu unsigned long long 
#define ll long long 
int read() { llu  x; if (scanf("%llu", &x) == -1)exit(0); return x; }
#define vi vector<int>
#define vb vector<bool>
#define LOCAL_JUDGE
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main() {
    //c_p_c();
    
    ll n;
    cin >> n;

    ll s = 0;
    for (ll i = 1; i <= n; ++i) {
        if (i % 5 && i % 3) s += i;
    }
    cout << s << endl;

    return 0;
}



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

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

    long long ans = 0;
    for (long long i = 1; i <= N; i++)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            ans += i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
from collections import deque
N,M = map(int,input().split())
P = list(map(int,input().split()))
P.insert(0,0)
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    x,y = map(int,input().split())
    G[x].append(y)
    G[y].append(x)
A = []
hist = [0 for _ in range(N+1)]
for i in range(1,N+1):
    if hist[i]==0:
        C = [i]
        hist[i]=1
        que = deque([i])
        while que:
            x = que.popleft()
            for y in G[x]:
                if hist[y]==0:
                    que.append(y)
                    C.append(y)
                    hist[y]=1
        C = sorted(C)
        A.append(C)
cnt = 0
for C in A:
    B = []
    for c in C:
        B.append(P[c])
    B = sorted(B)
    cur = 0
    for i in range(len(C)):
        if cur<len(B) and C[i]==B[cur]:
            cnt += 1
            cur += 1
        elif cur<len(B) and C[i]<B[cur]:
            continue
        elif cur<len(B) and C[i]>B[cur]:
            while cur<len(B) and C[i]>B[cur]:
                cur += 1
            if cur<len(B) and B[cur]==C[i]:
                cnt += 1
            else:
                continue
print(cnt)
    

Measured memory_bytes: 90472
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

// ユニオンファインドツリー
// find(i) = iの親, size(i) = iの属する集合の要素数
struct uf_tree {
    vector<int> parent;
    int internal_size;
    uf_tree(int size_) : parent(size_, -1), internal_size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            internal_size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return internal_size; }
};

int main(void) {
    int n, m;
    cin >> n >> m;
    uf_tree uf(n);
    rep (m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        uf.unite(a, b);
    }
    set<int> s;
    repeat (i, n) {
        s.insert(uf.find(i));
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 3e5 + 17;

int n;
int a[maxn], cnt[maxn];

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	forn (i, n)
		scanf("%d", a + i);

	return true;
}

void solve()
{
	forn (i, n)
		++cnt[a[i]];

	bool f = false;

	forn (i, maxn)
		if (cnt[i] > 2)
		{
			cnt[i] %= 2;

			if (cnt[i] == 0)
				cnt[i] = 2;
			else
				f = true;
		}

	vector<int> v;

	forn (i, maxn)
		if (cnt[i] == 2)
			v.push_back(i);

	forn (i, size(v) - size(v) % 2)
		cnt[v[i]] = 1;

	int add = 0;

	if (size(v) & 1)
		add = -2;

	printf("%d\n", add + accumulate(cnt, cnt + maxn, 0));
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
const ll N = 1e5+10 ;
int w[N],v[N];
int dp[N];
int main(){
   int n,k;
   cin >> n >> k;
   int m = -1;
   memset(dp,0x3f,sizeof dp);
   dp[0] = 0;
   for(int i = 1;i <= k;++i) {cin>>w[i]>>v[i];}
   for(int i = 1;i <= k;++i){
      for(int j = w[i];j <= 1e4;++j){
         if(dp[j-w[i]] != 0x3f3f3f3f) dp[j] = min(dp[j],dp[j-w[i]] + v[i]);
      }
   }
   m = 0x3f3f3f3f;
   for(int i = n;i <= 1e4;++ i){
      m = min(m,dp[i]);
   }
   cout<<m<<endl;
}


Measured memory_bytes: 640
using System.Collections.Generic;
using System.Linq;
using System;
using static System.Console;

class Program
{
  static void Main() => new Program().solve();

  void solve()
  {
    var n = int.Parse(ReadLine());
    var seq = ReadLine().Split(' ').Select(long.Parse).ToArray();

    var table = new long[n+1];
    for(int i = 0; i < n; i++)
    {
      table[i+1] = table[i] + seq[i];
    }

    var min = long.MaxValue;
    for(int i = 1; i < n; i++)
    {
      min = Math.Min(min, Math.Abs(table[i] * 2L - table[n]));
    }

    var ans = min;
    WriteLine(ans);
  }
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

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


int main()
{
  int n; cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int min_p = INF;
  int ans = 0;
  rep(i, n) {
    if(min_p >= p[i]) ++ans;
    chmin(min_p, p[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4004
A = input()
B = input()
ans = ''
if len(A) < len(B):
  ans = 'LESS'
elif len(A) > len(B):
  ans = 'GREATER'
elif len(A) == len(B):
  for i in range(len(A)):
    if int(A[i]) > int(B[i]):
      ans = 'GREATER'
      break;
    elif int(B[i]) > int(A[i]):
      ans = 'LESS'
      break;
    if i == len(A)-1:
      if int(B[i]) == int(A[i]):
        ans = 'EQUAL'
print(ans)

Measured memory_bytes: 3064
#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 main(){
	int N,K;
	int D[10];
	bool Db[10]={};
	scan(N);scan(K);
	rep(i,K){
		scan(D[i]);
		Db[D[i]]=true;
	}
	for(int i=N;;i++){
		int flag=1;
		int n=i;
		while(n){
			if(Db[n%10]==true){
				flag=0;
				break;
			}
			n/=10;
		}
		if(flag==1){
			prin(i);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

vector<int> ans;
void solve(int n,int a,int b,int alive){
	//cout << n << " " << a << " " << b << " " << alive << endl;
	if(a == b){
		ans.pb(a);
		return;
	}
	int m = 0;
	int id[20];
	for(int i = 0 ; i < n ; i ++){
		if((alive>>i)&1)id[m++] = i;
	}
	if(m == 0)return;
	for(int i = 0 ; i < m-1 ; i ++){
		if(((a>>id[i])&1) != ((b>>id[i])&1)){
			swap(id[i],id[m-1]);
			break;
		}
	}
	
	/*cout << "m=" << m << endl;
	rep(i,m)cout << id[i] << " ";
	cout << endl;*/
	
	rep1(i,(1<<(m-1))-1){
		ans.pb(a);
		int i_ = i&-i;
		int j = 0;
		while(((i_>>j)&1) == 0)j ++;
		a ^= 1<<id[j];
	}
	ans.pb(a);
	a ^= 1<<id[m-1];
	
	/*cout << "ans\n";
	for(int i = 0 ; i < ans.size() ; i ++){
		printf("%d%c",ans[i],(i+1==ans.size())?'\n':' ');
	}*/
	
	
	solve(n,a,b,alive-(1<<id[m-1]));
}

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	
	int cnt = 0;
	for(int i = 0 ; i < n ; i ++){
		if(((a>>i)&1) != ((b>>i)&1))cnt ++;
	}
	if(cnt%2 == 0){
		puts("NO");
		return 0;
	}
	puts("YES");
	solve(n,a,b,(1<<n)-1);
	for(int i = 0 ; i < ans.size() ; i ++){
		printf("%d%c",ans[i],(i+1==ans.size())?'\n':' ');
	}
}


Measured memory_bytes: 1656
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double a = sc.nextInt();
    double b = sc.nextInt();
    double x = sc.nextInt();
    double Re = 0;
    if(x<=a*a*b/2){
      Re = Math.atan(2*x/(a*b*b));
    }else{
      Re = Math.atan(a*a*a/(2*(a*a*b-x)));
    }
    System.out.println(90.0-Math.toDegrees(Re));
  }
}

Measured memory_bytes: 27096
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, X, Y; cin >> N >> X >> Y;
    X--, Y--;
    vector V(N,0);
    for (int i = 0; i < N; i ++) {
        for (int j = i + 1; j < N; j++) {
            int step = min({j-i, abs(X-i) + 1 + abs(Y-j), abs(X-j) + 1 + abs(Y-i)});
            V[step]++;
        }
    }
    for (int i = 1; i < N; i++) cout << V[i] << endl;
}


Measured memory_bytes: 3584
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // double
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) {
      int a = i;
      if(i % 3 == 0) cout << " " << i;
      else {
          while(a > 2) {
              if(a % 10 == 3) {
                  cout << " " << i;
                  break;
              }
              a /= 10;
          }
      }
  }
  cout << "\n";
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE = 1e6;
bool prime[MAX_SIZE + 1];
void sieve()
{

	memset(prime, true, sizeof(prime));

	for (int p = 2; p * p <= MAX_SIZE; p++) {
		if (prime[p] == true) {
			for (int i = p * p; i <= MAX_SIZE; i += p)
				prime[i] = false;
		}
	}
}
int nextprime(int n)
{

	int res = -1;
	for (int i = n ; i < MAX_SIZE; i++) {
		if (prime[i]==true) {
			res = i;
			break;
		}
	}

	return res;
}
int main()
{

	sieve();
	int n;
	cin>>n;
	cout << nextprime(n);
	return 0;
}



Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <string>
#include <sstream>
#include  <list>
//#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
/*
int cmp(shi a,shi b)
{
    return a.x<b.x;
}
long long cmd(long long a, long long  b)
{
    return a > b;
}*/

int cmd(int a, int b)
{
    return a>b;
}
int loda[100][100]={0};
int main()
{
    int n,m;
    cin >>n>>m;

    for(int i=1;i<=m;i++){
        int a, b;
        cin >>a >>b;
        loda[a][b]++;
        loda[b][a]++;
    }int sum=0;
    for(int i=1;i<=n;i++){
            sum=0;
        for(int j=1;j<=n;j++){
            if(loda[i][j])
                sum += loda[i][j];
        }
        cout<<sum<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

char* lower(char c[]){
    int len = strlen(c);

    for(int i = 0; i < len; i++){
        if('A' <= c[i] and c[i] <= 'Z'){
            c[i] = c[i] + 32;
        }
    }
    return c;

}


int main(){
    char word[10];
    char text[100];
    //char texts[20];

    scanf("%s", word);
    int count = 0;

    while(1){
        scanf("%s", text);//空白も読み込む
        if(strcmp(text, "END_OF_TEXT") == 0){
            break;
        }
        else{
            if(strcmp(word, lower(text)) == 0){
            //printf("%s\n", text[i]);
            count++;
            }
        }
    }

    
   
   printf("%d\n", count);
   //printf("aaaa\n");
   return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
const int INF = 1001001001;
vector<int> a;
ll n,m;
vector<ll> ruiseki;


ll f(ll x){
  ll y = 0;
  for(int i=0;i<n;i++){
  auto it = a.begin();
  advance(it,i);
  ll xx = x - *it;
  auto it2 = lower_bound(a.begin(),a.end(),xx);
  ll comb_at_i = n - (it2 - a.begin());
  y += comb_at_i;
  }
  return y;
}

ll g(ll x){
  ll y = 0;
  ll double_check = 0;
  ll minimum_check = INF;
  for(int i=0;i<n;i++){
  auto it = a.begin();
  advance(it,i);
  ll xx = x - *it;
  if(xx>a.at(n-1)) continue;
  auto it2 = lower_bound(a.begin(),a.end(),xx);
  ll left = it2 - a.begin() - 1;
  double_check += n-(it2-a.begin());
  minimum_check = min(minimum_check, (ll)(*it) + a.at(left+1));
  if(left>=0){
  y += ((ruiseki.at(n-1) - ruiseki.at(left)) + ((*it) * (n-(it2-a.begin()))));
  }else{
    y+= ruiseki.at(n-1) + ((*it) * (n-(it2-a.begin())));
  }
  }
  y -= (minimum_check * (double_check-m));
  return y;
}

int main(){
  cin >> n >> m;
  for(int i=0;i<n;i++){
    ll input;
    cin >> input;
    a.push_back(input);
  }
  sort(a.begin(),a.end());
  ll l = 0;
  ll r = a.at(n-1) * 2;
  ll c = (l+r)/2;
  while(r-l>1){
    if(f(c)<m) r = c; else l = c;
    c = (l+r)/2;
  }
  ruiseki.resize(n,0);
  ruiseki.at(0) = a.at(0);
  for(int i=1;i<n;i++){
    ruiseki.at(i) = ruiseki.at(i-1) + a.at(i);   
  }
     cout << g(l) << endl; 
}

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

int main() {
  long long int n, a, b;
  cin >> n >> a >> b;
  
  long long int ret = 0;
  ret += (n / (a + b)) * a; //b-ba-aの個数分
  
  n %= (a + b);
  
  if (n <= a) ret += n;
  else ret += a;

  cout << ret << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

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

	int n, m;
	cin >> n >> m;
	
	priority_queue<ll> a;
	rep(i, n) {
		ll t;
		cin >> t;
		a.push(t);
	}

	while (m) {
		ll k = a.top();
		a.pop();
		k = k >> 1;
		a.push(k);
		--m;
	}

	ll ans = 0;
	rep(i, n) {
		ans += a.top();
		a.pop();
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string n;
	cin>>n;
	int a=0,b=0;
	for(int i=0;i<n.size();i++)
	{
		if(i%2==0) 
		{
			if(n[i]=='0')
				++b;
			else
				++a;
		}
		else
		{
			if(n[i]=='1')
				++b;
			else
				++a;
			
		} 
	}
	
	if(a<b)
	{
		cout<<a;
	}
	else
	{
		cout<<b; 
	} 
	cout<<endl;
	
    return 0;	
} 

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, cnt;
  cin >> a >> b;
  
  cnt = 0;
  for (int i = a; i < b + 1; i++) {
    int foo = i / 1000;
    int bar = i % 100;
    
    bar = 10 * (bar % 10) + bar / 10;
    
    cnt += (foo == bar);
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
n = int(input())
import collections
dat = []
for _ in range(n):
    dat.append(input())
c = collections.Counter(dat)
mcc = c.most_common(1)[0][1]
#print(mcc)
res = []
for k in c:
    if c[k] == mcc:
        res.append(k)
res.sort()
for i in range(len(res)):
    print(res[i])

Measured memory_bytes: 100684
#include<map>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define ll long long
#define REP(i,e,s) for(register ll i=e; i<=s; i++)
#define DREP(i,e,s) for(register ll i=e; i>=s; i--)

#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)
#define int ll
int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=100000+10;

struct edge {
	int x,y;
} a[MAXN];

int ans[10];

map<pair<int,int>,int> mp;

signed main() {
	int h=read(),w=read(),n=read();

	REP(i,1,n) {
		int x=read(),y=read();
		REP(i,max(1ll,x-2),min(h-2,x)) REP(j,max(1ll,y-2),min(w-2,y)) mp[make_pair(i,j)]++;
	}	

	map<pair<int,int>,int>:: iterator iter;
	iter=mp.begin();
	while(iter!=mp.end()) {
		ans[iter->second]++;
		iter++;
	}

	int ans0=(h-2)*(w-2);

	REP(i,1,9) ans0-=ans[i];

	printf("%lld\n",ans0);
	REP(i,1,9) printf("%lld\n",ans[i]);

	return 0;
}

Measured memory_bytes: 56448
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
N,A,B,K=map(int,input().split())
p=998244353
fracmod=[1]*(N+1)
fracmodinv=[1]*(N+1)
ans=0
i=0
j=0
for i in range(1,N+1):
    fracmod[i]=(fracmod[i-1]*i)%p
#print(fracmod[:6])
for i in range(N+1):
    fracmodinv[i]=modinv(fracmod[i],p)
for i in range(N+1):
    forb=K-i*A      #bに割く得点
    if (forb%B==0)and(0<=(forb//B)<=N):
        j=forb//B
        #print(i,j)
        ans=(ans+((((fracmod[N]*fracmodinv[N-i]*fracmodinv[i])%p)*(fracmod[N]*fracmodinv[N-j]*fracmodinv[j]))%p))%p
print(ans)



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

int main(){
  int N;
  cin>>N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin>>d.at(i);
  }
  
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      ans+=d.at(i)*d.at(j);
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <set> 
#define maxn 2000005
typedef long long ll;
using namespace std;
int arr[maxn];
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n",max(max(a+b,a-b),a*b));
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
    const int L = (1 << 20) + 1;

    char buf[L], *S , *T, c;

    char getchar() {
        if(__builtin_expect(S == T, 0)) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }

    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }

    unsigned inpu()
    {
        unsigned x = 0; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar());
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x;
    }

    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }

    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;

        if(!a)*--outs = '0';
        else
            while(a)
                *--outs = (a % 10) + 48, a /= 10;

        if(x)
            *--outs = x;

        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
    if (!b) return 1;
    ll t = power(a, b/2, p);
    t = t*t%p;
    if (b&1) t = t*a%p;
    return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll px, py;
    ll d = exgcd(b, a%b, px, py);
    x = py;
    y = px-a/b*py;
    return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
    if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
    if (a < b) a = b;
}

const int MAXN = 100010;
const int MOD = 998244353;
const f80 MI = f80(1)/MOD;
const ll INF = 1000000000000000000;

int main()
{
    
    int n;
    cin >> n;
    ld ans = 0;
    while (n --)
    {
		ld x;
		string s;
		cin >> x >> s;
		if (s == "JPY")
			ans += x;
		else
			ans += x*380000;
	}
	printf("%.8f\n", (double)ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
void chmin(int &a, int b) {if(a > b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    int n;
    cin >> n;
    vi x(n);
    rep(i,0,n) cin >> x[i];
    int ave = round(accumulate(x.begin(), x.end(), 0) / (double)n);
    ll ans = 0;
    rep(i,0,n){
        ans += (ave-x[i])*(ave-x[i]);
    }
    cout << ans;
}

Measured memory_bytes: 512
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 != 0 and i % 5 != 0) sum += i;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

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

using namespace std;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x[4],y[4];
  repeat(i,2){
    cin>>x[i]>>y[i];
  }
  repeat(i,2){
    x[i+2]=y[i]-y[i+1]+x[i+1];
    y[i+2]=-x[i]+x[i+1]+y[i+1];
  }
  cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
int main(){
    ios::sync_with_stdio(0);
    int x; cin>>x;
    for(int i=2;;i++){
        if(x*i%360==0) return !printf("%d\n",i);
    }
}


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

const int m=1000000007;

int main()
{
    ll n,d;
    cin>>n>>d;
    vector<double>v;
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d)
            cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    ll n,m,i;
    cin>>n>>m;
    set<ll> ac;
    map<ll,ll> wa;
    ll pen=0;
    for(i=0;i<m;i++)
    {
        ll p;
        cin>>p;
        string s;
        cin>>s;
        if(ac.find(p)!=ac.end())
            continue;
        if(s[0]=='A')
        {   ac.insert(p);
            if(wa.find(p)!=wa.end())
            {
                pen+=wa[p];
                wa[p]=0;
            }
        }
        else
        {
            wa[p]++;
        }
    }
    cout<<ac.size()<<" "<<pen;
    return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
int main(void)
{
	int i,m,f,r;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1 && f==-1 && r==-1) break;
		else if(m==-1 || f==-1 || (m+f)<30)
			printf("F\n");
		else if((m+f)>=30 && (m+f)<50 && r<50)
			printf("D\n");
		else if(((m+f)>=50 && (m+f)<65) || r>=50)
			printf("C\n");
		else if((m+f)>=65 && (m+f)<80)
			printf("B\n");
		else if((m+f)>=80)
			printf("A\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 a[3][3];
  i64 x[3][3];
  rep(i,0,3) rep(j,0,3) {
    cin >> a[i][j];
    x[i][j] = 0;
  }
  i64 N;
  cin >> N;
  while(N--) {
    i64 b;
    cin >> b;
    rep(i,0,3) rep(j,0,3) {
      if(a[i][j] == b) {
        x[i][j] = 1;
      }
    }
  }
  bool OK = false;
  rep(i,0,3) {
    OK |= (x[i][0] && x[i][1] && x[i][2]);
  }
  rep(i,0,3) {
    OK |= (x[0][i] && x[1][i] && x[2][i]);
  }
  OK |= (x[0][0] && x[1][1] && x[2][2]);
  OK |= (x[2][0] && x[1][1] && x[0][2]);
  cout << (OK ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
n = int(input())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
d = [int(m) for m in d]#int型に直す
d.sort(reverse=True)
t = 0
for i in range(n):
    if i == 0:
        t += d[i]//2
    else:
        t += d[i]
print(t)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;
int n, p[1007], x[1007], dp[1007][5007], f[1007][5007], t, fa, lim,odp;

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

    cin >> n;
    for (int i = 2; i <= n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++) cin >> x[i];

    for (int i = n; i > 0; i--) {
        fa = p[i], lim = x[i];
        for (int j = x[fa]; j >= 0; j--) {
            odp=dp[fa][j];
            if (lim <= j)
                dp[fa][j] = dp[fa][j - lim] + dp[i][lim];
            else
                dp[fa][j] = (int) 1e7;

            if (dp[i][lim] <= j) {
                t = (dp[i][lim] == 0 ? odp : dp[fa][j - dp[i][lim]]) + lim;
                if (dp[fa][j] > t) dp[fa][j] = t;
            }
        }
    }
    cout << (dp[1][x[1]] < (int) 1e7 ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 20864
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int N;
	cin >> N;


	vstring S(N);
	vint T(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		cin >> T[i];
	}

	string X;
	cin >> X;

	int index;
	for (int i = 0; i < N; i++) {
		if (X == S[i]) {
			index = i;
			break;
		}
		
	}

	if (index == N - 1) {
		cout << 0;
		return 0;
	}

	ll ans = 0;
	for (int i = index+1; i < N; i++) {
		ans += T[i];
	}


	cout << ans;


}




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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define mp make_pair

int main(){
    int n;
    string a;
    long long b,c;
    map<string,long long> data;
    vector<string> id;
    while(cin>>n, n){
        id.clear();
        data.clear();
        rep(i,n){
            cin>>a>>b>>c;
            c*=b;
            if(data.find(a)==data.end()){
                data.insert(mp(a,c));
                id.push_back(a);
            }
            else{
                data[a]+=c;
            }
        }

        bool empty = true;
        rep(i,id.size()){
            if(data[id[i]]>=1000000){
                cout<<id[i]<<endl;
                empty = false;
            }
        }
        if (empty)
            cout<<"NA"<<endl;

    }
    return 0;
}

Measured memory_bytes: 1340
#include<iostream>
#include<string>
using namespace std;
string S;
int n;

string solve(string T) {
	int chain = 0, ok = 0;
	if (T.size() >= 3) {
		if (T[T.size() - 1] == '~') {
			if (T.substr(0, 2) == ">'" && T.size() >= 6) {
				for (int i = 2; i < T.size() - 1; i++) {
					if (T[i] == '#') {
						ok++;
					}
					else if (T[i] == '=') {
						if (ok == 0) { chain++; }
						else { chain--; }
					}
					else {
						goto NA;
					}
				}
				if (ok == 1 && chain == 0) { return "A"; }
			}

			if (T.substr(0, 2) == ">^" && T[T.size() - 2] == '~' && T.size() >= 6) {
				for (int i = 2; i < T.size() - 2; i += 2) {
					if (T.substr(i, 2) != "Q=") {
						goto E;
					}
				}
				return "B";
			E:;
			}
		}
	}
NA:;
	return "NA";
}

int main() {
	cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> S;
		cout << solve(S) << endl;
	}
}

Measured memory_bytes: 1212
#include<stdio.h>
int main()
{
	int H, W, i, j;

	while(1)
	{
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0)break;
	
		for(i=0; i<H; i++)
		{
			for(j=0; j<W; j++)
			{
				if(i == 0 || i == H-1 || j == 0 || j == W-1)
				{
					printf("#");
			
				}
				else
				{
					printf(".");
				}
			}
		
			printf("\n");
		}
		printf("\n");
		
	}

	return 0;
}

Measured memory_bytes: 572
(defun solve (n list)
  (loop for a in list
        if (and (evenp a)
                (not (or (= 0 (mod a 3))
                         (= 0 (mod a 5)))))
        do (return "DENIED")
        finally (return "APPROVED")))

#-swank
(let* ((n (read))
       (list (loop repeat n collect (read))))
  (format t "~A~%" (solve n list)))


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

#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

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

  vector<ii> a;
  int n, entra, i;
  i = 1;
  cin >> n;
  while (cin >> entra) {
    a.pb({entra, i});
    i++;
  }
  sort(all(a));
  for (int l = 0; l < a.size()-1; l++)
    cout << a[l].se << ' ';
  cout << a.back().se << ende;

  return 0;
}


Measured memory_bytes: 1780
import numpy as np
n=int(input())
s=input()
w=list(map(lambda x: x=="W",s))
e=list(map(lambda x: x=="E",s))
w = np.array([0]+w).cumsum()
e = np.array([0]+e[::-1]).cumsum()
e = e[::-1]
ans=n
for i in range(n+1):
    tmp=w[i-1]+e[i]
    ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 24308
import sys
input = sys.stdin.readline

n, x, y = [int(x) for x in input().split()]

g = [[] for _ in range(n)]

for i in range(n - 1):
    g[i].append(i + 1)
    g[i + 1].append(i)

g[x - 1].append(y - 1)
g[y - 1].append(x - 1)

from collections import deque

def bfs(u):
    d = [-1]*n
    d[u] = 0
    queue = deque([u])
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] < 0:
                d[i] = d[v] + 1
                queue.append(i)
    return d

ans = [0] * n

for i in range(n):
    d = bfs(i)
    for j in d:
        ans[j] += 1

for i in ans[1:]:
    print(i // 2)
        




Measured memory_bytes: 49372
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, M, X = Scanner.map_int()
    C = [0 for _ in range(N)]
    A = [[0 for _ in range(M)]for _ in range(N)]
    for i in range(N):
        c, *K = Scanner.map_int()
        C[i] = c
        for j in range(M):
            A[i][j] = K[j]
    ans = INF
    for i in range(1 << N):
        cnt = 0
        T = [0 for _ in range(M)]
        for j in range(N):
            if i >> j & 1:
                for k in range(M):
                    T[k] += A[j][k]
                cnt += C[j]
        if min(T) >= X:
            ans = min(ans, cnt)
    if ans == INF:
        print(-1)
    else:
        print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10736