akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int count = (n - 2) * (n - 1) / 2 - k;
		if (count < 0) {
			System.out.println(-1);
			return;
		}
		StringBuilder sb = new StringBuilder();
		sb.append(n - 1 + count).append("\n");
		for (int i = 2; i <= n; i++) {
			sb.append(1).append(" ").append(i).append("\n");
		}
		for (int i = 2; i < n && count > 0; i++) {
			for (int j = i + 1; j <= n && count > 0; j++) {
				sb.append(i).append(" ").append(j).append("\n");
				count--;
			}
		}
		System.out.print(sb);
	}
}


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

cnt = 0

if a[0] > x:
    cnt += a[0] - x
    a[0] = x

for i in range(n - 1):
    if a[i] + a[i + 1] <= x:
        continue
    rem = x - a[i]
    eat = a[i + 1] - rem
    cnt += eat
    a[i + 1] = rem

print(cnt)


Measured memory_bytes: 14052
#include <iostream>

using namespace std;

int main() {
 int x, y;

 cin >> x >> y;

 while(x != 0 || y != 0) {
  if(x < y) 
   cout << x << " " << y << endl;
  else
   cout << y << " " << x << endl;
  
  cin >> x >> y;
 } 

 return 0;
}

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

int main(){
    char sucu,nafmo,eiya,fal,hewla,bwam,keidaroo,moko,euglena;
    cin >> sucu >> nafmo >> eiya >> fal >> hewla >> bwam >> keidaroo >>moko >>euglena;
    cout << sucu << hewla << euglena << endl;
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;

#define error(args...) {} //{ vector<string> _debug = split(#args, ',');err(begin(_debug), args);}

vector<string> split(const string& s, char c){
	vector<string> v;stringstream ss(s);string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {cerr << endl;}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a,Args... args){
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << " ",err(++it, args...);
}
// Problem Specific Parameter:

const int limit = 100010;
int L[limit],R[limit];

using pii = pair<int,int>;

int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> L[i] >> R[i];

	vector<pii> lft,rht;

	rep(i,n){
		lft.push_back(pii(R[i],i));
		rht.push_back(pii(L[i],i));
	}

	sort(begin(lft),end(lft));
	sort(rbegin(rht),rend(rht));

	ll ans = 0LL;

	{	
		ll cur = 0LL,pos = 0LL;
		ll lb = 0LL ,rb = 0LL;
		vector<int> used(n,0);
		int i = 0, j = 0;

		while(i < n or j < n){
			while(i < n and used[lft[i].second] == true) i++;
			if(pos <= lft[i].first) break;

			if(i < n){
				error(i,lft[i].second);
				cur += abs(lft[i].first - pos);
				pos = lft[i].first;
				rb = pos;
				used[lft[i].second] = true;
			}

			while(j < n and used[rht[j].second] == true) j++;
			if(rht[j].first <= pos) break;


			if(j < n){
				error(j,rht[j].second);
				cur += abs(rht[j].first - pos);
				pos = rht[j].first;
				lb = pos;
				used[rht[j].second] = true;
			}
		}

		cur += abs(pos);

		chmax(ans,cur);
	}

	{	
		ll cur = 0LL,pos = 0LL;
		ll lb = 0LL ,rb = 0LL;
		vector<int> used(n,0);
		int i = 0, j = 0;

		while(i < n or j < n){
			while(j < n and used[rht[j].second] == true) j++;
			if(rht[j].first <= pos) break;

			if(j < n){
				error(j,rht[j].second);
				cur += abs(rht[j].first - pos);
				pos = rht[j].first;
				lb = pos;
				used[rht[j].second] = true;
			}

			while(i < n and used[lft[i].second] == true) i++;
			if(pos <= lft[i].first) break;

			if(i < n){
				error(i,lft[i].second);
				cur += abs(lft[i].first - pos);
				pos = lft[i].first;
				rb = pos;
				used[lft[i].second] = true;
			}
		}

		cur += abs(pos);

		chmax(ans,cur);

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2924
//Apparat : drobucs, aleonov, vit_72
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iomanip>
#include <algorithm>
#include <string>
#include <queue>
#include <numeric>

//#pragma warning(disable : 4996)
//#pragma GCC optimize("O3")

using namespace std;

#define nptr nullptr
#define all(x) (x).begin(), (x).end()
#define drobucs ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)(x).size()

typedef  long long ll;

const int maxn = (int)1e5 + 13;
const ll INFL = 9223372036854775807;
const ll INF = 2147483647;
const ll MOD = (int)1e9 + 7, MOD2 = 998244353;//1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll base = 101, base2 = 37;

ll a[maxn];
int main() {
	drobucs;
	
	ll n;
	cin >> n;
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		a[x]++;
		sum += x;
	}
	ll q;
	cin >> q;

	for (int i = 0; i < q; ++i) {
		int x, y;
		cin >> x >> y;
		sum += a[x] * y;
		sum -= a[x] * x;
		a[y] += a[x];
		a[x] = 0;
		cout << sum << "\n";
	}

	return 0;
}

Measured memory_bytes: 4448
def main():
        N, M = map(int, input().split())
        A = list(map(int, input().split()))

        ans = False
        total = 0

        A_sum = sum(A)
        threshold = A_sum/4/M

        for i in range(N):
                if A[i]>=threshold:
                        total += 1
                if total==M:
                        ans = True
                        break

        if ans:
                print("Yes")
        else:
                print("No")


if __name__=="__main__":
        main()

Measured memory_bytes: 9208
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

string find(string a, string b)
{
	int n = a.length();
	for(int i = 0; i<a.length(); i++)
	{
		int t = i-1;
		if(i==0)
			t = n-1;
		int g = i+1;
		if(i==n-1)
			g = 0;
		if(a[i]=='o')
		{
			if(b[i]=='S' && b[t]=='S')
				continue;
			else if(b[i]=='S' && b[t]=='W')
				b[g]='W';
			else if(b[i]=='W' && b[t]=='S')
				b[g]='W';
			else
				continue;
		}
		else
		{
			if(b[i]=='S' && b[t]=='S')
				b[g]='W';
			else if(b[i]=='S' && b[t]=='W')
				b[g]='S';
			else if(b[i]=='W' && b[t]=='S')
				b[g]='S';
			else
				b[g]='W';
		}
	}
	return b;
}

bool check(string s, string s2)
{
	bool flag = 1;
	int n= s.length();
	for(int i = 0; i<n; i++)
	{
		int t = i-1;
		if(i==0)
			t = n-1;
		int g = i+1;
		if(i==n-1)
			g = 0;
		if(s[i]=='x' && ((s2[i]=='W' && s2[t]!=s2[g]) || (s2[i]=='S' && s2[t]==s2[g]) ))
			flag = 0;
		else if(s[i]=='o' && ((s2[i]=='W' && s2[t]==s2[g]) || (s2[i]=='S' && s2[t]!=s2[g]) ))
			flag = 0;
	}
	return flag;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	string s;
	cin>>s;
	string s2(n,'S');
	int flag = 0;
	string g = find(s,s2),j="";
	if(check(s,g))
	{
		j = g;
		flag = 1;
	}
	g = s2;
	g[n-1]='W';
	g = find(s,g);
	if(check(s,g))
	{
		j = g;
		flag = 1;
	}
	g = s2; g[0]='W'; g = find(s,g);
	if(check(s,g))
	{
		j = g;
		flag = 1;
	}
	g = s2; g[n-1]=g[0]='W'; g= find(s,g);
	if(check(s,g))
	{
		j = g;
		flag = 1;
	}
	if(flag)
		cout<<j<<endl;
	else
		cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 960
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        
        int n = in.nextInt();
        int k = in.nextInt();
        int[] list = new int[n];
        for (int i = 0; i < n; i++) list[i] = in.nextInt();
        
        int curGCD = list[0];
        int max = list[0];
        for (int i = 1; i < n; i++) {
            curGCD = gcd(curGCD, list[i], 1);
            max = Math.max(max, list[i]);
        }
        
        if (max >= k && (max - k) % curGCD == 0) {
            System.out.println("POSSIBLE");
        } else System.out.println("IMPOSSIBLE");
    }
    
    static int gcd(int a, int b, int i) {
            if (a == b) {
                return a;
            } else if (a % 2 == 0 && b % 2 == 0) {
                return gcd(a / 2, b / 2, i * 2);
            } else if (a % 2 == 0) {
                return gcd(a / 2, b, i);
            } else if (b % 2 == 0) {
                return gcd(a, b / 2, i);
            } else if (a > b) {
                return gcd(a - b, b, i);
            } else return gcd(a, b - a, i);
        
    }
    

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 34668
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] x = new int[n];
		
		int sum = 0;
		
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			sum += Math.min(x[i],  k - x[i]) * 2;
		}
		
		System.out.println(sum);

	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define MAXN 200200
