akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 100000001
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
#define dbg(x) cout <<#x<<":"<<x<<endl;
ll max1(ll a, ll b, ll c=-inf, ll d=-inf) {ll mx1=(a>b)?a:b, mx2=(c>d)?c:d; return ((mx1>mx2)?mx1:mx2);}
#define int ll

signed main() {
	fast;
	
	ll a[10][10];

	for(int i=0;i<10;i++) a[i][i]=0;

	ll n;
	cin>>n;

	ll aa[n];
	for(int i=0;i<n;i++) aa[i]=i;
	map<ll,ll> mp1;
	
	ll v[]={1, 2, 4, 7, 12, 20, 29, 38, 52};
	ll mul=1;
	
	for(int i=0;i<n;i++){
		ll m1;
		for(int j=0;j<n;j++){
			if(j>i){
				a[i][j]=a[j][i]=v[j-i-1]*mul;
				m1=v[j-i-1];
			}
			//assert(a[i][j]<=10000000000);
		}
		mul*=v[n-1-i-1]+v[n-1-i-2];
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}

} 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
#ifdef DEBUG
	printf("");
#endif

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

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int A[101];
    
    for(int i=0; i<n; i++){
        cin >> A[i];
        if(i==0){
            cout << A[i];
        } else {
            cout << " " << A[i];
        }
    }
    cout <<endl;
    
    int v;
    for(int j=1; j<n; j++){
        v = A[j];
        
        int k=j-1;
        while(k>=0 && A[k]>v){
            A[k+1] = A[k];
            k--;
        }
        A[k+1] = v;
        
        cout << A[0];
        for(int l=1; l<n; l++){
            cout << " " << A[l];
        }
        cout << endl;
    }
    return 0;
}



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

#define INF 1E+08

int get_digit_sum(int n) {
	int digit_sum = 0;
	while(n > 0) {
		digit_sum += n % 10;
		n /= 10;
	}

	return digit_sum;
}

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

	int min = INF;
	for (int a = 1; a <= n - 1; a++) {
		int sum = get_digit_sum(a) + get_digit_sum(n - a);
		if (sum < min) min = sum;
	}

	cout << min << endl;

 	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>

using namespace std;

long long int conbi(long long int n) {
	return n * (n - 1) / 2;
}

int main() {
	int n;
	vector<long long int> a;
	map<int,int> v;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		v[a[i]]++;
	}
	long long int allc = 0;
	for (auto x : v) {
		allc += conbi(x.second);
	}
	for (int i = 0; i < n; i++) {
		cout << allc - (v[a[i]] - 1) << endl;
	}
	

	return 0;
}


Measured memory_bytes: 9088
import java.io.InputStreamReader;
import java.io.LineNumberReader;

/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_
 * 
 * @author eitatsuro
 * 
 */
public class Main {
    private final static String SPACE = " ";
    
    public static void main(String[] args) {
        try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            String outputStr = null;
            int n = 0;
            int m = 0;
            int l = 0;
            long[][] a = null;
            long[][] b = null;
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ????????????????????????
                if (lineNumReader.getLineNumber() == 1) {

                    StringBuilder sb = new StringBuilder();
                    char temp;
                    for (int i=0; i<inputStr.length(); i++){
                        temp = inputStr.charAt(i);
                        // ??§?????????????°????????????????
                        if (Character.isUpperCase(temp)) {
                            sb.append(Character.toLowerCase(temp));
                        // ?°???????????????§???????????????
                        } else if (Character.isLowerCase(temp)) {
                            sb.append(Character.toUpperCase(temp));
                        // ????????\????????????????????????
                        } else {
                            sb.append(temp);
                        }
                    }
                    outputStr = sb.toString();
                }

                if (lineNumReader.getLineNumber() == 1 ) {
                        break;
                }
            }

            // ??¢???????????????
            System.out.println(outputStr);

            lineNumReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
        
    }
}

Measured memory_bytes: 24212
args = [ int(x) for x in raw_input().split() ]
l0 = args[0]
x0 = args[1]

def get_length(l, x):
    if l % x == 0:
        part = l * 2 - x
        # print l, x, part
        return part
    part = int(l / x) * 2 * x
    # print l, x, part
    return part + get_length(x, l % x)

