akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=205,L=1e7+5;
bool mark[L],prime[L];
namespace match
{
  const int N=205;
  int l[N],r[N],n,m;
  bool a[N][N],seen[N];
  bool findmatch(int i)
  {
    rep(j,0,m)
      {
	if(a[i][j] && !seen[j])
	  {
	    seen[j]=true;
	    if(r[j]<0 || findmatch(r[j]))
	      {
		l[i]=j; r[j]=i;
		return true;
	      }
	  }
      }
    return false;
  }
  int bipartitematch()
  {
    int cnt=0;
    rep(i,0,n) l[i]=-1;
    rep(i,0,m) r[i]=-1;
    rep(i,0,n)
      {
	rep(j,0,m) seen[j]=false;
	if(findmatch(i)) cnt++;
      }
    return cnt;
  }
};
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  memset(prime,true,sizeof(prime));
  prime[1]=false;
  rep(i,2,L)
    {
      if(!prime[i]) continue;
      for(int j=2*i;j<L;j+=i)
	prime[j]=false;
    }
  prime[2]=false;
  int n,x;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>x;
      mark[x]=true;
    }
  vi arrodd,arreven;
  int odd=0,even=0;
  rep(i,1,L-1)
    if(mark[i]!=mark[i-1])
      {
	if(i&1) arrodd.pb(i);
	else arreven.pb(i);
      }
  odd=sz(arrodd); even=sz(arreven);
  match::n=odd; match::m=even;
  rep(i,0,sz(arrodd))
    rep(j,0,sz(arreven))
    {
      if(prime[abs(arrodd[i]-arreven[j])]) match::a[i][j]=1;
      else match::a[i][j]=0;
    }
  int k=match::bipartitematch();
  assert((even-odd)%2==0);
  even-=k; odd-=k;
  int ans=k+(even/2+odd/2)*2+(odd&1)*3;
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 18816
#include<iostream>
#include<algorithm>
#include <cmath>
using namespace std;
 
int main(){
    int N,a=0,b,c,d,e,f,i;
   // sort(M,M+N);
    cin >> N;
    b=log10(N)+1;
    if(b==6)cout <<90909;
    if(b==5){
       c=N-10000+1;
        cout<< c+909;
    }
    if(b==4)cout<<909;
    if(b==3){
            c=N/100;
       c=N-100+1;
       
        cout<<c+9;
    }
    if(b==2)cout<<9;
    if(b==1)cout<<N;
   

   }
   // int M[N];



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	string s,t;
	cin >> s >> t;

	int n = s.size();
	map<char,bool> mp1;
	map<char,char> dict1;
	int now = 0;
	for(int i = 0;i < n;i++){
		if(mp1[s[i]] == false){
			mp1[s[i]] = true;
			dict1[s[i]] = 'a' + now;
			s[i] = 'a' + now;
			now++;
		}
		else{
			s[i] = dict1[s[i]];
		}
	}

	now = 0;
	map<char,bool> mp2;
	map<char,char> dict2;
	for(int i = 0;i < n;i++){
		if(mp2[t[i]] == false){
			mp2[t[i]] = true;
			dict2[t[i]] = 'a' + now;
			t[i] = 'a' + now;
			now++;
		}
		else{
			t[i] = dict2[t[i]];
		}
	}

	if(s == t)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 776
n, k = map(int, input().split())
a = list(map(int, input().split()))

def check(l):
    cnt = 0
    for _ in a:
        cnt += _ // l
        if _ % l != 0:
            cnt += 1
        cnt -= 1
    if cnt <= k: return True
    else : return False

"""
left: ng
right: ok
"""
def binary(ng, ok):
    while ok - ng > 1:
        mid = (ng + ok) // 2
        if check(mid): ok = mid
        else: ng = mid
    return ok

print(binary(0, max(a)))

Measured memory_bytes: 104472
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 2e5 + 5;
bool used[N];

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

    int n, m;
    cin >> n >> m;

    if (n % 2) {
        for (int i = 0; i < m; i++) {
            cout << i + 1 << " " << n - i << "\n";
        }
    }
    else {
        set<int> st;
        for (int i = 0, j = 0; i < m; i++) {
            st.insert(n - i - j - i - 1);
            if (st.count(i * 2 + 1))
                j = 1;
            cout << i + 1 << " " << n - i - j << "\n";
            
        }
    }

    return 0;
}

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

