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

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

vector<int> Z_function(string S)
{
    int n = S.size();
    vector<int> z(n);
    int l = -1, r = -1;
    for (int i = 1; i < n; ++i)
    {
        if (i <= r)
            z[i] = min(r - i, z[i - l]);
        while (i + z[i] < n && S[z[i]] == S[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i];
    }
    return z;
}

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int n;
        cin >> n;
        vector<int> a(n);
        vector<int> b(n);
        for (auto &x : a)
            cin >> x;
        for (auto &x : b)
            cin >> x;
        vector<int> ans(n);
        for (size_t k = 0; k < 30; k++)
        {
            string s(3 * n, '*');
            string t(3 * n, '*');
            for (size_t i = 0; i < n; i++)
            {
                s[i] = (b[i] >> k & 1) + '0';
                t[i] = (~b[i] >> k & 1) + '0';
                t[i + n] = t[i + 2 * n] = s[i + n] = s[i + 2 * n] = (a[i] >> k & 1) + '0';
            }
            auto z0 = Z_function(s);
            auto z1 = Z_function(t);
            for (size_t i = 0; i < n; i++)
            {
                if (ans[i] == -1)
                    continue;
                if (z0[i + n] >= n)
                    continue;
                else if (z1[i + n] >= n)
                    ans[i] ^= 1 << k;
                else
                    ans[i] = -1;
            }
        }
        for (size_t i = 0; i < n; i++)
            if (ans[i] != -1)
                cout << i << ' ' << ans[i] << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

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

int main()
{
	int n;
	while(cin >> n){
		int a[25],b[25],c[25];
		int sum = 0;
		for(int i = 1; i <= n; i++)
			cin >> a[i];
		for(int i = 1; i <= n; i++){
			cin >> b[i];
			sum += b[i];
		}	
		for(int i = 1; i < n; i++)
			cin >> c[i];
		for(int i = 1; i <= n; i++){
			if(a[i] + 1 == a[i+1])
				sum += c[a[i]];
		}
		cout << sum << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
def solve():
    n, *p_l = map(int, open(0).read().split())
    ans = 0
    
    for i in range(1, n-1):
        if p_l[i-1] < p_l[i] < p_l[i+1] or p_l[i+1] < p_l[i] < p_l[i-1]:
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n; cin >> n;
    vector<ll> a(n); rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, n-1) if(a[i] > a[i+1]) {ans += a[i] - a[i+1]; a[i+1] = a[i];}
    cout << ans << endl;
}


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

inline long gl(void){
    long x = 0;
    for(;;){
        int c=getchar_unlocked();
        if('0'<= c && c <='9'){
            x = x*10 + c-'0';
        }else{
            break;
        }
    }
    return x;
}

int main(void){
    long n=gl();
    long h=gl();
    vector<long> b(n);
    long am=0;
    for(long i=0; i<n; i++){
        long a=gl();
        b[i] = gl();
        am = a>am ? a : am;
    }
    sort(b.begin(), b.end(), greater<long>());
    long m=0;
    for(;b[m]>am && h>0; m++){
        h-=b[m];
    }
    if(h>0){
        m+=(h+am-1)/am;
    }
    printf("%ld", m);
    return 0;
}


Measured memory_bytes: 1024
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a==b:
    print("YES")
elif b<a:
    if b-t*w<a-t*v:
        print("NO")
    else:
        print("YES")
else:
    if a+t*v<b+t*w:
        print("NO")
    else:
        print("YES")



Measured memory_bytes: 9184
n,m=map(int,input().split())
a = list(map(int,input().split()))
# if m == 1:
#     print(0)
#     exit()
a.sort()
# print(a)
b = []
for i in range(m-1):
    b.append(abs(a[i+1]-a[i]))
b.sort()
b.reverse()
# print(b)
ans = sum(b)-sum(b[0:n-1])
print(ans)

Measured memory_bytes: 56744
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353 
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n=s.length();
        for(int i=0;i<n;i++){
            if(s[i]=='?'){
                s[i]='D';
            }
        }
        cout<<s<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3788
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int D, T, S;
    cin >> D >> T >> S;

    if (T * S >= D) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
A, B = map(int, input().split())
S = input()

str_list = []
for i in S:
    str_list.append(i)

if str_list[A] == '-':
    str_list[A] = 0
    if not '-' in str_list:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
using namespace std;

int main(void){
  int N,W;
  cin >> N >>W;
  
  int64_t dp[N+1][W+1];
  memset(dp,0,sizeof(dp));
  
  vector<int> w;
  vector<int> v;
  w.push_back(0);
  v.push_back(0);
  for(int i=0;i<N;i++){
    int _w,_v;
    cin >> _w >> _v;
    w.push_back(_w);
    v.push_back(_v);
  }
  
  for(int i=1;i<=N;i++){
    for(int j=1;j<=W;j++){
      if(j<w[i]){
        dp[i][j] = dp[i-1][j];
      } else {
        dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
      }
    }
  }
  
  /*
  for(int i=0;i<=N;i++){
    for(int j=0;j<=W;j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  
  cout << dp[N][W] << endl;
}


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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

ll dp[109][5][2];

int main(){
  string S; int K;
  cin >> S >> K;
  int N = S.size();
  dp[0][0][0] = 1;
  REP(i, N){
    int D = S[i] - '0';
    REP(j, K+1){
      REP(k, 2){
        // 0を選ぶ
        dp[i+1][j][k||(D>0)] += dp[i][j][k];
        // 0以外を選ぶ
        if(k == 0){
          if(D == 0) continue;
          // Dを選ぶ
          dp[i+1][j+1][k] += dp[i][j][k];
          // 0 < x < D を選ぶ
          dp[i+1][j+1][1] += (D-1) * dp[i][j][k];
        }
        else{
          dp[i+1][j+1][k] += 9LL * dp[i][j][k];
        }
      }
    }
    cerr << "i:" << i << " dp:" << dp[i+1][K][1] << endl;
  }
  cerr << dp[N][K][0] << " " << dp[N][K][1] << endl;
  cout << dp[N][K][0] + dp[N][K][1] << endl;
  return 0;
}


Measured memory_bytes: 256
//sunuke さんのコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(n);++i)
#define chmax(x,y) x=max(x,y)
const ll INF = 1e18;
// ll dp[200001][4]; // [N][skip]
ll dp[200001][3]; // [N][skip]

int main() {
  int N; cin>>N;
  vector<int> A(N);
  rep(i, N) cin>>A[i];

  rep(i, N+1) dp[i][0] = dp[i][1] =  dp[i][2] =-INF;
  dp[0][0] = 0;

  rep(i, N){

		chmax(dp[i+1][0], dp[i][0] + ((i+0)%2? 0:A[i]));
		chmax(dp[i+1][1], dp[i][0]);

		chmax(dp[i+1][1], dp[i][1] + ((i+1)%2? 0:A[i]));
		chmax(dp[i+1][2], dp[i][1]);

		chmax(dp[i+1][2], dp[i][2] + ((i+2)%2? 0:A[i]));
		// chmax(dp[i+1][3], dp[i][2]);

  }

  cout << dp[N][N%2+1] << endl;

	// // print =====================
	// puts("---");//
	// rep(i,N)cout<<A[i]<<" ";//
	// puts("");//
	// puts("===");//
	// cout<<"i: ";
	// rep(i,N+1) printf("%5d ",i);//
	// puts("");//
	// rep(j,skip+1){
	// 	cout<<j<<": ";
	// 	rep(i,N+1){
	// 		if(dp[i][j] == -INF) cout<<"----- ";
	// 		else printf("%5lld ",dp[i][j]);
	// 	}
	// 	puts("");
	// }
	// puts("===");//
	// rep(i,N+1){
	// 	cout<<i<<": ";
	// 	rep(j,skip+1){
	// 		if(dp[i][j] == -INF) cout<<"----- ";
	// 		else printf("%5lld ",dp[i][j]);
	// 	}
	// 	puts("");
	// }
	// // ===========================

}


Measured memory_bytes: 8800
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
string res[8];
/*
 0123456789
0*****     
1     *****
2==========
3 **** ****
4* **** ***
5** **** **
6*** **** *
7**** **** 
*/
int main() {
    int flag=0;
    while (scanf("%d",&n)!=EOF) {
        if (flag) printf("\n");
        else flag=1;
        fill(res, res+8, "");
        res[2]="=====";
        int ten=10000;
        for (int i=0; i<5; i++) {
            int x=n/ten;
            n%=ten;
            ten/=10;
            if (0<=x&&x<=4) {
                res[0]+='*';
                res[1]+=' ';
            } else {
                res[0]+=' ';
                res[1]+='*';
            }
            if (x==0||x==5) res[3]+=' ';
            else res[3]+='*';
            if (x==1||x==6) res[4]+=' ';
            else res[4]+='*';
            if (x==2||x==7) res[5]+=' ';
            else res[5]+='*';
            if (x==3||x==8) res[6]+=' ';
            else res[6]+='*';
            if (x==4||x==9) res[7]+=' ';
            else res[7]+='*';
        }
        for (int i=0; i<8; i++) cout << res[i] << endl;
    }
}

Measured memory_bytes: 932
k=int(input())
if k==0:
  print(2)
  print(0,0)
elif k==1:
  print("""3
1 0 3
""")
elif k<=50:
  print(k)
  print(*[k for i in range(k)])
else:
  print(50)
  rep=k//50
  rem=k%50
  l=[]
  for i in range(50):
    if i<rem:
      l.append(50+rep-rem+50)
    else:
      l.append(50+rep-1-rem)
  print(*l)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

//https://atcoder.jp/contests/dp/tasks/dp_d
public class Main {

	public static void main(String[] args) throws Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		XeniaAndBitOperations solver = new XeniaAndBitOperations();
		// int test = in.nextInt();
		// while (test-- > 0)
		solver.solve(1, in, out);
		out.close();
	}

	static class XeniaAndBitOperations {
		
		int w[];
		long v[];
		int n;
		int W;
		
		public void solve(int testNumber, InputReader in, PrintWriter out) throws Exception {

			n = in.nextInt();
			W = in.nextInt();
			w = new int[n];
			v = new long[n];
			for(int i=0; i<n; i++){
				w[i] = in.nextInt();
				v[i] = in.nextLong();
			}
			
			long dp[][] = new long[n][W+1];
//			long max = maxsum(n-1, W);
//			System.out.println(max);
			for(int i=0; i<=W; i++){
				for(int j=0; j<n ;j++){
					long notinc = j-1>=0?dp[j-1][i]:0;
					long inc = 0;
					if(w[j]<=i){
						inc = (j-1>=0?dp[j-1][i-w[j]]:0) + v[j];
					}
					dp[j][i] = Math.max(notinc, inc);
				}
			}
			System.out.println(dp[n-1][W]);
			
		}

//		private long maxsum(int i, int w2) {
//			
//			if(i>=0 && w2>0){
//				
//				long notinc = maxsum(i-1, w2);
//				long inc = 0;
//				if(w[i]<=w2)
//					inc = maxsum(i-1, w2-w[i]) + v[i];
//				
//				return Math.max(notinc, inc);
//			}
//			
//			return 0;
//		}


	}

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

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}

Measured memory_bytes: 131540
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N = ni()
a_array = na()

dp = [[0] * (N+1) for _ in range(N+1)]

for s in range(N-1, -1, -1):
    turn = 1 if s % 2 == 0 else -1
    for l in range(s+1):
        r = s - l
        # print(l,r,turn)
        if turn == 1:
            dp[l][r] = max(dp[l][r+1] + a_array[-(r+1)] * turn,
                           dp[l+1][r] + a_array[l] * turn)
        else:
            dp[l][r] = min(dp[l][r+1] + a_array[-(r+1)] * turn,
                           dp[l+1][r] + a_array[l] * turn)
print(dp[0][0])


Measured memory_bytes: 144796
import java.util.*;
import java.io.*;

public class Main {

	void solve() {
		int n = in.nextInt();
		int resOdd = 1, resEven = 0;
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			if (x % 2 == 0) {
				resEven = resOdd + resEven * 3;
				resOdd *= 2;
			} else {
				resEven = resOdd * 2 + resEven * 3;
				resOdd *= 1;
			}
		}
		out.println(resEven);
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 21332
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int k = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		
		long[] cumsum = new long[n + 1];
		for (int i = 0; i < n; i++) {
			cumsum[i + 1] = cumsum[i] + a[i];
		}

		List<Long> b = new ArrayList<>(n * (n + 1) / 2);
		long max = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				b.add(cumsum[j + 1] - cumsum[i]);
				max = Math.max(max, cumsum[j + 1] - cumsum[i]);
			}
		}
