akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

ll imo[100000+20];
//-------------------------↓↓↓↓↓↓------------------------

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      ll n, m, a, b;
      cin >> n >> m;
      for(int i = 0; i < m; i++){
        cin >> a >> b;
        a--;b -= 2;
        imo[a]++;
        imo[b + 1]--;
      }
      for(int i = 1; i < 100000+10; i++){
        imo[i] += imo[i - 1];
      }
      for(int i = 0; i < n; i++){
        if(imo[i] % 2 == 1){
          cout << "NO\n";
          return 0;
        }
      }
      cout<<"YES\n";
    
       
return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
const long long N=200200;
const long long p=1e9+7;
  
long long a[N],n,b[N],f[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  f[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i - 1]) {
      f[i] = f[i - 1];
    } else {
      f[i] = (f[i - 1] + b[a[i]]) % p;
      b[a[i]] = f[i];
    }
  }
  cout << f[n] << endl;
}

Measured memory_bytes: 8320
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
cnt = 0
for b in B:
  pos_a = bisect.bisect_left(A, b)
  pos_c = bisect.bisect_right(C, b)
  cnt += pos_a * (N-pos_c)
print(cnt)

Measured memory_bytes: 23360
#include<bits/stdc++.h>
#include"unistd.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main(void)
{
    int n,d;
    while(cin >> n >> d && n)
    {
        vector<pii> nation(105);
        vector<int> missiles[105];
        for(int i=0;i<n;i++)
        {
            nation[i].first=0;
            nation[i].second=0;
            int m;
            cin >> m;
            int total=0;
            missiles[i].resize(m);
            for(int j=m-1;j>=0;j--)
            {
                int c;
                cin >> c;
                missiles[i][j]=c;
                total+=c;
            }
            nation[i]=(pii(total,0));
        }
        while(1)
        {
            bool notchange=true;
            for(int i=0;i<n;i++)
            {
                bool change=true;
                if(nation[i].first==0) continue;
                else
                {
                    int nxtindex,nxttotal;
                    nxtindex=nation[i].second;
                    nxttotal=nation[i].first-missiles[i][nxtindex];
                    for(int j=0;j<n;j++)
                    {
                        if(i==j)continue;
                        if(nation[j].first-nxttotal>d)
                        {
                            change=false;
                            break;
                        }
                    }
                    if(change)
                    {
                        nation[i]=(pii(nxttotal,nxtindex+1));
                    }
                }
                if(change) notchange=false;   
            }
            if(notchange) break;
        }
        bool clear=true;
        for(int i=0;i<n;i++)
        {
            if(nation[i].first!=0){
                cout << "No" << endl;
                clear=false;
                break;
            }
        }
        if(clear) cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3032
#pragma GCC optimize("O3", "unroll-loops")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <complex>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FIXED cout << fixed << setprecision(4);
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)])

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

signed main() {
    FAST; FIXED; RANDOM;
    int n;
    cin >> n;
    graph G(n);
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].pb(b);
        G[b].pb(a);
    }
    vector<ll> c(n), d(n);
    cin >> c;
    sort(c);
    set<pii> st;
    vector<int> cnt(n);
    for (int i = 0; i < n; ++i) cnt[i] = sz(G[i]), st.insert({cnt[i], i});
    vector<bool> used(n);
    int ptr = 0;
    while (sz(st)) {
        int f = st.begin()->s;
        st.erase(st.begin());
        used[f] = true;
        d[f] = c[ptr++];
        for (auto i : G[f])
            if (!used[i]) {
                st.erase({cnt[i], i});
                --cnt[i];
                st.insert({cnt[i], i});
            }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i)
        for (auto j : G[i])
            ans += min(d[i], d[j]);
    cout << ans / 2 << '\n';
    for (auto i : d) cout << i << ' ';
    return 0;
}   


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

