akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int x =sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    if (b<=a){
      System.out.println("delicious");
    } else if (b-x>a) {
      System.out.println("dangerous");
    } else {
      System.out.println("safe");
    }
  }
}

Measured memory_bytes: 22736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    ll n;
    ll br = 2;
    cin >> n;
    ll pomn = n;
    ll res = 0;
    while(br * br <= pomn){
        if(n%br){
            br++;
            continue;
        }
        ll kol = 0;
        while(n%br == 0){
            kol++;
            n /= br;
        }
        ll tr = 1;
        while(kol > 0){
            if(tr > kol)break;
            res++;
            kol -= tr;
            tr++;
        }
        br++;
    }
    if(n != 1)res++;
    cout << res << "\n";
    return 0;
}


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

int main(){
  string s;
  getline(cin,s);

  for(int i=0;s[i]!='\0';i++){
    if('a' <= s[i] && s[i] <= 'z'){
      s[i]=s[i]-32;
      cout<<s[i];
    }
    else if('A' <= s[i] && s[i] <= 'Z') {
      s[i]=s[i]+32;
     cout<<s[i];
    }
    else cout<<s[i];
  }
  cout<<endl;
  return 0;
}


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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

int n, m, a[1009], b[1009];

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

    cin >> n >> m;
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    sort(a, a + n, greater<int>());
    sort(b, b + m, greater<int>());
    ll ans = 1;
    int x = 0, y = 0;
    for(int i = n * m; i; i--) {
        if(a[x] != i && b[y] != i) {
            ans *= x * y + i - n * m;
        } else if(a[x] == i && b[y] == i) {
            x++;
            y++;
        } else if(a[x] == i && b[y] != i) {
            x++;
            ans *= y;
        } else {
            y++;
            ans *= x;
        }
        ans %= mod;
    }

    cout << ans << endl;
}

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

int main(){
    while(1){
        string str;
        cin>>str;
        if(str=="0"){
            break;
        }
        int sum=0;
        for(int i=0;i<(int)str.size();i++){
            sum+=str[i]-'0';
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 3144
s = list(input())

max = 0
for i in range(len(s)):
    for j in reversed(range(len(s) + 1)):
        cnt = 0
        for k in range(i, j):
            if s[k] == "A" or s[k] == "C" or s[k] == "G" or s[k] == "T":
                cnt += 1
            else:
                cnt = 0
                break
        if max < cnt:
            max = cnt
print(max)

Measured memory_bytes: 3060
N, W = map(int, input().split())
w = [0]
v = [0]

for _ in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [[0 for col in range(W+1)] for row in range(N+1)]

#dp[i][j] = i番目までのお菓子の中から，ナップサックの中のお菓子の重さの総和がjを超えないようにいくつかお菓子を選んで詰めるとき，価値の最大値

for i in range(1, N+1):
    for j in range(1, W+1):
        if j - w[i] >= 0: #ex.ナップサックの耐加重がj=100,で, i番目のお菓子の重さが20である場合，ナップサックに追加することができるのは，i-1番目までのお菓子でまだ80以下の重さしかないとき。
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i])

        dp[i][j] = max(dp[i][j], dp[i-1][j])

print(dp[N][W])

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

typedef struct
{
  int start;
  string time;
} Train;

class LessTime
{
public:
  bool operator() (const Train& lhs, const Train& rhs)
  {
    if (lhs.time == rhs.time)
      return lhs.start < rhs.start;
    return lhs.time < rhs.time;
  }
};

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<Train> train(2*n);
    for (int i = 0; i < 2*n; ++i) {
      cin >> train[i].time;
      if (i&1)
	train[i].start = 0;
      else
	train[i].start = 1;
    }

    sort(train.begin(), train.end(), LessTime());
    int ans = 0, pool = 0;
    for (int i = 0; i < train.size(); ++i) {
      if (train[i].start == 1) {
	if (pool == 0)
	  ++ans;
	else
	  --pool;
      } else {
	++pool;
      }
    }

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

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

int main(){

  char s[3];
  
  rep(i,3){
    cin >> s[i];
  }
  
  if(s[0] != s[1] || s[0] != s[2] || s[1] != s[2]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
    
    return 0;
}


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

a=[]
b=[0]*K
d=[0]*K

 
for i in range(K):
  d[i] = int(input())
  a.append(list(map(int, input().split())))

  
dic = {}

for i in a:
  for j in i:
    dic[j] = 1

#print(dic)
print(N-len(dic))

Measured memory_bytes: 67736
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 998244353
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int a, b;

	cin>>a>>b;

	if(a==1) a=14;
	if(b==1) b=14;

	if(a>b){
		cout<<"Alice"<<endl;
	} else if(a==b){
		cout<<"Draw"<<endl;
	} else{
		cout<<"Bob"<<endl;
	}
	
}


Measured memory_bytes: 256
using System;
class Program{
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		int[] a=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int[] s=new int[n];
		int b=n%2,c=n/2;
		s[c]=a[0];
		for(int i=1;i<n;i++){
			if(i%2==b){s[c+(i+1)/2]=a[i];}
			else {s[c-(i+1-b)/2]=a[i];}
		}
		Console.WriteLine("{0}",string.Join(" ",s));
	}
}

