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

using namespace std;
int main(){

int i=0;

string a[3];

for(i=0;i<3;i++){
cin>>a[i];
	if(a[i][0]=='a')cout<<"A";
	if(a[i][0]=='b')cout<<"B";
	if(a[i][0]=='c')cout<<"C";
	if(a[i][0]=='d')cout<<"D";
	if(a[i][0]=='e')cout<<"E";
	if(a[i][0]=='f')cout<<"F";
	if(a[i][0]=='g')cout<<"G";
	if(a[i][0]=='h')cout<<"H";
	if(a[i][0]=='i')cout<<"I";
	if(a[i][0]=='j')cout<<"J";
	if(a[i][0]=='k')cout<<"K";
	if(a[i][0]=='l')cout<<"L";
	if(a[i][0]=='m')cout<<"M";
	if(a[i][0]=='n')cout<<"N";
	if(a[i][0]=='o')cout<<"O";
	if(a[i][0]=='p')cout<<"P";
	if(a[i][0]=='q')cout<<"Q";
	if(a[i][0]=='r')cout<<"R";
	if(a[i][0]=='s')cout<<"S";
	if(a[i][0]=='t')cout<<"T";
	if(a[i][0]=='u')cout<<"U";
	if(a[i][0]=='v')cout<<"V";
	if(a[i][0]=='w')cout<<"W";
	if(a[i][0]=='x')cout<<"X";
	if(a[i][0]=='y')cout<<"Y";
	if(a[i][0]=='z')cout<<"Z";
	

}


}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int w,r,n;
    cin>>w>>r>>n;
    if(w<r)
    {
        int d = n/r;
        if(d*r<n)
        {
            cout<<d+1;
        }
        else
        {
            cout<<d;
        }
    }
    else if(w>r)
    {
        int d = n/w;
        if(d*w<n)
        {
            cout<<d+1;
        }
        else
        {

            cout<<d;
        }
    }
    else
    {
        int d = n/w;
        if(d*w<n)
        {
            cout<<d+1;
        }
        else
        {

            cout<<d;
        }
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for ( int i = 0; i < n; i++ )
#define MAX 20
static const int T[6] = { 10, 5, 3, 6, 12, 9 };
int G[MAX][MAX], H, W, ncell, vcell, V[MAX][MAX];
bool eq(int a, int i, int b, int j) {
	return ((a & (1 << i)) > 0) == ((b & (1 << j)) > 0);
}
// H,W ?????????????????????
void dfs(int i, int j) {
	V[i][j] = true;	vcell++;
	static int di[4] = { 0, -1, 0, 1 };
	static int dj[4] = { 1, 0, -1, 0 };
	rep(s, 4){
		int ni = i + di[s];
		int nj = j + dj[s];
		if ((G[i][j] & (1 << s)) && !V[ni][nj])	dfs(ni, nj);
	}
}
bool rec(int pos) {
	if (pos == H * W) {
		vcell = 0;
		rep(i, H)rep(j, W) V[i][j] = false;
		rep(i, H)rep(j, W)
			{	if (G[i][j] == 0)	continue;
				dfs(i, j);
				return ncell == vcell;
			}
		return false;
	}
	int i = pos / W; 	int j = pos % W;
	if (G[i][j] == 0) {
		int v = 0;
		if (j && !eq(G[i][j - 1], 0, v, 2))return false;
		if (i && !eq(G[i - 1][j], 3, v, 1))return false;
		if (rec(pos + 1))return true;
	} else {
		rep(t, 6){
			//??????????????????????????£?????¨?????????G[i][v]???????????????
			int v = T[t];
			if (j && !eq(G[i][j - 1], 0, v, 2))continue;
			if (i && !eq(G[i - 1][j], 3, v, 1))continue;
			if (i == 0 && (v & (1 << 1)))continue;
			if (i == H - 1 && (v & (1 << 3)))continue;
			if (j == 0 && (v & (1 << 2)))	continue;
			if (j == W - 1 && (v & 1))continue;
			G[i][j] = v;
			if (rec(pos + 1))return true;
		}
	}
	return false;
}
int main() {
	while (1) {
		cin >> W >> H;
		if (H == 0 && W == 0)	break;
		ncell = 0;
//0??¨??????????????????????????????3??????????????§???
rep(i, H)rep(j, W){	cin >> G[i][j];if (!G[i][j])ncell++;G[i][j] = (G[i][j] ? 0 : 1);}
		if (rec(0))cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 3068
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){

    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; ++i){
        cin >> vec[i];
    }

    vector<int> origin = vec;

    if(prev_permutation(vec.begin(), vec.end())){
        for(auto it = vec.begin(); it != vec.end(); ++it){
            if(it != vec.begin()){
                cout << " ";
            }
            cout << *it;
        }
        cout << endl;
    }
    
    for(auto it = origin.begin(); it != origin.end(); ++it){
        if(it != origin.begin()){
            cout << " ";
        }
        cout << *it;
    }
    cout << endl;

    if(next_permutation(origin.begin(), origin.end())){
        for(auto it = origin.begin(); it != origin.end(); ++it){
            if(it != origin.begin()){
                cout << " ";
            }
            cout << *it;
        }
        cout << endl;
    }

    return 0;
}


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


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

ll d[MAXn], x[MAXn], y[MAXn];

set<ii> st;

int main()
{
    IOS();
    ll h,w,n;
    cin>>h>>w>>n;
    REP(i,n)cin>>x[i]>>y[i], d[i] = i;
    sort(d,d+n,[](int a,int b){return ii(y[a], x[a]) < ii(y[b], x[b]);});
    ll mn = h, lw = 0;
    REP(i,n)
    {
        ll t = d[i];
        if(x[t] - 1 - y[t] >= lw && !st.count(ii(x[t] - 1, y[t])))mn = min(mn,x[t]-1);
        st.insert(ii(x[t],y[t]));
        if(x[t] - y[t] == lw)lw++;
    }
    cout<<mn<<endl;
}


Measured memory_bytes: 17408
def main():
    n = int(input())
    hs = list(map(int, input().split()))

    cnt = 0
    hss = [hs[:]]
    while True:
        tmp_sum = 0
        for tmp_hs in hss:
            tmp_sum += sum(tmp_hs)
        if tmp_sum == 0:
            break

        for hs_idx, tmp in enumerate(hss):
            if 0 in tmp:
                idx_0 = tmp.index(0)
                del hss[hs_idx]
                hss.append(tmp[:idx_0])
                hss.append(tmp[idx_0+1:])

        for tmp in hss:
            if not tmp:
                continue
            min_tmp = min(tmp)
            cnt += min_tmp

            for i in range(len(tmp)):
                tmp[i] -= min_tmp


        #print(hss)
    print(cnt)

main()


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			String input = in.nextString();
			String s = new String(input);

			String[] alpha = "abcdefghijklmnopqrstuvwxyz".split("");
			StringBuffer sb = new StringBuffer();
			int ans = INF;
			for (int i = 0; i < 26; i++) {
				int count = 0;
				s = input;
				while (!check(s)) {
					sb = new StringBuffer();
					for (int k = 0; k < s.length() - 1; k++) {
						if (alpha[i].equals(s.substring(k, k+1)) || alpha[i].equals(s.substring(k+1, k+2))) {
							sb.append(alpha[i]);
						} else {
							sb.append(s.substring(k, k+1));
						}
					}
					s = sb.toString();
					count++;
				}
				ans = Math.min(ans, count);
			}

			out.println(ans);

		}

		static boolean check(String s) {
			for (int i = 0; i < s.length() - 1; i++) {
				if (!s.substring(i, i+1).equals(s.substring(i+1, i+2))) {
					return false;
				}
			}
			return true;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 38224
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, int> pli;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const int INF = mod;
const int MAX =200010;

int n, x[1010];
vector<int> G[1010];
bool flag=true;

pii dfs(int v){
    int K=G[v].size();
    pii p[K];
    rep(i, K) p[i]=dfs(G[v][i]);

    int dp[2][x[v]+1];
    rep(i, 2)rep(j, x[v]+1) dp[i][j]=INF;
    dp[0][0]=0;
    rep(i, K){
        rep(j, x[v]+1)if(dp[0][j]<INF){
            if(j+p[i].fi<=x[v]) chmin(dp[1][j+p[i].fi], dp[0][j]+p[i].se);
            if(j+p[i].se<=x[v]) chmin(dp[1][j+p[i].se], dp[0][j]+p[i].fi);
        }
        rep(j, x[v]+1){
            swap(dp[0][j], dp[1][j]);
            dp[1][j]=INF;
        }
    }
    pii ret=pii(x[v], INF);
    rep(j, x[v]+1) chmin(ret.se, dp[0][j]);
    if(ret.se==INF) flag=false;
    return ret;
}

int main(){
    scanf("%d", &n);
    For(i, 1, n){
        int p;
        scanf("%d", &p);
        --p;
        G[p].push_back(i);
    }
    rep(i, n) scanf("%d", &x[i]);
    flag=true;
    dfs(0);
    printf("%s\n", flag ? "POSSIBLE" : "IMPOSSIBLE");
}

Measured memory_bytes: 384
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
const int MAXN = 2e5 + 5;
int a[MAXN],b[MAXN];
map<int,int>vis;
int main()
{
	int n;
	scanf("%d",&n);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		vis[a[i]]++;
	}
	int t = 1;
	sort(a+1,a+n+1);
	b[1] = a[1];
	for(int i = 1; i < n; i++){
		if(a[i] != a[i+1]) b[++t] = a[i+1];
	}
	for(int i = 1; i <= t; i++){
		if(vis[b[i]] % 2 == 1){
			ans++;
		}
 
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 5760
H,W = map(int,input().split())
 
ans = []
 
dp = [ list ( map(int,input().split()) )  for i in range(H)]
 
for i in range(H):
  for j in range(W):
    a = dp[i][j]
    if j != W -1:
      if a %  2 == 1:
        dp[i][j+1] += 1
        ans.append([i+1,j+1,i+1,j+2])
    elif i != H-1:
      if a % 2 == 1:
        dp[i+1][j] += a
        ans.append([i+1,j+1,i+2,j+1])
      
print(len(ans))
for i in range(len(ans)):
  print(ans[i][0],ans[i][1],ans[i][2],ans[i][3])

Measured memory_bytes: 30296
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("Yes")
# define no puts("No")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < ll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    fi>>n;
    int ans = 0;
    for (int i = 1;i <= n;++i)
        {
            int v;
            fi>>v;
            ans ^= v & 1;
        }
    if (!ans)
        puts("YES");
    else
        puts("NO");
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 764
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String ans = "";
      
		for(int i=0; i<S.length(); i++){
			String str = String.valueOf(S.charAt(i));
			if(str.equals("0")){
				ans += "0";
            }else if(str.equals("1")){
				ans += "1";
            }else {
				if(!(ans.isEmpty())){
					ans = ans.substring(0, ans.length()-1);
                }
            }
        }
					
		
		System.out.println(ans);
    }
}