#define ll long long
using namespace std;


int main(){
    ll n,a,b;

    cin>>n>>a>>b;

    ll q = n/(a+b);

    ll res = a*q + min(a, n%(a+b));

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

import queue

def dfs(node, edge, vis):
    vis[node] = True
    count = 1
    vq = []
    vq.append(node)
    vq = queue.LifoQueue()
    vq.put(node)
    while not vq.empty():
        fnode = vq.get()
        for b in edge[fnode]:
            if not vis[b]:
                count += 1
                vq.put(b)
                vis[b] = True
    return count

n, m = [int(i) for i in input().split(' ')]

edge = [[] for i in range(n)]

for _ in range(m):
    a, b = [int(i) for i in input().split(' ')]
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

vis = [False]*n

count = 0

for i in range(n):
    if not vis[i]:
        count = max(count, dfs(i, edge, vis))

print(count)


Measured memory_bytes: 111504
#include <bits/stdc++.h>
using namespace std;
#define pr(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod

void solve() {
        int n; cin >> n;
        set<int> st;
        for (int i= 0; i< n; i++) {
                int x; cin>> x;
                st.insert(x);
        }
        if (n== st.size()) {
                cout << "YES";
        } else cout << "NO";

}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int T= 1;
        //cin >> T;
        while ( T-- ) {
                solve();
        }
return 0;
}


