akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;
LLi mod=1000000007;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}
 
LLi modpow(LLi a, LLi n) {
    LLi res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){

	LLi n, ans, tmp, tmp2;

	cin>> n;

	if(n==1){
		cout<< 0 << endl;
		return 0;
	}

	ans=modpow(10, n)%mod;
	tmp=modpow(9, n)%mod;
	tmp2=modpow(8, n)%mod;

	cout<< (ans-((2*tmp-tmp2+mod)%mod)+mod)%mod << endl;
 
	return 0;
}

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

using namespace std;

typedef long long int ll;

void solve()
{
	ll a, b,  c, k;
	cin >> a >> b >> c >> k;
	if(a >= k)
	{
		cout << k << "\n";
	}
	else if(a + b >= k)
	{
		cout << a << "\n";
	}
	else
	{
		k -= (a + b);
		cout << a - k << "\n";
	}
}

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



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

using namespace std;

const int MAXN = 1e7 + 10;

int n, T, k, m;

int a[MAXN], dp[MAXN];

bool visited[MAXN];

string s, t;

vector<int> adj[MAXN];

const int MOD = 1e9 + 7;

vector<int> st;

void dfs(int v) {
    visited[v] = 1;
    for (auto &&u : adj[v])
        if (!visited[u])
            dfs(u);
    st.push_back(v);
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;

        x--, y--;

        adj[x].push_back(y);
    }
    
    for (int i = 0; i < n; i++)
        if (!visited[i])
            dfs(i);

    dp[0] = 0;
    for (auto &&i : st)
        for (auto &&u : adj[i])
            dp[i] = max(dp[i], dp[u] + 1);
    
    int ans = 0;
    for (int i = 0; i < n; i++)
        ans = max(ans, dp[i]);

    cout << ans;
}


Measured memory_bytes: 243732
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

struct Point{
    ll x, y;
    Point(ll x = 0, ll y = 0) : x(x), y(y) {}
    int orthan() const {
        if(x == 0 and y == 0)return 0;
        if(y >= 0)return x >= 0 ? 1 : 2;
        else return x >= 0 ? 4 : 3;
    }
    bool operator < (const Point& p) const {
        if(orthan() != p.orthan())return orthan() < p.orthan();
        return x * p.y - y * p.x > 0;
    }
};

int main(){

    int n;
    cin >> n;

    vector<Point> xy(n);
    rep(i, n)cin >> xy[i].x >> xy[i].y;

    sort(all(xy));
    ll ans = 0;
    rep(i, n){
        ll x = 0, y = 0;
        rep(j, n){
            x += xy[(i + j) % n].x;
            y += xy[(i + j) % n].y;
            chmax<ll>(ans, x * x + y * y);
        }
    }

    cout << fixed << setprecision(40) << sqrt(ans) << endl;
    return 0;

}

Measured memory_bytes: 256
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mp make_pair
#define ff first
#define ss second
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll mn=LLONG_MAX;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			mn=min(mn,(i+(n/i)));
		}
	}
	mn-=2;
	cout<<mn;
}

