akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DSimpleKnapsack solver = new DSimpleKnapsack();
        solver.solve(1, in, out);
        out.close();
    }

    static class DSimpleKnapsack {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long W = in.nextInt();

            int[] w = new int[n];
            long[] v = new long[n];

            for (int i = 0; i < n; i++) {
                w[i] = in.nextInt();
                v[i] = in.nextInt();
            }

            long w0 = w[0];
            for (int i = 0; i < n; i++) {
                w[i] -= w0;
            }

            long[][][] dp = new long[n + 1][n + 1][3 * n + 1]; // [prefix][used][extra]

            for (int i = 1; i <= n; i++) {
                for (int used = 0; used <= n; used++) {
                    for (int weight = 0; weight < dp[i][used].length; weight++) {
                        dp[i][used][weight] = Math.max(dp[i][used][weight], dp[i - 1][used][weight]);
                        if (used - 1 >= 0 && weight - w[i - 1] >= 0)
                            dp[i][used][weight] = Math.max(dp[i][used][weight], v[i - 1] + dp[i - 1][used - 1][weight - w[i - 1]]);
                    }
                }
            }

            long answer = 0;
            for (int used = 0; used <= n; used++) {
                for (int extra = 0; extra < dp[n][used].length; extra++) {
                    if (used * w0 + extra > W)
                        continue;
                    answer = Math.max(answer, dp[n][used][extra]);
                }
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 55636
from itertools import combinations
n,m,q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

ans = 0
for case in combinations([i for i in range(1,n+m)],n):
    now = 0
    A = [x-i for i,x in enumerate(case)]
    for i in range(q):
        a,b,c,d = abcd[i]
        if A[b-1]-A[a-1] == c:
            now += d
    ans = max(now,ans)

print(ans)

Measured memory_bytes: 74340
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree < int,  null_type,  less<int>,  rb_tree_tag,  tree_order_statistics_node_update > ordered_set;
typedef long long ll;
#define pb push_back
#define pi (acos(-1))
#define ull  unsigned long long
#define ld long double
#define all(v) v.begin(), v.end()
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
ll LCM(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a/g)*b ;
}
string numtostr(ll n)
{
    ostringstream str1 ;
    str1 << n ;
    return str1.str();
}
ll strtonum(string s)
{
    ll x ;
    stringstream str1(s);
    str1 >> x ;
    return x ;
}
short n;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   cin>>n;
   if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9)
    cout<<"hon\n";
   else if(n%10==3)
    cout<<"bon\n";
   else
    cout<<"pon\n";
    return 0;
}


Measured memory_bytes: 3616
# -*- coding:utf-8 -*-

def solve():
    S = input()
    K = int(input())
    INF = 5000000000000000

    # num**INF はでかすぎる。無限長とみなしてOK

    now_k = 1
    for s in S:
        num = int(s)

        if now_k == K:
            print(num)
            return
        
        if num != 1:
            # 2以外なら、もうそれ。
            print(num)
            return
        
        now_k += 1
        