Measured memory_bytes: 12928
#include <stdio.h>

int main(void){
	int n;
	int temp,cnt;
	scanf("%d",&n);
	int i,j,k;
	int decimal;
	int binary = 0;
	int base = 1;
	int max=-1e9;
	int f[n][10],p[n][11];
	for(i=0;i<n;i++){
		for(j=0;j<10;j++){
			scanf("%d",&f[i][j]);
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<=10;j++){
			scanf("%d",&p[i][j]);
		}
	}
	int a[10];
	
	temp=0;
	void func(int k){
		decimal = k;
		binary = 0;
		base = 1;
		while(decimal>0){
			binary = binary + ( decimal % 2 ) * base;
			decimal = decimal / 2;
			base = base * 10;
		}
		//binaryに2進数表記のkが入る
		//あとはそれを添え字に対応付ける
		i = 0;
		//printf("%d\n",binary);
		for(j=0;j<10;j++){
			int dig = binary%10;
			a[j]=dig;
			binary /=10;
		}
	}
	for(k=1;k<=1024;k++){
		//kの値に応じてa[0]~a[9]まで0と1を入れたい
		func(k);
		temp=0;
		for(i=0;i<n;i++){
			cnt = 0;
			for(j=0;j<10;j++){
				if(f[i][j]==a[j]&&a[j]==1){
					cnt++;
				}
			}
			temp += p[i][cnt];
		}
		if(max<temp)max=temp;
	}
	printf("%d",max);
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll inf = 1e9;



int main() {
	int N, M, s, g1, g2;
	while ( cin >> N >> M >> s >> g1 >> g2, N || M || s || g1 || g2 ) {
		--s, --g1, --g2;
		ll cost[100][100]; fill(cost[0], cost[100], inf);
		for (int i = 0; i < N; ++i) cost[i][i] = 0;
		for (int i = 0; i < M; ++i) {
			int a, b, c; cin >> a >> b >> c; --a, --b;
			cost[a][b] = c;
		}
		for (int k = 0; k < N; ++k) {
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < N; ++j) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		ll ans = inf;
		for (int i = 0; i < N; ++i) {
			ans = min(ans, cost[s][i] + cost[i][g1] + cost[i][g2]);
		}
		cout << ans << endl;
	}
}

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


int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i = 0; i < N; i++){
  	cin >> S.at(i);
  }
  int NAC, NWA, NTLE, NRE;
  NAC = 0;
  NWA = 0;
  NTLE = 0;
  NRE = 0;
  for(int i = 0; i < N; i++){
  	if(S.at(i) == "AC"){
    	NAC += 1;
    }
    if(S.at(i) == "WA"){
    	NWA += 1;
    }
    if(S.at(i) == "TLE"){
    	NTLE += 1;
    }
    if(S.at(i) == "RE"){
    	NRE += 1;
    }
  }
  cout << "AC x " << NAC << endl;
  cout << "WA x " << NWA << endl;
  cout << "TLE x " << NTLE << endl;
  cout << "RE x " << NRE << endl;
}

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

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
	int K=int.Parse(Console.ReadLine());
    string S=Console.ReadLine();
   if(S.Length<=K){
     Console.WriteLine(S);
   }else{
    Console.WriteLine (S.Substring(0,K)+"...");
   }
    }
    
  }

}

Measured memory_bytes: 27496
n, x = map(int, input().split())

if n == 0:
    print(0)
else:
    li = list(map(int,input().split()))
    if x == 0:
        print(1)

    else:

        sum1 = 0
        v = 1

        for l in li:
            sum1 += l
            if sum1 > x:
                break
            v += 1


        print(v)



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

#define long long long int
using namespace std;

// @author: pashka

vector<int> tree;
int size;

void init(int n) {
    size = 1;
    while (size < n) size *= 2;
    tree.resize(2 * size);
}

void put(int i, int v, int x, int lx, int rx) {
    if (rx == lx + 1) {
        tree[x] = (1 << v);
        return;
    }
    int m = (lx + rx) / 2;
    if (i < m) {
        put(i, v, 2 * x + 1, lx, m);
    } else {
        put(i, v, 2 * x + 2, m, rx);
    }
    tree[x] = tree[2 * x + 1] | tree[2 * x + 2];
}