Measured memory_bytes: 49816
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define SZ(a) (int)(a).size()
typedef long long ll;

int main() {
	cin.sync_with_stdio(false);
	bool ans = true;
	int n;
	cin >> n;
	for (auto i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x & 1) {
			ans = !ans;
		}
	}
	puts(ans ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

int main()
{
  int N = 0;
  std::cin >> N;
  std::vector<int> n(N);
  for (int i = 0; i < N; ++i)
    n[i] = i;
  std::vector<int> x(N), y(N);
  for (int i = 0; i < N; ++i)
    std::cin >> x[i] >> y[i];
  double sum = 0.;
  size_t counter = 0;
  do
  {
    ++counter;
    for (int i = 0; i < N - 1; ++i)
    {
      double _x = x[n[i + 1]] - x[n[i]];
      double _y = y[n[i + 1]] - y[n[i]];
      sum += sqrt(_x*_x + _y*_y);
    }
  }
  while (std::next_permutation(n.begin(), n.end()));
  std::cout << std::setprecision(std::numeric_limits<double>::max_digits10) << sum/counter << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static long M;

	public static void main(String[] args) {
		int N = sc.nextInt();
		M = sc.nextInt();
		ArrayList<ArrayList<Integer>> g = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			g.add(new ArrayList<>());
		}
		for (int i = 0; i < N - 1; i++) {
			int X = sc.nextInt() - 1;
			int Y = sc.nextInt() - 1;
			g.get(X).add(Y);
			g.get(Y).add(X);
		}
		int[] parent = new int[N];
		Arrays.fill(parent, -1);
		parent[0] = 0;
		int[] order = new int[N];
		for (int i = 0, pos = 1; i < N; i++) {
			int cur = order[i];
			for (int child : g.get(cur)) {
				if (parent[child] != -1) continue;
				order[pos++] = child;
				parent[child] = cur;
			}
		}
		parent[0] = -1;
		for (int i = 1; i < N; i++) {
			g.get(order[i]).remove((Integer) parent[order[i]]);
		}
		long[] count = new long[N];
		for (int i = N - 1; i >= 0; i--) {
			int cur = order[i];
			count[cur] = 1;
			for (int child : g.get(cur)) {
				count[cur] *= count[child] + 1;
				count[cur] %= M;
			}
		}
		long[] pcount = new long[N];
		pcount[0] = 0;
		final int BLOCK_SIZE = 256;
		for (int i = 0; i < N; i++) {
			int cur = order[i];
			ArrayList<Integer> children = g.get(cur);
			if (children.size() < BLOCK_SIZE) {
				for (int j = 0; j < children.size(); j++) {
					long mul = pcount[cur] + 1;
					for (int k = 0; k < children.size(); k++) {
						if (j == k) continue;
						mul *= count[children.get(k)] + 1;
						mul %= M;
					}
					pcount[children.get(j)] = mul;
				}
			} else {
				long[] block = new long[(children.size() + BLOCK_SIZE - 1) / BLOCK_SIZE];
				Arrays.fill(block, 1);
				for (int j = 0; j < children.size(); j++) {
					block[j / BLOCK_SIZE] *= count[children.get(j)] + 1;
					block[j / BLOCK_SIZE] %= M;
				}
				for (int j = 0; j < children.size(); j++) {
					long mul = pcount[cur] + 1;
					for (int k = 0; k < block.length; k++) {
						if (k != j / BLOCK_SIZE) {
							mul *= block[k];
							mul %= M;
						}
					}
					for (int k = j / BLOCK_SIZE * BLOCK_SIZE; k < children.size() && k < (j / BLOCK_SIZE + 1) * BLOCK_SIZE; k++) {
						if (j == k) continue;
						mul *= count[children.get(k)] + 1;
						mul %= M;
					}
					pcount[children.get(j)] = mul;
				}
			}
		}

		long[] ans = new long[N];
		for (int i = 0; i < N; i++) {
			ans[order[i]] = count[order[i]] * (pcount[order[i]] + 1) % M;
		}
		PrintWriter writer = new PrintWriter(System.out);
		for (int i = 0; i < N; i++) {
			writer.println(ans[i]);
		}
		writer.flush();
	}
}

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