Measured memory_bytes: 256
#include <iostream>
    using namespace std;
     
    int main() {
        int L; cin >> L;
        int tmp = (1<<20), N = 20;
        while(tmp > L) tmp >>= 1, --N;
     
        cout << N + 1 << " " << N * 2 + __builtin_popcount(L) - 1 << endl;
     
        // when L = 8
        // 1 - 2 - 3 - 4
        // cost : 01 02 04
        // path 1 ~ 4 : 000 100 020 120 004 104 024 124 (length : 0 ~ 7)
        for(int i = 0; i < N; ++i) {
            cout << i + 1 << " " << i + 2 << " " << 0 << '\n';
            cout << i + 1 << " " << i + 2 << " " << (1<<i) << '\n';
        }
        // for now, it can make the graph when L = 2^k
     
        // think about when L is between 2^k and 2^(k+1)
        // L = ... 4 : ok, 5 : more 1 path costs 4, 6 : more 2 path cost 4 and 5, 7 : more 3 path cost 4 and 5 and 6, 8 : ok
        // 5 : 101, 6 : 110, 7 : 111
     
     
        int cost = (1<<N);
        for(int i = N - 1; i >= 0; --i) {
            if(L & (1<<i)) {
                cout << i + 1 << " " << N + 1 << " " << cost << '\n';
                cost += (1<<i);
            }
        }
        return 0;
    }

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=1e5+4;
int n,a[N],b[N];
ll ans;
int main() {
	scanf("%d",&n);
	for (register int i=1;i<=n+1;++i) scanf("%d",&a[i]);
	for (register int i=1;i<=n;++i) scanf("%d",&b[i]);
	for (register int i=1;i<=n;++i) {
		if (b[i]<=a[i]) {
			a[i]-=b[i];
			ans+=b[i];
		} else {
			ans+=a[i];
			int delta=b[i]-a[i];
			a[i]=0;
			if (delta>=a[i+1]) {
				ans+=a[i+1];
				a[i+1]=0;
			} else {
				a[i+1]-=delta;
				ans+=delta;				
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int a[]={1,0,-1,0};
int b[]={0,1,0,-1};

int H,W;
char s[52][52];
int G[52][52];

int main(){
    cin>>H>>W;
    repn(i,H) repn(j,W) cin>>s[i][j];
    repn(i,H) fill(G[i]+1,G[i]+1+W,-1);

    queue<P> que;
    que.push(P(1,1));
    G[1][1]=0;
    while(!que.empty()){
        P p=que.front();
        int i=p.first, j=p.second;
        que.pop();
        rep(k,4){
            if(s[i+a[k]][j+b[k]]=='.' && G[i+a[k]][j+b[k]]==-1 &&
            1<=i+a[k] && i+a[k]<=H && 1<=j+b[k] && j+b[k]<=W){
                G[i+a[k]][j+b[k]]=G[i][j]+1;
                que.push(P(i+a[k],j+b[k]));
            }
        }
    }

    if(G[H][W]==-1){
        cout<<-1<<endl;
        return 0;
    }

    int wh=0;
    repn(i,H){
        repn(j,W){
            if(s[i][j]=='.') wh++;
        }
    }
    int ans=wh-(G[H][W]+1);

    cout<<ans<<endl;
}

Measured memory_bytes: 3536
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
int main() {
    	int p, n;
	cin >> p >> n;
	vector<int> v(n);
	for(int i=0; i<n; i++)
		cin >> v[i];
	int maxdist = p - v[n-1] + v[0];	
	for(int i=0; i<n-1; i++)
		maxdist = max(maxdist, v[i+1]-v[i]);
	cout << p - maxdist;
	return 0;
}

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

    const int MOD = 1000000007;
    const double PI = acos(-1); 

    //long long
    using ll = long long;

    //出力系
    #define print(x) cout << x << endl
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

    //for
    #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

    //最大公約数（ll）
    ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

    //素因数分解
    vector<pair<ll, int>>factorize(ll n){
      vector<pair<ll, int>> res;
      for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
          n /= i;
          res.back().second++;
        }
      }
    if(n != 1) res.emplace_back(n, 1);
    return res;
    }



  // // 二分探索(最小値を出す問題は疑う)
  // bool C(ll x){
  //     ll res = 0;
  //     for(int i = 0; i < N; ++i){
  // 		res += max(0ll, A[i]-x/F[i]);
  //     }
  //     return res <= K;
  // }

  //   ll binary_search(ll ok, ll ng){
  //     while(abs(ok - ng) > 1){
  //       ll mid = (ok + ng) / 2;
  //       if(C(mid)) ok = mid;
  //       else ng = mid;
  //     }
  //     return ok;
  //   }



  int main(){
    int r;
    cin >> r;
    int ans = r * r;
    print(ans);
  }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        
        int result = 0;
        for(int i=a; i<=b; i++) {
            if (c % i == 0) { result++; }
        }
        
        System.out.println(result);
    }
}


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

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    rep(i, n){
        int t;
        cin >> t;
        cnt += i + 1 != t;
    }
    cout << ((cnt <= 2)? "YES": "NO") << endl;
}


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

using namespace std;

int main() {
	int n, m, a;
	cin >> n >> m;

	priority_queue<int> que;
	for (int i = 0; i < n; i++) {
		cin >> a;
		que.push(a);
	}

	while (!que.empty() && m > 0) {
		auto x = que.top();
		que.pop();

		x /= 2;
		if (x > 0) {
			que.push(x);
		}
		m--;
	}

	long long ans = 0;
	while (!que.empty()) {
		ans += que.top();
		que.pop();
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 892
#include <stdio.h>
#define N 100

int main()
{
  int M[N][N];
  int i,j;
  int n,u,k,v;

  scanf("%d",&n);
  for(i = 0; i < n; i++)
    for(j = 0; j < n; j++)
      M[i][j] = 0;

  for(i = 0; i < n; i++)
    {
      scanf("%d %d",&u,&k);
      u--;
      for(j = 0; j < k; j++)
	{
	  scanf("%d",&v);
	  v--;
	  M[u][v] = 1;
	}
    }

  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n; j++)
	{
	  if(j) printf(" ");
	  printf("%d",M[i][j]);
	}
      printf("\n");
    }
  
  return 0;
}



Measured memory_bytes: 2060
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