if __name__ == "__main__":
    solve()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n,x; cin >> n >> x;
    if(x == 1 || x == 2*n-1) puts("No");
    else{
        puts("Yes");
        vl py(2*n-1);
        py[n-1] = x;
        rep(i,2*n-1){
            py[(n-1+i)%(2*n-1)] = (x-1+i)%(2*n-1) + 1;
        }
        rep(i,2*n-1){
            cout << py[i] << endl;
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 100100;

int m;
int n;
ll q[M];
ll a[M];

void read() {
  cin >> n;
  q[0] = n;
  m = 1;
  
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    ll x;
    cin >> x;
    while (m > 0 && q[m - 1] >= x)
      --m;
    q[m++] = x;
  }
}


void kill() {
  map<ll, ll> cnt;

  cnt[q[m - 1]] = 1;

  for (int i = m - 2; i >= 0; --i) {
    ll x = q[i];

    while (true) {
      ll y = cnt.rbegin()->first;
      ll by = cnt.rbegin()->second;

      if (y <= x)
        break;

      cnt.erase(cnt.find(y));

      cnt[x] += (y / x) * by;
      cnt[y % x] += by;
    }
  }

  for (int i = 0; i <= n; ++i)
    a[i] = cnt[i];
  for (int i = n - 1; i >= 1; --i)
    a[i] += a[i + 1];
  for (int i = 1; i <= n; ++i)
    cout << a[i] << "\n";
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


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

A_list = list(map(int, input().split()))
A_list = [A - 1 for A in A_list]

path = [0]
town = 0
k = K
j = 0

while k > 0:
  town = A_list[town]
   
  if k % 10000 == 0:
    if town in path:
      #print("town is {}".format(town))
      #print("path is {}".format(path))
      first_visit = path.index(town)
      loop_size = j - first_visit + 1
      #print("loop_size is {}".format(loop_size))
      #print("k is {}".format(k))
      k = (k-1) % loop_size 
      #print("k is now {}".format(k))
      town = path[first_visit + k]
      break
    
  path.append(town)
    
  k = k - 1
  j = j + 1

print(town+1)

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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int n, m;
	std::cin >> n >> m;
	std::vector<Int> h(n);
	RC(i, n){
		cin >> h[i];
	}
	std::vector<bool> good(n, true);
	RC(i, m){
		Int a, b;
		cin >> a >> b;
		--a;
		--b;
		if(h[a] <= h[b]){
			good[a] = false;
		}
		if(h[b] <= h[a]){
			good[b] = false;
		}
	}
	Int count = 0;
	RC(i, n){
		count += good[i];
	}
	cout << count << endl;
}


Measured memory_bytes: 4052
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;
    S[K - 1] -= 'A' - 'a';
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 
//Available in Snips
#define fi(i, x, y)   for (__typeof(x) i = x; i < y; i ++)
#define fir(i, x, y)  for (__typeof(x) i = x; i > y; i --)
#define fv(x)   for (auto itr = x.begin(); itr != x.end(); itr ++)
#define fvr(x)  for (auto itr = x.end() - 1; itr != x.begin() - 1; itr --)
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
	string s;
	cin >> s;
	set<char> t;
	for(char x:s){
		t.insert(x);
	}
	if(t.size()>1){
		cout << "Yes";
	}else {
		cout << "No";
	}
	
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " "
#define outline(x) cout << x << endl;
#define sortvector(v) sort(v.begin(), v.end());
#define sortvectorrev(v) sort(v.rbegin(), v.rend());
int main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n];
    ll b[m];
    arrinp(i, a, 0, n - 1)
    arrinp(i, b, 0, m - 1);
    vector<ll> p1(n + 1), p2(m + 1);
    p1[0] = 0, p2[0] = 0;
    forfront(i, 1, n)
    {
        p1[i] = a[i - 1] + p1[i - 1];
        // out(p1[i]);
    }    
    // cout << endl;
    forfront(i, 1, m)
    {
        p2[i] = p2[i - 1] + b[i - 1]; 
        // out(p2[i]);
    }
    // outline("");
    ll maxlen = 0;
    for(ll i = 0; i <= n; i++)
    {
        ll sumleft = k - p1[i];
        if(sumleft <= 0) break;
        // out(sumleft);
        ll j = upper_bound(p2.begin(), p2.end(), sumleft) - p2.begin();
        // outline(j);
        maxlen = max(maxlen, i + j - 1);
    }
    for(ll i = 0; i <= m; i++)
    {
        ll sumleft = k - p2[i];
        if(sumleft <= 0) break;
        // out(sumleft);
        ll j = upper_bound(p1.begin(), p1.end(), sumleft) - p1.begin();
        // outline(j);
        maxlen = max(maxlen, i + j - 1);
    }
    outline(maxlen);
    return 0;
}

Measured memory_bytes: 9528
package main

import (
        "fmt"
)

func main() {
        var s, t string
        fmt.Scanf("%s", &s)
        fmt.Scanf("%s", &t)

        s_len := len(s)
        t_len := len(t)
        min_dist := t_len

        for s_idx := 0; s_idx <= s_len-t_len; s_idx++ {
                dist := 0
                for t_idx := 0; t_idx < t_len; t_idx++ {
                        if t[t_idx] != s[s_idx+t_idx] {
                                dist++
                        }
                }

                if dist < min_dist {
                        min_dist = dist
                }
        }

        fmt.Printf("%d\n", min_dist)
}

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

namespace ITP1_11_C {
    class Dice {
        private int[] _dice;
        
        public Dice(int[] dice) {
            _dice = dice;
        }

        public bool IsSame(int[] arr) {
            string dir = "ENENEN";
            string turn = "RRRR";
            foreach (var d in dir) {
                foreach (var t in turn) {
                    if (_dice.SequenceEqual(arr))
                        return true;
                    Move(t);
                }
                Move(d);
            }
            return false;
        }

        public void Move(string dir) {
            foreach (var d in dir) {
                Move(d);
            }
        }

        public void Move(char dir) {
            switch (dir) {
                case 'E':
                    Replace(0, 3, 5, 2);
                    break;
                case 'W':
                    Replace(0, 2, 5, 3);
                    break;
                case 'N':
                    Replace(0, 1, 5, 4);
                    break;
                case 'S':
                    Replace(0, 4, 5, 1);
                    break;
                case 'R':
                    Replace(1, 3, 4, 2);
                    break;
            }
        }