namespace AtCoderTest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int h = int.Parse(s[0]);
            int w = int.Parse(s[1]);

            string hf = string.Concat(Enumerable.Repeat("#", w + 2));
            Console.WriteLine(hf);
            for (int i = 0; i < h; i++)
            {
                string p = Console.ReadLine();
                Console.WriteLine("#" + p + "#");
            }
            Console.WriteLine(hf);
        }
    }
}


Measured memory_bytes: 11220
import numpy as np
n,m=map(int,input().split())
height=np.zeros(n)
roads=np.zeros((m,2),dtype=np.int64)
height=list(map(int,input().split()))
for i in range(m):
    roads[i]=list(map(int,input().split()))
flg=np.zeros(n)
for left,right in zip(roads[:,0],roads[:,1]):
    left-=1
    right-=1
    if height[left]<=height[right]:
        flg[left]=1
    if height[right]<=height[left]:
        flg[right]=1
print(np.count_nonzero(flg==0))

Measured memory_bytes: 38548
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


K = int(input())

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(*[a, b, c])

print(ans)


Measured memory_bytes: 69640
#include <cstdio>
#include <cstring>

int main() {
	int n, s;
	char a[26];
	
	scanf("%d", &n);
	
	s = 0;
	
	scanf("%s", a);
	
	int la = strlen(a);
	int lb;
	for(int i=0;i<n;i++) {
		char b[101];
		scanf("%s", b);
		lb = strlen(b);
		
		for(int j=0;j<lb-la+1;j++) {
			if(b[j]==a[0]) {
				bool flg = false;
				for(int k=1;j+la*k-k<lb;k++) {
					bool flg2 = true;
					for(int l=1;l<la;l++) {
						if(a[l]!=b[j+l*k]) {
							flg2 = false;
							break;
						}
					}
					
					if(flg2) {
						flg = true;
						break;
					}
					
				}
				
				if(flg) {
					s++;
					break;
				}
			
			}
			
		}
		
	}
	
	printf("%d\n", s);
	
	return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
char s[13];
int l;
int a[13];
ll f[13], ans;

void dfs(int x, int cnt) {
	if(x >= l) {
		int pos = cnt;
		int dd = 0;
		pos--;
		for(int i = l; i >= 1; i--) {
			if(i == a[pos]) dd = 0, pos--;
			ans += (s[i] - '0') * f[dd];
			dd++;
		}
	}
	for(int i = x + 1; i <= l; i++) {
		a[cnt] = x;
		dfs(i, cnt + 1);
	}
}

int main() {
	f[0] = 1;
	for(int i = 1; i <= 10; i++) f[i] = f[i - 1] * 10;
	scanf("%s", s + 1);
	l = strlen(s + 1);
	dfs(0, 0);
	printf("%lld\n", ans);
}

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;

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ans = a[0] % 2 == 0 ? 2 : 1;
    rep(i, n - 1) ans *= a[i + 1] % 2 == 0 ? 2 : 1; 

    ans = pow(3,n) - ans;
    cout <<ans<<endl;
}

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

int main() {
    int n, y;
    cin >> n >> y;
    int a = -1, b = -1, c = -1;
    for(int i=0; i<=n; i++) {
        for (int j=0; i+j<=n; j++) {
            int k = n - i - j;
            int total = 10000 * i + 5000 * j + 1000 * k;
            if (total == y) {
                a = i;
                b = j;
                c = k;
            }
        }
    }
    
    
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3528
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  string s;
  cin >> s;
  set<string> one, two, ans;
  for (char &c : s) {
    for (const string &t : two) {
      ans.insert(t + c);
    }
    for (const string &t : one) {
      two.insert(t + c);
    }
    one.insert(string(1, c));
  }
  kek(SZ(ans));
  
  return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize("O2")
// #include <bits/stdc++.h>
#include <iostream>
// #include <vector>
// #include <algorithm>
// #include <functional>
// #include <numeric>
using namespace std;
#define MOD 1000000007


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	// int t ;
	// cin >> t ;
	// while (t--) {
	bool ok = false ;
	int k ;
	cin >> k ;
	int a , b ;
	cin >> a >> b ;
	for (int i = a ; i <= b ; i++) {
		if (i % k == 0) ok = true ;
	}
	if (ok) cout << "OK\n";
	else cout << "NG\n";



	// }
	return 0 ;
}