string s;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> s;
	vector<int> mod(2019);
	int ans = 0;
	for (auto& c : s)
	{
		vector<int> tmp(2019);
		for (int i = 0; i < 2019; ++i)
		{
			if (!mod[i]) continue;
			int nxt = (i * 10 + c - '0') % 2019;
			if (!nxt) ans += mod[i];
			tmp[nxt] = mod[i];
		}
		tmp[c - '0']++;
		mod = tmp;
	}
	cout << ans;
}

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

using namespace std;
#define ll long long
#define int long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

int N, K;
bool f[10];

bool ch(int x)
{
	if (x == 0) return true;
	if (!f[x % 10]) return false;
	return ch(x / 10);
}

signed main()
{
	cin >> N >> K;
	rep(i, 10) f[i] = true;
	rep(i, K) {
		CIN(int, t);
		f[t] = false;
	}
	reps(i, N, N*100) {
		if (ch(i)) {
			cout << i << endl;
			break;
		}
	}
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    ll k,a,b,ans=1;
    cin>>k>>a>>b;
    if(b-a<2 || k<=a)    //kankin shinai
    {
        ans = k+1;
    }
    else
    {
        ans=a;
        k=k-a+1;
        if(k%2==1)
        {
            ans++;
            k--;
        }
        k/=2;
        ll plus = b-a;
        ans+=plus*k;
    }

    cout<<ans<<endl;
    return 0;
}

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

int countBomb(vector<string> &g, int i, int j) {
  int count = 0;
  if(g.at(i - 1).at(j - 1) == '#') count++;  
  if(g.at(i - 1).at(j - 0) == '#') count++;  
  if(g.at(i - 1).at(j + 1) == '#') count++;  

  if(g.at(i - 0).at(j - 1) == '#') count++;  

  if(g.at(i - 0).at(j + 1) == '#') count++;  

  if(g.at(i + 1).at(j - 1) == '#') count++;  
  if(g.at(i + 1).at(j - 0) == '#') count++;  
  if(g.at(i + 1).at(j + 1) == '#') count++;
  return count;
}

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> ground(H + 2);
  for(int i = 0; i < W + 2; i++) {
    ground.at(0).push_back('.');
    ground.at(H + 1).push_back('.');
  }
  for(int i = 1; i < H + 1; i++) {
    string Sx;
    cin >> Sx;
    
    stringstream ss;
    ss << '.' << Sx << '.';
    ground.at(i) = ss.str();
  }

  for(int i = 1; i < H + 1; i++) {
    for(int j = 1; j < W + 1; j++) {
      if(ground.at(i).at(j) == '.') {
        int b = countBomb(ground, i, j);
        stringstream ss;
        ss << b;
        ground.at(i).at(j) = ss.str().at(0);
      }
    }
  }
  
  for(int i = 0; i < H + 2 ; i++) {
    if (i == 0 || i == H + 1) continue;
    
	for(int j = 1; j < W + 1; j++) {
      cout << ground.at(i).at(j);
    }
    cout << endl;
  }
}


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

#define int long long

main(void) {
	int n , m ;
	cin >> n >> m;
	if(n == 1 && m == 1) {
		puts("1"); return 0;
	}
	if(n > m) swap(n , m);
	if(n == 1 && m == 2) {
		puts("0"); return 0;
	}
	if(n == 2 && m == 2) {
		puts("0"); return 0; 
	}
	int ans = (n - 1) * (m - 1);
	if(n == 2) {
		cout << 0 << endl; return 0;
	}
	if(n == 1) {
		cout << m - 2 << endl; return 0;
	}
	cout << (n - 2) * (m - 2);
}

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

int n,m;
std::unordered_map<int,int> um; 

void input()
{
    std::cin>>n>>m;
    for(int i=0;i<n;i++){
        int ki;std::cin>>ki;
        for(int j=0;j<ki;j++){
            int tmp;
            std::cin>>tmp;
            tmp--;
            um[tmp]++;
        }
    }
}

int main()
{
    input();
    int cnt=0;
    for(int i=0;i<m;i++){
        if(um[i]==n)cnt++;
    }
    std::cout<<cnt<<std::endl;
}

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

using namespace std;

#define pb push_back

int n, s;

main() {
	srand(time(0));
	scanf("%d", &n);
	if (n == 3) {
		puts("2 5 63");
		return 0;
	}
	vector < int > v;
	for (int i = 1; i <= 30000; i++) {
		if (i % 2 == 0 || i % 3 == 0) v.pb(i);
	}
	while (1) {
		random_shuffle(v.begin(), v.end());
		int gc = v[0];
		s = 0;
		for (int i = 0; i < n; i++) {
			gc = __gcd(v[i], gc);
			s += v[i];
		}
		if (s % 6 != 0) continue;
		if (gc != 1) continue;
		for (int i = 0; i < n; i++) {
			cout << v[i] << ' ';
		} 
		return 0;
	}
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String first = br.readLine().substring(0, 1);
		String second = br.readLine().substring(1, 2);
		String third = br.readLine().substring(2, 3);
		System.out.println(first + second + third);
	}

}

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

