akhauriyash/Code-Regression huggingface dataset:
import sys
import fractions

def solve(N: int, A: "List[int]"):
    A.sort()
    gcd_left = [A[0]] ##iまでのgcd
    for i in range(1,N):
        gcd_left.append(fractions.gcd(A[i],gcd_left[i-1]))
        
    gcd_right = [A[-1]] ##右からiまでのgcd
    for i in range(N-2,-1,-1):
        gcd_right.append(fractions.gcd(A[i],gcd_right[N-2-i]))
    answer = 1

    for i in range(N):
        if i == 0:
            answer = max(answer,gcd_right[N-2])
        elif i == N-1:
            answer = max(answer,gcd_left[N-2])
        else:
            answer = max(answer,fractions.gcd(gcd_left[i-1],gcd_right[N-2-i]))
    print(answer)
    return 


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Measured memory_bytes: 19076
#include<stdio.h>
int main(void)
{
 int i,a=0,b=0,c=0;
 char s[3];
 scanf("%s", s);
 for(i=0;i<3;i++){
    if(s[i]=='a') a++;
    else if(s[i]=='b') b++;
    else if(s[i]=='c') c++;
 }
 if(a==1&&b==1&&c==1) printf("Yes\n");
 else printf("No\n");

 return 0;
}


Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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
 */

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);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        	String n = in.next();
        	for(int i = 0; i < n.length(); i++) {
        		if(n.charAt(i) == '1') {
        			out.print("9");
        		}else {
        			out.print("1");
        		}
        	}
        	out.println("");
        }
    }

    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: 21332
#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int N=5e5+9;
int color[N];
int rightMostIndex[N];
int BIT[N];

typedef struct node{
	int index,l,r;
	node(int _index,int _l,int _r):index(_index),l(_l),r(_r) {}
	bool operator < (const node a) const {
		if(r==a.r)	return l<a.l;
		return r<a.r;
	}
}qnode;

void update(int index,int delta) {
	while(index<=N-5){
		BIT[index]+=delta;
		index+=(index&(-index));
	}
}

int sum(int index) {
	int total=0;
	while(index) {
		total+=BIT[index];
		index-=(index&(-index));
	}
	return total;
}