Measured memory_bytes: 3652
import math
a = int(input().strip())
b = int(input().strip())
c = int(input().strip())
d = int(input().strip())
e = int(input().strip())
l = [a,b,c,d,e]
x = 0
ans = 0
for i in range (len(l)):
        ans = ans + math.ceil(l[i]/10)*10
        n = math.ceil(l[i]/10)*10 - l[i]
        if x < n:
                x = n
print(ans - x)


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

int main() {
	map<int,int> data;
	int n,max;
	while (cin >> n) {
		data[n]++;
	}
	max = 0;
	for (int i = 0; i < data.size();i++)
		if( data[i] > max )
			max = data[i];
	
	map<int,int>::iterator it = data.begin();
	while (it != data.end()) {
		if ( (*it).second == max )
			cout << (*it).first << endl;
		it++;
	}
	return 0;
}

Measured memory_bytes: 1200
// 2013/07/07 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	while(true){
		int N;
		cin >> N;

		if(N==0)
			break;

		if(N%1111==0){
			cout << "NA" << endl;
			continue;
		}

		int cnt = 0;

		while(N!=6174){
			int n[4];
			n[0] = N/1000;
			n[1] = N/100%10;
			n[2] = N/10%10;
			n[3] = N%10;

			sort(n, n+4);

			int L = n[3]*1000+n[2]*100+n[1]*10+n[0];
			int S = n[0]*1000+n[1]*100+n[2]*10+n[3];

			N = L-S;
			cnt++;
		}

		cout << cnt << endl;
	}

	return 0;
}

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


int main() {
  int N;
  cin>>N;
  vector<int> X(N);
  rep(i,N){
      cin>>X.at(i);
  }
  int ans=0;
  rep(j,N){
      ans+=(X.at(j)-0)*(X.at(j)-0);
  }
  rep(i,100){
      int now=0;
      rep(j,N){
          now+=(X.at(j)-i)*(X.at(j)-i);
      }
      ans=min(ans,now);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////



///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
	int d, n;
	cin >> d >> n;
	
	if(n == 100) n++;

	cout << n;
	for(int i = 1; i <= d*2; i++)
		cout << "0";
		
	
	
	return 0;
}


Measured memory_bytes: 892
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    s=str(input())
    if s[2]==s[3] and s[4]==s[5]:
        print("Yes")
    else:
        print("No")
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    string s; cin>>s;
    int n = s.size();

    vector<vector<int>> dp(n+1, vector<int>(5, -1));
    dp[0][0] = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<5; j++){
            if(dp[i][j] == -1) continue;
            if(i - j < 0) continue;

            for(int k=1; k<5 && i+k<=n; k++){
                if(j != k || s.substr(i-j, j) != s.substr(i, k)){
                    dp[i+k][k] = max(dp[i+k][k], dp[i][j] + 1);
                }
            }
        }
    }

    int ans = 0;
    for(int i=0; i<5; i++){
        chmax(ans, dp[n][i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 11412
import numpy as np
a, = [list(map(int, s.split())) for s in open(0)][0]
min_ = a - 1
for i in range(2,int(np.sqrt(a)+1)):
    if a % i == 0:
        tmp = i + a//i - 2
        if tmp < min_:
            min_ = tmp
print(min_)


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

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=1e5+10;

ll ps[MAXN];
ll pt[MAXN];

int main()
{
    string s,t;
    cin>>s>>t;

    if (s[0]=='A')
    {
        ps[0]=1;
    }
    else
    {
        ps[0]=-1;
    }

    for(ll i=1;i<s.size();i++)
    {
        if (s[i]=='A')
        {
            ps[i]=ps[i-1]+1;
        }
        else
        {
            ps[i]=ps[i-1]-1;
        }
    }

    if (t[0]=='A')
    {
        pt[0]=1;
    }
    else
    {
        pt[0]=-1;
    }

    for(ll i=1;i<t.size();i++)
    {
        if (t[i]=='A')
        {
            pt[i]=pt[i-1]+1;
        }
        else
        {
            pt[i]=pt[i-1]-1;
        }
    }

    ll q;
    cin>>q;

    for(ll i=0;i<q;i++)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;

        a--;
        b--;
        c--;
        d--;

        ll u=ps[b]-ps[a];

        if (s[a]=='A')
        {
            u++;
        }
        else
        {
            u--;
        }

        u%=3;

        if (u<0)
        {
            u+=3;
        }

        ll v=pt[d]-pt[c];

        if (t[c]=='A')
        {
            v++;
        }
        else
        {
            v--;
        }

        v%=3;

        if (v<0)
        {
            v+=3;
        }

        if (u==v)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }

    return 0;
}


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

using namespace std;

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

int n, m;
bool red[100000];
int box[100000];

int main() {
	cin >> n >> m;
	fill(box, box + n, 1);
	red[0] = true;
	REP(i, m) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		
		box[a]--;
		box[b]++;
		
		if (red[a]) red[b] = true;
		if (box[a] == 0) red[a] = false;
	}
	
	int ans = 0;
	REP(i, n) if (red[i]) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
// 😥😥😥
// 🤔🤔🤔
// 🤗🤗🤗
// 🥳🥳🥳

/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
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;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int r; cin >> r;
  cout << 3 * r * r << '\n';

  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int h1,h2,m1,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int diff;
    if(h1 < h2){
        int a = h1*60+m1;
        int b = h2*60+m2;
        diff = b-a;
    }else if(h1 > h2){
       int a = h1*60+m1;
        int b = h2*60+m2;
        diff = b-a;
    }
    else{
        if(m1 < m2){
            int a = h1*60+m1;
        int b = h2*60+m2;
        diff = b-a;
        }else if(m1 > m2){
            int a = h1*60+m1;
        int b = h2*60+m2;
        diff = b-a;
        }
        else{
            diff = 0;
        }
    }
    cout << diff - k << endl;
    return 0;
}

Measured memory_bytes: 3692
// Author: pankaj_m05 
// Problem: d 
// Created: 21.06.2020 18:28:02

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define f_in(file) freopen(file, "r", stdin)
#define f_out(file) freopen(file, "w", stdout)
#define sz(a) int((a).size())
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())  // Set and Maps
#define cpresent(c,x) (find(allc,x) != c.end()) // Vectors
using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef long long ll;