int main() {
  int w, n;
  vector<int> l;
  cin >> w; cin >> n;
  for (int i = 0; i < w; i++) l.push_back(i + 1);
  for (int i = 0; i < n; i++) {
    int a, b; char comma;
    cin >> a >> comma >> b; a--; b--;
    int buf = l[a]; l[a] = l[b]; l[b] = buf;
  }
  for (int i = 0; i < w; i++) cout << l[i] << endl;
  return 0;
}


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

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    mint choose(int n, int a){
        mint x = 1 ,y = 1;
        for(int i = 0; i < a; ++i){
            x *= n-i;
            y *= i+1;
        }
        return x / y;
    }
    friend istream& operator>>(istream& is, mint& m){
        is >> m.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

mint dp[100010][2];

int main(){
  string s;
  cin>>s;
  int n=s.size();
  dp[0][0]=1;
  for(int i=0; i<n; ++i){
    int D=s[i]-'0';
    dp[i+1][1]+=dp[i][1]*3;
    if(D==1){
      dp[i+1][0]+=dp[i][0]*2;
      dp[i+1][1]+=dp[i][0];
    }
    else{
      dp[i+1][0]+=dp[i][0];
    }
  }
  cout<<dp[n][0]+dp[n][1]<<endl;
}

Measured memory_bytes: 5324
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <limits>

using namespace std;
using ll = unsigned long long int;

ll calc_bit(vector<int> &bit)
{
  ll result = 0;
  ll temp = 1;
  for(int i = 0; i < bit.size(); i++)
  {
    if(bit[i] == 1)
    {
      result += temp;
    }
    temp *= 2;
  }
  return result;
}

int main()
{
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  //美しさの列挙
  vector<ll> beautiy;
  for(int i = 0; i < n; i++)
  {
    ll temp = 0;
    for(int j = i; j < n; j++)
    {
      temp += a[j];
      beautiy.push_back(temp);
    }
  }

  //bit列の用意
  vector<int> bit(40, 0);
  //各bitに対してそのbitを1にすることができるか大きい方から試していく
  for(int i = 39; i >= 0; i--)
  {
    vector<int> temp = bit;
    temp[i] = 1;
    ll check = calc_bit(temp);
    int count = 0;
    for(int j = 0; j < beautiy.size(); j++)
    {
      if((check & beautiy[j]) == check)
      {
        count++;
      }
    }
    if(count >= k)
    {
      bit[i] = 1;
    }
  }
  cout << calc_bit(bit) << endl;
  return 0;
}


Measured memory_bytes: 6256
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Set;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	static Node[] V;
	
	public static void main(String[] args) {
		int Vn = sc.nextInt();
		int En = sc.nextInt();
		int r = sc.nextInt();
		
		V = new Node[Vn]; 
		for(int i=0; i<Vn; i++) {
			V[i] = new Node();
		}
		
		for(int i=0; i<En; i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			int d = sc.nextInt();
			V[s].nbr.add(new Edge(t, d));
		}
		
		PriorityQueue<Node> cdt = new PriorityQueue<>((a, b) -> a.min - b.min);
		cdt.add(V[r]);
		V[r].min = 0;
		
		while(!cdt.isEmpty()) {
			Node n = cdt.poll();
			for(Edge e : n.nbr) {
				if(n.min + e.d < V[e.t].min) {
					V[e.t].min = n.min + e.d;
					if(cdt.contains(V[e.t])) {
						cdt.remove(V[e.t]);
					}
					cdt.add(V[e.t]);
				}
			}
		}
		
		StringBuilder ans = new StringBuilder();
		for(int i=0; i<Vn; i++) {
			if(V[i].min == Integer.MAX_VALUE) {
				ans.append("INF");
			} else {
				ans.append(V[i].min);
			}
			ans.append("\n");
		}
		System.out.print(ans);
	}
	
	static class Node {
		int min = Integer.MAX_VALUE;
		Set<Edge> nbr = new HashSet<>();
	}
	
	static class Edge {
		int t;
		int d;
		
		Edge(int t, int d) {
			this.t = t;
			this.d = d;
		}
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 145756
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int hanako[220];
int taro[220];

int main(){
    int n;
    while(cin >> n, n){
        fill(hanako, hanako+220, false);
        fill(taro, taro+220, false);

        for(int i=0; i < n; i++){
            int m;
            cin >> m;
            taro[m] = true;
        }
        for(int i=1; i <= n*2; i++){
            if(!taro[i]) hanako[i] = true;
        }

        bool player = true;
        int card = 0;
        while(true){
            int hanako_num = 0;
            int taro_num = 0;
            for(int i=0; i <=n*2; i++) if(hanako[i]) hanako_num++;
            for(int i=0; i <=n*2; i++) if(taro[i]) taro_num++;
            if(hanako_num == 0 || taro_num == 0) break;

            bool isExist = false;
            int submit = 0;
            if(player){
                for(int i=card+1; i<=n*2; i++) if(taro[i]){isExist = true; submit = i; taro[i] = false;break;}
            }else {
                for(int i=card+1; i<=n*2; i++) if(hanako[i]){isExist = true; submit = i; hanako[i] = false;break;}
            }

            if(!isExist) card = 0;
            else card = submit;

            player = !player;
        }
        int count = 0;
        for(int i=0; i <= n*2; i++) if(hanako[i]) count++;
        cout << count << endl;
        count = 0;
        for(int i=0; i <= n*2; i++) if(taro[i]) count++;
        cout << count << endl;
    }
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
	long long mod=1000000007;
	
	long long res=0;
	for(int i=0;i<61;i++){
		int no0=0,no1=0;
		for(int j=n-1;j>=0;j--){
			int bit=(a[j]>>i)&1;
			if(bit==1){
				res=(res+(1LL<<i)%mod*no0%mod)%mod;
				no1++;
			}else{
				res=(res+(1LL<<i)%mod*no1%mod)%mod;
				no0++;
			}
		}
	}
	cout << res << "\n";
	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n;
int A[111111];
int q;


int solve(int key) {
   auto check = [&](int mid) -> bool {
      // 判定処理を書く
      // 閉区間の方を >=, <= にする
      return A[mid] >= key;
   };

   int ok = n; // 解が存在する値
   int ng = -1; // 解が存在しない値

   while (abs(ok - ng) > 1) {
      int mid = (ok + ng) / 2;
      if (check(mid)) {
         ok = mid;
      } else {
         ng = mid;
      }
   }

   return A[ok] == key;
}

int main() {
   cin >> n;
   rep (i, n) { cin >> A[i]; }

   int ans = 0;
   cin >> q;
   while (q--) {
      int x;
      cin >> x;
      ans += solve(x);
   }

   cout << ans << endl;

   return 0;
}


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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#define db(x) cout << "> " << #x << " = " \
	<< (x) << '\n'
#define db2(x, y) cout << "> " << #x << " = " \
	<< (x) << ", " << #y << " = " << (y) << '\n'
#define db3(x, y, z) cout << "> " << #x << \
	" = " << (x) << ", " << #y << " = " << \
	(y) << ", " << #z << " = " << (z) << '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mii;
typedef set<int> si;

int n, l;

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin >> n >> l;
	int sum = 0;
	for (int i = 1; i <= n; ++i) {
		sum += l + i - 1;
	}
	int minDiff = OO, ans;
	for (int i = 1; i <= n; ++i) {
		int diff = abs(l + i - 1);
		if (diff < minDiff)
			minDiff = diff, ans = sum - (l + i - 1);
	}
	cout << ans << '\n';
	return 0;
}


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

int main (void){
  int n;
  int d[50];
  cin >> n;
  for(int i = 0; i < n ; i++){
    cin >> d[i];
  }
  
  int sum = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i == j) continue;
      sum += d[i]*d[j];
    }
  }
  cout << sum / 2;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