int main(){
	memset(rightMostIndex, -1, sizeof(rightMostIndex));
	int n,q;
	cin>>n>>q;
	for(int i=0;i<n;i++)	cin>>color[i];
	vector<qnode>queries;
	for(int i=0;i<q;i++) {
		int l,r;cin>>l>>r;l--;r--;
		queries.push_back(qnode(i,l,r));
	}
	sort(queries.begin(), queries.end());
	
	int q_index=0;
	int ans[q];
	for(int i=0;i<n;i++) {
		if(rightMostIndex[color[i]]!=-1)
			update(rightMostIndex[color[i]]+1,-1);

		rightMostIndex[color[i]]=i;
		update(rightMostIndex[color[i]]+1,1);

		while(q_index<q && queries[q_index].r==i) {
			ans[queries[q_index].index] = sum(queries[q_index].r+1)-((queries[q_index].l)?sum(queries[q_index].l):0);
			q_index++;
		}		
	}
	for(int i=0;i<q;i++)	cout<<ans[i]<<" \n";
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    string s[n];
    rep(i, 0, n) cin >> s[i];

    int ans = 0;
    rep(k, 0, n)
    {
        bool is_ok = true;
        rep(i, 0, n)
        {
            rep(j, 0, n)
            if (i < j)
            {
                int x1, y1, x2, y2;
                y1 = (k + i) % n; 
                x1 = j;
                y2 = (k + j) % n;
                x2 = i;

                is_ok &= s[x1][y1] == s[x2][y2];
            }
            if (!is_ok) break;
        }

        if (is_ok)
            ans += n;
        // cout << k << ' ' << is_ok << ' ' << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

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


	int N = getint();

	int A[1000001] = {};
	rep(i, N) A[getint()]++;

	int kotae = 0;
	rep1(i, 500000) {
		if (A[i]) {
			if (A[i] == 1) kotae++;
			for (int j = i + i; j <= 1000000; j += i) {
				A[j] = 0;
			}
		}
	}
	for (int i = 500001; i <= 1000000; i++) kotae += (A[i] == 1);
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 7692
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
int main()
{
    int n,money;
    cin>>n>>money;
    int i,j,k;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n;j++)
        {
            if(i+j>n)
            {
                break;
            }
            k=n-(i+j);
            if(i*10000+j*5000+k*1000==money)
            {
                cout<<i<<" "<<j<<" "<<k;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1;
    return 0;
}


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

class KMP {
public:
    KMP(const vector<int> &pat): pat(pat) {
        int n = pat.size();
        T.resize(n + 1, -1);
        for(int i = 0, j = -1; i < n; T[++i] = ++j) {
            while(j >= 0 && pat[i] != pat[j]) j = T[j];
        }
    }

    vector<int> operator()(const vector<int> &corp) {
        size_t corpPos = 0, patPos = 0;
        
        vector<int> ret;
        while(corpPos + patPos < corp.size()) {
            if(pat[patPos] == corp[corpPos + patPos]) {
                ++patPos;
                if(patPos < pat.size()) continue;
            }

            if(patPos == pat.size()) ret.push_back(corpPos);
            corpPos = corpPos + patPos - T[patPos];
            if(patPos > 0) patPos = T[patPos];
        }
        return ret;
    }

private:
    vector<int> pat;
    vector<int> T;
};


int main() {
    int N; cin >> N;
    vector<int> a(N), b(N);
    for(int i=0; i<N; ++i) cin >> a[i];
    for(int i=0; i<N; ++i) cin >> b[i];

    if(N == 1) {
        cout << 0 << (a[0] ^ b[0]) << endl;
        return 0;
    }

    vector<int> c(2 * N - 1), d(N - 1);
    for(int i=0; i+1<2*N; ++i) c[i] = (a[i % N] ^ a[(i + 1) % N]);
    for(int i=0; i+1<N; ++i) d[i] = (b[i] ^ b[i + 1]);

    KMP kmp(d);
    auto pos = kmp(c);
    for(int p : pos) {
        if(p == N) continue;
        cout << p << ' ' << (a[p] ^ b[0]) << '\n';
    }
}

Measured memory_bytes: 9844
n, k = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)

h =  nums.group_by{|num| num <=> 0}
(ns, nc), (_, zc), (ps, pc) = [-1, 0, 1].map{|v|
  h[v] || []}.map{|a|
    [a.sort_by(&:abs), a.size]
  }
x = nc * pc + # 積が負になる組み合わせの数
  zc * (nc + pc) + zc * (zc - 1) / 2 # 積が0になる組み合わせの数

puts case k
     when 0..nc*pc # K番目の値が負の場合
       # -10^9 <= Ai なので negative infinity は -(10**19)
       (-(10**19)..-1).bsearch{|v|
         c = 0
         r = pc - 1
         ns.each do |n|
           r -= 1 while r >= 0 && n*ps[r] <= v
           c += pc - r - 1
         end
         c >= k
       }
     when nc*pc..x # K番目の値が0の場合
       0
     else # K番目の値が正の場合
       # Ai <= 10^9 なので positive infinity は (10**19)
       (1..10**19).bsearch{|v|
         c = x
         [ns, ps].each do |as|
           l = 0
           r = as.size - 1
           while l < r
             r -= 1 while l < r && as[l]*as[r] > v
             c += r - l
             l += 1
           end
         end
         c >= k
       }
     end

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

int main() {
  int a,b;
  cin >> a >> b;
  
  if (a >=13) {cout << b << endl;}
  else if (a<13 && a>=6) {cout << b/2 << endl;}
  else {cout << 0 << endl;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mxN = 3*1e3+99;

set<ll> p5;
vector<ll> p(mxN,0);

ll binpow(ll a,ll b=5){
	ll res = 1;
	while(b>0){
		if(b&1)
			res*=a;
		a*=a;
		b>>=1;
	}
	return res;
}

void solve(){
	ll x;
	cin >> x;
	for(int i =0;i<mxN;i++){
		ll check = x-p[i];
		// cout << check << endl;
		if(p5.find(check)!=p5.end()){
			ll b = lower_bound(p.begin(),p.end(),check) -p.begin();
			cout << i << " " << -b << endl;return;
		}
		check*=-1;
		if(p5.find(check)!=p5.end()){
			ll b = lower_bound(p.begin(),p.end(),check) -p.begin();
			cout << i << " " << b << endl;return;
		}

	}

}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	p5.insert(0);
	for(ll i =1;i<mxN;i++){
		p[i] = binpow(i);
		p5.insert(binpow(i));
	}
	// sort(p.begin(),p.end());
	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 3788
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
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);
        BGoldenCoins solver = new BGoldenCoins();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoldenCoins {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            long x = s.nextLong();
            long res = 0;
            res += (x / 500) * 1000;
            x -= (x / 500) * 500;
            res += (x / 5) * 5;
            w.println(res);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22996
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)
int H,A[MAX+1];
void max(int i){
   int l,r,large;
   l=i*2;
   r=i*2+1;
   if(l<=H&&A[l]>A[i]) large=l;
   else large=i;
   if(r<=H&&A[r]>A[large]) large=r;
   if(large!=i)
   {
       swap(A[i],A[large]);
       max(large);
   }
}
int e()
{
    int maxv;
    if(H<1) return -INFTY;
    maxv=A[1];
    A[1]=A[H--];
    max(1);
    return maxv;
}
void inc(int i,int key)
{
    if(key<A[i]) return;
    A[i]=key;
    while(i>1&&A[i/2]<A[i])
    {
        swap(A[i],A[i/2]);
        i=i/2;
    }
}
void insert(int key)
{
    H++;
    A[H]=-INFTY;
    inc(H,key);
}
int main()
{
    int key;
     char com[10];
     while(1)
     {
         scanf("%s",com);
         if(com[0]=='e'&&com[1]=='n')break;
         else if(com[0]=='i')
         {
             scanf("%d",&key);
             insert(key);
         }
         else printf("%d\n",e());
     }
}

Measured memory_bytes: 6500
#include <stdio.h>
int main(void){
  int a, b;

  scanf("%d %d", &a, &b);

  if(a>=-1000 && a<=1000 && b>=-1000 && b<=1000){
    if(a<b){
      printf("a < b\n");
    }
    else if(a>b){
      printf("a > b\n");
    }
    else{
      printf("a == b\n");
    }
  }
  else{
    return 1;
  }
  return 0;
}

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

bool check(string a,string b){
    for(int i=0;i<a.length();i++){
        if(a[i]=='?')continue;
        else if(a[i]==b[i])continue;
        else return false;
    }
    return true;
}

int main(){
string s,t;cin>>s>>t;
if(t.length()>s.length()){cout<<"UNRESTORABLE";return 0;}
bool yes=false;
int slen=s.length(),tlen=t.length();int i;
for( i=slen-tlen;i>=0;i--){
    if(check(s.substr(i,tlen),t)){yes=true;break;}
}
 for(int i=0;i<slen;i++){
        if(s[i]=='?')s[i]='a';
    }
if(yes){
cout<<s.substr(0,i)<<t<<s.substr(i+tlen,slen-i-tlen);
}
else cout<<"UNRESTORABLE";
}

Measured memory_bytes: 256
program main
implicit None
	integer(8)::n,p=0,i
	character(len =100)::a,b,c
	
	read*,n
	read*,a,b,c
	
	do i = 1,n
		if(a(i:i) == b(i:i))then
			if(a(i:i) /= c(i:i)) p = p+1
			else
				if(a(i:i) == c(i:i))then
					p = p+1
					else if(b(i:i) == c(i:i))then
					p = p+1
					else
					p = p+2
				endif
		endif
	enddo
	
	print "(i0)",p
end program main

Measured memory_bytes: 640
def Segment(x, l, n): 
    if (n == 1): 
        return 1
    ans = 1
      
    for i in range(1, n): 
        if (x[i] - l[i] >= x[i - 1]): 
            ans += 1
        else:
            x[i] = x[i-1] 
        # print(x, l)
        # if (x[i] + l[i] < x[i + 1]): 
        #     x[i] = x[i] + l[i] 
        #     ans += 0
    return ans 

def main():
    N = int(input())
    X, L = [], []
    for n in range(N):
        x, l = list(map(int, input().split()))
        X.append(x+l)
        L.append(2*l)
    X, L = zip(*sorted(zip(X, L)))
    X = list(X)
    L = list(L)

    print(Segment(X, L, N))

if __name__ == "__main__":
    main()


Measured memory_bytes: 25988
#include "bits//stdc++.h"
using namespace std;

int n, ans = 0;
int a[100010], b[100010];

int main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> b[i];
	}
	ans = b[0] + b[n - 2];
	for (int i = 0; i < n - 2; i++) {
		ans += min(b[i], b[i + 1]);
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
calculate = {
    0: lambda n: "#." * ((n // 2) + 1),
    1: lambda n: ".#" * ((n // 2) + 1), }
while True:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    else:
        for x in range(h):
            print(calculate[x % 2](w)[0:w])
        print()



Measured memory_bytes: 5612
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long quickpow(long long b, int e)
{
	return e ? ((e & 1 ? b : 1)*quickpow(((b%MOD)*(b%MOD)) % MOD, e >> 1)) % MOD : 1;
}

int x, y;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> x >> y;
	if ((x + y) % 3) {
		cout << 0 << E;
	}
	else {
		int k = (x + y) / 3;
		x -= k;
		y -= k;
		if (x < 0 || y < 0) {
			cout << 0 << E;
			return 0;
		}
		long long ans = 1;
		for (int i = 1; i <= k; i++) {
			ans *= i;
			ans %= MOD;
		}
		long long tmp = 1;
		for (int i = 1; i <= x; i++) {
			tmp *= i;
			tmp %= MOD;
		}
		ans *= quickpow(tmp, MOD - 2);
		ans %= MOD;
		tmp = 1;
		for (int i = 1; i <= y; i++) {
			tmp *= i;
			tmp %= MOD;
		}
		ans *= quickpow(tmp, MOD - 2);
		ans %= MOD;
		cout << ans << E;
	}
	//system("pause");
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> num(n, vector<int>(3));
    for (int i=0; i<n; i++) for (int j=0; j<3; j++) cin >> num[i][j];
    vector<vector<int>> dp(n+1, vector<int>(3, 0));

    for (int i=0; i<n; i++) {
        for (int j=0; j<3; j++) {
            for (int k=0; k<3; k++) {
                if (j == k) continue;
                if (dp[i+1][k] < dp[i][j] + num[i][k]) dp[i+1][k] = dp[i][j] + num[i][k];
            }
        }
    }

    int ans = 0;
    for (int i=0; i<3; i++) {
        if (ans < dp[n][i]) ans = dp[n][i];
    }

    cout << ans << endl;

    return 0;
}



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

int main() {
	int N, T, a;
	cin >> N >> T;
	int total = 0;
	for (int i = 0; i < T; i++) {
		cin >> a;
		if (N < 2 * a) {
			total += 2 * a - N - 1;
		}
	}
	cout << total << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
const int mod=1000000007;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll n;cin>>n;
    string s;cin>>s;
    vi d(2*n);
    ll ans=1;
    if(s[0]=='W'||s[sz(s)-1]=='W'){
        cout<<0<<endl;
        return 0;
    }
    rep(i,sz(s)){
        if(i==0)d[i]=1;
        else if(s[i]==s[i-1]){
            if(d[i-1]==0)d[i]=1;
            else d[i]=0;
        }
        else if(s[i]!=s[i-1]){
            d[i]=d[i-1];
        }
    }
    ll cnt=0;
    rep(i,sz(s)){
        if(d[i]==1){
            cnt++;
        }
        else{ans*=cnt;ans%=mod;cnt--;}
        if(cnt<0){
            cout<<0<<endl;
            return 0;
        }
    }
    if(cnt!=0){
        cout<<0<<endl;
        return 0;
    }
    for(int i=1;i<=n;i++){ans*=i;ans%=mod;}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1412
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [int(input()) for i in range(N)]
ans='No'
for i in range(3):
    for j in range(3):
        if A[i][j] in B:
            A[i][j]=-1
for i in range(3):
    if sum(A[i])==-3:
        ans='Yes'
    if A[0][i]+A[1][i]+A[2][i]==-3:
        ans='Yes'
if A[0][0]+A[1][1]+A[2][2]==-3:
    ans='Yes'
if A[0][2]+A[1][1]+A[2][0]==-3:
    ans='Yes'
print(ans)

Measured memory_bytes: 3064
import copy
import math
n,m = map(int,input().split())

#取得
scores = list()
for i in range(n):
    score = list(map(int,input().split()))
    scores.append(score)

smax=None
for p in range(8):
    x=math.floor((p/4)%2)
    y=math.floor((p/2)%2)
    z=math.floor((p/1)%2)
    
    scores_=copy.deepcopy(scores)
    sumlist=list()

    for i in range(n):
        scores_[i][0] = pow(-1,x)*scores[i][0]
        scores_[i][1] = pow(-1,y)*scores[i][1]
        scores_[i][2] = pow(-1,z)*scores[i][2]
        sumlist.append(sum(scores_[i]))
    sumlist.sort()
    
    tmp=0
    for eat in range(m):
        tmp+=sumlist[-1]
        sumlist.pop()
    if smax==None or tmp>smax:
        smax=tmp
print(smax)

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

#define ll long long
using namespace std;

int main()
{
    ll X;
    cin >> X;
    for(int i = -1000; i <= 1000; ++i){
        for(int j = -1000; j <= i; ++j){
            ll x = (ll)i*i*i*i*i, y = (ll)j*j*j*j*j;
            if(x - y == X){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3548
import math
def getDegree(H,M):
  H_deg = H / 12 * 360 + M / 60 * (360/12)
  M_deg = M / 60 * 360
  return min([abs(H_deg-M_deg),abs(360-(H_deg-M_deg))])

A,B,H,M=map(int, input().split())
cc = A**2 + B**2 - 2*A*B*math.cos(getDegree(H,M)/360*2*math.pi)
print(cc**0.5)

Measured memory_bytes: 9516
#include<iostream>
#include<float.h>
#include<cfloat>
#include<string>
#include<ctype.h>
#include<algorithm>
#include<errno.h>
#include<cerrno>
#include<assert.h>
#include<cassert> 
#include<map>
#include<memory.h>
#include<cctype>
#include<ctype.h>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<new>
#include<memory>
#include<cmath>
#include<queue>
#include<cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std;
int a[150],ans;
int main()
{int n;
 cin>>n;
 fo(i,0,n)
 cin>>a[i];
 sort(a,a+n);
 fo(i,0,n)
 if(a[i]!=a[i-1])
 ans++;
 cout<<ans; 
 system("pause");
 return 0;
}

Measured memory_bytes: 504
#include<stdio.h>

int main(void){
  int N;
  //入力
  scanf("%d", &N);
  //出力
  if(N % 2 == 0){ 
    printf("%d",N / 2);
  }else{
    printf("%d",N / 2 + 1);
  }
  
  return 0;
}
  
   
  

Measured memory_bytes: 128
N,K = map(int,input().split())
X = list(map(int,input().split()))
ls = []
rs = []
for x in X:
    if x < 0:
        ls.append(-x)
    else:
        rs.append(x)
ls.reverse()

ans = float('inf')
if len(ls) >= K:
    ans = min(ans, ls[K-1])
if len(rs) >= K:
    ans = min(ans, rs[K-1])

for l in range(1,K):
    if l > len(ls): break
    r = K-l
    if r > len(rs): continue
    ans = min(ans, ls[l-1]*2 + rs[r-1])
    ans = min(ans, rs[r-1]*2 + ls[l-1])
print(ans)

Measured memory_bytes: 14480
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int md = 1e9+7;
const int sz = 1e6+1;
int F[sz+1]; 
int A[sz+1];

vector<vector<int>> g;
vector<int> vis;

void dfs(int index){
    // cout<<"dfs"<<endl;
    // vis[index] = 1;
    stack<int> st;
    st.push(index);
    // cout<<"visited:"<<endl;
    while(!st.empty()){
        int cur = st.top();
        st.pop();
        vis[cur]=1;
        // cout<<cur<<endl;
        for(int i=0;i<g[cur].size();i++){
            if(!vis[g[cur][i]])
                st.push(g[cur][i]);
        }        
    }
    return;
}


void solve(){
    int n,m;cin>>n>>m;
    g.clear();
    g.resize(n);
    vis.clear();
    vis.resize(n,0);
    int from, to;
    for (int i = 0; i < m; ++i)
    {   
        cin>>from>>to;
        from--;to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(!vis[i]){
            // cout<<"unvisited  = "<<i<<endl;
            dfs(i);
            ans++;
        }
    }

    // cout<<ans<<endl;

    cout<<ans-1<<endl;


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

Measured memory_bytes: 10068
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    vl a(x), b(y), c(z);
    for (int i = 0; i < x; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < y; ++i) {
        cin >> b[i];
    }
    for (int i = 0; i < z; ++i) {
        cin >> c[i];
    }
    vl ab;
    ab.reserve(x * y);
    for (int i = 0; i < x; ++i) {
        for (int j = 0; j < y; ++j) {
            ab.push_back(a[i] + b[j]);
        }
    }
    sort(ab.begin(), ab.end(), greater<ll>());
    vl abc;
    abc.reserve(k * z);
    for (int i = 0; i < min(k, x * y); ++i) {
        for (int j = 0; j < z; ++j) {
            abc.push_back(ab[i] + c[j]);
        }
    }
    sort(abc.begin(), abc.end(), greater<ll>());
    for (int i = 0; i < k; ++i) {
        cout << abc[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 31616
# https://atcoder.jp/contests/abc014/submissions/3935971
class SegmentTree(object):
    __slots__ = ["elem_size", "tree", "default", "op"]
    def __init__(self, a: list, default: int, op):
        from math import ceil, log
        real_size = len(a)
        self.elem_size = elem_size = 1 << ceil(log(real_size, 2))
        self.tree = tree = [default] * (elem_size * 2)
        tree[elem_size:elem_size + real_size] = a
        self.default = default
        self.op = op
        for i in range(elem_size - 1, 0, -1):
            tree[i] = op(tree[i << 1], tree[(i << 1) + 1])

    def get_value(self, x: int, y: int) -> int:  # 半開区間
        l, r = x + self.elem_size, y + self.elem_size
        tree, result, op = self.tree, self.default, self.op
        while l < r:
            if l & 1:
                result = op(tree[l], result)
                l += 1
            if r & 1:
                r -= 1
                result = op(tree[r], result)
            l, r = l >> 1, r >> 1
        return result

    def set_value(self, i: int, value: int) -> None:
        k = self.elem_size + i
        self.tree[k] = value
        self.update(k)

    def update(self, i: int) -> None:
        op, tree = self.op, self.tree
        while i > 1:
            i >>= 1
            tree[i] = op(tree[i << 1], tree[(i << 1) + 1])

from operator import itemgetter
N, M = map(int, input().split())
LRC = [list(map(int, input().split())) for _ in range(M)]
LRC.sort(key=itemgetter(0))

idx_LRC = 0
q = []

seg = SegmentTree([float("inf")] * (N+1), float("inf"), min)

seg.set_value(1, 0)
for v in range(1, N+1):
    d = seg.get_value(v, N+1)
    while idx_LRC < M:
        l, r, c = LRC[idx_LRC]
        if l <= v:
            seg.set_value(r, min(seg.tree[r+seg.elem_size], d + c))
            idx_LRC += 1
        else:
            break
ans = seg.tree[N+seg.elem_size]
print(ans if ans!=float("inf") else -1)


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

using namespace std;

typedef long long ll;

int gcd(int a, int b) {
  if (b > a) {
      swap(a, b);
  }
  
  if (b == 0) {
    return a;
  }
  
  return gcd(b, a % b);
}

int main() {
  int K;
  
  cin >> K;
  
  int sum = 0;
  
  for (int i = 1; i <= K; i++) {
      for (int j = 1; j <= K; j++) {
          for (int k = 1; k <= K; k++) {
              sum += gcd(gcd(i, j), k);
          }
      }
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 3620
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = [[-1]*W for _ in range(H)]
col = []

for i in range(N):
    col += [i+1]*a[i]

idx = 0

for i in range(H):
    if i%2==0:
        for j in range(W):
            ans[i][j] = col[idx]
            idx += 1
    else:
        for j in range(W-1, -1, -1):
            ans[i][j] = col[idx]
            idx += 1

for ans_i in ans:
    print(*ans_i)

Measured memory_bytes: 74076
package main

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

func solve() {
	l, r := getInt(), getInt()

	ans := inf
	if d := r - l + 1; d > 673 {
		ans = 0
	} else {
		for i := l; i <= r; i++ {
			for j := i + 1; j <= r; j++ {
				ans = min(ans, (i*j)%2019)
			}
		}
	}

	fmt.Fprintln(wr, ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


vector<int>G[100010];
int ds[100010],dt[100010];
bool vis[100010];
void dfs(int n,int pre,int res,int d[]){
    vis[n]=true;
    d[n]=res;
    for(auto nxt:G[n]){
        if(nxt==pre)continue;
        if(vis[nxt])continue;
        dfs(nxt,n,res+1,d);
    }
}
void solve() {
    int N,s,t;cin>>N>>s>>t;
    s--,t--;
    REP(i,N-1){
        int u,v;cin>>u>>v;
        u--,v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(s,s,0,ds);
    REP(i,N)vis[i]=false;
    dfs(t,t,0,dt);
    ll ans=0;
    REP(i,N){
        if(ds[i]<dt[i]){
            ans=max(ans,dt[i]-1);
        }
    }
    print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int sch(ll j, auto& bs) {
  for (ll i = j; i >= 0; i--) {
    if (bs.at(i) == i+1)  return i;
  }
  throw "not found";
}

int main() {
  ll n;
  cin >> n;
  vector<ll> bs(n);
  for (ll i = 0; i < n; i++)  cin >> bs.at(i);

  vector<ll> ans(n);
  try {
    for (ll j = n-1; j >= 0; j--) {
      ll i = sch(j, bs);
      ans.at(j) = i+1;
      move(bs.begin()+i+1, bs.end(), bs.begin()+i);
    }
    for (auto x : ans)   cout << x << endl;
  }catch(const char* msg) {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Affine Cipher
public class Main{

	static long gcd(long a, long b){
		if(a < b){
			long tmp = a;
			a = b;
			b = tmp;
		}
		while(b!=0){
			long r = a%b;
			a = b;
			b = r;
		}
		return a;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		sc.nextLine();
		Set<String> valid = new HashSet<String>();
		for(int a=1;a<=100;a++){
			if(gcd(a,26)>1)continue;
			for(int b=1;b<=100;b++){
				boolean f = true;
				boolean[] c = new boolean[26];
				for(int j=0;j<26;j++){
					int x = (a*j+b)%26;
					if(c[x])f=false;
					c[x] = true;
				}
				if(f)valid.add(a+" "+b);
			}
		}
		while(t--!=0){
			String[] s = sc.nextLine().split(" ");
			for(String vv:valid){
				String[] v = vv.split(" ");
				int a = Integer.parseInt(v[0]);
				int b = Integer.parseInt(v[1]);
				boolean f = false;
				StringBuilder sb = new StringBuilder();
				boolean head = true;
				for(String m : s){
					if(!head)sb.append(' ');
					head = false;
					char[] ch = new char[m.length()];
					for(int i=0;i<ch.length;i++)ch[i]=(char)(((m.charAt(i)-'a')*a+b)%26 + 'a');
					String x = new String(ch);
					if(x.equals("that")||x.equals("this"))f=true;
					sb.append(x);
				}
				if(f){
					System.out.println(sb);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 13000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		a[0] = 0;
		for(int i=1; i<n+1; i++) {
			a[i] = sc.nextInt();
		}
		int sum =0;
		for(int i=0; i<=n; i++) {
			sum += cost(i, next(i, n), a);
		}
		for(int i=1; i<=n; i++) {
			int x = cost(prev(i, n), i,a);
			int y = cost(i, next(i, n), a);
			int z = cost(prev(i, n), next(i, n), a);
			System.out.println(sum-x-y+z);
		}
	}
	
	static int next(int i, int n) {
		if(i==n) return 0;
		return i+1;
	}
	
	static int prev(int i, int n) {
		if(i==0) return n;
		return i-1;
	}
	
	static int cost(int f, int t, int[] a) {
		return Math.abs(a[f]-a[t]);
	}

	static class MyScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public MyScanner(InputStream s)
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 47780
import java.util.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] place = new int[w][h];
		for (int j = 0; j < h; j++) {
			for (int i = 0; i < w; i++) {
				place[i][j] = sc.nextInt();
			}
		}
		int i = 0; 
		int j = 0;
		int ni = 0;
		int nj = 0;
		int count = 0;
		StringBuilder sb = new StringBuilder();
		while (true) {
			if (j % 2 == 0) {
				if (i == w - 1) {
					ni = i;
					nj = j + 1;
					if (nj == h) {
						break;
					}
				} else {
					ni = i + 1;
					nj = j;
				}
			} else {
				if (i == 0) {
					ni = i;
					nj = j + 1;
					if (nj == h) {
						break;
					}
				} else {
					ni = i - 1;
					nj = j;
				}
			}
			if (place[i][j] % 2 != 0) {
				sb.append(j + 1).append(" ").append(i + 1).append(" ").append(nj + 1).append(" ").append(ni + 1).append("\n");
				place[i][j] -= 1;
				place[ni][nj] += 1;
				count++;
			}
			i = ni;
			j = nj;
		}
		System.out.println(count);
		System.out.print(sb);
	}
	
}

Measured memory_bytes: 95328
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define endl '\n'
#define ALL(V) V.begin(),V.end()
#define ALLR(V) V.rbegin(),V.rend()
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using PLL = pair<ll, ll>;

bool solve() {
    ll N;
    cin >> N;
    if(!N) return false;

    V<PLL> books;
    ll rsum = 0;
    ll wsum = 0;
    for(ll i = 0; i < N; i++) {
        ll r, w;
        cin >> r >> w;
        rsum += r;
        wsum += w;
        books.emplace_back(r, w);
    }

    sort(ALLR(books));
    ll max_r = books[0].first;

    if(rsum - max_r >= max_r) {
        cout << rsum + wsum << endl;
        return true;
    }

    ll ans = rsum + wsum;
    ll rest = max_r - (rsum - max_r);

    const ll dp_size = 1001;
    bool dp[dp_size][dp_size];
    for(ll i = 0; i <= N; i++) for(ll j = 0; j <= rest; j++) dp[i][j] = false;
    dp[0][0] = true;

    for(ll i = 1; i < N; i++) {
        for(ll j = 0; j <= rest; j++) {
            if(!dp[i - 1][j]) continue;
            dp[i][j] = true;
            ll nxtj = j + books[i].second;
            if(nxtj <= rest) dp[i][nxtj] = true;
        }
    }

    ll maxv = 0;
    for(ll i = rest; i >= 0; i--) if(dp[N - 1][i]) {
        maxv = i;
        break;
    }

    ans = max(ans, max_r + max_r + (wsum - maxv));
    cout << ans << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}



Measured memory_bytes: 4108
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 5010;

ll d[MAX_N];

int main(){
	int n, L;
	scanf("%d %d", &n, &L);
	vi x(n), a(n);
	rep(i, n) scanf("%d", &x[i]);
	rep(i, n) scanf("%d", &a[i]);
	{
		if(a.back() != 0) {
			for(int i = x.back(); i < L; i += a.back()) {
				d[i] = 1;
			}
		}
		else {
			d[x.back()] = 1;
		}
	}
	repr(i, n-1) {
		ll sum = 0LL;
		rep(j, L) (sum += d[j]) %= MOD;
		if(a[i] == 0) {
			rep(j, x[i]+1) {
				sum -= d[j];
				(sum += MOD) %= MOD;
			}
			d[x[i]] = sum;
			REP(j, x[i]+1, L) d[j] = 0;
			continue;
		}
		rep(j, L) {
			if(j < x[i] || (j - x[i]) % a[i] != 0 || j >= L - (n-1-i)) {
				sum -= d[j];
				(sum += MOD) %= MOD;
				d[j] = 0;
			}
			else {
				sum -= d[j];
				(sum += MOD) %= MOD;
				d[j] = sum;
			}
		}
	}
	ll ans = 0LL;
	rep(i, L) (ans += d[i]) %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3320
N=int(input())
D=list(map(int, input().split()))

from collections import Counter
C = Counter(D)

ans = 0
import heapq
for pattern in range(1<<11):
    if C[0] >= 1: continue
    if C[12] >= 2: continue
    if C.most_common(1)[0][1] >= 3: continue
    q = [24]
    for d in range(1,12):
        if C[d] == 1:
            if pattern & 1: heapq.heappush(q, d)
            else: heapq.heappush(q, 24-d)
        elif C[d] == 2:
            heapq.heappush(q, d)
            heapq.heappush(q, 24-d)
        pattern>>=1
    if C[12] == 1: heapq.heappush(q, 12)
    pre = 0
    tmp = 24
    for _ in range(N+1):
        d = heapq.heappop(q)
        tmp = min(tmp, d-pre)
        pre = d
    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 58328
#include <iostream>
using namespace std;
int main(void){
    
    int H,W;
    while(true){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        for(int j=0; j<W;j++){
            cout<<'#';
        }
        cout<<endl;
        for(int i=1;i<H-1;i++){
            cout<<'#';
            for(int j=1;j<W-1;j++){
            cout<<'.';
        }
        cout<<'#'<<endl;
        }
        for(int j=0;j<W;j++){
            cout<<'#';
        }
        cout<<endl<<endl;
    }
}


Measured memory_bytes: 3108
N,K=map(int,input().split())
S=input()
if N==1:
 print(1)
else:
 lst=[]
 ct=1
 if int(S[0])==0:
  lst.append(0)
 ima=int(S[0])
 for i in range(1,N):
  if int(S[i])==ima:
   ct+=1
  else:
   lst.append(ct)
   ima=int(S[i])
   ct=1
 lst.append(ct)
 if ima==0:
  lst.append(0)
 A=len(lst)-2
 if A<=K*2-1:
  print(N)
 else:
  for i in range(1,len(lst)):
   lst[i]+=lst[i-1]
  ans=0
  for i in range((len(lst)-1-2*K)//2+1):
   if i==0:
    ans=max(ans,lst[2*i+2*K])
   else:
    ans=max(ans,lst[2*i+2*K]-lst[2*i-1])
  print(ans)

Measured memory_bytes: 44508
#include <stdio.h>
 
int main(){
  int A,B;

  scanf("%d %d",&A,&B);
  
  if(A%3==0){
    printf("Possible\n");
  }else if(B%3==0){
    printf("Possible\n");
  }else if((A+B)%3==0){
    printf("Possible\n");
  }else{
printf("Impossible\n");
}}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define ms(a, x) memset(a, x, sizeof(a))
#define fore(i, a, n) for (long long i = a; i < n; i++)
#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define debug(a) cout << a << endl
#define pr(a) printf("%d ", a)
#define endl '\n'
#define pi acos(-1.0)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define ull unsigned long long
#define py puts("Yes")
#define pn puts("No")
#define pY puts("YES")
#define pN puts("NO")
#define re(i, a, b) for (int i = a; i <= b; ++i)
#define de(i, a, b) for (int i = a; i >= b; --i)
const double eps = 1e-8;
inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
const ll mode = 192600817;
template <class T>
inline void cmin(T &a, T b) { ((a > b) && (a = b)); }
template <class T>
inline void cmax(T &a, T b) { ((a < b) && (a = b)); }
int main()
{
  ll x;
  sl(x);
  double a = 100;
  int cnt = 0;
  while (a < x)
  {
    ll tem = a * (1.01);
    a = tem;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3768
import java.util.Scanner;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();

		int count = 0;
		for (int n = 0; n < N; n++) {
			long x = sc.nextLong();
			long y = sc.nextLong();
			double d = Math.sqrt(x * x + y *y);
			if (d <= D) {
				count++;
			}
		}
		System.out.println(count);
	}
}


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

int main() {
	string S;
	int K;
	cin >> S >> K;
	char ans;
	for (int i = 0; i < K; i++)
	{
		if (S[i] != '1')
		{
			ans = S[i];
			break;
		}
		else if (i == K - 1)
		{
			ans = S[i];
		}
	}

	cout << ans << endl;
}


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

#define MAXDATA 200100
vector<vector<int>> to(MAXDATA);
vector<bool> seen(MAXDATA, false);
vector<int> ans(MAXDATA, 0);

void dfs(const vector<vector<int>> &G, int v)
{
    seen[v] = true;
    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        ans[next_v] += ans[v];
        dfs(G, next_v);
    }
}

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

    rep (i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        to[a - 1].push_back(b - 1);
        to[b - 1].push_back(a - 1);
    }

    rep (i, q)
    {
        int p, x;
        cin >> p >> x;
        ans[p - 1] += x;
    }

    dfs(to, 0);

    rep(i, n)
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int N = 3*1e5, M = 7 + 1e9;
int n, m, a[N];
int main()
{
	ll n, k;
	cin >> n >> k;
	if(n > k){
		n -= (n-k)/k*k;
	}
	if(n > k){
		n -= k;
	}
	cout << min(n, k-n);
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int IMAX = 200010;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1];
	unko() : fac(), ifac() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
	}
} f;

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


	int N, M, K;
	scanf("%d %d %d", &N, &M, &K);

	if (M == 1) {
		if (K == N - 1) printf("1");
		else printf("0");

		return 0;
	}
	if (N == 1) {
		printf("%d", M);
		return 0;
	}

	ll kotae = 0;
	ll tmp = ll(M) * f.fac[N - 1] % mod * modpow(M - 1, N - K - 1) % mod;
	for (int k = K; k >= 0; k--) {
		kotae += tmp * f.ifac[k] % mod * f.ifac[N - 1 - k] % mod;
		tmp = tmp * (M - 1) % mod;
	}

	printf("%lld", kotae % mod);



	Would you please return 0;
}

Measured memory_bytes: 3264