        private void Replace(int a, int b, int c, int d) {
            int temp = _dice[a];
            _dice[a] = _dice[b];
            _dice[b] = _dice[c];
            _dice[c] = _dice[d];
            _dice[d] = temp;
        }
    }

    class Program {
        static void Main(string[] args) {
            int[] d1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] d2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Dice dice = new Dice(d1);
            Console.WriteLine(dice.IsSame(d2) ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 9876
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		double r = sc.nextDouble();
		double a = r*r*Math.PI;
		double b = 2*r*Math.PI;
		String menseki = String.format("%.6f",a);
		String enshuu = String.format("%.6f",b);
		System.out.println(menseki+" "+enshuu);
	}
}



Measured memory_bytes: 28240
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <utility>
#include <bitset>
using namespace std;
typedef long long ll;
const ll inf = 4e18;
const ll mod = 1e9+7;
#define print(X) cout << (X) << endl
#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 (ll (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define repd(i, m, n) for (ll (i) = (m); (i) > (n); --(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

int main(void)
{
    ll N;
    cin >> N;
    vector<ll> A(N+2);
    A[0]=0;
    rep (i,N) {
        cin >> A[i+1];
    }
    A[N+1]=0;
    ll base=0;
    rep (i,N+1) {
        base += abs(A[i]-A[i+1]);
    }
    repp (i,1,N+1) {
        ll ans = base;
        ans -= abs(A[i-1]-A[i]);
        ans -= abs(A[i]-A[i+1]);
        ans += abs(A[i-1]-A[i+1]);
        print(ans);
    }
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  int r = A-B;
  cout<<max(0, C-r)<<endl;

  return 0;
}


Measured memory_bytes: 256
from math import ceil
t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a1 -= b1
a2 -= b2
a1 *= t1
a2 *= t2
if a1 + a2 == 0:
    print("infinity")
    exit()
if a1*(a1+a2) > 0:
    print(0)
    exit()

x = -a1/(a1+a2)
n = ceil(x)
if n == x:
    print(2*n)
else:
    print(2*n-1)

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

int main(){
    int a,b;
    string op;
    while (1){
      cin>>a>>op>>b;
      if (op=="?")break;
      else if(op=="+"){
        cout<<a+b<<endl;
      }else if(op=="-"){
        cout<<a-b<<endl;
      }else if(op=="/"){
        cout<<a/b<<endl;
      }else if(op=="*"){
        cout<<a*b<<endl;
      }
    }


}



Measured memory_bytes: 3128
n = int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

ans = 0

for i in range(n):
  ans += b[a[i]-1]
  if a[i] == a[i-1]+1:
    if i >=1:
      ans += c[a[i-1]-1]


print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  
  //変数の受取処理
  for (int i = 0;i < N; i++){
    int da;
    cin >> da;
    D[i] = da;
  }
  
  //足していく
  int ans = 0;
  for (int i = 0;i < N;i++){
    for (int j = i + 1;j < N; j++){
      ans += D[i] * D[j];
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
def phi(n)
  return 0 if n == 0
  lim = 1000000000
  ret = n
  i = 2
  while i * i <= lim
    if n % i == 0
      ret -= ret / i
      n /= i while n % i == 0
    end
    i += 1
  end
  ret -= ret / n if n > 1
  ret
end

n = gets.to_i
puts phi(n)



Measured memory_bytes: 6876
#include<stdio.h>
int main(){
	char ch;
	while(1){
		scanf("%c", &ch);
		if ('a' <= ch && ch <= 'z') {
			ch -= 32;
		}else if('A' <= ch && ch <= 'Z') {
			ch += 32;
		}
		if(ch == '\n') break;
		printf("%c", ch);
	}
	printf("\n");
}


Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

// string bin(int x, int n) {
// 	string res;
// 	while (n--) {
// 		res.push_back('0'+ x % 2);
// 		x >>= 1;
// 	}
// 	return res;
// }

// void test(int n, string X = "") {
// 	map<int, int> freq;
// 	int lim = 1 << n;
// 	if (!X.empty()) {
// 		lim = 0;
// 		for (char ch: X) lim = lim * 2 + ch - '0';
// 	}
// 	for (int x = 0; x < lim; x++) {
// 		int y = x;
// 		int c = 0;
// 		do {
// 			y = (y >> 1) | (((y & 1) ^ 1) << (n - 1));
// 			c++;
// 		} while (y != x);
// 		string z = bin(x, n);
// 		if (!freq[c]) {
// 			trace(z, c, c/2, x);
// 		}
// 		freq[c]++;
// 	}
// 	for (auto [c, f]: freq) {
// 		trace(c, f);
// 	}
// }

const int N = 2e5 + 10;
const LL MOD = 998244353;
LL nf[N];

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

	// for (int n; cin >> n; test(n)); return 0;

	int n; cin >> n;
	string X; cin >> X;

	// test(n, X);

	int p2 = 1;
	while (n % p2 == 0) p2 *= 2;
	p2 /= 2;
	int odd = n / p2;

	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % p2 != 0) continue;
		if (odd % (i / p2) != 0) continue;
		// if X has period p2*i, then use X[0..i-1], else X[0..i-1] - 1
		bool valid = true;
		for (int j = 0; valid && j + i < n; j++) {
			if (X[j] == X[j + i]) valid = false;
		}

		LL pref = 0;
		for (int j = 0; j < i; j++) {
			pref = (pref * 2 + (X[j] - '0')) % MOD;
		}
		if (!valid) {
			for (int j = 0; j < n; j++) {
				char curr = X[j % i];
				if ((j / i) % 2 == 1) curr = curr == '0' ? '1' : '0';
				if (curr < X[j]) {
					valid = true;
					break;
				}
				if (curr > X[j]) {
					break;
				}
			}
		}
		if (valid) {
			pref = (pref + 1) % MOD;
		}

		nf[i] = pref;
		for (int j = 1; j < i; j++) {
			if (i % j == 0) nf[i] -= nf[j];
		}
		nf[i] %= MOD;
		nf[i] += MOD;
		nf[i] %= MOD;
		// trace(i, valid, nf[i]);
		ans += (i * nf[i]) % MOD;
	}