Measured memory_bytes: 38296
#include <bits/stdc++.h>
#define ll        long long
#define endl      "\n"
#define loop(n)   for(int i=0;i<n;i++)

using namespace std;
int main(){
    int n;
    string s,s1;
    cin>>n>>s;
    if(s.size()<=n){cout<<s<<endl;}
    else{loop(n){cout<<s[i];}cout<<"..."<<endl;}
 
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String[] params = in.nextLine().split(" ");
        int n = Integer.parseInt( params[0] );
        int m = Integer.parseInt( params[1] );

        System.out.println( n == m ? "Yes" : "No" );

    }

}


Measured memory_bytes: 21844
n,a = map(int,input().split())
x = list(map(int,input().split()))

x_m = []
x_0 = []
x_p = []
for i in range(n):
    tmp = x[i] - a
    if(tmp < 0):
        x_m.append(tmp * -1)
    elif(tmp == 0):
        x_0.append(tmp)
    else:
        x_p.append(tmp)

len_m = (len(x_m))
len_0 = (len(x_0))
len_p = (len(x_p))

dp_m = [[0] * 1300 for i in range(len_m+1)]
dp_p = [[0] * 1300 for i in range(len_p+1)]

dp_m[0][0] = 1
dp_p[0][0] = 1


for i in range(1,len_m+1):
    for j in range(1300):
        dp_m[i][j] = dp_m[i-1][j]
        if(j >= x_m[i-1]):
            dp_m[i][j] += dp_m[i-1][j-x_m[i-1]]