int sum(int l, int r, int x, int lx, int rx) {
    if (l >= rx || lx >= r)
        return 0;
    if (lx >= l && rx <= r)
        return tree[x];
    int m = (lx + rx) / 2;
    return sum(l, r, 2 * x + 1, lx, m) |
           sum(l, r, 2 * x + 2, m, rx);
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string s;
    cin >> s;

    init(n);

    for (int i = 0; i < n; i++) {
        put(i, (s[i] - 'a'), 0, 0, size);
    }

    int q;
    cin >> q;
    for (int tt = 0; tt < q; tt++) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;
            string s;
            cin >> i >> s;
            i--;
            put(i, (s[0] - 'a'), 0, 0, size);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            cout << __builtin_popcount(sum(l, r, 0, 0, size)) << "\n";
        }

    }

    return 0;
}

Measured memory_bytes: 5020
n = int(input())
s = input()
l = 0
r = 0
for i in range(n):
  if s[i] == "(":
    l += 1
  else:
    if l > 0:
      l -= 1
    else:
      r += 1
    
    

s = "".join(["("]*r+list(s)+[")"]*l)
  
print(s)


Measured memory_bytes: 3060
/**
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 2019-12-01 20:49:23
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

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

  int x; cin >> x;

  int d = x / 100;
  int m = x % 100;

  //debug(d); debug(m);

  if (d * 5 >= m) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long res = 0;

        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        int max = a[0];
        for(int i=1; i<n; i++) {
            if(max > a[i]) {
                res += max-a[i];
            }
            max = Math.max(max, a[i]);
        }
        System.out.println(res);


    }


}

Measured memory_bytes: 59720
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e5+10;
const int P=1e9+7;
int n,m,k,a[N],l[N],dp[110][N];
map<int,int> b; 

int main()
{
	cin>>n>>k;
	for (int x=1,gx;x<=n;x=gx+1) {
		gx=n/x ? min(n/(n/x),n) : n;
		a[++m]=gx; l[m]=gx-x+1;
		b[gx]=m;
	}
	for (int j=0;j<=m;j++) dp[0][j]=1;
	for (int i=1;i<=k;i++) {
		for (int j=1;j<=m;j++) {
			dp[i][j]=(dp[i][j-1]+(LL)l[j]*dp[i-1][b[n/a[j]]]%P)%P;
		}
	}
	cout<<dp[k][m]<<endl;
	return 0;
}

Measured memory_bytes: 45952
from collections import Counter
N, P = map(int, input().split())
S = input()

def largeSol():
    T = [0] * (N + 1)
    for i, s in enumerate(map(int, S[:: -1])):
        T[i + 1] = (s * pow(10, i, P) + T[i]) % P

    ans = 0
    cnt = Counter(T[1:])
    for p in range(P):
        x = cnt[p]
        ans += x * (x - 1) // 2
    ans += cnt[0]
    return ans

def smallSol():
    dp = [0] * P
    ans = 0
    for s in map(int, S):
        newDp = [0] * P
        newDp[s % P] += 1
        for p in range(P):
            newDp[(p * 10 + s) % P] += dp[p]
        dp = newDp
        ans += dp[0]
    return ans

print(smallSol() if N * P <= 10**7 else largeSol())


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

ll n;

int dfs(ll x, int a, int b, int c) {
    if(x > n) return 0;
    int ans = 0;
    if(a == 0 || b == 0 || c == 0) ans = 0;
    else ans += 1;
    ans += dfs(x*10+7, a+1, b, c);
    ans += dfs(x*10+5, a, b+1, c);
    ans += dfs(x*10+3, a, b, c+1);
    return ans;
}

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

    cin >> n;

    cout << dfs(0,0,0,0) << endl;
    return 0;
}

Measured memory_bytes: 3644
package main

import (
	"fmt"
	"math"
	"sort"
)

type Num struct {
	value  int
	factor map[int]int
}

func NewNum(i int) *Num {
	num := &Num{}
	num.value = i
	num.factor = make(map[int]int)
	//	num.primeFactors()
	return num
}

func calcGCD(a, b int) int {
	if b == 0 {
		return a
	} else {
		return calcGCD(b, a%b)
	}
}

func (n *Num) primeFactors() {
	num := n.value
	i := 2
	for i*i <= num {
		if num%i == 0 {
			num /= i
			n.factor[i] += 1
		} else {
			i += 1
		}
	}
	if num != 1 {
		n.factor[num] += 1
	}
}

func getMin(divisor []int, length int) (min, nextMin int) {
	switch {
	case len(divisor) <= length-2:
		min = 0
		nextMin = 0
	case len(divisor) == length-1:
		sort.Ints(divisor)
		min = 0
		nextMin = divisor[0]
	default:
		sort.Ints(divisor)
		min = divisor[0]
		nextMin = divisor[1]
	}
	return min, nextMin
}

func getGCD(A []*Num) int {
	factors := make(map[int][]int)
	for _, a := range A {
		for value, count := range a.factor {
			if _, ok := factors[value]; !ok {
				factors[value] = make([]int, 0, 0)
			}
			factors[value] = append(factors[value], count)
		}
	}
	max := 0.0
	gcd := 1
	for value, factor := range factors {
		min, nextMin := getMin(factor, len(A))
		gcd *= int(math.Pow(float64(value), float64(min)))
		tmpMax := math.Pow(float64(value), float64(nextMin-min))
		if max < tmpMax {
			max = tmpMax
		}
	}
	return gcd * int(max)
}

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]*Num, 0, N)
	var input int
	for i := 0; i < N; i++ {
		fmt.Scan(&input)
		A = append(A, NewNum(input))
	}
	max := 0
	var gcd int
	cacheGCDFromStart := make([]int, 0, N)
	cacheGCDFromEnd := make([]int, 0, N)
	gcd = A[0].value
	cacheGCDFromStart = append(cacheGCDFromStart, gcd)
	for i := 1; i < N; i++ {
		gcd = calcGCD(gcd, A[i].value)
		cacheGCDFromStart = append(cacheGCDFromStart, gcd)
	}

	gcd = A[N-1].value
	for i := N - 1; i >= 0; i-- {
		gcd = calcGCD(gcd, A[i].value)
		cacheGCDFromEnd = append(cacheGCDFromEnd, gcd)
	}
	max = cacheGCDFromEnd[N-2]
	if max < cacheGCDFromStart[N-2] {
		max = cacheGCDFromStart[N-2]
	}
	/*
		fmt.Println(cacheGCDFromStart)
		fmt.Println(cacheGCDFromEnd)
	*/

	for i := 1; i < N-1; i++ {
		gcd = calcGCD(cacheGCDFromStart[i-1], cacheGCDFromEnd[N-2-i])
		if max < gcd {
			max = gcd
		}
	}
	fmt.Println(max)

}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;