length = l0 + get_length(l0 - x0, x0)

print length


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    long long sum[n];
    long long diff[n];
    for(int i=0;i<n;i++)
    {
        long long x,y;
        cin >> x >> y;
        sum[i]=x+y;
        diff[i]=x-y;
    }
    sort(sum,sum+n);
    sort(diff,diff+n);
    cout << max((sum[n-1]-sum[0]),(diff[n-1]-diff[0])) << endl;
}


Measured memory_bytes: 6696
n,x = map(int,input().split())
L = list(map(int,input().split()))

d = [0]*(n+1)
d[0] = 0
for i in range(1,n+1):
    d[i] = d[i-1] +L[i-1]

print(len([i for i in d if i<=x]))

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

public class Main extends PrintWriter {
    Main() { super(System.out, true); }
    Scanner sc = new Scanner(System.in);
    public static void main(String[] $) {
        Main o = new Main(); o.main(); o.flush();
    }

    void main(){
        int N = sc.nextInt();
        if(N > 50){
            N = 50;
        }
        String S = sc.next();
        int Y = 0;
        int U = 0;
        for(int i = 0; i < N;i++){
            if(Y == 0){
                if(S.charAt(i) == 'A'){
                    Y = 1;
                }
            }
            else if(Y == 1){
                if(S.charAt(i) == 'B'){
                    Y = 2;
                }
                else if(S.charAt(i) == 'A'){
                    Y = 1;
                }
                else{
                    Y = 0;
                }
            }
            else if(Y == 2){
                if(S.charAt(i) == 'C'){
                    Y = 0;
                    U++;
                }
                else if(S.charAt(i) == 'C'){
                    Y = 1;
                }
                else{
                    Y = 0;
                }
            }
        }
        print(U);
    }
}


Measured memory_bytes: 21972
n, d = map(int, input().split())
x_lst = []
y_lst = []
d_square = d * d
ans = 0

for i in range(n):
    x, y = map(int, input().split())
    # x_lst.append(x)
    # y_lst.append(y)
    if (x ** 2 + y ** 2) <= d_square:
        ans += 1
print(ans)

Measured memory_bytes: 9172
/**********************************************************
 * サンプル通すのに丸一日かかったよ(泣)
***********************************************************/

#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	int n;
	cin >> n;
	vector<int> t(n+1,0),v(n+1,0);

	for(int i = 1; i <= n; i++) cin >> t[i];
	for(int i = 1; i <= n; i++) cin >> v[i];
	for(int i = 1; i <= n; i++) t[i] += t[i-1];
	for(int i = 1; i <= n; i++) t[i] *= 2, v[i] *= 2;

	vector<int> g(t.back()+10,0);
	for(int i = 1; i <= n; i++) g[t[i]] = v[i];
	for(int i = 1; i <= n; i++){
		for(int j = t[i-1]+1; g[j] != v[i]; j++) g[j] = v[i];
	}
	for(int i = 1; i <= n; i++){
		for(int j = t[i-1]; g[j] != v[i]; j++) g[j] = min(g[j],v[i]);
	}

	g[0] = g[t.back()] = 0;
	for(int x = 1; x < t.back(); x++){
		g[x] = min(g[x],g[x-1]+1);
	}
	for(int x = t.back()-1; x >= 0; x--){
		g[x] = min(g[x],g[x+1]+1);
	}
/*
	for(int i = 0; i <= t.back(); i++){
		cout << i << ":";
		for(int j = 0; j < g[i]; j++){
			printf("%3d",g[i]);
		}
		cout << endl;
	}
*/
	double ans = 0,tmp;
	for(int i = 0; i < t.back(); ){
		tmp = i;
		//cout << "======================================" << endl;
		if(g[i] == g[i+1]){
			while(g[i] == g[i+1]) i++;
			ans += (g[i]+g[tmp])*(i-tmp)/8.0;
			//cout << "a" << endl;
		}else if(g[i] > g[i+1]){
			while(g[i] > g[i+1]) i++;
			ans += (g[i]+g[tmp])*(i-tmp)/8.0;
			//cout << "b" << endl;
		}else{
			while(g[i] < g[i+1]) i++;
			ans += (g[i]+g[tmp])*(i-tmp)/8.0;
			//cout << "c" << endl;
		}
		//cout << i << " " << tmp << endl;
		//cout << ans << endl;
	}
	//cout << "============================================" << endl;
	cout << fixed << ans << endl;
	return 0;
}