for i in range(1,len_p+1):
    for j in range(1300):
        dp_p[i][j] = dp_p[i-1][j]
        if(j >= x_p[i-1]):
            dp_p[i][j] += dp_p[i-1][j-x_p[i-1]]

ans = 0
for i in range(0,1300):
    ans += dp_m[-1][i] * dp_p[-1][i]

ans = ans * 2**len_0 -1

print(ans)

Measured memory_bytes: 40048
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i  ;
        //inv[i] = MOD - inv[MOD%i] * (MOD / i)  ;
        //finv[i] = finv[i - 1] * inv[i]  ;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] / fac[k] / fac[n - k]  ;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[400010];
    // 前処理
    //COMinit();
    
    for (int i=0;i<n;i++) {
        cin >> a[i];
    }
    map<int, ll> m;
    for (int i=0;i<n;i++) {
        m[a[i]] = m[a[i]] + 1;
    }
    ll sum = 0;
    for (const auto& x : m) {
        sum += x.second * (x.second-1) / 2;
    }
    for (int i=0; i<n; i++) {
        // if (even[a[i]]){
        //     cout << sum - COM() << "\n";
        // } else {
        //     cout << sum << "\n";
        // }
        // if (m[a[i]] - 1 >= 0) {
            ll res = sum - m[a[i]] * (m[a[i]]-1)/2  + (m[a[i]]-2) * (m[a[i]]-1)/2;
            cout << res << "\n";
        // } else {
        //     cout << sum << "\n";
        // }
        
    }

}


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

int main() {
  
  int N,M;
  cin >> N >> M;

  int ans = 0;
  vector<bool> seen(N,false);
  vector<vector<int>> p(N,vector<int>(0));
  for(int i = 0;i < M;i++) {
    int x,y,z;
    cin >> x >> y >> z;
    --x; --y;
    p[x].push_back(y);
    p[y].push_back(x);
  }

  for(int i = 0;i < N;i++) {
    if(seen[i]) continue;
    queue<int> Q;
    Q.push(i);
    seen[i] = true;
    while(!Q.empty()) {
      int q = Q.front();
      Q.pop();
      seen[q] = true;
      for(int nv:p[q]) {
        if(seen[nv]) continue;
        seen[nv] = true;
        Q.push(nv);
      }
    }
    ans++;
  }

  for(int i = 0;i < N;i++) {
    if(!seen[i]) ans++;
  }

  cout << ans << endl;



}


Measured memory_bytes: 6520
#include <algorithm>
#include <iostream>
#include <vector>
#include <string> 

typedef long long ll;
using namespace std;
const ll m = 1e9 + 7;