	// LL nx = 0;
	// for (char ch: X) nx = (nx * 2 + ch - '0') % MOD;
	// for (int i = 1; i <= odd; i++) {
	// 	nx -= nf[i];
	// }
	// nx %= MOD;
	// nx += MOD;
	// nx %= MOD;
	// ans += (nx * odd) % MOD;


	ans = (ans * 2) % MOD;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;

  cout << a / b << " " << a % b << " ";
  cout << fixed << setprecision(8) << static_cast<double>(a) / static_cast<double>(b) << endl;

  return 0;
}



Measured memory_bytes: 3272
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }


int main() {
	ll a,b,c;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double A = Double.parseDouble(sc.next());
		double B = Double.parseDouble(sc.next());
		double H = Double.parseDouble(sc.next());
		double M = Double.parseDouble(sc.next());
		sc.close();

		double degree = 0;
		double shortDegree = (H * 60 + M) * 0.5;
		double longDegree =  M * 6;
		if(Math.abs(longDegree - shortDegree) <= 180) {
			degree = Math.abs(longDegree - shortDegree);
		}else {
			degree = 360 - Math.abs(longDegree - shortDegree);
		}

		double r=Math.sqrt(Math.pow(A,2)+Math.pow(B,2)-2*A*B*Math.cos(Math.toRadians(degree)));
		System.out.println(String.format("%.15f", r));
	}

}

Measured memory_bytes: 35956
import java.util.Scanner;

public class Main {
    private static Scanner sc;

    public Main() {
    }

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

    }

    private void solve() {
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        System.out.println((int) Math.ceil((a + b) / 2));
    }
}


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

double gaiseki(double x1,double y1,double x2,double y2){

	double ab;
	ab = x1*y2 - y1*x2;
	if (ab>=0)
		ab=1;
	else
		ab=-1;
	return ab;
}

int main() {

	//A(x1,y1,0)
	//B(x2,y2,0)
	//C(x3,y3,0)
	
	double x1,y1,x2,y2,x3,y3,xp,yp;
	
	while(cin >>x1>>y1>>x2>>y2>>x3>>y3>>xp>>yp){
		if (  ( gaiseki(x1-x2,y1-y2,xp-x2,yp-y2)+gaiseki(x2-x3,y2-y3,xp-x3,yp-y3)+gaiseki(x3-x1,y3-y1,xp-x1,yp-y1) == 3 )||( gaiseki(x1-x2,y1-y2,xp-x2,yp-y2)+gaiseki(x2-x3,y2-y3,xp-x3,yp-y3)+gaiseki(x3-x1,y3-y1,xp-x1,yp-y1) == -3 )  )
			cout << "YES" <<endl;
		else
			cout << "NO" <<endl;
	}

	return 0;
  
}

Measured memory_bytes: 1216
# coding: utf-8
# Your code here!

n,k=map(int,input().split())
v=list(map(int,input().split()))
ans=0