//		Collections.sort(b, Collections.reverseOrder());

		long mask = Long.highestOneBit(max);
		while (mask > 0) {
			List<Long> tmp = new ArrayList<>();
			for (long e : b) {
				if ((e & mask) != 0) {
					tmp.add(e);
				}
			}
			
			if (tmp.size() >= k) {
				b = tmp;
			}
			
			mask >>= 1;
		}
		
		if (b.size() < k) {
			pr.println(0);
		} else {
			long ans = -1L;
			for (long e : b) {
				ans &= e;
			}
			
			pr.println(ans);
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

int main(){
    int N,M,X,Y;
    cin>>N>>M>>X>>Y;
    vector<int> x(N);
    vector<int> y(M);

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

    for(int i=0; i<M; i++){
        cin>>y[i];
    }

    vector<int>::iterator xitr = max_element(x.begin(),x.end());
    vector<int>::iterator yitr = min_element(y.begin(),y.end());

    for(int z = X+1; z <= Y; z++){
        if(z > *xitr && z <= *yitr){
            cout<<"No War"<<endl;
            return 0;
        }
    }

    cout<<"War"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int N,M;
    scanf("%d %d",&N,&M);
    int hako[N+1];
    hako[1]=1;
    int ans=0;
    for(int i=2;i<N+1;i++)hako[i]=0;
    int hakokazu[N+1];
    for(int i=1;i<N+1;i++)hakokazu[i]=1;
    int a,b;
    for(int i=0;i<M;i++){
        scanf("%d %d",&a,&b);
        if(hako[a]==1&&hakokazu[a]==1){hako[a]=0;hakokazu[a]=0;hakokazu[b]++;hako[b]=1;}
        else if(hako[a]==1&&hakokazu[a]!=1){hako[a]=1;hako[b]=1;hakokazu[a]--;hakokazu[b]++;}
        else if(hako[a]==0){hakokazu[a]--;hakokazu[b]++;}
        
    }
    for(int i=0;i<N;i++)ans+=hako[i+1];
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 896
//C:\Program Files(x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\x86_64-w64-mingw32\bits\stdc++.h
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

using namespace std;

int n;
int a[200005];
long long ans;
vector<int> sum[200005];

bool cmp(const vector<int> &a,const vector<int> &b){
	bool f=true;
	for(int i=0;i<a.size();i++){
		if(a[i]>=b[i]) f=false;
	}
	return f;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		sum[i].resize(25);
		for(int j=0;j<=20;j++){
			if(i) sum[i][j]=sum[i-1][j];
			else sum[i][j]=0;
			if(a[i]&(1<<j)) sum[i][j]++;
		}
	}
//	for(int i=0;i<n;i++){
//		for(int j=0;j<=20;j++) printf("%d ",sum[i][j]);
//		puts("");
//	}
	for(int i=0;i<n;i++){
		vector<int> now;
		if(i) for(int j=0;j<=20;j++) now.push_back(sum[i-1][j]+1);
		else for(int j=0;j<=20;j++) now.push_back(1);
		int lb=i,rb=n;
		while(rb-lb>1){
			int md=(rb+lb)/2;
			vector<int> mid=sum[md];
			bool f=true;
			for(int j=0;j<=20;j++){
				if(mid[j]>now[j]){
					f=false;
					break;
				}
			}
			if(f) lb=md;
			else rb=md;
		}
//		printf("%d %d\n",i,lb);
		ans+=lb-i+1;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 27648
#include <iostream>

using namespace std;

int main() {
    int n = 0;
    while (cin>>n && n != 0) {
        int a[5001] = {};
        cin>>a[0];
        int max = a[0];
        for (int i = 1; i < n; i++) {
            cin>>a[i];
            if (a[i] >= 0) {
                int temp = 0;
                for (int s = i; s >= 0; s--) {
                    temp += a[s];
                    if (temp > max) max = temp;
                    if (temp < 0) break;
                }
            }
        }
        cout<<max<<endl;
    }
}

Measured memory_bytes: 3060
n,k = map(int, input().split())
al = list(map(int, input().split()))
inner_invs = [0]*n
outer_invs = [0]*n

for i in range(n):
    inner_cnt = 0
    outer_cnt = 0
    for j in range(n):
        if al[i] > al[j]:
            if i < j:
                inner_cnt += 1
                outer_cnt +=1
            elif i > j:
                outer_cnt += 1
    inner_invs[i] = inner_cnt
    outer_invs[i] = outer_cnt


ans = 0
MOD = 10**9+7

for v in outer_invs:
    ans += v*k*(k-1)//2
    ans %= MOD

for v in inner_invs:
    ans += v*k

print(ans%MOD)


Measured memory_bytes: 68600
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#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 ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
int sum;
int h, w, s;
vvi cells;
vvi wa;
pii dp[32][32][32][32];
pii dfs(int lx,int ly,int rx,int ry) {
	if (dp[lx][ly][rx][ry].first != -1)
		return dp[lx][ly][rx][ry];
	int kukanwa = wa[ry][rx];
	if (ly - 1 >= 0)
		kukanwa -= wa[ly - 1][rx];
	if (lx - 1 >= 0)
		kukanwa -= wa[ry][lx - 1];
	if (ly - 1 >= 0&& lx - 1 >= 0)
		kukanwa += wa[ly - 1][lx - 1];
	pii res = {1,s-(sum-kukanwa)};
	if (res.second < 0)
		return{ -1e9,1e9 };
	//vdiv
	FOR(i, lx + 1, rx+1) {
		pii p1 = dfs(lx, ly, i-1, ry);
		pii p2 = dfs(i, ly, rx, ry);
		pii res2 = { p1.first + p2.first,min(p1.second,p2.second) };
		res = max(res, res2);
	}
	//hdiv
	FOR(i, ly + 1, ry + 1) {
		pii p1 = dfs(lx, ly, rx, i-1);
		pii p2 = dfs(lx, i, rx, ry);
		pii res2 = { p1.first + p2.first,min(p1.second,p2.second) };
		res = max(res, res2);
	}
	dp[lx][ly][rx][ry] = res;
	return res;
}
int main() {
	while (cin>>h>>w>>s,h) {
		sum=0;
		cells.clear();
		cells.resize(h, vi(w));
		REP(i, h) {
			REP(j, w) {
				cin >> cells[i][j];
				sum += cells[i][j];
			}
		}
		wa = cells;
		REP(i, h) {
			REP(j, w) {
				if (i != 0)
					wa[i][j] += wa[i - 1][j];
				if (j != 0)
					wa[i][j] += wa[i][j-1];
				if(i!=0&&j!=0)
					wa[i][j] -= wa[i-1][j - 1];
			}
		}
		REP(i, h)
			REP(j, w)
			REP(k, h)
			REP(l, w)
			dp[j][i][l][k] = {-1,0};
		pii p=dfs(0,0,w-1,h-1);
		cout << p.first << " " << p.second << endl;
	}
}

Measured memory_bytes: 11324
#https://atcoder.jp/contests/abc174/tasks/abc174_c
K= int(input())

if K%2==0 or K%5==0:
    print(-1)
elif K==1 or K==7:
    print(1)
else:
    B = 7
    i = 1
    while 1:
        if B==0:
            print(i)
            break
        else:
            B = (10 * B + 7) % K
            i = i + 1

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX = 1 << 30;

struct node {
	ll sum, add;
	node *lch, *rch;
};

const int pmax = 1e7;
node pool[pmax];
int it = 0;

node* fix(node *x) {
	node *y = &pool[it++];
	if (x) {
		*y = *x;
	}
	else {
		y->sum = y->add = 0;
		y->lch = y->rch = nullptr;
	}
	return y;
}

node* add(node *x, int l, int r, int lb = 0, int ub = MAX) {
	if (r <= lb || ub <= l) return x;
	x = fix(x);
	if (l <= lb && ub <= r) {
		x->add++;
		return x;
	}
	int c = (lb + ub) / 2;
	x->lch = add(x->lch, l, r, lb, c);
	x->rch = add(x->rch, l, r, c, ub);
	x->sum += min(r, ub) - max(l, lb);
	return x;
}

ll find(node *x, int l, int r, int lb = 0, int ub = MAX) {
	if (!x || r <= lb || ub <= l) return 0;
	if (l <= lb && ub <= r) return x->sum + x->add * (ub - lb);
	int c = (lb + ub) / 2;
	return find(x->lch, l, r, lb, c) + find(x->rch, l, r, c, ub) + x->add * (min(r, ub) - max(l, lb));
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<int>> vab(M, vector<int>(3));
	vector<int> vs;
	for (int i = 0; i < M; i++) {
		cin >> vab[i][1] >> vab[i][2] >> vab[i][0]; vab[i][1]--;
		vs.push_back(vab[i][0]);
	}
	sort(vab.begin(), vab.end());
	sort(vs.begin(), vs.end());
	vs.erase(unique(vs.begin(), vs.end()), vs.end());
	int s = vs.size();
	node* root = nullptr;
	vector<node*> rts(s);
	for (int i = 0, j = 0; i < s; i++) {
		while (j < M && vab[j][0] == vs[i]) {
			root = add(root, vab[j][1], vab[j][2]);
			j++;
		}
		rts[i] = root;
	}
	while (Q--) {
		int x, y;
		ll j;
		cin >> x >> y >> j; x--, j--;
		int lb = -1, ub = s - 1;
		while (ub - lb > 1) {
			int m = (lb + ub) / 2;
			if (find(rts[m], x, y) <= j) {
				lb = m;
			}
			else {
				ub = m;
			}
		}
		printf("%d\n", vs[ub]);
	}
	return 0;
}



Measured memory_bytes: 271560
#all you can eat

N, T = map(int, input().split())
food = [tuple(map(int, input().split())) for i in range(N)]

dp = [[0]*(3010) for i in range(3010)]

for i in range(N):
    time, value = food[i]
    for j in range(T):
        if j >= time:
            dp[i+1][j] = max(dp[i][j], dp[i][j-time] + value)
        else:
            dp[i+1][j] = dp[i][j]
        dp[i][j] = max(dp[i][j], dp[i][j-1])

rev_dp = [[0]*(3010) for i in range(3010)]
food.reverse()

for i in range(N):
    time, value = food[i]
    for j in range(T):
        if j >= time:
            rev_dp[i+1][j] = max(rev_dp[i][j], rev_dp[i][j-time] + value)
        else:
            rev_dp[i+1][j] = rev_dp[i][j]
    dp[i][j] = max(dp[i][j], dp[i][j-1])


ans = 0
for x in range(N):
    ans = max(ans, max(dp[N-1-x][t] + rev_dp[x][T-1-t]
                       for t in range(T))+food[x][1])
print(ans)



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

int main() {
  int A_1, A_2, A_3;
  cin >> A_1 >> A_2 >> A_3;
  if (A_1 + A_2 + A_3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;
bool prime[100005];
int a[100005];
int ji = 0;
void init()
{
    memset(prime, true, sizeof(prime));
    prime[1] = false;
    for(int i = 2; i <= 100000; i++)
    if(prime[i])
    {
        for(int j = i*2; j <= 100000; j+=i)
        {
            prime[j] = false;
        }
    }
    for(int i = 1; i <= 100000; i++)
    {
        if(prime[i])
        {
            int kk = (i+1)/2;
            if(prime[kk])a[ji++] = i;
        }
    }
}
int main()
{
    int n;
    cin >> n;
    init();
    while(n--)
    {
        int l, r;
        cin >> l >> r;
        int x = lower_bound(a, a+ji, l)-a;
        int y = lower_bound(a, a+ji, r)-a;
        if(a[y] != r)y--;
        cout << y-x+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    ll max_diff = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            max_diff = max(max_diff, abs(a[i] - a[j]));
        }
    }
    cout << max_diff << endl;
}

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

using namespace std;

int main(){
	int N;
	while(cin >> N){
		vector<int> a(N);
		for(int& t : a) cin >> t;
		int midx = -1, pidx = -1;
		for(int i=0;i<N;i++){
			if(a[i] > 0 && (pidx == -1 || a[pidx] < a[i])) pidx = i;
			if(a[i] < 0 && (midx == -1 || a[midx] > a[i])) midx = i;
		}
		vector<pair<int,int>> res;
		if(midx != -1 || pidx != -1){
			if(midx != -1 && pidx != -1){
				if(a[pidx] >= -a[midx]){
					for(int i=0;i<N;i++){
						if(a[i] < 0) res.emplace_back(pidx, i);
					}
					midx = -1;
				} else {
					for(int i=0;i<N;i++){
						if(a[i] > 0) res.emplace_back(midx, i);
					}
					pidx = -1;
				}
			}
			if(pidx != -1){
				for(int i=0;i+1<N;i++) res.emplace_back(i, i+1);
			} else {
				for(int i=N-2;i>=0;i--) res.emplace_back(i+1, i);
			}
		}
		cout << res.size() << endl;
		for(const auto& p : res) cout << p.first+1 << " " << p.second+1 << endl;
	}
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = set(map(int,input().split()))
b = set(map(int,input().split()))

mod = 10**9 + 7

## nCkのmodを求める関数
# テーブルを作る(前処理)
max = n*m +10
fac, finv, inv = [0]*max, [0]*max, [0]*max

def comInit(max):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,max):
      fac[i] = fac[i-1]* i% mod
      inv[i] = mod - inv[mod%i] * (mod // i) % mod
      finv[i] = finv[i-1] * inv[i] % mod

comInit(max)

# 二項係数の計算
def com(n,k):
    if(n < k):
        return 0
    if( (n<0) | (k < 0)):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

ab = []
check = set()
for i in a:
    check.add(i)
    if(i in b):
        ab.append((i,'ab'))
    else:
        ab.append((i,'a'))
for i in b:
    check.add(i)
    if(not i in a):
        ab.append((i,'b'))

ab.sort()

if(len(check) != len(ab))|(len(a) != n)|(len(b) !=m):
    print(0)
    exit()

col = 0
row = 0
used = 0
ans = 1

for tmp in ab:
    i,s = tmp
    x = i-used
    ab_flag = 0
    if(s=='a'):
        y = m - row
        col += 1
    elif(s=='b'):
        y = n - col
        row += 1
    else:
        y = (n-col) + (m-row) - 1
        col += 1
        row += 1
        ab_flag = 1
    used += y
    # print('{} {} {} {}'.format(i,used,x,y))
    if(i < used):
        print(0)
        exit()
    if(col==n)|(row==m):
        break

    ans = ans * com(x-1, y-1) * fac[(y-ab_flag)]   % mod

print(ans)

Measured memory_bytes: 63856
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void readin(T &x) {
	x = 0;
	T fh = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
	x *= fh;
}
inline void d_read(double &x) {
	x = 0.0;
	int fh = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
	for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
	if (ch == '.') {
		double num = 1.0;
		ch = getchar();
		for (; isdigit(ch); ch = getchar()) x = x + (num /= 10) * (ch ^ 48);
	}
	x *= fh;
}

template <typename T>
inline void wt(T x) {
	if (x > 9) wt(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void writeln(T x, char c) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	wt(x);
	putchar(c);
}

int main() {
	int n;
	cin >> n;
	if (n >= 30) {
		puts("Yes");
	}
	else puts("No");
	return 0;
}




Measured memory_bytes: 3640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		insertionSort(A, N);
	}

	public static void insertionSort(int[] A, int N) {
		// ??????????????????
		String output = Arrays.toString(A).replaceAll(",", "");
		// ?????????????????????
		System.out.println(output.substring(1, output.length() - 1));
		
		for (int i = 1; i < N; i++) {
			int v = A[i];
			int j = i - 1;
			// ?????§???????????????????????°???????????????????????\????????????????????????????????§??????
			while (j >= 0 && A[j] > v) {
				A[j + 1] = A[j];
				j--;
				A[j + 1] = v;
			}

			output = Arrays.toString(A).replaceAll(",", "");
			System.out.println(output.substring(1, output.length() - 1));
		}
	}
}

Measured memory_bytes: 31096
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;
int main()
{
  ll N, tallest = 0, ans = 0; cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
  	cin >> A[i];
    if (tallest < A[i]) {
    	tallest = A[i];
    }
  }
  // L = i + Ai, R = i - Ai
  vector<ll> L(N, 0), R(N, 0);
  for (ll i = 0; i < N; i++) {
  	if (i + A[i] > 0 && i + A[i] < N) L[i + A[i]]++;
    if (i - A[i] > 0 && i - A[i] < N) R[i - A[i]]++;
  }
  for (ll x = 1; x < N; x++) { //time consuming
  	ans += L[x] * R[x];
  }
  cout << ans << endl;
}

Measured memory_bytes: 8012
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] a = new int[n];
		long[] visit = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
			long count = 0;
			int now = 0;
			while(visit[now]==0) {
				count++;
				visit[now]=count;
				now = a[now]-1;
			}
			long loop = count+1-visit[now];
			//System.out.println(loop);
			if(k>=count) {
				long sub = count-loop;
				long circ = k-sub;
				circ %= loop;
				circ %= loop;
				int ans = 0;
				for(int i = 0; i < circ+sub; i++) {
					ans = a[ans]-1;
				}
				System.out.println(ans+1);
			}
			else {
				int ans = 0;
				for(int i = 0; i < k; i++) {
					ans = a[ans]-1;
				}
				System.out.println(ans+1);
			}
		}
}