char g[110][110];
int ans[110][110];
int main() {
    int i, j, k;
    int n, t, m;
    int r, c;
    cin >> r >> c;
    for(i = 0; i < r; i++) {
        scanf("%s", &g[i]);
    }
    memset(ans, 0x3f, sizeof(ans));
    ans[0][0] = (g[0][0] == '#');
    for(i = 0; i < r; i++) {
        for(j = 0; j < c; j++) {
            if(i-1 >= 0) {
                int tmp = ans[i-1][j];
                if(g[i][j] == '#' && g[i-1][j] != '#') tmp++;
                ans[i][j] = min(ans[i][j], tmp);
            }
            if(j-1 >= 0) {
                int tmp = ans[i][j-1];
                if(g[i][j] == '#' && g[i][j-1] != '#') tmp++;
                ans[i][j] = min(ans[i][j], tmp);
            }
        }
    }
    printf("%d\n", ans[r-1][c-1]);
    return 0;
}


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

using namespace std;

#define ll 			long long
#define db			double
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cadd(a,b)		a = add (a, b)
#define cpop(a,b)		a = pop (a, b)
#define cmul(a,b)		a = mul (a, b)
#define pr			pair<int, int>
#define fi			first
#define se			second
#define SZ(x)		(int)x.size()
#define bin(i)		(1 << (i))
#define Auto(i,node)	for (int i = LINK[node]; i; i = e[i].next)