for a in range(n+1):
    for b in range(n+1):
        if a+b>n:
            break
        if a+b>k:
            break
        if a+b==n:
            val=sum(v)
            ans=max(ans,val)
            # print(a,b,val)
            continue
        tmp=v[:a]+v[::-1][:b]
        val=sum(tmp)
        c=k-a-b
        tmp.sort()
        for i in range(min(c,a+b)):
            if tmp[i]<0:
                val-=tmp[i]
            else:
                break
        ans=max(ans,val)
        # print(a,b,val)
print(ans)

Measured memory_bytes: 80192
S=input()
l=len(S)
s=0
e=0
L=0
max=0
for i in range(l):
	if S[i]=="A" or S[i]=="T" or S[i]=="G" or S[i]=="C":
		L=L+1
		if L>max:
			max=L
	else:
		L=0
print(max)

Measured memory_bytes: 3064
[A, B, C, K] = map(int, list(input().split(' ')))
left = K
ans = 0
# A
left = K - A
if(left >= 0):
    ans += A
else:
    ans += K
# B .. do nothing as diff would be 0
left = left - B
# C .. no need to subtract the left anymore
if(left > 0):
    ans -= left

print(ans)



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

const int INF = 100000000;

int n;
int dp[100010];
int coins[2] = {6, 9};

int main(){

    cin >> n;
    fill(dp, dp+100010, INF);

    dp[0] = 0;

    for(int i = 1; i <= n; i++){
        dp[i] = dp[i-1] + 1;

        int v_6 = INF, v_9 = INF;
        bool flag = false;

        for(int j = 0; j < 2; j++){

            
            if(i < coins[j]) break;
            flag = true;

            int back = 1;

            while(i >= back){
                back *= coins[j];
            }
            back /= coins[j];

            if(j == 0){
                v_6 = dp[i - back] + 1;
            }
            if(j == 1){
                v_9 = dp[i - back] + 1;
            }
        }
        if(flag) dp[i] = min(v_6, v_9);
    }

    // for(int i = 0; i <= 40; i++){
    //     cout << "i=" << i << "  " <<  dp[i] << endl;
    // }

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
#include <iterator>     // std::back_inserter
const double PI = acos(-1);
using namespace std;
using ll =long long;
#define rep(i,n)for(ll i=0;i<(n);i++)
const int mod = 1000000007;
const ll inf = 1e18+1;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
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;
}
//小文字=大文字+32
int main() {
	ll res=-inf;
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	res = max(res, a * c);
	res = max(res, b * c);
	res = max(res, a * d);
	res = max(res, b * d);
	cout << res;
}


Measured memory_bytes: 3672
#include<stdio.h>
#include <iostream>
#include <string>
#include <vector>
int main()
{
	using namespace std;
	string str;
	cin >> str;

	string ans;

	int w, len;

	scanf("%d", &w);

	len = str.length();

	for (int tmp = 0; (w * tmp) < len; tmp++)
		ans.push_back(str[w * tmp]);

	printf("%s\n", ans.c_str());

	return 0;
}


Measured memory_bytes: 256
#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)

vi g[114514], g2[114514];
int root, child;
bool used[114514], used2[114514];
pii ans[114514];