int f(int x){
  if(x < 0){x *= (-1);}
  return x;
}

int main(){
  ll n, y; cin >> n >> y;
  ll a, b, c;
  a = -1; b = -1; c = -1;
  bool f = false;
  for(ll i = 0; i <= n; i++){
    for(ll j = 0; j <= n-i; j++){
      if(y - (10000LL * i + 5000LL * j) == (n-i-j) * 1000LL){
        a = i, b = j, c = n - i - j;
        f = true;
        break;
        }
    }
    if(f){break;}
  }
  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int n = sc.nextInt();
        int array[] = new int[w];
        for (int i = 0; i < w; i++) array[i] = i+1;
        for (int i = 0; i < n; i++){
            String str = sc.next();
            String ab[] = str.split(",");
            int a = Integer.parseInt(ab[0]) - 1;
            int b = Integer.parseInt(ab[1]) - 1;
            int tmp = array[a];
            array[a] = array[b];
            array[b] = tmp;
        }
        for (int i = 0; i < w; i++){
            System.out.println(array[i]);
        }
    }
}



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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int a,b,k; cin >> a >> b >>k;
    set<int> s;
    FOR(i,a,a+k)s.insert(i);
    for(int i=b;i>b-k;i--)s.insert(i);
    for(auto itr = s.begin();itr!=s.end();itr++){
        if(*itr >= a && *itr <= b)cout << *itr << endl;
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

	int n;
	cin >> n;
	switch (n%10) {
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon" << endl;
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		cout << "pon" << endl;
		break;
	case 3:
		cout << "bon" << endl;
		break;
	}
}

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

int n;
string s;

bool check(int x)
{
    map<string, int> v;
    for(int i = 1; i <= n + 1 - x; i++)
    {
        string a = s.substr(i - 1, x);
        if(v[a])
        {
            if(i - v[a] >= x)
                return true;
        }
        else
            v[a] = i;
    }
    return false;
}

int main()
{
    cin >> n >> s;
    int l = 0, r = n / 2;
    while(l <= r)
    {
        int m = (l + r) >> 1;
        if(check(m))
            l = m + 1;
        else
            r = m - 1;
    }
    cout << r << endl;
}