int main(){
  int n, m, ans1=0, ans2=0;
  cin >> n >> m;
  vector<int> a(n+1), b(n+1);
  
  for(int i = 0; i < m; i++){
  	int p; cin >> p;
  	string s; cin >> s;
  
  	if(s=="AC" && !a[p]){
    	ans1++;
    	a[p]++;
    	ans2 += b[p];
    }
  
  	if(s=="WA" && !a[p]){
    	b[p]++;
    }
  
  }
  
  cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <queue>
#include <string>

using namespace std;
typedef unsigned long long llong;

#define MAX 100001
const llong mod = 1000000000 + 7;

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

  llong x;
  queue<llong> q;
  q.push(1);
  q.push(2);
  q.push(3);
  q.push(4);
  q.push(5);
  q.push(6);
  q.push(7);
  q.push(8);
  q.push(9);

  for (int i = 0; i < K; i++)
  {
    x = q.front();
    q.pop();

    if (x % 10 != 0)
      q.push(x * 10 + (x % 10) - 1);

    q.push(x * 10 + (x % 10));

    if (x % 10 != 9)
      q.push(x * 10 + (x % 10) + 1);
  }

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

  return 0;
}

Measured memory_bytes: 4632
#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;
typedef long long ll;
int main(){
	int a,sum=0,b,c=0;
	cin>>a;
	b=a;
	while(b){
		b/=10;
		c=c*10+7;
		sum++;
	}
	while(c%a){
		c=(c%a)*10+7;
		sum++;
		if(sum>=100000000){
			cout<<"-1";
			return 0;
		}
	}
	cout<<sum;
}

Measured memory_bytes: 3188
T = 26

D = int(input())
cs = list(map(int, input().split()))
ss = [list(map(int, input().split())) for _ in range(D)]

def greedy(D, cs, ss):
    ts = []
    last = [0] * T
    for d in range(D):
        d_true = d + 1
        diffs = []
        ssc = ss[d]
        for t in range(T):
            s = ssc[t]
            d = s + cs[t] * (d_true - last[t])
            diffs.append((d, t))
        
        dc, tc = max(diffs)
        last[tc] = d_true
        ts.append(tc)
    
    return ts


ts = greedy(D, cs, ss)
ts = [t + 1 for t in ts]

for t in ts:
    print(t)


Measured memory_bytes: 9520
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;ll m;
  cin >> n >> m;
  int a[n];
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  int l = 0;
  int r = 200005;
  auto check = [&](int x){
    ll sum = 0;
    rep(i,n){
      sum += a+n-lower_bound(a,a+n,x-a[i]);
    }
    if(sum>=m)return true;
    else return false;
  };
  while(r-1>l){
    int mid = (l+r)/2;
    if(check(mid))l=mid;
    else r = mid;
  }
  ll s[n+1];
  s[0]=0;
  rep(i,n)s[i+1]=s[i]+a[i];
  ll ans = 0;
  rep(i,n){
    int ind = lower_bound(a,a+n,l-a[i])-a;
    ans += s[n]-s[ind];
    ans += (ll)a[i]*(n-ind);
  }
  ll sum = 0;
  rep(i,n){
    sum += a+n-lower_bound(a,a+n,l-a[i]);
  }
  ans -= (sum-m)*l;
  cout << ans << endl;
}

Measured memory_bytes: 4316
/*  (: ///////|||||| BEGINS |||||||\\\\ :) */
/* REMEMBER
Deletes all characters except first one     Deletes 4 characters from index number 1
    str.erase(1);                               str.erase(1,4);
Deletes character at position 4
 str.erase(str.begin() + 4);
bool compare(const pair<int, int>&a, const pair<int, int>&b)
{
   return a.second<b.second;
}
maxn = max_element(mp.begin(), mp.end(), compare)->second;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second < b.second);
}
min(a,b,c,d)==min({a,b,c,d});
priority_queue <int, vector<int>, greater<int>> gquiz; // to create min heap
*/
#include<bits/stdc++.h>
using namespace std;
#define ll             long long int
#define endl           '\n'
#define mod            1000000007
#define fo(i,n)        for(int i=1;i<=n;i++)
#define tol(s)         transform(s.begin(),s.end(),s.begin(),::tolower)
#define tou(s)         transform(s.begin(),s.end(),s.begin(),::toupper)
#define all(x)         (x).begin(), (x).end()
#define pb             push_back
#define lb             lower_bound
#define ub             upper_bound
#define tr(it, a)      for(auto it = a.begin();it!=a.end();it++)
#define gcd(a,b)       __gcd(a,b)
#define pq             priority_queue
#define fr             first
#define sc             second
#define sz(x)          x.size()