template<typename T> inline bool cmax(T & x, T y){return y > x ? x = y, true : false;}
template<typename T> inline bool cmin(T & x, T y){return y < x ? x = y, true : false;}
template<typename T> inline T dmax(T x, T y){return x > y ? x : y;}
template<typename T> inline T dmin(T x, T y){return x < y ? x : y;}

const ll oo = 1e18;

int main(){
#ifdef cydiater
	freopen("input.in", "r", stdin);
#endif
	ll a, b, c, n;
	cin >> a >> b >> c >> n;
	printf("%lld\n", !(n & 1) ? a - b : b - a);
	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func sum(a []float64) float64 {
	ret := 0.0
	for _, v := range a {
		ret += v
	}
	return ret
}

func max(nums ...float64) float64 {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	p := nextFloat64s(n)
	s := sum(p[0:k])
	maxSum := s
	for i := 1; i <= n-k; i++ {
		s = s - p[i-1] + p[i+k-1]
		maxSum = max(maxSum, s)
	}
	ans := (float64(k) + maxSum) / 2.0
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


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

long long memo[10][10];

int main(){
	int n;	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%10==0)continue;

		int b=i;

		int a=b%10;
		while(b>=10)b/=10;

		memo[b][a]++;
	}

	long long ans=0;
	for(int i=1;i<=n;i++){
		if(i%10==0)continue;

		int b=i;

		int a=b%10;
		while(b>=10)b/=10;
		//printf("%d: [%d--%d]\n",i,b,a);

		ans+=memo[a][b];
	}
	cout<<ans<<endl;



	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int X = Integer.parseInt(st.nextToken());
        int T = Integer.parseInt(st.nextToken());

        int result = 0;

        while(N > 0) {
            N = N - X;
            result += T;

        }

        pw.println(result);
        br.close();
        pw.close();
    }
}

Measured memory_bytes: 32844
/**
 *    author:  tourist
 *    created: 26.11.2019 11:55:10       
**/
#include <bits/stdc++.h>

using namespace std;