Measured memory_bytes: 6668
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    println!("{}", 700 + 100 * s.iter().filter(|&x| *x == 'o').count())
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i64 k,a,b; cin >> k >> a >> b;
    if(a+2 < b) {
        if(k < a+1) {
            cout << k+1 << '\n';
        }
        else {
            i32 ans = (b-a)*((k-a+1)/2) + a;
            if((k-a+1)%2) ans += 1;
            cout << ans << '\n';
        }
    }
    else cout << k+1 << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i=0;i<n;i++) cin>>s.at(i);
  int m;
  cin >> m;
  vector<string> t(m);
  for (int i=0;i<m;i++) cin>>t.at(i);
  
  int max=0;
  for (int i=0;i<n;i++) {
	int cnt=0;
	for (int j=0;j<n;j++) {
	  if(s.at(i)==s.at(j)) cnt++;
	}
	for (int j=0;j<m;j++) {
	  if(s.at(i)==t.at(j)) cnt--;
	}
	if(cnt>max) max=cnt;
  }
		  cout <<max;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i, n){
        cin >> p[i];
    }
    rep(i, n) {
        cin >> q[i];
    }
    vector<int> a(n);
    rep(i,n) a[i] = i+1;
    int temp = 0;
    map<vector<int>, int> mp;
    do{
        temp++;
        mp[a] = temp;
    } while (next_permutation(a.begin(), a.end()));
    int ans = abs(mp[p] - mp[q]);
    cout << ans <<endl;
    return 0;
}

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

g = [[-1]*n for i in range(n)]

for i in range(n):
	a = int(input())
	for _ in range(a):
		x, y = map(int, input().split())
		g[i][x-1] = y

ans = 0
for s in range(2**n):
	ok = True
	for i in range(n):
		if (s>>i&1) == 1:
			for j in range(n):
				if g[i][j] == -1: continue
				if (s>>j&1) != g[i][j]: ok = False
	if ok:
		ans = max(ans, bin(s).count("1"))

print(ans)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
const int mod = 1e9 + 7;

const int inf = 1e9 + 10;
int main()
{
  int n;
  cin >> n;
  int arr[3][n];
  for (int i = 0; i < n; ++i)
  {
    cin >> arr[0][i] >> arr[1][i] >> arr[2][i];
  }
 

  int dp[3][n];

  dp[0][0] = arr[0][0];
  dp[1][0] = arr[1][0];
  dp[2][0] = arr[2][0];

  for (int i = 1; i < n; ++i)
  {
     dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + arr[0][i];
     dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + arr[1][i];
     dp[2][i] = max(dp[1][i-1], dp[0][i-1]) + arr[2][i];
  }

  int a = dp[0][n-1];
  a = max(a, dp[1][n-1]);
  a = max(a, dp[2][n-1]);

  cout << a;



}

Measured memory_bytes: 2560
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class K
{
	static void Main()
	{
		var I = ReadLine().Split().Select(int.Parse).ToArray();
		int N = I[0], A = I[1], B = I[2];
		if (BitCount(A ^ B) % 2 < 1) { WriteLine("NO"); return; }
		WriteLine("YES");
		WriteLine(string.Join(" ", Generate(N, A, B)));
	}
	static IEnumerable<int> Generate(int N, int A, int B)
	{
		if (N == 1) return new[] { A, B };
		var p = new int[N];
		int c = BitCount(B ^= A), o = N - 1, z = 0;
		for (var i = 0; i < N; i++) p[i] = (B & (1u << i)) != 0 ? o-- : z++;
		B = ((1 << c) - 1) << (N - c);
		var l = new List<int>();
		var M = 1 << (N - 1);
		for (var i = 0; i < M; i++) l.Add(i ^ (i >> 1));
		foreach (var i in Generate(N - 1, 1 << (N - 2), B ^ M)) l.Add(i ^ M);
		return l.Select(x =>
		{
			var s = A;
			for (var j = 0; j < N; j++) s ^= ((x >> p[j]) & 1) << j;
			return s;
		});
	}
	static int BitCount(int n)
	{
		n = (n & 0x55555555) + ((n >> 1) & 0x55555555);
		n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
		n = (n & 0x0f0f0f0f) + ((n >> 4) & 0x0f0f0f0f);
		n = (n & 0x00ff00ff) + ((n >> 8) & 0x00ff00ff);
		return (n & 0x0000ffff) + ((n >> 16) & 0x0000ffff);
	}
}


Measured memory_bytes: 24924
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int x,y,ans;