int main() {
	string s; cin >> s;
	int res = 0;
	for (int i = 0; i < s.size(); ++i) {
		res += s[i] - '0';
		
	}	
	if (res % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

    return 0;
}

Measured memory_bytes: 3664
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll arr[200200];
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    int tc;
    cin >> n;
    ll maxi = 0;
    ll chaeng = 0;
    for(i=1;i<=n;i++) {
        cin >> arr[i];
        maxi = max(maxi, arr[i]);
        chaeng += maxi-arr[i];
    }
    cout<<chaeng<<endl;
    return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()

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

const long long INF = 1LL << 60;

struct edge {
    int to, cost;
};

vector<edge> G[100000];
vector<bool> visit(100000, false);
vector<int> dist(100000, 0);

bool dfs(int v, int d) {
    if (visit[v]) {
        if (dist[v] != d) {
            return true;
        }
        else {
            return false;
        }
    }
    visit[v] = true;
    dist[v] = d;
    for (int i = 0; i < G[v].size(); i++) {
        edge e = G[v][i];
        if (dfs(e.to, e.cost + dist[v])) {
            return true;
        }
    }

    return false;
}

int main()
{
    int N, M;
    cin >> N >> M;

    rep(i, M) {
        int L, R, D;
        cin >> L >> R >> D;
        L--; R--;
        G[L].push_back({R, D});
        G[R].push_back({L, -D});
    }

    rep(i, N) {
        if (!visit[i] && dfs(i, 0)) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 12032
fun main(args: Array<String>) {
    var (N, W) = pairIntLong()
    val WV = Array(N) { pairIntLong() }
    val WVs = Array(4) { mutableListOf<Long>() }
    val baseW = WV[0].first.toLong()
    WV.forEach { wv -> WVs[wv.first - WV[0].first].add(wv.second) }
    WVs.forEach {
        it.sortDescending()
        it.add(0, 0)
    }
    var ans = 0L
    for (n0 in WVs[0].indices)
    for (n1 in WVs[1].indices)
    for (n2 in WVs[2].indices)
    for (n3 in WVs[3].indices) {
        val w0 = (baseW + 0) * n0
        val w1 = (baseW + 1) * n1
        val w2 = (baseW + 2) * n2
        val w3 = (baseW + 3) * n3
        if (w0 + w1 + w2 + w3 > W) continue
        val v0 = WVs[0].subList(0, n0 + 1).sum()
        val v1 = WVs[1].subList(0, n1 + 1).sum()
        val v2 = WVs[2].subList(0, n2 + 1).sum()
        val v3 = WVs[3].subList(0, n3 + 1).sum()
        ans = Math.max(ans, v0 + v1 + v2 + v3)
    }
    println(ans)
}
fun pairIntLong(offset: Pair<Int, Long> = Pair(0, 0L)) = listOfLong().let { Pair(it[0].toInt() + offset.first, it[1] + offset.second) }

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 43012
#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>;

int main(){
    int n;cin>>n;
    vector<int>a(n+1);rep(i,n+1)cin>>a[i];
    vector<int>b(n);rep(i,n)cin>>b[i];
    ll ans=0;
    rep(i,n+1){
        if(i==0){
            if(a[i]>b[i]){
                ans=b[i];
                 b[i]=0;
            }else{
                ans=a[i];
                b[i]=b[i]-a[i];
            }
            continue;
        }
        if(a[i]>b[i]+b[i-1]){
            ans=ans+b[i]+b[i-1];
            b[i]=0;
        }else{
            ans=ans+a[i];
            if(a[i]<b[i-1]){
            }else{
                b[i]=b[i]-a[i]+b[i-1];
            }
        }
    }

cout<<ans;

}

Measured memory_bytes: 3972
#include<stdio.h>
#include<math.h>
int kock(int n, double p1x, double p1y, double p2x, double p2y) {
    double sx, sy, tx, ty, ux, uy;
    double cos60 = 0.5, sin60 = sqrt(3) / 2;
    if (n == 0) {
        return 0;
    }
    sx = (2 * p1x + p2x) / 3;
    sy = (2 * p1y + p2y) / 3;
    tx = (p1x + 2 * p2x) / 3;
    ty = (p1y + 2 * p2y) / 3;
    ux = (tx - sx) * cos60 - (ty - sy) * sin60 + sx;
    uy = (tx - sx) * sin60 + (ty - sy) * cos60 + sy;
     
    kock(n-1, p1x, p1y, sx, sy);
    printf("%f %f\n", sx, sy);
    kock(n-1, sx, sy, ux, uy);
    printf("%f %f\n", ux, uy);
    kock(n-1, ux, uy, tx, ty);
    printf("%f %f\n", tx, ty);
    kock(n-1, tx, ty, p2x, p2y);
}
 
int main() {
    int n;
    double p1x = 0.0, p1y = 0.0, p2x = 100.0, p2y = 0.0;
    scanf("%d", &n);
    printf("%f %f\n", p1x, p1y);
    kock(n, p1x, p1y, p2x, p2y);
    printf("%f %f\n", p2x, p2y);
    return 0;
}



Measured memory_bytes: 2032
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (arr[i] <= x) {
                count++;
                x -= arr[i];
            }
        }
        if (count == n && x != 0) {
            count--;
        }
       System.out.println(count);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lloop(i, a, b) for(ll i=a;i<(ll)b; i++)
#define loop(i, a, b) for(int i=a;i<b;i++)
#define pool(i, a, b) for(int i=a;i>b;i--)
#define pooll(i, a, b) for(ll i=a;i>b;i--)

#define MOD 1000000007

ll fastpower(ll a, ll b){
    ll res = 1;
    a %= MOD;
    while(b){
        if(b&1) res = (res * a) % MOD;
        a *= a; a %= MOD;
        b >>= 1;
    }
    return res;
}

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	vector<ll> a(k+1);
	pool(i, k, 0){
		ll multiples=k/i;
		multiples=fastpower(multiples, n);
		multiples%=MOD;
		ll temp=0;
		for(int j=2*i;j<=k;j+=i){
			temp=(temp+a[j])%MOD;
		}
		a[i]=(multiples-temp+MOD)%MOD;
	}
	//cout<<a[2]<<endl;
	//a[i] is the number of sequences with GCD of k. So, now, we need the sum of all GCDs. So, i*a[i] gives that sum for all sequences with gcd=i.
	ll ans=0;
	loop(i, 1, k+1){
		ll temp=(a[i]%MOD*i%MOD)%MOD;
		ans=(ans+temp)%MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4048
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<unordered_map>
using namespace std;
#define ll long long
int main() {
	int k, n;
	cin >> n >> k;
	int nums[1010];
	for (int i = 0; i < n; i++) {
		cin >> nums[i];
	}
	sort(nums, nums + n);
	int ans = 0;
	for (int i = 0; i < k; i++)ans += nums[i];
	cout << ans;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	bool r = false;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		r |= s.front() == 'Y';
	}
	cout << (r ? "Four" : "Three") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    char a[101];
    cin>>a;
    int m=0;
    for(int i=0;i<101;i++){
    	if(a[i]==0){
			cout<<"No"<<endl;
    		return 0;
		}
    	if(m==0&&a[i]==67){
    		m++;
    		continue; 
		}
		if(m==1&&a[i]==70){
    		cout<<"Yes"<<endl;
    		return 0;
		}
	}
	
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [str(input()) for _ in range(H)]

ans = [[0 for _ in range(W)] for _ in range(H)]
dx = [-1, 0, 1]
dy = [-1, 0, 1]
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            tmp = 0
            for i in range(3):
                for j in range(3):
                    if h == 0:
                        if dx[i] == -1:
                            continue
                    if h == H-1:
                        if dx[i] == 1:
                            continue
                    if w == 0:
                        if dy[j] == -1:
                            continue
                    if w == W-1:
                        if dy[j] == 1:
                            continue
                    new_x, new_y = h+dx[i], w+dy[j]
                    if S[new_x][new_y] == '#':
                        tmp += 1
            ans[h][w] = str(tmp)
        elif S[h][w] == '#':
            ans[h][w] = '#'

for h in range(H):
    print(''.join(ans[h]))


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}

int main(){
    ll H,W,K;
    cin>>H>>W>>K;
    vector<string> c(H);
    rep(i,0,H)cin>>c[i];
    ll ans = 0;

    rep(i,0,1<<H)rep(j,0,1<<W){
        ll sum = 0;
        rep(x,0,H)rep(y,0,W){
            if((i ^ (1<<x)) < i || (j ^ (1<<y)) < j)continue;
            if(c[x][y] == '#')sum++;
        }
        if(sum == K)ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3628
N = int(input())
S = input()

R = [0] * (N + 1)
G = [0] * (N + 1)
B = [0] * (N + 1)
for i, s in enumerate(S):
    R[i + 1] = R[i] + (s == 'R')
    G[i + 1] = G[i] + (s == 'G')
    B[i + 1] = B[i] + (s == 'B')
ans = 0
for i, s in enumerate(S):
    cnt1 = 0
    for j in range(i):
        if (i + i - j) >= N:
            continue
        t = S[j]
        u = S[i + (i - j)]
        if s != t and t != u and u != s:
            cnt1 += 1
    if s == 'R':
        X = G
        Y = B
    elif s == 'G':
        X = R
        Y = B
    else:
        X = R
        Y = G
    cnt2 = X[i] * (Y[N] - Y[i + 1])
    cnt3 = (X[N] - X[i + 1]) * Y[i]
    ans += (cnt2 + cnt3) - cnt1

print(ans)


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long int n,ans=0,l=1;
    cin>>n;
    vector<string> s(n);
    for(int i=0;i<n;i++)
    {
       cin>>s[i];
       sort(s[i].begin(),s[i].end());
    }
    sort(s.begin(),s.end());
     string check=s[0];
    for(int i=1;i<n;i++)
    {
        if(check==s[i]) l++;
        else
        {
            ans+=l*(l-1)/2;
            check=s[i];
            l=1;
        }
    }
    ans+=l*(l-1)/2;
    cout<<ans<<endl;

    return 0;

}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const double INF=1000000000000000.0;

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

int main(){
	//input
	ll N; cin>>N;
	vector<ll> t(N);
	rep(i,N) cin>>t[i];
	vector<ll> v(N);
	rep(i,N) cin>>v[i];

	vector<P> A(N+1);
	A[0]=P(0,0);
	ll tmpt=0;
	rep(i,N){
		tmpt+=t[i];
		A[i+1]=P(tmpt,v[i]);
	}
	vector<pair<ll,P>> B(N+1);
	rep(i,N){
		if(A[i+1].b>A[i].b) B[i]=mp(A[i].a,P(1ll,A[i].b-A[i].a));
		else B[i]=mp(A[i].a,P(-1ll,A[i].a+A[i+1].b));
	}
	B[N]=mp(A[N].a,P(-1ll,A[N].a));

	/*
	rep(i,N+1){
		printf("A[%lld].a=%lld A[%lld].b=%lld\n",i,A[i].a,i,A[i].b);
	}
	cout<<endl;
	rep(i,N+1){
		printf("B[%lld].a=%lld B[%lld].b.a=%lld B[%lld].b.b=%lld\n",i,B[i].a,i,B[i].b.a,i,B[i].b.b);
	}
	*/

	double tmp,ans=0;

	for(double i=0.0;i<=(double)tmpt;i+=0.5){
		double maxV=INF;
		rep(j,N+1){ //B(条件)をすべて見る
			if(B[j].b.a==1){
				if(i>=B[j].a){ //B[j]の条件適用
					chmin(maxV,i*B[j].b.a+B[j].b.b);
				}
			}
			else{
				if(i<=B[j].a){
					chmin(maxV,i*B[j].b.a+B[j].b.b);
				}
			}
		}

		ll sub=0;
		while(sub<=N){
			if((double)A[sub].a>=i) break;
			sub++;
		}
		chmin(maxV,(double)A[sub].b);

		//cout<<i<<":"<<sub<<endl;
		//printf("i:%.1f maxV:%.12f\n",i,maxV);

		if(i==0) tmp=maxV;
		else{
			ans+=(maxV+tmp)*0.25;
			tmp=maxV;
		}
	}

	printf("%.10f",ans);
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(int[]);

    auto ps = new int[](10^^6+1);
    foreach (a; AS) {
        for (int i = 2; i^^2 <= a; ++i) {
            if (a%i == 0) {
                ps[i] += 1;
                while (a%i == 0) a /= i;
            }
        }
        if (a != 1) ps[a] += 1;
    }

    auto pc = true;
    foreach (p; ps) {
        if (p == N) {
            writeln("not coprime");
            return;
        } else if (p > 1) {
            pc = false;
        }
    }
    writeln(pc ? "pairwise coprime" : "setwise coprime");
}

Measured memory_bytes: 45588
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll K;
    ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cin >> K;

    cout << a[K-1] << endl;

    return 0;
}

Measured memory_bytes: 256
N, L = map(int,input().split())
real_sum = L*N + int(1/2*N*(N-1))
ans = 0

if L >= 0:
    ans = real_sum - L
elif L <= -N:
    ans = real_sum - (L + N - 1)
else:
    ans = real_sum

print(ans)

Measured memory_bytes: 3060
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

typedef pair<int, int> pos;

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> s(H);
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}
	queue<pos> q;	//cur
	vector<vector<int>> vis(H, vector<int>(W, -1));
	vis[0][0] = 0;
	q.push(pos(0, 0));
	int ans = -1;
	while (!q.empty()) {
		pos cur = q.front(); q.pop();
		int n = vis[cur.first][cur.second];
		n++;
		if (cur == pos(H-1, W-1)) {
			ans = n;
			break;
		}
		static int dx[4] = { 1,0,-1,0 };
		static int dy[4] = { 0,1,0,-1 };
		for (int i = 0; i < 4; i++) {
			int x = cur.first + dx[i];
			int y = cur.second + dy[i];
			if (x >= 0 && y >= 0 && x < H && y < W && vis[x][y] < 0 && s[x][y] == '.') {
				vis[x][y] = n;
				q.push(pos(x, y));
			}
		}
	}
	if (ans < 0) {
		;
	} else {
		int white = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (s[i][j] == '.')
					white++;
			}
		}
		ans = white - ans;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){

	int hairetsu[3],temp;

	cin >> hairetsu[0] >> hairetsu[1] >> hairetsu[2];


	for(int i=0;i<2;i++)
	{
		for(int i=0;i<2;i++)
			{
			if(hairetsu[i] < hairetsu[i+1])
				{
				}else{
				temp = hairetsu[i] ;
				hairetsu[i] = hairetsu[i+1] ;
				hairetsu[i+1] = temp ;
				}
			}
	}


	cout<< hairetsu[0] << " " << hairetsu[1] << " " << hairetsu[2] << endl;


	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, i, j, k, ans, even, odd;

	cin >> n;
	even = n / 2;
	odd = n - even;
	ans = even * odd;
	cout << ans << "\n";

	return 0;
}


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