class dsu {
 public:
  vector<int> p;
  int n;

  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  inline int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }

  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<tuple<int, int, int>> e(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    --x; --y;
    e[i] = make_tuple(z, x, y);
  }
  sort(e.rbegin(), e.rend());
  vector<int> info(n);
  for (int i = 0; i < n; i++) {
    info[i] = i;
  }
  vector<int> sz(n, 1);
  vector<int> pv(2 * n, -1);
  vector<long long> pe(2 * n, 0);
  dsu d(n);
  int cnt = n;
  for (auto& ee : e) {
    int z = get<0>(ee);
    int x = get<1>(ee);
    int y = get<2>(ee);
    x = d.get(x);
    y = d.get(y);
    pv[info[x]] = cnt;
    pv[info[y]] = cnt;
    pe[info[x]] = sz[y] * 1LL * z;
    pe[info[y]] = sz[x] * 1LL * z;
    info[y] = cnt;
    sz[y] += sz[x];
    d.p[x] = y;
    ++cnt;
  }
  for (int i = cnt - 2; i >= 0; i--) {
    pe[i] += pe[pv[i]];
  }
  for (int i = 0; i < n; i++) {
    cout << pe[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 6400
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int n, k, q;
	cin >> n >> k >> q;
	vint a(n, 0);
	rep(i, q) {
		int x;
		cin >> x;
		a[x - 1]++;
	}
	rep(i, n) {
		Yes(a[i] > q - k);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	string S,T;
	cin>>S>>T;
	T+=S;
	cout<<T<<endl;
	return 0;
}


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

int main() {
	int H,W;
  	cin >> H >> W;
  
  	vector<vector<char>> board(H,vector<char>(W));
  
  	for(int i = 0; i < H; i++) {
    	for(int j = 0; j < W; j++) {
        	cin >> board.at(i).at(j);
        }
    }
  
  	vector<int> distx = {1,-1,0,0,1,1,-1,-1};
  	vector<int> disty = {0,0,1,-1,1,-1,1,-1};
  
  	for(int i = 0; i < H; i++) {
   		for(int j = 0; j < W; j++) {
        
         if(board.at(i).at(j) == '#') continue;
          	
         int num = 0;
         for(int k = 0; k < 8; k++) {
         	int ni = i + distx.at(k);
           	int nj = j + disty.at(k);
           
           	if(ni < 0 || ni >= H) continue;
           	if(nj < 0 || nj >= W) continue;
           
           	if(board.at(ni).at(nj) == '#') num++;
         }
          
          	board.at(i).at(j) = char(num + '0');
         }
    }
  
  		for(int i = 0; i < H; i++) {
    		for(int j = 0; j < W; j++) {
        		cout << board.at(i).at(j);
        }
          cout << endl;
    }
}

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

using namespace std;

#ifdef LOCAL
  #include "debug.h"
#else
  #define debug(...) 42
#endif

struct dsu {
  vector<int> p;
  vector<int> r;

  dsu(int n) {
    p.resize(n + 1);
    r.resize(n + 1);
    for (int i = 1; i <= n; i++) {
      p[i] = i;
      r[i] = 1;
    }
  }
  
  int find(int u) {
    if (p[u] == u) {
      return u;
    } 
    return p[u] = find(p[u]);
  }

  void unite(int u, int v) {
    u = find(u), v = find(v);
    if (u != v) {
      if (r[u] < r[v]) {
        swap(u, v);
      }
      p[v] = u;
      r[u] += r[v];
    }
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  dsu d(n + 1);
  while (m--) {
    int x, y;
    cin >> x >> y;
    d.unite(x, y);
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    int par = d.find(i);
    ans = max(ans, d.r[par]);
  }
  cout << ans << '\n';
}


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

using namespace std;


int main() {
    string s;
    cin >> s;
    if (s == "Sunny") {
    cout << "Cloudy"; }
    else {
        if (s == "Cloudy") {
            cout << "Rainy";
        } else {
            cout << "Sunny";
        }
    }

    return 0;
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = [int(_) for _ in input().split()]
A = []
for i in range(N):
    A.append([int(_) for _ in input().split()])

right = 0

for i in range(N):
    src = 0
    for j in range(M):
        src += A[i][j]*B[j]
    if src+C>0:
        right+=1

print(right)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int N, M;
	cin >> N >> M;

	vector<int> a(M);
	vector<int> b(M);
	vector<int> city(N+1);// 都市の番号は１～Ｎ

	for (int i = 0; i < M; i++)
	{
		cin >> a.at(i) >> b.at(i);
		city.at(a.at(i))++;
		city.at(b.at(i))++;
	}
	
	for (int j = 1; j <= N; j++)// 都市の番号は１～Ｎ
	{
		cout << city.at(j) << endl;
	}
}

Measured memory_bytes: 256
x,y=map(int,input().split())
if 0<=x<y or x<y<=0:print(y-x)
elif y<x==0:print(1-y)
elif 0==y<x:print(1+x)
elif y<x<0 or 0<y<x:print(x-y+2)
elif x<0<y and abs(x)<=abs(y):print(y+x+1)
elif x<0<y and abs(x)>abs(y):print(-x-y+1)
elif y<0<x and abs(x)<=abs(y):print(-x-y+1)
elif y<0<x and abs(x)>abs(y):print(y+x+1)

Measured memory_bytes: 3064
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    int A;
    string S;
    
    bool operator<( const Data& right ) const {
        return A == right.A ? S < right.S : A < right.A;
        //return A < right.A;
    }
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    int N, M;
    int K[30];
    int A[30][30];
    
    cin >> N >> M;
    
    for (int i=0;i<N;i++) {
        cin >> K[i];
        for (int j=0;j<K[i];j++) {
            cin >> A[i][j];
        }
    }
    
    int result[30] = {};
    
    for (int i=0;i<N;i++) {
        for (int j=0;j<K[i];j++) {
            result[A[i][j]-1] += 1;
        }
    }
    
    int count = 0;
    for (int i=0;i<M;i++) {
        if (result[i]==N) count += 1;
    }
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (n); i += (s))
#define rep(...) _overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void print(const T& x) {cout << x << "\n";}
template<typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
struct Init {Init() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10);}} init;