int main(){
    cin>>x>>y;
    if(x==1&&y==1)ans+=400000;
    if(x==1)ans+=300000;
    if(x==2)ans+=200000;
    if(x==3)ans+=100000;
    if(y==1)ans+=300000;
    if(y==2)ans+=200000;
    if(y==3)ans+=100000;
    out(ans);
    
    
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>

#define INF (1<<29)
 
using namespace std;
 
int main(void){
  
  int n,m,p,a,b,x,y,z,in;
  double dp[(1<<8)][31],graph[31][31];
  vector<int>t;
  
  while(cin >> n >> m >> p >> a >> b){
    if(!(n|m|p|a|b))break;
    
    t.clear();
    
    fill(graph[0],graph[31],-1);
    fill(dp[0],dp[(1<<8)],INF);

    for(int i=0;i<n;i++){
      scanf("%d",&in);
      t.push_back(in);
    }
    
    for(int i=0;i<p;i++){
      scanf("%d %d %d",&x,&y,&z);
      graph[x][y]=graph[y][x]=z;
    }
    
    dp[0][a]=0;
    double res=INF;
    for(int S=0;S<(1<<8);S++){
      res=min(res,dp[S][b]);
      for(int v=1;v<=m;v++){
	for(int i=0;i<n;i++){
	  if(!(S>>i & 1)){
	    for(int u=1;u<=m;u++){
	      if(graph[v][u]>0){
		dp[S|(1<<i)][u]=min(dp[S|(1<<i)][u],dp[S][v]+graph[v][u]/t[i]);
	      }
	    }
	  }
	}
      }
    }
    if(res==INF)printf("Impossible\n");
    else printf("%.3f\n",res);
  }
  
  return 0;
}

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

const int maxA = 100000;

int main() {
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> freq(maxA + 1, 0);
    for (int i = 0; i != N; ++i) {
        int a;
        cin >> a;
        freq[a] += 1;
    }
    int odd = 0;
    int even = 0;
    for (auto f : freq){
        if (f == 0) continue;
        if (f % 2) {
            ++odd;
        }else{
            ++even;
        }
    }
    if (even % 2){
        cout << odd + even - 1 << endl;
    }else{
        cout << odd + even << endl;
    }
    return 0;
}

Measured memory_bytes: 640
w, h, x, y = (int(i) for i in input().split())


if x==0 or x==w:
    kadoa=1
else:
    kadoa=0

if y==0 or y==h:
    kadob=1
else:
    kadob=0

first=x*h
second=(w-x)*h

mazu=min(first, second)
 
first=y*w
second=(h-y)*w
 
tugi=min(first, second)

chisai=min(mazu,tugi)

if x==(w/2) and y==(h/2):
    print(w*h/2, 1)
else:
    print(w*h/2, 0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
struct edge{ll to, cost;};
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define INF 1000000000000

using Graph = vector<vector<edge>>;

int main(){
    static const double pi = 3.141592653589793;
    ll a,b,h,m;
    cin >> a >> b >> h >> m;
    double naga,tan;
    naga = 2.0 * pi * m / 60.0;
    tan = 2.0 * pi * h / 12.0+ (pi / 6.0) * m / 60.0;
    double kaku;
    double koko = abs(naga-tan);
    kaku = min(koko,2 * pi - koko);
    double ans;
    ans = sqrt(a*a + b*b - 2 * a * b * cos(kaku));
    cout <<fixed << setprecision(15) << ans << endl;
}

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

int main() {
  string str;
  long long K;
  cin >> str >> K;
  bool flag = true;
  for (long long i = 0; i < min(K, (long long)str.size()); i++) {
    if (str.at(i) != '1') {
      cout << str.at(i) << endl;
      flag = false;
      break;
    }
  }
  if (flag) cout << '1' << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n;
vector<int> edge[100000];

int dfs(int x, int p) {
    int sum = 0, cnt = 0;
    for (int i : edge[x]) {
        if (i == p) continue;
        int ret = dfs(i, x);
        sum += ret;
        cnt += (ret == 0);
    }
    if (cnt) sum += cnt - 1;
    return sum;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	
	for (int i = 1; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        edge[x].push_back(y);
        edge[y].push_back(x);
	}
	int mx = 0;
	for (int i = 1; i < n; ++i) {
        if (edge[mx].size() < edge[i].size()) mx = i;
	}
	
	if (edge[mx].size() <= 2u) printf("1\n");
	else printf("%d\n", dfs(mx, -1));
	
	return 0;
}


Measured memory_bytes: 10496
n = gets.to_i
a = (n.times.map{[gets.to_i,0]}+n.times.map{[gets.to_i,1]}).sort_by{|i,j|i}
ans = 1
mod = 10**9+7
s = [0,0]

for i in 0..2*n-1
  if s[1^a[i][1]] == 0
    s[a[i][1]] += 1
  else
    ans *= s[1^a[i][1]]
    ans %= mod
    s[1^a[i][1]] -= 1
  end
end

puts ans

Measured memory_bytes: 23928
import sys
input = sys.stdin.readline
 
 
def main():
    num = 0
    _ = input()
    A = sorted(list(map(int, input().split())))
    for i in range(len(A)-1):
        for j in range(i+1, len(A)):
            a = A[i]
            b = A[j]
            thresh = a + b
            ok = j
            ng = len(A)
            idx = binary_search(A, ok, ng, thresh)
            num += idx - j
 
    print(num)
 
 
def binary_search(li, ok, ng, value):
    while abs(ok-ng) > 1:
        mid = (ok + ng) // 2
        if li[mid] < value:
            ok = mid
        else:
            ng = mid
 
    return ok
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 43100
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

long double dp[110][100100];

int main(void){
    string s;
    cin >> s;

    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            int counter = 0;
            while(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
                counter++;
                i++;
            }

            ans = max(ans, counter);
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v.at(i);
    }
    for (int i = 0; i < n; i++)
    {
        cin >> c.at(i);
    }

    int count =0;

    for (int i = 0; i < n; i++)
    {
        if(v.at(i)>c.at(i)){
            count += v.at(i)-c.at(i);
        }
    }

    cout << count << endl;
    
    
    
    return 0;
}

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

sum = 0
for n in range(1,N + 1):
  d5, mod = divmod(n,10**4)
  d4, mod = divmod(mod,10**3)
  d3, mod = divmod(mod,10**2)
  d2, mod = divmod(mod,10)
  d1 = mod
  s = d1 + d2 + d3 + d4 + d5
  if A <= s <= B:
    sum += n

print(sum)

Measured memory_bytes: 9092
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
double p[maxn];
double dp[3050][3050];
int n;
int main()
{
    gg(n);
    repd(i,1,n)
    {
        scanf("%lf",&p[i]);
    }
    dp[1][1]=p[1];
    dp[1][0]=1.0000000-p[1];

    repd(i,2,n)
    {
        for(int j=0;j<=i;j++)
        {
            if(j==0)
            {
                dp[i][j]=dp[i-1][j]*(1.00000-p[i]);
                continue;
            }
            dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1.0000-p[i]);
//            dp[i][j-1]=dp[i-1][j-1]*(1.000000-p[i]);
        }
    }
    double ans=0.0000000000000000000;
    for(int i=(n+1)/2;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    printf("%.10lf\n", ans);
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

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

bool isPalindrome(string s)
{
  int idxmax = s.size() - 1;
  if(idxmax == 0) return true;
  else if(idxmax == 1 && s[0] != s[1]) return false;
  else if(idxmax == 1 && s[0] == s[1]) return true;
  
  for(int i = 0; i < idxmax / 2; i++)
  {
    if(s[i] != s[idxmax-i])
      return false;
  }
  
  return true;
}

int main()
{
  string s, sleft, sright, res = "Yes";
  cin >> s;
  sleft = s.substr(0, (s.size() - 1) / 2);
  sright = s.substr((s.size() + 1) / 2, (s.size() - 1) / 2);
  
  if(!isPalindrome(s) || !isPalindrome(sleft) || !isPalindrome(sright))
    res = "No";
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip> //setprecision()
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<999>>;

using ll = long long;
using namespace std;



int main(){
    Real a,b,c;
    Real a2,b2,c2;
    cin>>a>>b>>c;

    a2=sqrt(a);
    b2=sqrt(b);
    c2=sqrt(c);
        
    if(a2+b2<c2)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3832
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n < 3) {
            System.out.println(0);
        } else {
            System.out.println(n / 3);
        }
    }
}

Measured memory_bytes: 35636
n,m=map(int,input().split())
es=[list(map(int,input().split())) for _ in range(m)]
inf=float("inf")
d=[-inf]*(n+1)
d[1]=0

def bellman_ford():
  for i in range(n):
    isUpdated=False
    for e_from,e_to,cost in es:
      if d[e_to]<d[e_from]+cost:
        d[e_to]=d[e_from]+cost
        isUpdated=True
        if i==n-1 and e_to==n:return inf
    if not isUpdated:
      break
  return d[n]

print(bellman_ford())

Measured memory_bytes: 44904
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length == 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function slove() {
    const sc = new Scanner();
    const N = +(await sc.getLine());
    const A = (await sc.getLine()).split(' ').map((x) => +x);

    while (true) {
      if (A.filter((x) => x > 0).length === 1) {
        break;
      }
      A.sort((a, b) => a - b);
      let min = 10000000000;
      let index = -1;
      for (let i = 0; i < A.length; i++) {
        if (A[i] > 0 && min > A[i]) {
          min = A[i];
          index = i;
        }
      }
      for (let i = index + 1; i < A.length; i++) {
        A[i] = A[i] % min;
      }
    }
    console.log(A.sort((a, b) => b - a)[0]);
    sc.close();
  }

  slove();
}


Measured memory_bytes: 27900
a = int(input())
b = []
clo = True
for i in range(a):
    b.append(input())

c = int(input())
for i in range(c):
    d = input()
    for j in range(a):
        if d == b[j]:
            know = True
            break
        else:
            know = False
    if know:
        if clo:
            clo = False
            print("Opened by " + d)
        else:
            clo = True
            print("Closed by " + d)
    else:
        print("Unknown " + d)



Measured memory_bytes: 5604