const int mod = 1e9 + 7;

void testcase() {
	int n;
	cin >> n;
	int a[n]; 
	ll sum = 0;
	unordered_map<int, int> freq;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
		freq[a[i]]++;		
	}
	// cout << sum << '\n';
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {	
		int b, c;
		cin >> b >> c;
        freq[c] += freq[b];
        sum = sum + freq[b] * (c - b);
        freq[b] = 0;
        cout << sum << '\n';	
	}
}

int main(void) { 
	fast
	int t = 1; 
	// cin >> t;
	while (t--) {
		testcase();
	}
	return 0;
}                                          

Measured memory_bytes: 7420
n = int(input())
a = [-1]
for i in range(n):
    a.append(int(input()))
cnt = 0
next_ = 1
for i in range(1, n):
    cnt += 1
    if a[next_] == 2:
        print(cnt)
        exit()
    else:
        next_ = a[next_]
print(-1)

Measured memory_bytes: 7080
// c++include
#include <iostream>
#include <algorithm>
// cinclude
#include <stdio.h>
#include<string.h>
#include<math.h>
//c++標準ライブラリ
#include<vector>
#include<string>
//std使用<-namespace
using namespace std;

// define, typedef
#define rpt(i, n) for(ll i = 0; i < (n); i++)
typedef long long ll;

int kh(ll n) {
	return (int)to_string(n).length();
}

// main関数
int main(void) {
	ll n, a;
	cin >> n;
	int min = kh(n);
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			a = n / i;
			ll tmp = max(kh(a), kh(i));
			if (tmp < min) {
				min = tmp;
			}
		}
	}
	cout << min;
	return 0;
}

Measured memory_bytes: 256
x = int(input())

# xが5未満の時
if 0<=x and x< 5:
    print(0)