Measured memory_bytes: 61724
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		long A = nextLong();
		long B = nextLong();

		TreeMap<Long,Long> mapA = primeFactorize(A);
		TreeMap<Long,Long> mapB = primeFactorize(B);
		mapA.put(1L, 1L);
		mapB.put(1L, 1L);

		long cnt =0;
		for(Long key:mapA.keySet()){

			if(mapB.containsKey(key)){
				cnt++;
			}
		}

		long ans = cnt;
		System.out.println(ans);


	}
public static TreeMap<Long, Long> primeFactorize(long N) {
	TreeMap<Long, Long> map = new TreeMap<>();
	for (long i = 2; i * i <= N; i++) {
		long k = 0;
		while (N % i == 0) {
			k++;
			N /= i;
		}
		if(k!=0)
			map.put(i, k);
	}
	map.put(N, 1L);
	return map;
}

public static long gcd(long a, long b) {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

bool f[100001];
int c[100002];


int main(){
  int q;
  cin >> q;
  vector<int> l(q),r(q);
  for(int i=0;i<q;++i){
    cin >> l[i] >> r[i];
  }


  for(int i=2;i<=100000;++i) if(!f[i]) for(int j=i+i;j<=100000;j+=i)f[j]=true;

  for(int i=3;i<=100000;i+=2) if(!f[i] && !f[(i+1)/2]) c[i]++;
  for(int i=3;i<=100000;i++) c[i]+=c[i-1];


  for(int i=0;i<q;++i){
    cout << c[r[i]]-c[l[i]-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 1920
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Lucas Number
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 86;

/* typedef */

typedef long long ll;

/* global variables */

ll lcs[MAX_N + 1];

/* subroutines */

/* main */

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

  lcs[0] = 2, lcs[1] = 1;
  for (int i = 2; i <= n; i++) lcs[i] = lcs[i - 1] + lcs[i - 2];

  printf("%lld\n", lcs[n]);
  return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    if n%10 == 3:
        print('bon')
    elif n%10 == 0:
        print('pon')    
    elif n%10 == 1:
        print('pon')    
    elif n%10 == 6:
        print('pon')    
    elif n%10 == 8:
        print('pon')
    else:
        print('hon')    
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 10856
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>
#include <cstdio>

using namespace std;

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

const ll MOD = 1000000007;
int A[100000];
ll dp[100000][13];

int main() {
    string S;
    cin >> S;
    int N = S.size();
    reverse(S.begin(), S.end());
    rep(i, N) {
        if (S[i] == '?') A[i] = -1;
        else A[i] = S[i] - '0';
    }
    int D = 1;
    dp[0][0] = 1;
    for (int j = 1; j < 13; j ++) dp[0][j] = 0;
    rep(i, N) {
        if (A[i] == -1) {
            rep(j, 13) {
                ll num = 0;
                rep(x, 10) {
                    int d = x * D % 13;
                    num = (num + dp[i][(j + 13 - d) % 13]) % MOD;
                }
                dp[i + 1][j] = num;
            }
        } else {
            int d = A[i] * D % 13;
            rep(j, 13) {
                dp[i + 1][j] = dp[i][(j + 13 - d) % 13];
            }
        }
        D = (D * 10) % 13;
    }
    cout << dp[N][5] << endl;


    return 0;
}

Measured memory_bytes: 11008
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Walking Takahashi
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  ll x, k, d;
  scanf("%lld%lld%lld", &x, &k, &d);
  x = abs(x);

  ll q = x / d, y;
  if (q >= k) y = x - k * d;
  else if ((k - q) & 1) y = abs(x - (q + 1) * d);
  else y = x - q * d;

  printf("%lld\n", y);
  return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
  int n;cin>>n;
  int a[200010];
  for(int i=0;i<n;i++)cin>>a[i];
  int po=0;
  for(int i=0;i<n;i++){
    if(a[i]==po+1)po++;
  }
  if(po==0)cout<<-1<<endl;
  else cout<<n-po<<endl;
  return 0;
}

Measured memory_bytes: 1024
import math

def end():
    print(-1)
    exit()

a, b = map(int, input().split())
if a > b:
    end()

n = a/0.08
m = b/0.1

if n <= m:
    dif = m-n
    if 0 <= dif < 12.5:
        ans = math.ceil(m)
        if ans >= n + 12.5: ans -= 1
        print(ans)
    else:
        end()
    
elif m < n:
    dif = n-m
    if 0 <= dif < 10:
        ans = math.ceil(n)
        if ans >= m + 10: ans -= 1
        print(ans)
    else:
        end()




Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long n,ans,res[30],cnt[30];
char s[201001];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
	{
		int idx=s[i]-'a';
		cnt[idx]++;
	}
	ans=n*(n-1)/2+1;
	for(int i=0;i<=25;i++)
	{
		if(cnt[i]<=1)continue;
		ans-=(cnt[i]*(cnt[i]-1))/2;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int mod=1e9+7;
int a[N];
int b[N];
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
	{
        int x,y;
		cin>>x>>y;
        a[i]=x-y;
        b[i]=x+y;
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    int ans=max(a[n]-a[1],b[n]-b[1]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5208
N = int(input())
H = list(map(int,input().split()))

ans = 0
for i in range(N):
 judge = 1
 for j in range(0,i+1):
   if(H[i] < H[j]): 
     judge = 0
 if(judge == 1):
  ans += 1
print(ans)

Measured memory_bytes: 3060
(function(input) {
    var a = input.split(' ').map(Number);
    console.log(distance(a[0], a[1], a[2], a[3]));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function distance(x1, y1, x2, y2) {
    return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

Measured memory_bytes: 7644
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n,x; cin >> n >> x;
	ll ans = 0;
	if(n % x == 0) cout << 3*(n-x) << endl;
	else{
		ll ans = n;
		n = n - x;
		while(1){
			if(n % x == 0){
				ans += (2 * n / x - 1) * x;
				break;
			}else{
				ans += n / x * x * 2;
				ll tmp = n;
				n = x;
				x = tmp % x;
			}
		}
		cout << ans << endl;
	}	
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int A,B,C,K,sum=0,result=0;
  scanf("%d %d %d %d",&A,&B,&C,&K);
  if(1<=K && K<=A+B+C && A+B+C<=2000000000) {
    if(K>A) {
      K-=A;
      sum+=A;
      result+=A;
      if(K>B) {
	K-=B;
	result-=K;
      }
    }else {
      sum+=K;
      result+=K;
    }
  }
  printf("%d",result);
  return 0;
}

Measured memory_bytes: 1704
#include<stdio.h>
int main(void){
	int n, last, a[100], i, j, min_ind, tmp, cnt = 0;
	
	scanf("%d\n", &n);
	last = n-1;
	for(i = 0; i < n; i++){
		if(i == last){
			scanf("%d\n", &a[i]);
			break;
		}
		scanf("%d ", &a[i]);
	}
	for(i = 0; i < last; i++){
		min_ind = i;
		for(j = i+1; j < n; j++){
			if(a[min_ind] > a[j]){
				min_ind = j;
			}
		}
		if(min_ind != i){
			tmp = a[i];
			a[i] = a[min_ind];
			a[min_ind] = tmp;
			cnt++;
		}
	}
	for(i = 0; i < n; i++){
		if(i == last){
			printf("%d\n", a[i]);
			break;
		}
		printf("%d ", a[i]);
	}
	printf("%d\n", cnt);
	return 0;
}


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

#define int long long int 
const double PI=3.1415926535897932384626433832795;
int32_t main()
{
   double r;
  cin>>r;
  cout<<fixed<<setprecision(20)<<2*PI*r<<endl;
  return 0;
}

Measured memory_bytes: 3744
# coding: utf-8

s = input()
check = True
for i in range(len(s)):
    char = ''
    if i % 2 == 0:
        char = 'h'
    else:
        char = 'i'
    if s[i] != char:
        check = False
        break
    
print('Yes' if check and len(s) % 2 == 0 else 'No')

Measured memory_bytes: 3060