void dfs(int u){
	if(g[u].size()>1){
		for(auto  v : g[u]){
			bool ok=true;
			for(auto v2 : g2[v]){
				if(ans[v2].first==0){
					ok=false;
					break;
				}
			}
			if(ok && ans[v].second<ans[u].second+1){
				ans[v]=pii(u, ans[u].second+1);
				dfs(v);
			}
		}
	}
	else{
		if(g[u].size()==0){
			return;
		}
		ans[g[u][0]]=pii(u, ans[u].second+1);
		dfs(g[u][0]);
	}
	return;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, a, b;
	cin>>n>>m;
	REP(i, n+m){
		cin>>a>>b;
		g[a].push_back(b);
		g2[b].push_back(a);
		used[b]=true;
		used2[a]=true;
	}
	FOR(i, 1, n+1){
		if(!used[i]){
			root=i;
			break;
		}
	}
	FOR(i, 1, n+1){
		if(!used2[i]){
			child=i;
			break;
		}
	}
	ans[root]=pii(-1, 0);
	dfs(root);
	FOR(i, 1, n+1){
		if(ans[i].first!=-1){
			cout<<ans[i].first<<'\n';
		}
		else{
			cout<<0<<'\n';
		}
	}
	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;

  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
  return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int X,N;
int A[110];
set<int> U;

signed main(){
	cin>>X>>N;
	REP(i,N){
		cin>>A[i];
		U.insert(A[i]);
	}
	for(int i=0;;i++){
		int k=X-i;
		if(U.find(k)==U.end()){
			cout<<k<<endl;
			return 0;
		}
		k=X+i;
		if(U.find(k)==U.end()){
			cout<<k<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3580
#include<iostream>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int t[100001],x[100001],y[100001];
  t[0]=x[0]=y[0]=0;
  for(int i=0;i<N;++i)cin >> t[i+1] >> x[i+1] >> y[i+1];
  
  bool can=true;
  for(int i=0;i<N;++i){
    int dt=t[i+1]-t[i];
    int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(dt<dist)can=false;
    if(dist%2 != dt%2)can=false;
  }
  if(can)cout << "Yes" <<endl;
  else cout <<"No"<<endl;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

namespace {
#define VERA(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ANDY(i,a,b) for(ll i=ll(a);i>ll(b);--i)
#define SIZE(x) (ll)(x.size())

typedef long long ll;
typedef double dd;

struct Person {
  ll hei, pw;

  bool operator<(const Person& per) const {
    return make_pair(hei+pw, hei) < make_pair(per.hei + per.pw, per.hei);
  }
};

const ll INF = ll(1) << 60;
ll N;
vector<Person> ppl;

void Min(ll& a, ll b) {a=min(a,b);}

void Solve() {
  sort(ppl.begin(), ppl.end());
  vector<ll> dp(N+1,INF);
  dp[0] = 0;
  VERA(i,0,N) {
    ANDY(j,i,-1) {
      if (dp[j] <= ppl[i].hei)
        Min(dp[j+1], dp[j] + ppl[i].pw);
    }
  }
  ll res=N;
  while(dp[res] == INF) --res;
  cout << res << endl;
}

bool Input() {
  if(!(cin >> N))
    return false;
  ppl.resize(N);
  for(auto& per : ppl) {
    cin >> per.hei >> per.pw;
  }
  return true;
}

}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  while (Input()) {
    Solve();
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

bool reached[1000000]={0};
ll chouten[1000000];
vector<pair<ll,ll>> b[100010];

void dfs(ll a,ll c){
  if(reached[a])return;
  reached[a]=1;
  for(int i=0;i<b[a].size();i++){
    if((c+b[a][i].second)%2==1){
      chouten[b[a][i].first]=1;
    }else{
      chouten[b[a][i].first]=0;
    }
    dfs(b[a][i].first,c+b[a][i].second);
  }
}

ll n;
ll w[1000000],v[1000000],u[1000000];


int main(){
  
  cin >> n;
  
  FOR(i,n-1){
    cin >> u[i] >> v[i] >> w[i];
    b[u[i]].push_back(make_pair(v[i],w[i]));
    b[v[i]].push_back(make_pair(u[i],w[i]));  
  }

  
  chouten[1]=1;
  dfs(1,0);

  FOR(i,n){
    cout << chouten[i+1] << endl;
     
  }
  

  
}

Measured memory_bytes: 18688
#include <iostream>
#include <algorithm>
#define ll long long int
using namespace std;
 
ll H,W;
 
ll maxfun(int  a, int b , int c){
  ll result;
  a>b? (result = a):(result =b);
  (result >c)? (result):(result = c);
  return result;
}
ll minfun(int  a, int b , int c){
  ll result;
  a<b? (result = a):(result =b);
  result <c? (result):(result = c);
  return result;
}
int main(){
  ll s1,s2,s3;
  ll result=100000;
  ll min, max;
  
  cin >> H >> W;
 
  if((H%3)*(W%3)==0){
    cout << "0" << endl;
    return 0;
  }
  else{
    result = std::min(H,W);
  }
  for(int i =H/3; i< H/2+1;i++){
    for(int j = W/3; j< W/2+1; j++){
      s1 = i*W;
      s2 = j*(H-i);
      s3 = (H-i)*(W-j);
      min = minfun(s1,s2,s3);
      max = maxfun(s1,s2,s3);
      if(result> (max-min)) result = max-min;
 
      s1 = j*H;
      s2 = i*(W-j);
      s3 = (H-i)*(W-j);
      min = minfun(s1,s2,s3);
      max = maxfun(s1,s2,s3);
      if(result> (max-min)) result = max-min;
    }
  }
 
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


const ll INF = 1e18;

struct edge
{
	int to;
	ll co;
	edge(int to, ll co):to(to), co(co){}
};
struct vertex
{
	int p, h; ll c;
	vertex(int p, int h, ll c) :p(p), h(h), c(c) {}
	bool operator<(const vertex& v)const {
		return c > v.c;
	}
};

int N, M, X;
int H[100005];
ll cost[100005];
vector<edge> G[300005];
int main() {
	cin >> N >> M >> X;
	rep(i, N) cin >> H[i];
	rep(i, M) {
		int a, b, t;
		cin >> a >> b >> t;
		a--; b--;
		if(H[a] >= t) G[a].emplace_back(b, t);
		if(H[b] >= t) G[b].emplace_back(a, t);
	}

	rep(i, N) cost[i] = INF;
	cost[0] = 0;
	priority_queue<vertex> pq;
	pq.emplace(0, X, 0);
	int last = 0;
	while (!pq.empty())
	{
		vertex now = pq.top(); pq.pop();
		if (cost[now.p] != now.c) continue;
		if (now.p == N - 1) break;
		for (auto e : G[now.p]) {
			int add = 0, h = now.h - e.co;
			if (h < 0) add = -h, h = 0;
			if (h > H[e.to]) add = h - H[e.to], h = H[e.to];
			if (cost[e.to] > now.c + e.co + add) {
				if (e.to == N - 1) last = h;
				cost[e.to] = now.c + e.co + add;
				pq.emplace(e.to, h, cost[e.to]);
			}
		}
	}

	if (cost[N - 1] == INF) cout << -1 << endl;
	else cout << cost[N - 1] + H[N - 1] - last << endl;


	return 0;
}



Measured memory_bytes: 27208
#include<bits/stdc++.h>
using namespace std;
#define N 2333333
#define mod 1000000007

int n,x[6],y[6];
long long fac[N],inv[N],ans;

long long c(int x,int y){
	return fac[x+y]*inv[x]%mod*inv[y]%mod;
}

long long solve(int lx,int rx,int ly,int ry){
	return (c(rx+1,ry+1)-c(lx,ry+1)-c(rx+1,ly)+c(lx,ly))%mod;
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	for (int i=0;i<6;i++) x[i]=read();
	for (int i=0;i<6;i++) y[i]=read();
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for (int i=2;i<N;i++) fac[i]=fac[i-1]*i%mod;
	for (int i=2;i<N;i++) inv[i]=-(mod/i)*inv[mod%i]%mod;
	for (int i=2;i<N;i++) inv[i]=inv[i-1]*inv[i]%mod;
	for (int i=x[2];i<=x[3];i++){
		ans=(ans-(i+y[2]-1)
			*solve(i-x[1],i-x[0],y[2]-1-y[1],y[2]-1-y[0])%mod
			*solve(x[4]-i,x[5]-i,y[4]-y[2],y[5]-y[2]))%mod;
		ans=(ans+(i+y[3])
			*solve(i-x[1],i-x[0],y[3]-y[1],y[3]-y[0])%mod
			*solve(x[4]-i,x[5]-i,y[4]-y[3]-1,y[5]-y[3]-1))%mod;
	}
	for (int i=y[2];i<=y[3];i++){
		ans=(ans-(i+x[2]-1)
			*solve(x[2]-1-x[1],x[2]-1-x[0],i-y[1],i-y[0])%mod
			*solve(x[4]-x[2],x[5]-x[2],y[4]-i,y[5]-i))%mod;
		ans=(ans+(i+x[3])
			*solve(x[3]-x[1],x[3]-x[0],i-y[1],i-y[0])%mod
			*solve(x[4]-x[3]-1,x[5]-x[3]-1,y[4]-i,y[5]-i))%mod;
	}
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 36736
import queue

class Graph:

    INF = 10**27+1
    
    def __init__(self,v_num,is_directed = False):
        self.is_directed = is_directed
        self.v_num = v_num
        self.E = []
        self.v_s_list = [[] for i in range(self.v_num)]
        
    def appendEdge(self,v1,v2,weight=1):
        if max(v1,v2,self.v_num-1)>=self.v_num or min(v1,v2)<0:
            print("ERROR: The vertex ID is wrong.")
            return False

        self.E.append([v1,v2,weight])
        
        if self.is_directed:
            self.v_s_list[v1].append([v2,weight])
        else:
            self.v_s_list[v1].append([v2,weight])
            self.v_s_list[v2].append([v1,weight])
        
        
    def BFS(self,v,usage="SSSP"):
        is_processed = [False for i in range(self.v_num)]
        distance_list = [Graph.INF for i in range(self.v_num)]
        Q = queue.Queue()
        Q.put(v)
        is_processed[v]=True
        distance_list[v] = 0
        while not Q.empty():
            v1 = Q.get()
            for v2 in self.v_s_list[v1]:
                if not is_processed[v2[0]]:
                    is_processed[v2[0]] = True
                    distance_list[v2[0]] = min(distance_list[v1]+1,distance_list[v2[0]])
                    Q.put(v2[0])
        if usage=="SSSP":
            return distance_list
        elif usage=="ConnectedComponent":
            cc_list = []
            for i in range(self.v_num):
                if is_processed[i]:
                    cc_list.append(i)
            return cc_list

    def getSSSPwithBFS(self,v):
        return self.BFS(v,"SSSP")
        
    def getConnectedComponent(self,v):
        return self.BFS(v,"ConnectedComponent")
        
    def getSSSPwithBellmanFord(self,v):
        distance_list = [Graph.INF for i in range(self.v_num)]
        distance_list[v] = 0
        pre_list = [None for i in range(self.v_num)]

        for i in range(self.v_num-1):
            for e in self.E:
                v1 = e[0]
                v2 = e[1]
                d = e[2]
                if distance_list[v2] > distance_list[v1] + d:
                    distance_list[v2] = distance_list[v1] + d
                    pre_list[v2] = v1
                    
        negative_loop_list = [False for i in range(self.v_num)]
        
        for i in range(self.v_num):
            for e in self.E:
                v1 = e[0]
                v2 = e[1]
                d = e[2]
                if d + distance_list[v1] < distance_list[v2]:
                    distance_list[v2] = d + distance_list[v1]
                    pre_list[v2] = v1
                    negative_loop_list[v2] = True
        
        return distance_list, pre_list, negative_loop_list


N,M=list(map(int,input().split()))

G = Graph(N,True)

for i in range(M):
    a,b,c = list(map(int,input().split()))
    G.appendEdge(a-1,b-1,-c)
    
res=G.getSSSPwithBellmanFord(0)

if res[2][N-1]:
    print('inf')
else:
    print(-res[0][N-1])

Measured memory_bytes: 4592
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;
int main() {
	while (true) {
		int a, b; string s;
		cin >> a >> s >> b;
		if (s == "?")break;
		if (s == "+")cout << a + b << endl;
		if (s == "-")cout << a - b << endl;
		if (s == "*")cout << a * b << endl;
		if (s == "/")cout << a / b << endl;
	}
	return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[400000];
signed main(){
	int n, k;
	scanf("%lld%lld", &n, &k);
	rrep(i,n)a[i%k]++;
	int ans = 0;
	if(k%2 == 0)ans += a[k/2]*a[k/2]*a[k/2];
	ans += a[0]*a[0]*a[0];
	printf("%lld\n", ans);
	return 0;
}






Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define double long double
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6; 
using namespace std;

int n;

vector<int> a, b, ans;

signed main() {

	cin >> n;

	for(int i = 0; i < n; i++){
		int x; cin >> x;
		a.push_back(x);
		b.push_back(x);
	}

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

	//cout << b.back(); return 0;

	for(int i = 0; i < n; i++){
		int maxx = b.back();

		if(maxx > a[i]) ans.push_back(maxx);
		else{
			if(n == 1) ans.push_back(maxx);
			else ans.push_back(b[n-2]);
		}

	}

	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}


	return 0;
}

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

bool is_prime(int x)
{
  if(x==1) return true;
  for(int i = 2; i*i <= x; ++i)
  {
    if(x%i == 0) return false;
  }
  return true;
}

int main()
{
  int x;
  cin >> x;
  while(!is_prime(x))
  {
    ++x;
  }
  cout << x << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,m;
  while(cin>>n>>m){
    cout<<__gcd(n,m)<<endl;
  }
}

Measured memory_bytes: 3040
#include<bits/stdc++.h> 
using namespace std; 
#define deb(x) cout <<"\n"<< (#x) << " = " << (x) << "\n"
const long long  INF = 1e18;
const long long mod=1e9+7 ;
void inputoutput()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); 
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	    
}


vector<int> adj[200500];
vector<int> vis(200500);

void dfs(int v,int& ans)
{
	++ans;
	vis[v]=true;
	for(auto u : adj[v])
	{
		if(!vis[u])
			dfs(u,ans);
	}
}



void solve()
{
		// dfs implementation in undirected graph
	int n ;   // no. of vertices
	cin>>n ;
	int e;    // no. of edjes
	cin>>e;
	for(int i=0 ; i<e ; ++i)
	{
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int sol=INT_MIN ;
	for(int i=0 ; i<n ; ++i)
	{
		if(!vis[i])
		{
			int ans=0;
			dfs(i,ans);
			sol=max(sol,ans);
		}
	}

	cout<<sol<<"\n";


}

int32_t main()
{ 
	inputoutput() ;
	solve();


	return 0;
}


Measured memory_bytes: 21060
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}
int mm[100005];

signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int a[n+1];
    int x=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        x^=a[i];
    }
    for(int i=1;i<=n;i++)
    {
        cout<<(x^a[i])<<" ";
    }
        

} 
    
 


Measured memory_bytes: 5104