# xが500未満の場合   
if 5<= x and x<500:
    print((x//5)*5)
# xが500以上の場合
if x >= 500:
   f = x//500
   a = x % 500
   if 5<= a:
       b = a//5
       print(f*1000 + b*5)
   else:
        print(f*1000)

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll a, b, c;
	cin >> a >> b >> c;

	ll ans = min(c, a);
	c -= min(c, a);

	ans += 2 * min(b, c);
	ll t = min(b, c);
	b -= t;
	c -= t;
	ans += b;
	if(c > 0) ans++;

	cout << ans << endl;
}


Measured memory_bytes: 256
while (1):
    n=int(raw_input())
    if n==0:
        break
    else:
        top=-1
        fault=[0]
        S=0
        for i in range(n/2): #i=0,2,... is othello i=1,3,...is donothing
            s=int(raw_input()) #oddstone
            if top!=s: 
                fault.append(i)
                top=s
            s=int(raw_input()) #evenstone
            if top!=s:
                fault.pop()
                top=s
            if fault==[]:
                fault=[0]
        i=len(fault)-1
        while i>0:
            S=S+(fault[i]-fault[i-1])*2
            i=i-2
        if not top:
            S=2*(n/2)-S
        if n%2==1:
            s=int(raw_input())
            S=S+(1-s)
        print S

Measured memory_bytes: 5804
from collections import deque
h,w=map(int,input().split())
s=[input() for _ in range(h)]
visited=[[True]*w for _ in range(h)]
def bfs(sx,sy):
    q=deque([(sx,sy)])
    visited[sx][sy]=False
    black=1
    white=0
    while q:
        x,y=q.popleft()
        for dx,dy in [[0,1],[1,0],[0,-1],[-1,0]]:
            nx,ny=x+dx,y+dy
            if 0<=nx<h and 0<=ny<w:
                if visited[nx][ny]:
                    if s[x][y]=="#" and s[nx][ny]==".":
                        visited[nx][ny]=False
                        q.append((nx,ny))
                        white+=1
                    elif s[x][y]=="." and s[nx][ny]=="#":
                        visited[nx][ny]=False
                        q.append((nx,ny))
                        black+=1
    return black,white
ans=0
for sx in range(h):
    for sy in range(w):
        if s[sx][sy]=="#" and visited[sx][sy]:
            black,white=bfs(sx,sy)
            ans+=black*white
print(ans)

Measured memory_bytes: 4852
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>

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

using namespace std;

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



Measured memory_bytes: 256
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int n;
    cin>>n;
    int arr[n];
    f0(n)cin>>arr[i];
    int dist=highest(int);
    for(int i=1;i<=100;i++){
        int tot=0;
        for(int j=0;j<n;j++){
            tot+=(arr[j]-i)*(arr[j]-i);
        }
        dist=min(dist,tot);
    }
    cout << dist << endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3640
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  string s;
  cin >> s;

  rep(i,sz(s))
  {
    s[i] = 'x';
  }

  cout << s;
  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, a[112345];

int main() {

	scanf("%d", &N);
	rep(i, N) scanf("%d", &a[i]);

	map<int, int> m;
	rep(i, N) m[a[i]]++;

	if (m.size() > 3) {
		printf("No\n");
		return 0;
	}

	if (m.size() == 1) {
		if (m[0]) {
			printf("Yes\n");
			return 0;
		}
		printf("No\n");
		return 0;
	}

	if (m.size() == 2) {
		if (N % 3 || !m[0]) {
			printf("No\n");
			return 0;
		}

		int n;
		for (auto mm : m) {
			n = mm.first;
		}

		if (m[0] * 2 == m[n]) {
			printf("Yes\n");
			return 0;
		}
		printf("No\n");
		return 0;

	}

	if (N % 3) {
		printf("No\n");
		return 0;
	}
	vector<int> v;
	for (auto mm : m) {
		v.push_back(mm.first);
	}

	if ((v[0] ^ v[1]) == v[2]) {
		if (m[v[0]] == m[v[1]] && m[v[1]] == m[v[2]]) {
			printf("Yes\n");
			return 0;
		}
	}

	printf("No\n");

	return 0;
}


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

using namespace std;

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

    int a;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 && a % 5 != 0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

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

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

int findSumOfDigit(int n){
    int sum = 0;
    while(n>0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}

int main(){
    int n; cin>>n;
    int sum = findSumOfDigit(n);
    if(n%sum==0) cout << "Yes" << endl;
    else cout << "No" << endl;   
}

Measured memory_bytes: 256
a, b = map(int, input().split())
sum=0
if a >= b:
    sum += a
    a -= 1
    if a >= b:
        sum += a
    else:
        sum += b
else:
    sum += b
    b -=1
    if a < b:
        sum += b
    else:
        sum +=a
print(sum)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)
#define EPS (1e-10)

double p,e,t;
int k;
double ans = 0;

void rec(double l, double r,int yes,int no){
    if(yes+no>k)return;
    if( r<t-e+EPS || t+e-EPS<l){
        return ;
    }
    
    double mid = (l+r)/2;
    if(t-e-EPS<=l && r<=t+e+EPS || yes+no==k && t-e-EPS<=mid && mid<=t+e+EPS){
        ans += pow(p,no) * pow((1-p),yes);
        return;
    }

    if((l+r)/2<t+EPS){
        rec(l,(l+r)/2,yes,no+1);
        rec((l+r)/2, r,yes+1,no);
    }else{
        rec(l,(l+r)/2,yes+1,no);
        rec((l+r)/2, r,yes,no+1);
    }
}

int main(){
    int r,l;
    cin>>k>>l>>r;
    cin>>p>>e>>t;
    
    rec(l,r,0,0);
    
    printf("%.20lf\n",ans);
}

Measured memory_bytes: 3400
#include<bits/stdc++.h>
using namespace std;
#define int long long
void Digvijay()
{
   int n;
   cin>>n;
   vector<int> a(n);
   for(auto& it:a)cin>>it;
   int val=1;
   bool ok=false;
   for(int i=0;i<n;i++)
   {
       if(a[i]==val)
       {
           ok=true;
           val++;
       }
   }
   if(ok)
   {
       cout<<n-val+1<<"\n";
   }
   else
   {
       cout<<-1<<"\n";
   }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=0;__<_;__++)
    {
        Digvijay();
    }
}