#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define popcount __builtin_popcountll

const int INF = 1LL<<60;
const int MOD = 1000000007;

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}

template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}

template <typename A>
string to_string(A x[], int n) {
    string result = "{";
    REP(i, 0, n) {
        if (i!=0) result += ", ";
        result += to_string(x[i]); 
    }
    return result + "}";
}

string bin_string(int x) {
    const int d = 64;
    string result(d, ' ');
    REP(i, d-1, -1) result[d-1-i] = '0'+((x&1LL<<i)!=0);
    return result;
}

vector<int> getZ(string s) {
    int n = s.size();
    vector<int> z(n);
    int x = 0, y = 0;
    REP(i, 1, n) {
        z[i] = max(0LL, min(z[i-x], y-i+1));
        while (i+z[i] < n && s[z[i]] == s[i+z[i]]) {
            x = i;
            y = i+z[i];
            ++z[i];
        }
    }
    return z;
}

int powa(int base, int exp) {
    if (exp<=0) return 1;
    if (base<=0) return 0;
    int val = powa(base, exp>>1);
    val = val*val % MOD;
    if (exp&1) {
        val = val*base % MOD;
    }
    return val;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    string res[] = {"bust", "win"};
    int n = 0;
    REP(i, 0, 3) {
        int x;
        cin >> x;
        n += x;
    }
    cout << res[n<22];
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;
  cin >> s;
  int n = (int)s.size();
  deque<char> dq;

  if (n == 1) {
    if (s == "?")
      cout << "D" << endl;
    else
      cout << s << endl;
    return 0;
  } else if (n == 2) {
    if (s == "??")
      cout << "PD";
    else if (s == "?P")
      cout << "DP";
    else if (s == "P?")
      cout << "PD";
    else if (s == "?D")
      cout << "PD";
    else if (s == "D?")
      cout << "DD";
    cout << endl;
    return 0;
  }

  rep(i, n - 1) {
    if (s[i] == 'D' || s[i] == 'P')
      dq.push_back(s[i]);
    else if (s[i] == '?') {
      if (0 < i) {
        if (dq.back() == 'P')
          dq.push_back('D');
        else if (dq.back() == 'D')
          if (s[i + 1] == 'D' || s[i + 1] == '?')
            dq.push_back('P');
          else
            dq.push_back('D');
      } else if (i == 0) {
        if (s[1] == 'D' || s[1] == '?')
          dq.push_back('P');
        else
          dq.push_back('D');
      } else if (i == n - 1) {
        dq.push_back('D');
      }
    }
  }

  if (s[n - 1] == '?')
    dq.push_back('D');
  else
    dq.push_back(s[n - 1]);

  while (dq.size()) cout << dq.front(), dq.pop_front();

  cout << endl;
  return 0;
}


Measured memory_bytes: 3812
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 100010
#define inf 1000000007
int a[N];
int main()
{
    int i,j,k,n,m,ans,x,y;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    a[0]=0;
    sort(a,a+1+n);
    ans=inf;
    for(i=m;i<=n;i++)
    {
        x=a[i-m];
        y=a[i];
        if(y<0||x>0)
            continue;
        ans=min(ans,x*(-2)+y);
        ans=min(ans,y*2+(-x));
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int T = sc.nextInt();
		int c[] = new int[N];
		int t[] = new int[N];
		
		for(int i = 0; i < N; i++) {
			c[i] = sc.nextInt();
			t[i] = sc.nextInt(); 
		}
		
		int min = 10000;
		for(int i = 0; i < N; i++) {
			if(t[i] <= T) {
				min = Math.min(min, c[i]);
			}
		}
		
		
		System.out.println(min != 10000 ? min : "TLE");
	}
}


Measured memory_bytes: 23124
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    int q;
    cin>>q;
    int count=0;
    while(q--)
    {
        int n;
        cin>>n;
        if(n == 1)  ++count;
        else
        {
            int m;
            string ch;
            cin>>m>>ch;
            if(count%2 == 0)
            {
                if(m == 2)
                    s += ch;
                else
                    s.insert(0,ch);
            }
            else
            {
                if(m == 1)
                    s += ch;
                else
                    s.insert(0,ch);
            }
        }
    }
    if(count%2) reverse(s.begin(),s.end());
    cout<<s;
    return 0;
}