const int inf=0x3f3f3f3f;
bool ispalindrome(string s) 
{ 
    ll len=s.length(); 
    for(ll i=0;i<len;i++){ 
        if(s[i]!=s[len-i-1]) 
        return false; 
    } 
    return true; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
long long isprime(long long n)
{
    for(long long i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)return 0;
    }
    return 1;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);



int a,b,c,d,e;
cin>>a>>b>>c>>d>>e;
if(a==0)cout<<1<<endl;
else if(b==0)cout<<2<<endl;
else if(c==0)cout<<3<<endl;
else if(d==0)cout<<4<<endl;
else if(e==0)cout<<5<<endl;








return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
  
int main () {
	int a, b;
  	cin >> a >> b;
  	int cross = a * b % 2;

  
  	if (cross == 0) {
    	cout << "Even" << endl;
    } else {
    	cout << "Odd" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    String S = sc.next();

    sc.close();

    if (S.equals("Sunny")) {
      System.out.println("Cloudy");
    } else if (S.equals("Cloudy")) {
      System.out.println("Rainy");
    } else {
      System.out.println("Sunny");
    }

  }

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) {
            break;
        }
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) {
                        cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


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

typedef long long int ll;
double PI = 3.14159265358979;

int main(){
   int N;
   cin >> N;
   int A[N];
   int cnt = 0;
   for(int i = 0;i < N;i++){
       cin >> A[i];
       if(A[i] % 2 == 0){
           cnt++;
       }
   }
   cout << pow(3,N) - pow(2,cnt) << endl;

}




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


int main(int argc, char *argv[]){
  int mochi_num;
  cin >> mochi_num;
  
  int mochi[mochi_num];
  for(int i=0; i<mochi_num; i++) cin >> mochi[i];
  
  sort(mochi, mochi+mochi_num, greater<int>());
  int count = 0;
  int mark = 0;
  
  for(int i=0; i<mochi_num; i++){
    if(mark != mochi[i]) mark = mochi[i], count++;
  }
  
  printf("%d", count);
}

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

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

string conv(int a){
	stringstream ss;
	ss << a;
	string str = ss.str();
	return str;
}


string conv(char a){
	stringstream ss;
	ss << a;
	string str = ss.str();
	return str;
}

int conv(string a){
    stringstream geek(a); 
    int x = 0; 
    geek >> x;   
	return x;
}

int main(void) 
{	
	int a, b, c;
	cin>> a >> b>> c;
	int mini = min(a,b);
	int maxi = max(a,b);
	
	if(mini <= c && c <= maxi)
		cout<<"Yes";
	else 
		cout<<"No";
	return 0;
} 



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

using namespace std;

struct UnionFind {
    vector<int> parent;
    UnionFind(int N) : parent(N) {
        for(int i = 0; i < N; i++) {
            parent[i] = i;
        }
    }

    int root(int x) {
        if(parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        parent[rx] = ry;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind t(N);
    vector<int> f(N, 0);
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        t.unite(a, b);
        f[a]++;
        f[b]++;
    }

    vector< vector<int> > bl(N);
    for(int i = 0; i < K; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        bl[a].push_back(b);
        bl[b].push_back(a);
    }

    vector<int> num(N, 0);
    for(int i = 0; i < N; i++) {
        num[t.root(i)]++;
    }

    for(int i = 0; i < N; i++) {
        int n = num[t.root(i)];
        for(const auto x: bl[i]) {
            if(t.same(x, i)) {
                n--;
            }
        }
        cout << n - f[i] - 1;
        if(i != N - 1) cout << " ";
        else cout << endl;
    }
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define peek(v)      \
	for (auto i : v) \
		cout << i << ' ';
#define rep(i, begin, end) \
	for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

void solve()
{
	int n;
	string s;
	cin >> n >> s;
	int x = 0;
	int m = x;
	for (auto i : s)
	{
		if (i == 'D')
			x--;
		if (i == 'I')
			x++;
		m = max(x, m);
	}
	cout << m;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(){
  int data[10];
  int v,w;
  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", data, data+1, data+2, data+3, data+4, data+5, data+6, data+7, data+8, data+9, &v, &w)!=EOF){
    for(int i=1;i<10;i++) data[i] += data[i-1];

    double x = data[9]*v/(double)(v+w);

    for(int i=0;i<10;i++) {
      if(data[i] >= x){
        printf("%d\n", i+1);
        break;
      }
    }
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s[3];
    cin>>s[0];
    cin>>s[1];
    cin>>s[2];
    int i=1,j=0,l=0,t=s[0][0]-'a';
    while(1){
        if(t==0){
            if(i==s[0].size()){
                cout<<"A"<<endl;
                return 0;
            }
            t=s[0][i]-'a';
            i++;
        }
        else if(t==1){
            if(j==s[1].size()){
                cout<<"B"<<endl;
                return 0;
            }
            
            t=s[1][j]-'a';
            j++;
        }
        else if(t==2){
            if(l==s[2].size()){
                cout<<"C"<<endl;
                return 0;
            }
            t=s[2][l]-'a';
            l++;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

n = input()

if ord(n) < 97:
    print('A')
else:
    print('a')


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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     (_obj).begin(), (_obj).end()
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define CeilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    char c;
    cin >> c;
    if ('A' <= c && c <= 'Z') {
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner =new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int c=scanner.nextInt();
        if(a>b){
            int x=b;
            b=a;
            a=x;
        }
        if(b>c){
            int y=c;
            c=b;
            b=y;
        }
        if(a>b){
            int z=b;
            b=a;
            a=z;
        }
        System.out.println(a+" "+b+" "+c);
    }
}


Measured memory_bytes: 26096
#include<iostream>

using namespace std;

int n;


int CheckAnswer(int m,int k,int *vec){
    if(k==0){
        return 1;
    }else if(m>=n){
        return 0;
    }else{
        int res= CheckAnswer(m+1,k,vec)||CheckAnswer(m+1,k-vec[m],vec);
        return res;
    }
}



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

    int q;
    cin>>q;
    int l;
    for(int j=0;j<q;++j){
        cin>>l;
        if(CheckAnswer(0,l,vec)==1){
            cout<<"yes"<<endl;
        }else{
            cout<<"no"<<endl;
        }
    }

}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, i=0;
  cin >> N;

  string x,text="Three";
 
  while(i < N){
    cin >> x;
    if(x == "Y"){
      text = "Four";
      break;
    }
    i++;
  }


cout << text << endl;
  return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N; cin >> N;
    int odd = 0, even = 0;
    rep(i, N) {
        int A; cin >> A;
        if (A % 2) odd++;
        else even++;
    }
    if (odd % 2) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

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

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

int main() {
  int X, Y;
  cin >> X >> Y;

  if (Y % 2 == 1 || 4 * X < Y) {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i <= X; i++) {
    int j = X - i;
    if ((2 * i + 4 * j) == Y || (4 * i + 2 * j) == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3636
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    mod=10**9+7
    n=int(readline())
    a=list(map(int,readline().split()))
    a=np.array(a,dtype=np.int64)

    b=np.array([((a>>i)&1).sum() for i in range(61)],dtype=np.int64)
    c=np.full(61,n,dtype=np.int64)-b
    d=b*c
    d%=mod

    ans=0
    now=1
    for i in range(60):
        ans+=d[i]*now
        ans%=mod
        now*=2
        now%=mod

    print(ans)

if __name__=="__main__":
    main()

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

using namespace std;

int main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
	
    vector<string> vec;
    int n, l;
    
    cin >> n >> l;
    for(int i = 0; i < n; i++){
    	string str;
    	cin >> str;
    	vec.push_back(str);
	}
	
	sort(vec.begin(), vec.end());
	
	for(int i = 0; i < n; i++){
		cout << vec[i];
	}
	cout << endl;
   
    return 0;
}

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

using namespace std;

int main(){

  string s;
  
  int total=0;
  
  while(cin>>s){

	//	if(s=="0")
	// break;
	
	for(int i=0;i<s.size();++i){

	  if(s[i] >= '0' && s[i] <= '9'){
		int p=0;
		vector<char> t;
		t.push_back(s[i]-'0');
		while(1){
		  i++;
		  if(s[i] >= '0' && s[i] <= '9'){
			t.push_back(s[i]-'0');
			p++;
		  }
		  else
			break;
		}
		for(int j=p;j>=0;--j)
		  total+=t[p-j]*pow(10,j);
		  
	  }
	}
	
  }

  cout<<total<<endl;
  
}



Measured memory_bytes: 3336
#include <bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

int main(){
    int N;  cin >> N;
    vector<int> T(N+2,0), A(N+2,0);
    for(int i=1; i<=N; i++) cin >> T[i];
    for(int i=1; i<=N; i++) cin >> A[i];
    vector<pair<int,int>> rangeT(N+1,{0,0}), rangeA(N+1,{0,0}); // {min, max}
    for(int i=1; i<=N; i++){
        rangeT[i].first = (T[i] > T[i-1] ? T[i]:1);
        rangeT[i].second = T[i];
    }
    for(int i=N; i>=1; i--){
        rangeA[i].first = (A[i] > A[i+1] ? A[i]:1);
        rangeA[i].second = A[i];
    }

    ll mod = 1e9+7;
    ll ans = 1;
    for(int i=1; i<=N; i++){
        ll minT = rangeT[i].first;
        ll maxT = rangeT[i].second;
        ll minA = rangeA[i].first;
        ll maxA = rangeA[i].second;
        if(maxT < minA || maxA < minT){
            cout << 0 << endl;
            return 0;
        }

        ll val[4] = {minT, maxT, minA, maxA};
        sort(val, val+4);
        ans = ans*(val[2]-val[1]+1)%mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
N = int(input())
ABC = [None] * N
for i in range(N):
    ABC[i] = list(map(int, input().split()))

l = [[None] * 3 for _ in range(N)]
for i in range(N):
    l[i] = (ABC[i])

dp = [[0] * 3 for _ in range(N)]
dp[0] = ABC[0]

for i in range(1, N):
    dp_p = sorted(dp[i - 1])
    a = dp_p[-1]
    b = dp[i - 1].index(a)
    for j in range(3):
        if j == b:
            dp[i][j] = dp_p[-2] + l[i][j]
        else:
            dp[i][j] = a + l[i][j]
ans = max(dp[-1])
print(ans)

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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
#define fileio freopen("template.in", "r", stdin), freopen("template.out", "w", stdout);
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    fastio;
    //fileio;

    ll n;
    cin >> n;
    unordered_map<ll, ll> B;
    ll sum = 0;
    FOR(i, 0, 1e5) {B[i+1] = 0;}
    FOR(i, 0, n) {
        ll x;
        cin >> x;
        B[x]++;
        sum += x;
    }
    ll Q;
    cin >> Q;
    FOR(i, 0, Q) {
        ll a, b;
        cin >> a >> b;
        ll x = B[a];
        B[a] = 0;
        sum += (b-a)*x;
        B[b] += x;
        cout << sum << "\n";
    }
    return 0;
}


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

int main(){
  int N;
  int left, right;
  cin >> N;
  
  int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> left;
    cin >> right;
    sum += (right - left + 1);
  }
  cout << sum;
}

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

int main()
{
        int n,k,p[10000],i,s=0;
        cin>>n>>k;
        for(i=0;i<n;i++)
        {
                cin>>p[i];
        }
        sort(p,p+n);
        for(i=0;i<k;i++)
        {
                s=s+p[i];
        }
        cout<<s<<endl;
        return 0;
}


Measured memory_bytes: 3640
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    dist = float('inf')
    index = None
    for j in range(m - 1, -1, -1):
        d = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if d <= dist:
            dist = d
            index = j
    print(index + 1)


Measured memory_bytes: 3064
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> S = new ArrayList<Integer>();
        int n = sc.nextInt();
        
        for(int i = 0;i<n;i++ ){
            S.add(sc.nextInt());
        }
        int cnt = 0;
        int q = sc.nextInt();
        for(int i = 0;i<q;i++ ){
            int num = sc.nextInt();
            if(S.contains(num))cnt++;
        }
        System.out.println(cnt);
        
    }
}


Measured memory_bytes: 40752
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
N,P = map(int,input().split())

def prime_factorize(n):  #nの素因数分解結果をリストで返す。Counterで素数ごとの指数確認可能 
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

cnt =Counter(prime_factorize(P))

ans = 1
for k,v in cnt.items():
    if v >= N:
        ans *= k**(v//N)

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 3444
#include<map>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
typedef long long int ll;
using namespace std;
#define MAX   150002
#define X first
#define Y second
#define MOD 1000000007

ll t,n,i,j;
int main()
{
    ll k,x;
    cin>>k>>x;
    for(i=(x-k+1);i<=(x+k-1);i++)
        cout<<i<<" ";
    cout<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
    int K,l,i;
    char S[110];

    scanf("%d",&K);
    scanf("%s",S);

    l=strlen(S);

    if(l<=K){
        printf("%s",S);
    }
    else{
        for(i=0;i<K;i++){
            printf("%c",S[i]);
        }
        printf("...");
    }
    return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> dp(n);
	int ball = 0;
	for (int i = n - 1; i >= 0; i--) {
		int num = 0;
		for (int j = (i + 1) * 2; j <= n; j += (i + 1)) {
			num += dp[j - 1];
		}
		if ((num & 1) == a[i]) {
			dp[i] = 0;
		}
		else dp[i] = 1;
		ball += dp[i];
	}
	cout << ball << endl;
	for (int i = 0; i < n; i++) {
		if (dp[i]) cout << i + 1 << " ";
	}
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    in(x);
    in(n);

    if (n == 0) {
        out(x);
        return 0;
    }
    repin(p, n);
    sort(all(p));

    auto it = std::find(p.begin(), p.end(), x);

    if (it == p.end()) {
        out(x);
        return 0;
    }

    ll o = std::distance(p.begin(), it);
    ll idx = std::distance(p.begin(), it);
    ll idx2 = idx;

    ll _max = x + 1;
    while (true) {
        idx++;
        if (idx == p.size()) {
            break;
        }
        if (p[idx] == _max) {
            _max++;
        } else {
            break;
        }
    }

    ll _min = x - 1;
    while (true) {
        idx2--;
        if (idx2 < 0) {
            break;
        }
        if (p[idx2] == _min) {
            _min--;
        } else {
            break;
        }
    }

    if (abs(o - idx) == abs(o - idx2)) {
        out(_min);
    } else if (abs(o - idx) < abs(o - idx2)) {
        out(_max);
    } else {
        out(_min);
    }
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

char buff[312345];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  scanf("%s", buff);
  string s = buff;
  vector<vector<int>> graph(n);
  vector<int> samedeg(n), diffdeg(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
    if (s[a] == s[b]) {
      samedeg[a]++;
      samedeg[b]++;
    }
    else {
      diffdeg[a]++;
      diffdeg[b]++;
    }
  }
  queue<int> removeQ;
  vector<bool> alive(n, true);
  for (int i = 0; i < n; i++) {
    if (samedeg[i] == 0 || diffdeg[i] == 0) {
      removeQ.push(i);
      alive[i] = false;
    }
  }
  while (!removeQ.empty()) {
    int cur = removeQ.front(); removeQ.pop();
    for (auto next : graph[cur]) {
      if (!alive[next]) continue;
      if (s[cur] == s[next]) {
        samedeg[next]--;
      }
      else {
        diffdeg[next]--;
      }
      if (samedeg[next] == 0 || diffdeg[next] == 0) {
        removeQ.push(next);
        alive[next] = false;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (alive[i]) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}


Measured memory_bytes: 12416
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nmq = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var q = new Query[nmq[2]];
            for (var i = 0; i < nmq[2]; i++)
            {
                var abcd = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
                q[i] = new Query { A = abcd[0], B = abcd[1], C = abcd[2], D = abcd[3] };
            }

            var max = 0L;
            void Dfs(IEnumerable<long> items)
            {
                var list = items.ToList();
                if (items.Count() == nmq[0] + 1)
                {
                    var current = 0;
                    current = q.Where(x => list.ElementAt(x.B - 1) - list.ElementAt(x.A - 1) == x.C).Sum(x => x.D);
                    max = Math.Max(max, current);
                    return;
                }

                list.Add(list.LastOrDefault() != 0 ? list.LastOrDefault() : 1);
                while (list.LastOrDefault() <= nmq[1])
                {
                    Dfs(list);
                    list[list.Count() - 1]++;
                }
            }
            Dfs(new long[] { 1 });
            Console.WriteLine(max);
        }

        public struct Query
        {
            public int A { get; set; }
            public int B { get; set; }
            public int C { get; set; }
            public int D { get; set; }

        }
    }
}


Measured memory_bytes: 41376
use std::io;

fn read_line() -> String {
    let mut s: String = String::new();
    io::stdin().read_line(&mut s).unwrap();
    return s.trim().to_string();
}

fn read_tokens() -> Vec<String> {
    return read_line().split(' ').map(|x| x.to_string()).collect();
}

fn read_ints() -> Vec<i64> {
    return read_line().split(' ').map(|x| x.parse::<i64>().unwrap()).collect();
}

fn main() {
    let nm = read_ints();
    let n = nm[0] as usize;
    let m = nm[1] as usize;

    let mut xs: Vec<i64> = Vec::new();
    let mut ys: Vec<i64> = Vec::new();
    let mut zs: Vec<i64> = Vec::new();

    for _ in 0..n {
        let ns = read_ints();
        xs.push(ns[0]);
        ys.push(ns[1]);
        zs.push(ns[2]);
    }

    let mut ans: i64 = 0;
    let can = vec![-1, 1];

    for xm in &can {
        for ym in &can {
            for zm in &can {
                let mut dp: Vec<i64> = vec![-1e15 as i64; m + 1];
                dp[0] = 0;

                for i in 0..n {
                    for j in 0..m {
                        dp[m - j] = std::cmp::max(dp[m - j], dp[m - j - 1] + xs[i] * xm + ys[i] * ym + zs[i] * zm)
                    }
                }

                ans = std::cmp::max(ans, dp[m]);
            }
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

int main()
{
    int n,a1,a2,a3,a4;
    cin>>n;
    a1=n%10;
    a2=(n/10)%10;
    a3=(n/100)%10;
    a4=(n/1000)%10;
    if(((a4==a3)&&(a3==a2))||((a1==a2)&&(a2==a3)))
       cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256