int main() {
    ll n; cin >> n;
    ll ans = 0;
    rep(i, 1, n + 1) {
        ll m = n / i;
        ans += m * (m + 1) * i / 2;
    }
    print(ans);
}

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  3 19:52:44 2019

@author: Yamazaki Kenichi
"""

A,B,K = map(int,input().split())

counta = 0
ans = []
for i in range(1,101):
    if A%i == 0 and B%i == 0:
        ans.append(i)
print(ans[-K])

Measured memory_bytes: 2940
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut vec: Vec<usize> = Vec::with_capacity(n);
    for _i in 0..n {
        vec.push(iterator.next().unwrap().parse().unwrap());
    }

    vec.sort();

    let a = vec[n / 2 - 1];
    let b = vec[n / 2];

    return if a == b {
        String::from("0")
    } else {
        format!("{}", b - a)
    };
}


Measured memory_bytes: 6396
import * as fs from "fs";

let S = fs.readFileSync("/dev/stdin", "utf8").trim();

// BWBWBW = 6
let position = S.length-1;
let answer = 0;
for(let i=S.length-1; i>=0; i--) {
    if (S[i] == 'B') {
        answer += position-i;
        position -= 1;
    }
}
console.log(answer);


Measured memory_bytes: 33328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    bool ok_p = true, ok_n = true;
    rep(i,n){
        if(a[i] > 0) ok_n = false;
        if(a[i] < 0) ok_p = false;
    }
    if(ok_n){
        cout << n-1 << endl;
        for(int i = n; i >= 2; i--){
            cout << i << " " << i-1 << endl;
        }
        return 0;
    }
    if(ok_p){
        cout << n-1 << endl;
        rep(i,n-1){
            cout << i+1 << " " << i+2 << endl;
        }
        return 0;
    }
    int b = -1e7, s = 1e7;
    int pos_b,pos_s;
    rep(i,n){
        if(b < a[i]){
            b = a[i];
            pos_b = i+1;
        }
        if(s > a[i]){
            s = a[i];
            pos_s = i+1;
        }
    }

    if(abs(b) >= abs(s)){
        cout << 2*n - 1 << endl;
        rep(i,n){
            cout << pos_b << " " << i+1 << endl;
        }
        rep(i,n-1){
            cout << i+1 << " " << i+2 << endl;
        }
        return 0;
    }else{
        cout << 2*n - 1 << endl;
        rep(i,n){
            cout << pos_s << " " << i+1 << endl;
        }
        for(int i = n; i >= 2; i--){
            cout << i << " " << i-1 << endl;
        }
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    string str;
    cin >> str;
    string T;
    cin >> T;

    REP(a,str.size()){
        bool result = true;
        REP(b,str.size()){
            if(str.at(((a+b)%(str.size()))) != T.at(b)){
                result = false;
            }
        }
        if(result){
            COUT("Yes");
            return 0;
        }
    }
    COUT("No");
    return 0;
}


Measured memory_bytes: 256
N, T=list(map(int, input().split()))
CT=[list(map(int, input().split())) for i in range(N)]
ans=[]
CT = sorted(CT, key = lambda x:x[0] )
for i in range(N):
    if CT[i][1]<=T:
        ans.append(CT[i])
if ans ==[]:
    print('TLE')
else:
    print(ans[0][0])

Measured memory_bytes: 3060
/* package whatever; // don't place package name! */
 
import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc =new Scanner(System.in);
		while(sc.hasNext()){
			int a=sc.nextInt();
		    int b=sc.nextInt();
			int c=sc.nextInt();
		    int x=sc.nextInt();
		    int n=0;
		    for(int i=0;i<=a;i++){
		    	 for(int j=0;j<=b;j++){
		    	 for(int k=0;k<=c;k++){
		    	 	 	if((i*500+j*100+k*50)==x){
		    	 	 		n++;
		    	 	 	}
		    	 	 }
		    	 	
		    	 }
		    }
		    System.out.println(n);
		    
			
			
			
			
		}
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

void dump(ll *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

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

	int n;
	cin >> n;
	int p[n];
	int a[n];
	rep(i,n) cin >> p[i];
	a[0]=1;
	FOR(i,1,n) a[i]=a[i-1]+n;
	rep(i,n) a[p[i]-1]+=i;

	rep(i,n) cout << a[i] << " \n"[i==n-1];
	rep(i,n) cout << 1+n*(n-1-i) << " \n"[i==n-1];

	return 0;
}

Measured memory_bytes: 768
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

    static long N;
//    static int M;
    static int A;
    static long B;
    static long C;
    //    static int[][] map;
    static int min = 9999999;


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s = scanner.nextLine();

        Long M = scanner.nextLong();

        if(s.charAt(0) != '1'){
            System.out.println(s.charAt(0));
        }else{
            for (int i = 0; i < s.length(); i++) {
                if(i == M - 1){
                    System.out.println(s.charAt(i));
                    break;
                }
                if(s.charAt(i) != '1'){
                    System.out.println(s.charAt(i));
                    break;
                }
            }


        }

    }
}



Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    auto mp = min_element(all(A)), Mp = max_element(all(A));
    ll mi = mp - A.begin(), Mi = Mp - A.begin();

    vc<pair<ll, ll>> ans;
    if(abs(*mp)<abs(*Mp)){
        rep(i, N) if (i != Mi) ans.eb(Mi, i);
        ans.eb(Mi, Mi);
        rep(i, N - 1) ans.eb(i, i + 1);
    }
    else{
        rep(i, N) if (i != mi) ans.eb(mi, i);
        ans.eb(mi, mi);
        repr(i, N - 1) ans.eb(i + 1, i);
    }

    cout << ans.size() << '\n';
    repa(p, ans) cout << p.first + 1 << " " << p.second + 1 << '\n';
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//

int main(){
    int k;
    string s;
    cin >> k >> s;
    if(s.size() <= k) cout << s;
    else{
        cout << (s.substr(0, k) + "...");
    }
}

Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
T, D = {i: [] for i in range(N)}, [-1] * N
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    T[a - 1].append((b - 1, c))
    T[b - 1].append((a - 1, c))


def dfs(p, c, d):
    D[c] = d
    for c2, d2 in T[c]:
        if c2 != p:
            dfs(c, c2, d + d2)


Q, K = map(int, input().split())
dfs(-1, K - 1, 0)
for _ in range(Q):
    x, y = map(int, input().split())
    print(D[x - 1] + D[y - 1])


Measured memory_bytes: 140128
def phi(n):
    res = n
    i = 2
    while i * i <= n:
        if n % i == 0:
            res = res // i * (i - 1)
            while n % i == 0:
                n //= i
        i += 1
    if n != 1:
        res = res // n * (n - 1)
    return res


def divisors(n):
    sq = int(n ** .5)
    res = ((i, n // i) for i in range(1, sq + 1) if n % i == 0)
    from itertools import chain
    flatten = chain.from_iterable
    return sorted(set(flatten(res)))


def f(K):
    L = 9 * K
    if K % 7 == 0:
        L //= 7
    r1 = phi(L)
    for d in divisors(r1):
        if pow(10, d, L) == 1:
            return d
    return -1


###
if __name__ == '__main__':
    K = int(input())
    res = f(K)
    print(res)

Measured memory_bytes: 9228
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    if(S[1] == 'B')S[1] = 'R';
    else if(S[1] == 'R') S[1] = 'B';
    cout << S << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll N; cin >> N;
    ll ans = 0;

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

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3652
#include<stdio.h>

int line,row;
char map[11][11];
bool vis[11][11];

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

int total;
int finalans[1100];
int recordans;
bool dfs(int x,int y,int now,int step)
{
	int ind=(now+4-1)%4;
	int nowx=x+dx[ind],nowy=y+dy[ind];
	while(nowx>=0&&nowx<line&&nowy>=0&&nowy<row)
	{
		if(map[nowx][nowy]=='o'&&!vis[nowx][nowy])break;
		nowx=nowx+dx[ind],nowy=nowy+dy[ind];
	}
	
	if(nowx>=0&&nowx<line&&nowy>=0&&nowy<row)
	{
		vis[nowx][nowy]=true;
		if(dfs(nowx,nowy,ind,step+1))
		{
			finalans[recordans++]=ind;
			return true;
		}
		vis[nowx][nowy]=false;
	}
	
	ind=now;
	nowx=x+dx[ind],nowy=y+dy[ind];
	while(nowx>=0&&nowx<line&&nowy>=0&&nowy<row)
	{
		if(map[nowx][nowy]=='o'&&!vis[nowx][nowy])break;
		nowx=nowx+dx[ind],nowy=nowy+dy[ind];
	}
	if(nowx>=0&&nowx<line&&nowy>=0&&nowy<row)
	{
		vis[nowx][nowy]=true;
		if(dfs(nowx,nowy,ind,step+1))
		{
			finalans[recordans++]=ind;
			return true;
		}
		vis[nowx][nowy]=false;
		
		
	}
	
	ind=(now+1)%4;
	nowx=x+dx[ind],nowy=y+dy[ind];
	while(nowx>=0&&nowx<line&&nowy>=0&&nowy<row)
	{
		if(map[nowx][nowy]=='o'&&!vis[nowx][nowy])break;
		nowx=nowx+dx[ind],nowy=nowy+dy[ind];
	}
	if(nowx>=0&&nowx<line&&nowy>=0&&nowy<row)
	{
		vis[nowx][nowy]=true;
		if(dfs(nowx,nowy,ind,step+1))
		{
			finalans[recordans++]=ind;
			return true;
		}
		vis[nowx][nowy]=false;
	}
	
	if(step==total)return true;
	return false;
}

int main()
{
	scanf("%d%d",&line,&row);
	
	int i,j;
	int startx,starty;
	total=0;
	for(i=0;i<line;i++)
	{
		scanf("%s",map[i]);
		
		for(j=0;j<row;j++)
		{
			if(map[i][j]=='o')total++;
			else if(map[i][j]=='.')continue;
			else
			{
				startx=i;
				starty=j;
			}
		}
	}
	
	vis[startx][starty]=true;
	if(map[startx][starty]=='U')dfs(startx,starty,0,0);
	else if(map[startx][starty]=='R')dfs(startx,starty,1,0);
	else if(map[startx][starty]=='D')dfs(startx,starty,2,0);
	else if(map[startx][starty]=='L')dfs(startx,starty,3,0);
	finalans[recordans++]=map[startx][starty];
	
	for(i=total-1;i>=0;i--)
	{
		if(finalans[i]==0)printf("U");
		else if(finalans[i]==1)printf("R");
		else if(finalans[i]==2)printf("D");
		else printf("L");
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 1004