Measured memory_bytes: 912
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int a,b,c,d; cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << '\n';
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long long N; cin >> N; 
	long long ans = 0; 
	for(long long i = 1; i < N; i++){
		ans += (N-1) / i;
	}
	cout << ans << "\n"; 
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
void test_case()
{
	ll n, k;
	cin>>n>>k;
	ll h[n];
	for(ll i=0; i<n; i++){
		cin>>h[i];
	}
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(ll i=2; i<n; i++){
		dp[i] = INT_MAX;
		for(ll j=i-1; j>=0 && j>=i-k; j--){
			dp[i]=min(dp[i], dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1]<<endl;
}
int main ()
{
	fastio
	int t;
	t=1;
	while(t--)
	test_case();
	return 0;
	
}

Measured memory_bytes: 1792
from itertools import permutations
n=int(input())
p=[]
for i in range(1,n+1):
    p.append(i)
a=list(map(int,input().split()))
b=list(map(int,input().split()))
perm=list(permutations(p))
for i in perm:
    if a==list(i):
        res=perm.index(i)
    if b==list(i):
        temp=perm.index(i)
print(abs(res-temp))


Measured memory_bytes: 8052
import sys
sys.setrecursionlimit(10**6)
result = []
def calc(a, b, c, i):
    if a < 0 or b < 0 or c < 0:
        return False
    if i >= N:
        return True
    command = s[i]
    if command == "AB":
        if calc(a+1, b-1, c, i+1):
            result.append("A")
            return True
        if calc(a-1, b+1, c, i+1):
            result.append("B")
            return True
        return False
    elif command == "AC":
        if calc(a+1, b, c-1, i+1):
            result.append("A")
            return True
        if calc(a-1, b, c+1, i+1):
            result.append("C")
            return True
        return False
    elif command == "BC":
        if calc(a, b-1, c+1, i+1):
            result.append("C")
            return True
        if calc(a, b+1, c-1, i+1):
            result.append("B")
            return True
        return False
def main():
    global N, s
    N, A, B, C = map(int, input().split())
    s = [input() for _ in range(N)]
    if calc(A, B, C, 0):
        print("Yes")
        for c in result[::-1]:
            print(c)
    else:
        print("No")
main()

Measured memory_bytes: 110036
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn get_vec(val: u64) -> Vec<u64> {
    let mut vec: Vec<u64> = Vec::new();
    for i in 0..50 {
        // 2の個数
        let d = (2 as u64).pow(i + 1);
        let pat1_num1 = (val / d) * d / 2;

        let v1: u64 = val % d + 1;
        let v1: i64 = (v1 as i64) - d as i64 / 2;
        let pat2_num1: i64 = std::cmp::max(v1, 0);
        vec.push(pat1_num1 + pat2_num1 as u64);
    }
    vec.into_iter().rev().collect()
}

fn main() {
    input! {
        a: u64,
        b: u64,
    }
    let vec_a = get_vec(a - 1);
    let vec_b = get_vec(b);

    let mut ans: u64 = 0;
    for (i, (num_a, num_b)) in vec_a.into_iter().zip(vec_b).rev().enumerate() {
        let num = num_b - num_a;
        if num % 2 == 1 {
            ans += (2 as u64).pow(i as u32);
        }
    }
    println!("{}", ans);
}


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

int main() {
  int N;
  int M;
  int sum=0;
  cin >> N;
  M=N;
  
  sum = N % 10;
  
  while (N/10>0) {
    N /= 10;
    sum += N%10;
  }
  if (M%sum==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);





int main(){
  ll N=10000000;
  vector<ll> res;
  vector<bool> is_prime(N + 1, true);
  for (ll p = 2; p <= N; p++) {
    if (!is_prime[p]) continue;
    for (ll k = p * 2; k <= N; k += p) is_prime[k] = false;
    res.push_back(p);
  }
  vector<ll>v;
  for(ll i=3;i<res.size();i++){
    if(res[i-3]+2==res[i-2]&&res[i-2]+4==res[i-1]&&res[i-1]+2==res[i])v.push_back(res[i]);
  }
  ll x;
  cin>>x;
  while(x){
    cout<<*(--(upper_bound(v.begin(), v.end(),x)))<<endl;
    cin>>x;
  }

}




Measured memory_bytes: 12240
#include <iostream>
#include <string>

using namespace std;

int main()
{
	long long int a, b, c, d, e, f, g, t, v, w;
	cin >> a >> v;
	cin >> b >> w;
	cin >> t;
	if (a < b) {
		c = b - a;
	}
	else {
		c = a - b;
	}
	//cは座標の差
	d = v - w;
	//dは追いつく座標数
	if (d != 0) {
		e = c / d;
		f = c % d;
	}
	else {
		e = t + 1;
		f = 0;
	}
	if (f == 0) {
		g = 0;
	}
	else {
		g = 1;
	}
	e = e + g;
	if (d >= 0){
		if (e <= t) {
			cout << "YES";
		}
		else if (d == 0) {
			cout << "NO";
		}
		else {
			cout << "NO";
		}
	}
	else {
		cout << "NO";
	}
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(void){
    int a=0,b=0;
    for(;-1 != scanf("%d %d", &a, &b);){
        
        
        
        long long m = (long long) a * b;
        
        if (a<b) {
            int t = a;
            a = b;
            b = t;
        }
        
        while (b>0) {
            int r = a%b;
            a = b;
            b = r;
        }
        
        int gcd = a;
        
        long long lcm = m / gcd;
        
        printf("%d %lld\n", gcd, lcm);
    }
    return 0;
}

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

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    string s1 = "", s2 = "";
    rep(i, w - a) s1 += '1', s2 += '0';
    rep(i, a) s1 += '0', s2 += '1';

    rep(i, h - b) cout << s1 << endl;
    rep(i, b) cout << s2 << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
  int N; cin>>N;
  vector<int> v;
  for(int i=0;i<N;i++){
    int b; cin>>b; v.push_back(b);
  }
  vector<int> ans;
  bool found = true;
  while(!v.empty() && found){
    found = false;
    for(auto it=v.end()-1; it>=v.begin(); it--){
      int idx = it-v.begin()+1;
      if(idx==(*it)){ found = true; ans.push_back(*it); v.erase(it); break; }
    }
  }
  if(!v.empty()){
    cout<<-1<<endl;
  } else {
    for(int i=0;i<N;i++){
      cout<<ans[N-1-i]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal

n = int(input())

def how_many_prime(n):
    prime = {}
    num = n
    i = 2
    while True:
        if i * i > n:
            if(num > 1):
                prime[num] = 1
            break
        while num % i == 0:
            prime[i] = prime.get(i, 0) + 1
            num = num//i
        i += 1
    return prime

prime = how_many_prime(n)

count = 0
for val in prime.values():
    use = 1
    while True:
        if(val < use):
            break
        val -= use
        use += 1
        count += 1
print(count)


Measured memory_bytes: 72796
import sys

def solve():
    N, K = [int(i) for i in input().split()]
    H = []
    for _ in range(N):
        H.append(int(input()))
    H.sort()
    ans = sys.maxsize
    for i in range(N - K + 1):
        ans = min(ans, H[i + K - 1] - H[i])
    print(ans)

if __name__ == "__main__":
    solve()

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


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

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


Measured memory_bytes: 640
/*
author: Apoorv Singh
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector <int> vi;
typedef vector <long long> vl;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
#define ll long long
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second

ll modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

ll fpow(ll a, ll n)
{
    ll ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

const int M = 1e5 + 10;
int visited[M] = {0};
vi graph[M];
stack <int> s;

void topological(int source)
{
    visited[source] = 1;
    for (int a : graph[source])
    {
        if (!visited[a])
            topological(a);
    }
    s.push(source);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin >> n >> m;
    FOR(i,0,m+n-1)
    {
        int u,v;
        cin >> u >> v;
        graph[u].pb(v);
    }
    FOR(i,1,n+1)
    {
        if (!visited[i])
            topological(i);
    }
    vi arr;
    int ans[n+1] = {0};
    while (!s.empty())
    {
        int a = s.top();
        s.pop();
        arr.pb(a);
    }
    FOR(i,0,n)
    {
        for (int a : graph[arr[i]])
            ans[a] = arr[i];
    }
    FOR(i,1,n+1)
        cout << ans[i] << endl;
    return 0;
}

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


int main(){
  string S,T,U;
  int A,B;
  
  cin >>S>>T>>A>>B>>U;
  
  if(S==U){
    cout <<A-1<<' '<<B;
  }else{
    cout <<A<<' '<<B-1<<endl;
}
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
//#include "ext/pb_ds/tree_policy.hpp"
//#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
const ld eps = 1e-9;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a) {
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}

template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}

template<typename T> inline void in(T &x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch))  {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}

ll twop(int x) {
    return 1LL<<x;
}

template<typename A,typename B > inline void in(A&x,B&y) {
    in(x);
    in(y);
}
template<typename A,typename B,typename C>inline void in(A&x,B&y,C&z) {
    in(x);
    in(y);
    in(z);
}
template<typename A,typename B,typename C,typename D> inline void in(A&x,B&y,C&z,D&d) {
    in(x);
    in(y);
    in(z);
    in(d);
}

namespace SOLVE {
    void main(){
    }
}
void calcNext(const string& s,int nxt[]){
    int p = nxt[0] = -1;
    REP(i,1,sz(s)){
        while(p!=-1 && s[p+1]!=s[i])p = nxt[p];
        p+=s[p+1]==s[i];
        nxt[i] = p;
    }
}


int main(){
    string s;cin>>s;
    vector<char>v;
    for(auto i:s){
        if(sz(v) && v.back()=='S' && i == 'T'){
            v.pop_back();
        }else v.PB(i);
    }
    cout<<sz(v);
    return 0;
}


Measured memory_bytes: 772
n, m = map(int, input().split())
tupList = []
for i in range(n):
    a, b = [int(i) for i in input().split()]
    tupList.append((a, b))

def tupVal(tup):
    return tup[0]
tupList.sort(key = tupVal)
ans = 0
for i in tupList:
    if m >= i[1]:
        ans += i[0] * i[1]
        m -= i[1]
    else:
        ans += i[0] * m
        break
print(ans)


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

int main(){
  string S;
  int i,j,cnt;
  cnt = 0;
  i = 0;
  
  cin >> S;
  j = S.size() - 1;
  
  while(i < j){
      if(S[i] != S[j]){
          cnt++;
      }
      i++;
      j--;
  }
    
  cout << cnt << endl;
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  ll N,M, mod = 1000000007; cin >> N >> M;
  bool imp = false;
  vector<ll> fvec(N+1); fvec[0] = 1; fvec[1] = 1;
  if (M == 0) {
    if (N > 1) {
      for (ll i = 2; i <= N; ++i) fvec[i] = (fvec[i-1]+fvec[i-2])%mod;
    }
    cout << fvec[N] << endl;
  }
  else {
    vector<ll> avec(M); cin >> avec[0];
    for (ll i = 1; i < M; ++i) {
      cin >> avec[i];
      if (avec[i]-avec[i-1]==1) {
        imp = true;
        break;
      }
    }
    if (imp) cout << 0 << endl;
    else {
      ll bpos = 0;
      for (ll i = 1; i <= N; ++i) {
        if (i == avec[bpos]) {
          fvec[i] = 0; bpos++;
        }
        else {
          if (i > 1) fvec[i] = (fvec[i-1]+fvec[i-2])%mod;
        }
      }
      cout << fvec[N] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1792
def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())
mod = 10**9 + 7
dog = 10 ** 15 + 1

def main():
  n = int(input())
  ans = ''
  while n > 0:
    n -= 1
    ans += chr(ord('a') + n % 26)
    n //= 26
  print(ans[::-1])

if __name__ == '__main__':
  main()

Measured memory_bytes: 9176
import itertools
n = int(input())
ori = [3, 5, 7]
num = []
num.append(0)
ans = []
i = 1
while i < 10:
    num.append(list(itertools.product(ori, repeat=i)))
    for k in range(len(num[i])):
        if (3 in num[i][k]) and (5 in num[i][k]) and (7 in num[i][k]):
            ans.append(int(''.join([str(x) for x in num[i][k]])))
    i += 1
count = 0
for f in ans:
    if n >= f:
        count += 1
print(count)

Measured memory_bytes: 7984
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll t1,t2;
  ll a1,a2,b1,b2;
  cin>>t1>>t2>>a1>>a2>>b1>>b2;
  if(a1<b1){
    swap(a1,b1);
    swap(a2,b2);
  }
  if(t1*a1+a2*t2>t1*b1+t2*b2){
    COUT(0);
    return 0;
  }
  else if(t1*a1+a2*t2==t1*b1+t2*b2){
    COUT("infinity");
    return 0;
  }
  else{
    ll u=t1*a1-t1*b1;
    ll d=t1*b1+t2*b2-t1*a1-a2*t2;
    ll ans=(u+d-1)/d*2-1;
    if(u%d==0) ans++;
    COUT(ans);
  }
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int k; cin >> k;
    vector<ll> v;
    REP(i,1,10) v.push_back(i);
    while(1){
        if(k <= v.size()){
            cout << v[k-1] << endl;
            return 0;
        }
        k -= v.size();
        vector<ll> pv;
        swap(pv, v);
        for(ll x : pv){
            REP(i,-1,2){
                int d = x % 10 + i;
                if(d < 0 || 9 < d) continue;
                ll nx = x * 10 + d;
                v.push_back(nx);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1712
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int p = sc.nextInt();
    int q = sc.nextInt();
    int r = sc.nextInt();
    int pq = p + q;
    int qr = q + r;
    int rp = r + p;
    
    int result = pq;
    if(qr < result){
      result = qr;
    }
    if(rp < result){
      result = rp;
    }
    // 出力
    System.out.println(result);
  }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

void dfs(ll u, vector<ll> e[], vector<bool> &vis, vector<ll> &col, ll cnt)
{
   col[u] = cnt;
   for(auto v: e[u])
   {
       if(!vis[v])
       {
           vis[v]=true;
           dfs(v,e,vis,col,cnt);
       }
   }
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll n,k,l;
    cin>>n>>k>>l;
    ll i,j;
    ll u,v;
    vector<ll> e[n], e1[n];
    for(i=0;i<k;i++)
    {
        cin>>u>>v;
        u--;v--;
        e[u].pb(v);
        e[v].pb(u);
    }
    ll road = 0, rail = 0;
    vector<bool> vis(n,false);
    vector<ll> col1(n,0),col2(n,0);
    for(i=0;i<n;i++)
    {
        if(!vis[i])
        {
            road++;
            vis[i] = true;
            dfs(i,e,vis,col1,road);
        }
    }
    // for(i=0;i<n;i++) cout<<col1[i]<<" ";
    for(i=0;i<l;i++) 
    {
        cin>>u>>v;
        u--;v--;
        e1[u].pb(v);
        e1[v].pb(u);
    }
    fill(all(vis), false);
    for(i=0;i<n;i++)
    {
        if(!vis[i])
        {
            rail++;
            vis[i] = true;
            dfs(i,e1,vis,col2,rail);
        } 
    }
    // for(i=0;i<n;i++) cout<<col2[i]<<" ";
    vector<ll> ans(n,1);
    map<pair<ll,ll>, ll> mp;
    for(i=0;i<n;i++)
    {
      mp[{col1[i], col2[i]}]++;
    }
    for(i=0;i<n;i++) cout<<mp[{col1[i], col2[i]}]<<" ";
}


Measured memory_bytes: 31872
n, q = map(int, input().split())
s = list(input())
l,r = [0] * q, [0] * q
for i in range(q):
    l[i], r[i] = map(int, input().split())

#acの場所把握
ac = [0] * (n + 1)
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ac[i + 1] = ac[i] + 1
    else:
        ac[i + 1] = ac[i]

for i in range(q):
    print(ac[r[i] - 1] - ac[l[i] - 1])



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

pair<int, int> getMinAndSum(const string &str) {
    int mn = 0, sum = 0;
    for(auto &c : str) {
        sum += (c == '(' ? 1 : -1);
        mn = min(mn, sum);
    }
    return {mn, sum};
}

void fail() {
    cout << "No" << '\n';
    exit(0);
}

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> pos, neg;
    for(int i = 0; i < N; ++i) {
        string S;
        cin >> S;
        auto tmp = getMinAndSum(S);
        if(tmp.second >= 0) pos.push_back(tmp);
        else neg.push_back(tmp);
    }
    sort(pos.begin(), pos.end(), greater<pair<int, int>>());
    sort(neg.begin(), neg.end(), [](auto a, auto b) {
        return a.second - a.first > b.second - b.first;
    });
    int now = 0;
    for(auto[mn, sum] : pos) {
        if(now + mn < 0) fail();
        now += sum;
    }
    for(auto[mn, sum] : neg) {
        if(now + mn < 0) fail();
        now += sum;
    }
    cout << (now == 0 ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 11308
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  int H, W;
  cin >> H >> W;
  int N;
  cin >> N;
  int a[N];
  rep(i, N)
    cin >> a[i];
  // 入力終了

  int ans[H][W];

  // [0][0]から始めて右に移動していく．
  // [0][W-1]まで来たら[1][W-1]に移動し，次は左に移動していく．
  // それを繰り返す

  // 1だけ先に書いておいてa[0]を1つ減らしておく
  ans[0][0] = 1;
  a[0]--;

  // 現在地点
  int cury = 0, curx = 1;

  // 右に進むか左に進むか
  bool left = false, right = true;
  
  rep(i, N){
    rep(j, a[i] ){
      ans[cury][curx] = i+1;
      // 左端に着いた，かつ右から移動してきた
      if(curx == 0 && left){
	cury++;
	// 次は右に移動していく
	right = true;
	left  = false;
      }
      // 右端に着いた，かつ左から移動してきた
      else if(curx == W-1 && right){
	cury++;
	// 次は左に移動していく
	right = false;
	left  = true;
      }
      // 右へ移動
      else if(right)
	curx++;
      // 左へ移動
      else if(left)
	curx--;
    }
  }

  // 解答
  rep(i, H){
    rep(j, W)
      cout << ans[i][j] <<" ";
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <map>
#include <algorithm>    
#include <vector>       
#include <set>
#include <utility>  
#include <cstring>
#include <stdio.h>
#include <limits.h>
#include <queue>
#include <algorithm> 
#define MAX_DOUBLE  40000000000.0 
#include <math.h> 
#include <unistd.h>

using namespace std;

long long mod = 1e9 + 7;

long long group_val[65536];

long long res[65536];


long long point[16][16];


int pow_to_index(int num){
	if (!num)
        return 0;

    int ret = 0;

    while (num >>= 1)
        ret ++;

    return ret;
}


int hob (int num)
{
    if (!num)
        return 0;

    int ret = 1;

    while (num >>= 1)
        ret <<= 1;

    return ret;
}



bool good(int a, int b){
	int tmp = b - a;
	
	int ans = tmp & a;
	
	if(ans != 0) return false;
	
	return true;
}

int main(){
	int n;
	cin>>n;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			int a;
			cin>>a;
			point[i][j] = a;
		}
	}
	
	int pow = 1;
	
	for(int i = 0; i < n; i++){
		pow *= 2;
	}	
	
	for(int i = 1; i < pow; i++){
		int q = hob(i);
		
		int q_index = pow_to_index(q);
//		
//		cout<<i<<"  q  "<<q<<" ind "<<q_index<<endl;
		
		group_val[i] = group_val[i-q];
		for(int j = 0; j < q_index; j++){
//			cout<<i<<" "<<(1<<j)<<endl;
			if((i-q) & (1<<j)){
				group_val[i] += point[q_index][j];
			}
		}			
	}
	
//	for(int i = 0; i < pow; i++){
//		cout<<i<<"    -    "<<group_val[i]<<endl;
//	}
	
	
	for(int i = 1; i < pow; i++){
		int q = hob(i);
		int q_index = pow_to_index(q);
		
		res[i] = res[i - q];
		
		for(int j = 1; j <= i - q; j++){
			if(good(j, i - q)){		
				
				res[i] = max(res[i], res[i - q - j] + group_val[j + q]);
			}
		}
	}
	
	
	
//	cout<<good(3,7)<<endl;
	
	cout<<res[pow-1]<<endl;
	return 0;
}















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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

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

    sort(d.begin(), d.end());

    cout << (d[int(N/2)] - d[int(N/2-1)]) << endl; 


    return 0;
}



Measured memory_bytes: 640
ops = {'+': lambda a, b: a+b, '-': lambda a, b: a-b, '*': lambda a, b: a*b, '/': lambda a, b: int(a/b)}
while True:
    a, op, b = input().split()
    if op not in ops.keys():
        break
    print(ops[op](int(a),int(b)))


Measured memory_bytes: 5600
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

func main() {
	var N int
	fmt.Scanf("%d\n", &N)

	A := make([]int, N)

	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		A[i] = a
	}
	var sum int
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			sum += A[i] * A[j]
		}
	}
	fmt.Println(sum)

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll dp[60][5334];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a, x[60];
	cin>>n>>a;
	REP(i, n){
		cin>>x[i];
		x[i]-=a;
	}
	dp[0][2500]=1;
	REP(i, n){
		REP(j, 5000){
			if(j-x[i]>=0 && j-x[i]<5000){
				dp[i+1][j]=dp[i][j]+dp[i][j-x[i]];
			}
			else{
				dp[i+1][j]=dp[i][j];
			}
		}
	}
	cout<<dp[n][2500]-1<<'\n';
	return 0;
}


Measured memory_bytes: 2304
import numpy
M=10**9+7
n,k=map(int,input().split())
a=numpy.matrix([list(map(int,input().split()))for i in[0]*n],dtype='O')
b=numpy.eye(n,dtype='O')
while k:
 if k&1:b=b*a%M
 a=a*a%M
 k>>=1
print(b.sum()%M)

Measured memory_bytes: 14564