using namespace std;
long long x[10000010], y[10000010];
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lep(j, n) for (int j = 0; j < (n); j++)
#define reps(i, n) for (int i = 1; i < (n); i++)
#define leps(i, n) for (int j = 1; j < (n); j++)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define int long long
#define gsort(x, n) sort((x), (x) + (n), greater<int>());
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

signed main()
{

   cin.tie(0);
   ios::sync_with_stdio(false);

   int h, w;
   cin >> h >> w;
   string s;
   int a, b;

   rep(i, h)
   {
      rep(j, w)
      {
         cin >> s;
         if (s == "snuke")
         {
            cout << char('A' + j) << i + 1 << '\n';
            return 0;
         }
      }
   }
   return 0;
}

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

int main() {
	int n, m, x_c, y_c;
	cin >> n >> m >> x_c >> y_c;

	int x[n];
	int y[m];
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int  i = 0; i < m; i++) {
		cin >> y[i];
	}

	string ans = "War";
	if (x_c < y_c) {
		sort(x, x+n);
		sort(y, y+m);
		if (x[n-1] < y[0] && x[n-1] < y_c && x_c < y[0]) {
			ans = "No War";
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public string via { get; set; }
    public int to { get; set; }
    public int L { get; set; }
}

public class Node
{
    public List<int> to { get; set; }
    public List<int> toc { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            int n, m;
            var p = 0;
            while (!int.TryParse(line[p++], out n)) ;
            while (!int.TryParse(line[p++], out m)) ;
            if (n == 0 && m == 0) break;
            var nodes = new Node[n];
            for (int i = 0; i < n; i++)
                nodes[i] = new Node { to = new List<int>(), toc = new List<int>() };
            for (int i = 0; i < m; i++)
            {
                p = 0;
                int a, b, c;
                line = Console.ReadLine().Trim().Split(' ');
                while (!int.TryParse(line[p++], out a)) ;
                while (!int.TryParse(line[p++], out b)) ;
                while (!int.TryParse(line[p++], out c)) ;
                nodes[a - 1].to.Add(b - 1);
                nodes[a - 1].toc.Add(c);
                nodes[b - 1].to.Add(a - 1);
                nodes[b - 1].toc.Add(c);
            }
            getAns(nodes, n);
        }
    }
    static void getAns(Node[] nodes, int n)
    {
        var maxL = 0;
        var ans = new List<string>();
        var q = new Queue<P>();
        var p = 0;
        foreach (var x in nodes)
        {
            for (int i = 0; i < x.to.Count(); i++)
                q.Enqueue(new P { via = p.ToString() + x.to[i].ToString(), L = x.toc[i], to = x.to[i] });
            p++;
        }
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            var wn = nodes[w.to];
            var find = false;
            for (int i = 0; i < wn.to.Count(); i++)
            {
                var t = wn.to[i];
                var ts = t.ToString();
                var tt0 = w.to.ToString() + ts;
                var tt1 = ts + w.to.ToString();
                if (!w.via.Contains(tt0) && !w.via.Contains(tt1))
                {
                    q.Enqueue(new P { via = w.via + ts, L = w.L + wn.toc[i], to = t });
                    find = true;
                }
            }
            if (!find)
            {
                if (w.L == maxL) ans.Add(w.via);
                else if (w.L > maxL) { ans.Clear(); ans.Add(w.via); maxL = w.L; }
            }
        }
        Console.WriteLine(maxL);
        putAns(ans);
    }
    static void putAns(List<string> ans)
    {
        ans.Sort();
        var t = ans[0];
        var t1 = new int[t.Length];
        for (int i = 0; i < t.Length; i++)
            t1[i] = int.Parse(t[i].ToString()) + 1;
        Console.WriteLine(string.Join(" ", t1));
    }
}


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