Measured memory_bytes: 384
x = int(input())

ans = -1
if 400 <= x <=599:
    ans = 8
if 600 <= x <=799:
    ans =7
if 800 <= x <=999:
    ans = 6
if 1000 <= x <=1199:
    ans = 5
if 1200 <= x <=1399:
    ans = 4
if 1400 <= x <=1599:
    ans = 3
if 1600 <= x <=1799:
    ans = 2
if 1800 <= x <=1999:
    ans = 1
print(ans)

Measured memory_bytes: 9188
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=500010, inf=1e9;
int n;
char s[maxn];

template<typename T>
inline void read(T &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;
}

int main()
{
	scanf("%s", s+1); n=strlen(s+1);
	int now=n; ll ans=0;
	for(int i=n;i;i--)
	if(s[i]=='B')
	{
		ans+=now-i;
		now--;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0;
bool graph[8][8];
 
const int NUMBER_OF_SAMPLES = 100000000;
int main(){
    int x,y,z;cin >> x >> y >> z;
    cout << z <<" "<< x<< " " << y << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 2010;

char s[N];

int g[N][N], t0[N][N], t1[N][N], t2[N][N];

int main()
{
	int n, m, q;
	scanf("%d%d%d", &n, &m, &q);
	Rep(i, n) {
		scanf("%s", s + 1);
		Rep(j, m) g[i][j] = (s[j] == '1');
	}
	Rep(i, n) Rep(j, m){
		t0[i][j] = t0[i - 1][j] + t0[i][j - 1] - t0[i - 1][j - 1] + g[i][j];
		t1[i][j] = t1[i - 1][j] + t1[i][j - 1] - t1[i - 1][j - 1];
		t2[i][j] = t2[i - 1][j] + t2[i][j - 1] - t2[i - 1][j - 1];
		if (g[i][j] && g[i - 1][j]) t1[i][j] ++;
		if (g[i][j] && g[i][j - 1]) t2[i][j] ++;
		//printf("%d %d : %d\n", i, j, t1[i][j]);
	}

	Rep(i, q) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		int cnt0 = t0[x2][y2] - t0[x1 - 1][y2] - t0[x2][y1 - 1] + t0[x1 - 1][y1 - 1];
		int cnt1 = t1[x2][y2] - t1[x1][y2] - t1[x2][y1 - 1] + t1[x1][y1 - 1];
		int cnt2 = t2[x2][y2] - t2[x1 - 1][y2] - t2[x2][y1] + t2[x1 - 1][y1];
		
		printf("%d\n", cnt0 - cnt1 - cnt2);
	}
	
	return 0;
}

Measured memory_bytes: 64768
#include<stdio.h>
int main()
{
    int x,a,b;
    while(~scanf("%d%d%d",&x,&a,&b))
    {
        int m,n;
        if(a>x)
            m=a-x;
        else
            m=x-a;
        if(b>x)
            n=b-x;
        else
            n=x-b;
        if(m>n)
            printf("B\n");
        else
            printf("A\n");
    }
}

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

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define int ll
#define endl "\n"
#define all( x ) x.begin(), x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);

typedef unsigned long long ull;

const int inf = 1e9 + 5;
const long double PI = 3.141592653589793;


void solve(){
  int n, k;
  cin >> n >>k;
  vector<int> v(n);
  for(int& x:v)cin>>x;
  sort(all(v));
  int ans = 0;
  int i = 0;
  while(i<k){
    ans += v[i];
    i++;
  }
  cout << ans <<endl;
}  
signed main(){
  fast;
  int t;
  t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}



Measured memory_bytes: 3624
import os
import heapq
import sys
import math
from collections import defaultdict
from io import BytesIO, IOBase
def check_kth_power(n, k):
        while n%k == 0:
            n = n/k

        if n != 1:
            return False
        return True
def main():
    #for _ in range(int(input())):
    n,m=map(int,input().split())
    arr=[int(k) for k in input().split()]
    
    total=0
    for i in range(n):
        total+=arr[i]
    val=(total/(4*m))
    counter=0
    #print(val)
    ans="No"
    for i in range(n):
        if arr[i]>=val:
            counter+=1
        if counter==m:
            ans="Yes"
    print(ans)
        
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


Measured memory_bytes: 67444
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int ans = -1;
            for (int i = B * 10; i <= B * 15; i++) {
                if (Math.floor(i * 0.08) == A && Math.floor(i * 0.1) == B) {
                    ans = i;
                    break;
                }
            }
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}



Measured memory_bytes: 23380
/**
 *    author:  tourist
 *    created: 22.10.2017 08:48:47       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  string w = "";
  for (int i = 0; i < (int) s.length(); i++) {
    if (s[i] != 'x') {
      w += s[i];
    }
  }
  string ww = w;
  reverse(ww.begin(), ww.end());
  if (w != ww) {
    printf("%d\n", -1);
    return 0;
  }
  int ans = 0;
  int i = 0, j = n - 1;
  while (i < j) {
    if (s[i] == s[j]) {
      i++;
      j--;
      continue;
    }
    ans++;
    if (s[i] == 'x') {
      i++;
    } else {
      j--;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}

int fu(int x,int a[],int l,int r)
{
	int p=l;
	int ans=r+1;
	while(l<=r)
	{
		int m=(l+r)/2;
		if(a[m]>=x)
		r=m-1;
		else
		{
		l=m+1,ans=m;
		}
	}
	return ans;
}
int main()
{
	IOS;
	int n;
	cin>>n;
	int a[n];
	rep(i,0,n)cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int p=fu(a[i]+a[j],a,j+1,n-1);
			if(p!=n)
			ans+=(p-j);
		
		}
	}
	cout<<ans;
}



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

#define int long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main() {
	IOS;
	int a,p;
	cin>>a>>p;
	int tot = a*3 + p ; 
	cout << tot / 2 ;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

int k, ans;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    read(k);
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= k; ++j) {
            for (int l = 1; l <= k; ++l) {
                ans += gcd(i, gcd(j, l));
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

void chmax(Int& a, Int b) { if (a < b) { a = b; } };

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

	sort(ai.rbegin(), ai.rend());
	vector<vector<Int>> dp(N + 1, vector<Int>(N + 1, 0));
	for (int i = 0; i < N; ++i) {
		Int val = ai[i].first, idx = ai[i].second;
		for (int l = 0; l <= i + 1; ++l) {
			int r = i + 1 - l;
			if (l > 0) { 
				chmax(dp[l][r], dp[l - 1][r] + val * abs(idx - (l - 1)));
			}
			if (r > 0) {
				chmax(dp[l][r], dp[l][r - 1] + val * abs(idx - (N - r)));
			}
		}
	}

	Int ans = 0;
	for (int i = 0; i <= N; ++i) {
		chmax(ans, dp[i][N - i]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 34600
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a = N%10;
        String ans = "";
        if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9) ans = "hon";
        if (a == 0 || a == 1 || a == 6 || a == 8) ans = "pon";
        if (a == 3) ans = "bon";
        System.out.println(ans);
    }
}


Measured memory_bytes: 35724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        System.out.println(mergeSort(a));
    }

    private static long merge(int[] a1, int[] a2, int a[]) {
        long cnt = 0;
        int i1 = 0;
        int i2 = 0;
        while (i1 < a1.length || i2 < a2.length) {
            if (i1 < a1.length && (i2 >= a2.length || a1[i1] <= a2[i2])) {
                a[i1 + i2] = a1[i1++];
            } else {
                a[i1 + i2] = a2[i2++];
                cnt += a1.length - i1;
            }
        }
        return cnt;
    }

    private static long mergeSort(int[] a) {
        if (a.length < 2) {
            return 0;
        }
        long cnt = 0;
        int n1 = a.length / 2;
        int n2 = a.length - n1;
        int[] a1 = new int[n1];
        int[] a2 = new int[n2];
        for (int i = 0; i < n1; i++) {
            a1[i] = a[i];
        }
        for (int i = 0; i < n2; i++) {
            a2[i] = a[n1 + i];
        }
        cnt += mergeSort(a1);
        cnt += mergeSort(a2);
        return cnt + merge(a1, a2, a);
    }
}

Measured memory_bytes: 101344
import sys

sys.setrecursionlimit(10**9)


N, K = map(int, input().split())
mod = 1000000007 

def dfs(K, graph, now, source):
  if source == -1:
    can_use_color_num = K - 1
  else:
    can_use_color_num = K - 2
  if len(graph[now]) > K:
    return 0
  else:
    case_num = 1
    for dst in graph[now]:
      if dst == source:
        continue
      case_num *= can_use_color_num
      can_use_color_num -= 1
      case_num %= mod
    for dst in graph[now]:
      if dst == source:
        continue
      case_num *= dfs(K, graph, dst, now)
      case_num %= mod
    return case_num
  

graph = [[] for i in range(N)]
for i in range(N - 1):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a].append(b)
  graph[b].append(a)

answer = K * dfs(K, graph, 0, -1)
answer %= mod
print(answer)

Measured memory_bytes: 88484
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	int n;
	cin >> n;
	vector<ll> v(n);
	for(int i=0;i<n;++i)
	cin >> v[i];
	sort(v.rbegin(),v.rend());
	ll ans=0;
	ans+=v[0];
	int l=1;
	int use=0;
	for(int i=0;i<n-2;++i)
	{
		if(use<2)
		{
			use++;
			ans+=v[l];
		}
		else
		{
			use=1;
			ans+=v[++l];
		}
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


Measured memory_bytes: 4792
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 2*(int)1e5+5;

pair<long long,long long> a[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> a[i].second >> a[i].first;
	}
	sort(a, a+n);
	long long time = 0;
	for(int i=0;i<n;i++) {
		if(time+a[i].second>a[i].first) {
			cout << "No";
			exit(0);
		}
		time += a[i].second;
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 3328
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
		
const double eps = 1e-9;																							   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
///////////////////////////////////////////////////////////////////////////////////////////////////////////
   
   int a, b, c;
   cin >> a >> b >> c;
   if((a == b && a != c)|| (a == c && a != b)|| (b == c && b != a)){
	   cout << "Yes" << endl;
   }
   else cout << "No" << endl;
   
   
   
   
   
   
   
   
   
	
	return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


// 桁DP
// dp[DIGIT][SMALLER] := [決定した桁数][A+B<Lかどうかの未満フラグ]
// i) 未満フラグがたっていない場合
// Lの対応桁が0ならA,Bの対応桁はともに0
//          1ならA,Bの対応桁はそれぞれ0,1か1,0
// ii) 未満フラグがたっている
// A+B<LであるからLの対応桁に関係なくA,Bの対応桁を選べる
// (A,B) = (0, 0) or (0, 1) or (1, 0)

#define MAX_DIGIT 100002
#define SMALLER 2
#define MOD 1000000007 // 10^9 + 7

string L;
i64 dp[MAX_DIGIT][SMALLER];


void solve() {
  REP(i, L.length()) {
    REP(j, SMALLER) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;

  REP(i, L.length()) {
    i64 D = L[i] - '0'; // 0/1
    REP(j, SMALLER) {
      if (j == 0) {
        for (i64 d = 0; d <= D; d++) {
          dp[i + 1][d < D] += (d + 1) * dp[i][j];
          dp[i + 1][d < D] %= MOD;
        }
      } else {
        dp[i + 1][j] += 3 * dp[i][j];
        dp[i + 1][j] %= MOD;
      }
    }
  }

  i64 cnt = (dp[L.length()][0] + dp[L.length()][1]) % MOD;
  cout << cnt << endl;
}


int main() {
  cin >> L;

  solve();

  return 0;
}

Measured memory_bytes: 2000
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int l, r, d;
    cin >> l >> r >> d;
    int cnt=0;
    for(int i =l ; i <= r; i++){
        if(i%d==0) cnt++;
    }
    cout << cnt;

}

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

int main(void){
   int N;
   cin>>N;
   vector<int> a(N);
   for(int i=0;i<N;i++){
      cin>>a[i];
   }
   sort(a.begin(),a.end());
   cout<<a[N-1]-a[0]<<endl;
   return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections
from collections import defaultdict

import heapq


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


N = int(input())
ans = 0
facts = factorization(N)
# print(facts)
for fact in facts:
    p = fact[0]
    if (p == 1):
        continue
    num = fact[1]
    if (num == 1):
        # print(p, 1)
        ans += 1
        continue
    i = 1
    while True:
        # print('num', num)
        num = num-i
        if (num < 0):
            break
        else:
            i += 1
    # print(p, i-1)
    ans += (i-1)
print(ans)


Measured memory_bytes: 27152
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> c(n-1), s(n-1), f(n-1);
  rep(i, n-1){
    int a, b, d;
    cin >> a >> b >> d;
    c.at(i) = a; s.at(i) = b; f.at(i) = d;
  }
  rep(i, n){
    int now = 0;
    rep2(j, i, n-1){
      int nx = now % f.at(j);
      if(nx != 0) nx = f.at(j) - nx;
      now = max(s.at(j), (now + nx));
      now += c.at(j);
    }
    cout << now << endl;
  }
  return 0;
}

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

int main(){
  int h,w,n;
  int x[10],y[10];
  string map[1000];
  int dmap[1000][1000];
  queue<int> qx,qy;
  int dis;

  cin >> h >> w >> n;

  for(int i=0;i<h;i++)cin >> map[i];
 
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(map[i][j] == 'S'){
	x[0] = j;
	y[0] = i;
      }
      if(map[i][j] != 'X' && map[i][j] != '.'){
	x[map[i][j] - '0'] = j;
	y[map[i][j] - '0'] = i;
      }
    }
  }

  dis = 0;
  for(int i=0;i<n;i++){
    while(!qx.empty())qx.pop();
    while(!qy.empty())qy.pop();
    for(int k=0;k<h;k++){
      for(int j=0;j<w;j++){
	dmap[k][j] = 10000000;
      }
    }
    dmap[y[i]][x[i]] = 0;
    qx.push(x[i]);
    qy.push(y[i]);

    while(!qx.empty()){
      if(qx.front()>0 && map[qy.front()][qx.front()-1] != 'X' && dmap[qy.front()][qx.front()-1] > dmap[qy.front()][qx.front()] + 1){
	dmap[qy.front()][qx.front()-1] = dmap[qy.front()][qx.front()] + 1;
	qx.push(qx.front()-1);
	qy.push(qy.front());
      }
      if(qy.front()>0 && map[qy.front()-1][qx.front()] != 'X' && dmap[qy.front()-1][qx.front()] > dmap[qy.front()][qx.front()] + 1){
	dmap[qy.front()-1][qx.front()] = dmap[qy.front()][qx.front()] + 1;
	qx.push(qx.front());
	qy.push(qy.front()-1);
      }
      if(qx.front()<w-1 && map[qy.front()][qx.front()+1] != 'X' && dmap[qy.front()][qx.front()+1] > dmap[qy.front()][qx.front()] + 1){
	dmap[qy.front()][qx.front()+1] = dmap[qy.front()][qx.front()] + 1;
	qx.push(qx.front()+1);
	qy.push(qy.front());
      }
      if(qy.front()<h-1 && map[qy.front()+1][qx.front()] != 'X' && dmap[qy.front()+1][qx.front()] > dmap[qy.front()][qx.front()] + 1){
	dmap[qy.front()+1][qx.front()] = dmap[qy.front()][qx.front()] + 1;
	qx.push(qx.front());
	qy.push(qy.front()+1);
      }
      qx.pop();
      qy.pop();
    }
    
    dis += dmap[y[i+1]][x[i+1]];
  }

  cout << dis << endl;
}

Measured memory_bytes: 5832
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys

INF = float('inf')


def solve(S: str, T: str):
    return sum([s != t for s, t in zip(S, T)])


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    print(solve(S, T))


if __name__ == '__main__':
    main()


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

using namespace std;
#define BUF (200005)
#define ll long long 

int n,m;
vector<pair<int,int>> e[BUF];

int used[BUF];
int pos[BUF];

int dfs(int nd){
	
	vector<int> next;
	for(auto x:e[nd]){
		if(used[x.first]==0){
			used[x.first]=1;
			pos[x.first]=pos[nd]+x.second;
			next.push_back(x.first);
		}else{
			if(pos[x.first]!=pos[nd]+x.second) return -1;
		}
	}
	int ret=0;
	for(auto x:next){
		if(dfs(x)<0)ret = -1;
	}
	return ret;

}

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

	for(int i=1;i<=m;i++){
		pair<int,int> p;
		int l,r,d;
		cin >> l >> r >> d;
		p.first=r;
		p.second=d;
		e[l].push_back(p);
		p.first=l;
		p.second=-d;
		e[r].push_back(p);
	}

	for(int i=1;i<=n;i++){
		if(used[i]==0){
			if(dfs(i)<0){
				cout << "No\n";
				return 0;
			}
		}
	}

	cout << "Yes\n";
	
	return 0;
}


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

using namespace std;
vector < char > v;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    for(int i=0;i<n;i++)
        v.push_back(s[i]);
    for(int i=0;i<s.size();i++){
        i = max(i , 0);
        if(s[i] == 'S' && s[i+1] == 'T'){
            s.erase(s.begin()+i);
            s.erase(s.begin()+i);
            i-=2;
            i = max(i , -1);
        }
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 772
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 h = sc.nextInt();
    int w = sc.nextInt();

    int total = H * W;
    int b = W * h + (H - h) * w;

    System.out.println(total - b);

  }

}


Measured memory_bytes: 22100
#include<stdio.h>
#include<string.h>

int main(void)
{
    int a=0,b=0,c,d,i,l;
    char n[99999];

    scanf("%s",n);
    l=strlen(n);
    for(i=0;i<l;i++){
          if(n[i]=='0') a=a+1;
     else if(n[i]=='1') b=b+1;
     }
     if(a>b) c=b;
     else c=a;
     d=c*2;
     printf("%d\n",d);
     return 0;
}


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


int main() {
  string S;
  cin >> S;
  int len = S.length();
  if(len<1 || len>10){
    return 0;
  }
  uint64_t sum = 0;
  int msb = 1<<len-2;
  // 文字列(数字列)の長さがlenの場合、'+'を置くことができる場所の数は(len-1)。
  // したがって'+'を置く場合の数は、2^(len-1) == 1<<(len-1)。
  for(int i=0; i<(1<<(len-1)); ++i){
    cerr << "i: " << i << endl;
    int start = 0; // 数値の開始位置
    int cnum = 0; // 使用せず
    int j = 0;
    for(; j<len-1; j++){
      if((msb>>j)&i){
        sum += atol(S.substr(start, j-start+1).c_str());
        cerr << "start: " << start << " cnum: " << j-start+1
          << "substr: " << S.substr(start, j-start+1) << endl;
        cerr << "sum: " << sum << endl;
        start = j+1;
      }
    }
    sum += atol(S.substr(start).c_str());
    cerr << "start: " << start << " cnum: " << j-start+1 
      << " substr: " << S.substr(start) << endl;
    cerr << "sum: " << sum << endl;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<double> p(N);
  REP(i,N) { cin >> p[i]; }

  ll left = 0;
  ll sum = 0;
  REP(i,K){
    sum += p[i];
  }
  ll maxv = sum;
  REP3(i,1,N-K+1){
    sum -= p[i-1];
    sum += p[i+K-1];
    if (sum > maxv){
      left = i;
      maxv = sum;
    }
  }

  double ans = 0;
  REP(i,K){
    ans += (p[left+i]+1.0)/2;
  }
  cout << fixed << setprecision(10) << ans << "\n";
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  int ans=0;
  int size=s.size();
  char tmp=s.at(0);
  for(int i=1;i<size;i++){
    if(s.at(i)!=tmp){
      ans++;
      tmp=s.at(i);
    }
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<pair<int,int>> p(n);
  rep(i,n){
    cin>>p[i].fi>>p[i].se;
  }

  vector<vector<int>> q(3100,vector<int>(3100));
  rep(i,n){
    rep(j,t+10){
      chmax(q[i+1][j],q[i][j]);
      chmax(q[i][j+1],q[i][j]);
      if(j-p[i].fi>=0) chmax(q[i+1][j],q[i][j-p[i].fi]+p[i].se);
    }
  }

  reverse(all(p));
  vector<vector<int>> r(3100,vector<int>(3100));
  rep(i,n){
    rep(j,t+10){
      chmax(r[i+1][j],r[i][j]);
      chmax(r[i][j+1],r[i][j]);
      if(j-p[i].fi>=0) chmax(r[i+1][j],r[i][j-p[i].fi]+p[i].se);
    }
  }

  reverse(all(p));

  int ans=0;
  rep(i,n){
    rep(j,t){
      chmax(ans,q[i][j]+r[n-i-1][t-1-j]+p[i].se);
    }
  }

  cout << ans << endl;
}

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

D = []
D = list(map(str, input().split()))

res = N
while True:
    t = str(res)
    flg = True
    for i in D:
        if not flg:
            break
        for x in t:
            if i == x:
                flg = False
                break

    if flg :
        break
    res += 1
print(res)

Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, M, K, Q, W, H;
long long int ans;

int main() {
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int box = 0;
	for (auto i : s) {
		if (!box&&i == 'C')box++;
		if (box&&i == 'F') {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
char s[666];
int L,A,B;
bool ok(){
    if(A+B+1!=L)return 0;
    if(s[A]^45)return 0;
    F(A)if(!isdigit(s[i]))return 0;
    F(B)if(!isdigit(s[i+A+1]))return 0;
    return 1;
}
int main(void){
    scanf("%d%d%s",&A,&B,s),L=strlen(s);
    puts(ok()?"Yes":"No");
    return 0;
}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e5 + 100;

bool vis[MAX_N];

int main() {
	int K;
	cin >> K;
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int,int>>> Q;
	Q.emplace(0, K);
	while(!Q.empty()) {
		int dist, node;
		tie(dist, node) = Q.top(); Q.pop();
		if(vis[node]) continue; vis[node] = true;
		if(node == 0) {
			printf("%d\n", dist);
			return 0;
		}
		for(int i=0; i<=9; ++i) {
			int targ = K*i+node;
			Q.emplace(dist+targ%10, targ/10);
		}
	}
	return 0;
}


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

ll a[300][300];
ll b[300][300];

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

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

    // ワーシャルフロイド法
    bool is_ng = false;
    for (int k = 0; k < N; k++)
    {
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if (a[i][j] > a[i][k] + a[k][j])
                {
                    is_ng = true;
                }
                else if (i != j && j != k && k != i && a[i][j] == a[i][k] + a[k][j])
                {
                    b[i][j] = 1;
                }
            }
        }
    }
    if (is_ng)
    {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (b[i][j] == 0)
            {
                ans += a[i][j];
            }
        }
    }

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

Measured memory_bytes: 5016
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int N; cin >>N;
  vi a(N+1,0);
  rep(i,N-1) {
    int e; cin>>e; e--;
    a[e]++;
  }
  rep(i,N) cout << a[i] << endl;
  return 0;
}

Measured memory_bytes: 4048
s = input()[::-1]

mod = 2019
dp = [0]*mod
dp[0] = 1

num, d = 0, 1

for c in s:
    num += int(c)*d
    num %= mod
    d *= 10
    d %= mod
    dp[num] += 1

ans = 0
for cnt in dp:
    if cnt == 0:
        continue
    ans += cnt*(cnt-1)//2

print(ans)

Measured memory_bytes: 9384
import numpy as np
H,W = map(int,input().split())
HL=list(range(H))
WL=list(range(W))
Gd = np.array([list(input()) for _ in HL])
Gd = np.where(Gd=='.', 1, 0)
L=np.zeros((H,W),dtype=np.int64)
R=np.zeros((H,W),dtype=np.int64)
U=np.zeros((H,W),dtype=np.int64)
D=np.zeros((H,W),dtype=np.int64)

for w in WL:
  R[:,w]=(R[:,w-1]+1)*Gd[:,w]
  L[:,-w-1]=(L[:,-w]+1)*Gd[:,-w-1]
for h in HL:
  D[h,:]=(D[h-1,:]+1)*Gd[h,:]
  U[-h-1,:]=(U[-h,:]+1)*Gd[-h-1,:]
print(np.max(D+U+L+R-3))

Measured memory_bytes: 248612