Measured memory_bytes: 4760
#include <iostream>
#include <vector>

#define A_MIN 1

int main() {
	int N, K;
	std::cin >> N >> K;
	
	int minIndex;
	for(int i = 0; i < N; i++) {
		int A;
		std::cin >> A;
		if(A == A_MIN) {
			minIndex = i;
		}
	}

	const int left = (minIndex - 1 < 0) ? 0 : (minIndex - 1) / (K - 1) + 1;
	const int leftRem = minIndex % (K - 1);
	const int right = (N - minIndex - 1 - 1 < 0) ? 0 : (N - minIndex - 1 - 1) / (K - 1) + 1;
	const int rightRem = (N - minIndex - 1) % (K - 1);
	const int opt = (leftRem > 0 && rightRem > 0 && (leftRem + rightRem) <= (K - 1)) ? -1 : 0;

	std::cout << (left + right + opt) << std::endl;

	return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  int cities1[2*M];
  int cities2[N+1];
  for(int i = 0; i < N + 1; i++) cities2[i] = 0;
  for(int i = 0; i < M; i++) cin >> cities1[2*i] >> cities1[2*i + 1];
  for(int i = 0; i < 2*M; i++) cities2[cities1[i]]++;
  for(int i = 1; i < N + 1; i++) cout << cities2[i] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
ll INF=pow(10,18);

mat dist(310,vec(310,INF)),dist0(310,vec(310,INF));
//頂点数
int V;

void warshall_floyd(){
    for(int k=1;k<=V;k++){
        for(int i=1;i<=V;i++){
            for(int j=1;j<=V;j++)
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
        }
    }
}
void warshall_floyd0(){
    for(int k=1;k<=V;k++){
        for(int i=1;i<=V;i++){
            for(int j=1;j<=V;j++)
                dist0[i][j]=min(dist0[i][j],dist0[i][k]+dist0[k][j]);
        }
    }
}

int main(){
    cin>>V;
    int M;ll L;cin>>M>>L;
    for(int i=0;i<M;i++){
        int A,B;cin>>A>>B;
        ll C;cin>>C;
        if(C<=L){
            dist[A][B]=dist[B][A]=C;
        }
    }
    for(int i=1;i<=V;i++)
        dist[i][i]=0;
    
    warshall_floyd();
    for(int i=1;i<=V;i++){
        for(int j=1;j<=V;j++){
            if(dist[i][j]<=L)dist0[i][j]=1;
        }
        dist0[i][i]=0;
    }
    warshall_floyd0();

    int Q;cin>>Q;
    for(int i=0;i<Q;i++){
        int s,t;cin>>s>>t;
        if(dist0[s][t]==INF){
            cout<<-1<<endl;
        }
        else{
            cout<<dist0[s][t]-1<<endl;
        }
    }
    return 0;

}

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

const int N=2e5+5;
int n,m;
vector<int> adj[N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;++i){
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	bool ok=false;
	for(int i=1;i<=n;++i){
		sort(adj[i].begin(),adj[i].end());
		if(int(adj[i].size())<2) continue;
		if(adj[i][0]==1&&adj[i].back()==n) ok=true;
	}
	cout<<(ok?"POSSIBLE\n":"IMPOSSIBLE\n");
}



Measured memory_bytes: 14964
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef pair<int,int> P;
P p[3000];
int n;
int ans;
int main(){
  while(cin>>n&&n){
    ans=0;
    for(int i=0;i<n;i++)
      scanf("%d %d",&p[i].first,&p[i].second);
    sort(p,p+n);
    for(int i=0;i+1<n;i++){
      for(int j=i+1;j<n;j++){
	P a=p[i],b=p[j],c,d;
	c.first = a.first + a.second - b.second;
	c.second = a.second + b.first - a.first;
	d.first = b.first + a.second - b.second;
	d.second = b.second + b.first - a.first;
	if(binary_search(p,p+n,c) == false)continue;
	if(binary_search(p,p+n,d) == false)continue;
	int d1 = (a.first-b.first);
	int d2 = (a.second-b.second);
	int d3 = d1*d1 + d2*d2;
	ans=max(ans,d3);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1272
n, m, x = gets.chomp.split(" ").map(&:to_i)

cost = []
a = []
ans = 0
isOk = Array.new(m, 0)

n.times do
    input = gets.chomp.split(" ").map(&:to_i)
    cost << input.shift
    a << input
end

a.each do |arr|
    m.times do |i|
        isOk[i] += arr[i]
    end
end

if isOk.any?{|v| v < x}
    puts -1
    exit
end

ans = 1 << 40

[0, 1].repeated_permutation(n) do |bits|
    isOk = Array.new(m, 0)
    res = 0
    n.times do |i|
        if bits[i] == 1 then
            m.times do |j|
                isOk[j] += a[i][j]
            end
            res += cost[i]
        end
    end
    ans = [ans, res].min if isOk.all?{|v| v >= x}
end

puts ans

Measured memory_bytes: 14616
#include <iostream>
#include <cstdio>

using namespace std;

long long n, k;
long long sum;

int main()
{
    scanf("%lld%lld", &n, &k);
    if(k == 0)
    {
        printf("%lld", n * n);
        return 0;
    }
    for(int i = k + 1; i <= n; i++)
    {
        sum += (n / i) * (i - k);
        sum += max(0ll, n % i - k + 1);
    }
    printf("%lld", sum);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);
const ll LLINF = 1e15;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n+1);
    for(int i=0;i<n+1;i++){
        cin >> a[i];
    }
    vector<ll> maxint(n+1,2);
    maxint[0] = 1;
    if(maxint[0] < a[0]){
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        maxint[i+1] = min((maxint[i] - a[i]) *2,LLINF);
        if(maxint[i+1] < a[i+1]) {
            cout << -1 << endl;
            return 0;
        }
    }
    /*
    for(auto x:maxint){
        cout << x << endl;
    }
    */
    ll ans = 0;
    bool ok = true;
    vector<ll> sum(n+1);
    sum[n] = a[n];
    for(int i=n;i>0;i--){
        sum[i-1] = sum[i] + a[i-1];
    }
    /*
    for(auto x:sum){
        cout << x << endl;
    }
    */
    for(int i=n;i>=0;i--){
        if(sum[i] <= maxint[i]){
            ans += sum[i];
        }else{
            ans += maxint[i];
        }
    }
    cout << ans << endl;
}

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

int main(int argc, const char * argv[]) {
    int N, X;
    int count = 0;
    
    cin >> N >> X;
    vector<int> m(N);
    
    for (int i = 0; i < N; i++) {
        cin >> m[i];
        count++;
    }
    
    sort(m.begin(), m.end());
    
    for (int i = 0; i < N; i++) {
        X -= m[i];
    }
    
    while (X >= m[0]) {
        X -= m[0];
        count++;
    }
    
    cout << count << endl;
    
    return 0;
}

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

using namespace std;

int main(){
   int N;
   cin >> N;
   bool ok = true;
   int t = 0;
   int x = 0;
   int y = 0;
   for( int i = 0 ; i < N; i++){
    int nt, nx, ny;
    cin >> nt >> nx >> ny;
    int dx = abs(nx-x);
    int dy = abs(ny-y);
    int d = dx+dy;
    int dt = nt-t;
    if( d <= dt && (dt-d)%2==0){
       // do nothing;
    }
    else{
       ok=false;
    }
    t=nt;
    x=nx;
    y=ny;
   }
   if(ok){
      cout <<"Yes"<<endl;
   }else{
      cout <<"No"<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
#define N 100000000000000000
using namespace std;
typedef	long long int ll;

int main(){
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > q, q2;
    vector<pair<int, int> > v[n+1];
    vector<pair<int, int> > v2[n+1];
    int a, b, c, e;
    ll d[n+1];
    ll d2[n+1];
    for(int i = 1; i <= n; i++){
        d[i] = N;
    }
    for(int i = 1; i <= n; i++){
        d2[i] = N;
    }
    for(int i = 0; i < m; i++){
        cin >> a >> b >> c >> e; 
        v[a].push_back(make_pair(b, c));
        v[b].push_back(make_pair(a, c));
        v2[b].push_back(make_pair(a, e));
        v2[a].push_back(make_pair(b, e));
    }
    q.push(make_pair(0,s));
    while(!q.empty()){
        pair<ll, ll> p = q.top();
        q.pop();
        if(p.first < d[p.second]) {
            d[p.second] = p.first;
            for(int j = 0; j < v[p.second].size(); j++){
                if(v[p.second][j].second + d[p.second] < d[v[p.second][j].first]){
                    q.push(make_pair(v[p.second][j].second + d[p.second], v[p.second][j].first));
                }
            }
        }
    }
    q2.push(make_pair(0,t));
    while(!q2.empty()){
        pair<ll, ll> p = q2.top();
        q2.pop();
        if(p.first < d2[p.second]) {
            d2[p.second] = p.first;
            for(int j = 0; j < v2[p.second].size(); j++){
                if(v2[p.second][j].second + d2[p.second] < d2[v2[p.second][j].first]){
                    q2.push(make_pair(v2[p.second][j].second + d2[p.second], v2[p.second][j].first));
                }
            }
        }
    }
    ll dis[n];
    for(int i = n-1; i >= 0; i--){
        if(i == n-1){
            dis[i] = d[n] + d2[n];
        }
        else{
            dis[i] = min(dis[i+1], d[i+1] + d2[i+1]);
        }
    }
    for(int i = 0; i < n; i++){
        cout << 1000000000000000-dis[i] << endl;
    }
    // for(int i = 0; i < n; i++){
    //     cout << d[i+1]+d2[i+1] << endl;
    // }
    // cout << d[t] << " " << d2[s] << endl;
    return 0;
}

Measured memory_bytes: 17396
package main


import (
    "fmt"
)

func main() {
  var N,l,r int
  var res int = 0

  fmt.Scan(&N)

  for i := 0; i < N; i++ {
    fmt.Scan( &l, &r )
    res += r - l + 1

  }

    fmt.Println(res)

}


Measured memory_bytes: 512
#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<string> s(n);
  rep(i,n) cin >> s[i];
  int ac=0,wa=0,tle=0,re=0;
  rep(i,n){
    if(s.at(i)=="AC")
        ac++;
    else if(s.at(i)=="WA")
        wa++;
    else if(s.at(i)=="TLE")
        tle++;
    else if(s.at(i)=="RE")
        re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 6424
#include <cstdio>
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int A[n][m];
    int b[m];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            scanf("%d", &A[i][j]);
        }
    }
    for (int i = 0; i < m; i++){
        scanf("%d", &b[i]);
    }
    for (int i = 0; i < n; i++){
        int c = 0;
        for (int j = 0; j < m; j++){
            c += A[i][j] * b[j];
        }
        printf("%d\n", c);
    }
    return 0;
}

Measured memory_bytes: 2780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
char s[15];
int l;
ll res;

void Dfs(int x, ll last, ll sum) {
	if(x >= l + 1) {
		res += sum + last; 
		return ;
	}
	Dfs(x + 1, last * 10 + s[x] - '0', sum); 
	Dfs(x + 1, 0, sum + last); 
}

int main() {
	scanf("%s", s + 1);
	l = strlen(s + 1);
	Dfs(1, 0, 0);
	printf("%lld\n", res);
}

Measured memory_bytes: 256