int main()
{
    string s;
    cin>>s;
    int counter=0;
    for(int i=s.size()-1;i>0;i--)
    {
        if(i-1>=0&&s[i]!=s[i-1])counter++;
    }
    cout<<counter<<endl;
}


Measured memory_bytes: 512
#!/usr/bin/env python3

import itertools

def li_753():
    li = ["0", "7", "5", "3"]
    com = list(itertools.product(li, repeat=9))
    res = []
    for c in com:
        s = "".join(c)
        x = int(s)
        if "3" in s and "5" in s and "7" in s and "0" not in str(x):
            res.append(x)
    return res

def main():
    n = int(input())
    com = li_753()
    com = [x for x in com if x <= n]
    print(len(com))

main()


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

const unsigned long long int inf=1e18;


bool isprime(ll a)
{
	
	ll cnt=0;	
	for(ll i=1;i*i<a;i++)
	{
		
	 	if(a%i==0)
	 	{
	 		cnt+=2;
		 }
		
		
	}
	
		if(cnt==2)
		return true;
		else
		return false;
		
}
void solve()
{

ll n,num;
cin>>n;
map<ll,ll>m;
num=n;
for(ll i=2;i*i<n;i++)
{
	
	while(n%i==0)
	{
		n/=i;
		m[i]++;
		
	}
	
}



ll x=0,ans=0;
if(isprime(n))ans++;
for(auto i:m)
{	x=0;
 //cout<<i.first<<" "<<i.second<<"\n";
	for(ll j=1;;j++)
	{
		x+=j;
		
		if(x>i.second)
		break;
		else
		ans++;
		
		
	}
	
	
	
	
}

cout<<ans;

}


int main()
{


ios::sync_with_stdio(0); 
	cin.tie(0);


		solve();
	
return 0;

		
	}
	
	
	


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

int compare(const void *a, const void *b){
	long long int *A = (long long int *)a;
	long long int *B = (long long int *)b;
	if (*A > *B) return 1;
	if (*A < *B) return -1;
	return 0;
}

long long max(long long x,long long y){
	if(x>y)return x;
	return y;
}

long long ab(long long x){
	if(x<0)return -x;
	return x;
}

int solve(long long *h,long long mid,long long A,long long B,long long N){
	long long c=0;
	for(int i=0;i<N;i++){
		if(h[i]>B*mid)c+=(h[i]-B*mid+A-1)/A;
	}
	if(c<=mid)return 1;
	else return 0;
}

int main(){
	long long N,A,B,sum=0,i;
	scanf("%lld%lld%lld",&N,&A,&B);
	long long h[N];
	for(i=0;i<N;i++){
		scanf("%lld",&h[i]);
		sum+=h[i];
	}
	qsort(h,N,sizeof(long long),compare);
	
	A-=B;
	
	long long ok=h[N-1]/B+1;
	long long ng=(sum+A+B*N-1)/(A+B*N)-1;
	
	while(ab(ok-ng)>1){
		long long mid=(ok+ng)/2;
		long long c=0;
		for(int i=0;i<N;i++)if(h[i]>B*mid)c+=(h[i]-B*mid+A-1)/A;
		if(c<=mid)ok=mid;
		else ng=mid;
	}
	printf("%lld\n",ok);
	return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string::const_iterator State;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int number(State &begin);
int term(State &begin);
int expression(State &begin);
int factor(State &begin);

bool isdigit(char in) {
    if((in <= '9') && (in >= '0')) return true;
    else return false;
}

int number(State &begin) {
    int ret = 0;
    while(isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

int term(State &begin) {
    int ret = factor(begin);
    for(;;) {
        if(*begin == '*'){
            begin++;
            ret *= factor(begin);
            continue;
        }
        if(*begin == '/'){
            begin++;
            ret /= factor(begin);
            continue;
        }
        break;
    }
    return ret;
}

int expression(State &begin) {
    int ret = term(begin);
    for(;;) {
        if(*begin == '+'){
            begin++;
            ret += term(begin);
            continue;
        }
        if(*begin == '-'){
            begin++;
            ret -= term(begin);
            continue;
        }
        break;
    }
    return ret;
}

int factor(State &begin) {
    int ret;
    if(*begin == '(') {
        begin++;
        ret = expression(begin);
        begin++;
    } else {
        ret = number(begin);
    }
    return ret;
}
int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    cin.ignore();
    while(n--){
        string s;
        getline(cin, s);
        State begin = s.begin();
        int ans = expression(begin);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3156
n = gets.to_i
m = gets.to_i

cards = [*1..(2*n)]

m.times do
    k = gets.to_i
    if k==0 then
        tmp = cards.dup
        n.times do |i|
            tmp[i*2+1,0] = cards[n+i]
        end
        cards = tmp[0..(2*n-1)]
    else
        tmp = cards.dup
        tmp[0,0] = cards[k..-1]
        cards = tmp[0..(2*n-1)]
    end
end

#p cards
cards.each do |x| puts x end

Measured memory_bytes: 5004
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [i*-1 for i in a]
heapq.heapify(a)
for i in range(m):
    x = ((-1) * heapq.heappop(a)) //2
    heapq.heappush(a, -x)
print(-sum(a))

Measured memory_bytes: 20200
#include "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

bool isAbove(pair<double, double> p1, pair<double, double> p2, pair<double, double> p3) {
	if (p1.first == p2.first) {
		return p3.first > p1.first;
	} else {
		return p3.second > p1.second + (p2.second - p1.second) * (p3.first - p1.first) / (p2.first - p1.first);
	}
}

void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif

	vector<pair<double, double>> vertices(4);
	while (cin >> vertices[0].first) {
		cin >> vertices[0].second;
		rep(i, 3) cin >> vertices[i + 1].first >> vertices[i + 1].second;

		bool flag = (isAbove(vertices[0], vertices[1], vertices[2]) == isAbove(vertices[0], vertices[1], vertices[3]));
		flag &= (isAbove(vertices[0], vertices[2], vertices[1]) == isAbove(vertices[0], vertices[2], vertices[3]));
		flag &= (isAbove(vertices[1], vertices[2], vertices[0]) == isAbove(vertices[1], vertices[2], vertices[3]));

		cout << (flag ? "YES" : "NO") << endl;
	}


}




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


	solve();
	return 0;
}

Measured memory_bytes: 3216
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1)(n(2).readFileSync("/dev/stdin","UTF-8"))},function(e,t){e.exports=function(e){var t=e.split("\n"),n=Number(t[0]);console.log(3*n*n)}},function(e,t){e.exports=require("fs")}]);

Measured memory_bytes: 7372