akhauriyash/Code-Regression huggingface dataset:
public class Main {


  private static void solve() {
    int n = ni();
    int m = ni();
    
    long[] imos = new long[n + 2];
    for (int i = 0; i < m; i ++) {
      imos[ni()] ++;
      imos[ni() + 1] --;
    }
    
    long now = 0;
    
    
    int ret = 0;
    for (int i = 1; i <= n; i ++) {
      now += imos[i];
      imos[i] = now;
      if (imos[i] == m) ret ++;
    }
    
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    cout << fixed << setprecision(15);

    string s, t;
    double n,m,x,y;
    cin >>  n;



    cout << n*2*Pi     << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3836
#include <iostream>

using namespace std;
int K,T,a[100],M,i;
int main()
{
    cin >> K >> T;
    M = 0;
    for(i = 1; i <= T; i++)
     {
         cin >> a[i];
         if( M < a[i])
            M = a[i];
     }
    if(M > K - M + 1)
        cout << 2*M - K -1;
    else
        cout << 0;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

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

	int ans = 0;
	string s;
	cin >> s;

	for(int i=0; i<4; i++){
		if(s[i] == '+') ans++;
		else			ans--;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding : utf-8 -*-

import sys

def main() :
	lines=sys.stdin.readlines()
	N=int(lines[0])
	l=map(int, lines[1].split(" "))
	
	af=1.0*sum(l)/N
	ai=int(af)
	
	x=min(ai, ai+1, key=lambda a: abs(a-af))
	
	print sum((a-x)**2 for a in l)

if __name__=="__main__" :
	main()


Measured memory_bytes: 2820
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class Main {
    public void exec(Stdin stdin, PrintWriter stdout) {
        int x = stdin.nextInt();
        int n = stdin.nextInt();
        int[] p = stdin.nextIntArray(n);

        Set<Integer> q = Arrays.stream(p).boxed().collect(Collectors.toSet());
        int abs = 0;
        while (true) {
            if (!q.contains(x - abs)) {
                stdout.println(x - abs);
                return;
            }
            if (!q.contains(x + abs)) {
                stdout.println(x + abs);
                return;
            }
            abs++;
        }
    }

    public static void main(String[] args) {
        Stdin stdin = new Stdin();
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().exec(stdin, stdout);
        stdout.flush();
    }


    public static class Stdin {
        private BufferedReader stdin;
        private Deque<String> tokens;
        private Pattern delim;

        public Stdin() {
            stdin = new BufferedReader(new InputStreamReader(System.in));
            tokens = new ArrayDeque<>();
            delim = Pattern.compile(" ");
        }

        public String nextString() {
            try {
                if (tokens.isEmpty()) {
                    String line = stdin.readLine();
                    delim.splitAsStream(line).forEach(tokens::addLast);
                }
                return tokens.pollFirst();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

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

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
    }
}


Measured memory_bytes: 34700
N, K = map(int, input().split())
Pn = list(map(int, input().split()))


def f(n):
    return (1+n)*n/2


Rn = list(map(lambda x: f(x)/x, Pn))

Sn = [0] * (N+1)
for i in range(1, N+1):
    Sn[i] = Sn[i-1] + Rn[i-1]

ans = -float("inf")
for i in range(K, N+1):
    # print(i, i-1)
    ans = max(ans, Sn[i] - Sn[i-K])

print(ans)


Measured memory_bytes: 25060
/*
power code taken from geeks for geeks
*/

#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 100000000
#define MAX_N 200001
using namespace std;
typedef long long ll;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}


bool comp(pair<ll,ll>& a, pair<ll,ll>& b){
    return a.first<b.first;
}

void swap(ll& s1, ll &s2){
    ll temp=s1;
    s1=s2;
    s2=temp;
}
ll gcd(ll a, ll b){
    if(b==0){
        return a;
    }
    return gcd(b, a%b);
}


void solve(){
    ll n;
    cin>>n;
    while(n>0){
        if(n%10==7){
            cout<<"Yes\n";
            return;
        }
        n/=10;
    }
    
    cout<<"No"<<endl;
}


int main(){
  

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll t=1;
    
    // cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3644
R, G, B, N = map(int, input().split())
ans = 0
for r in range(3001):
    for g in range(3001):
        if (N - r * R - g * G) / B == (N - r * R - g * G) // B and (N - r * R - g * G) / B >= 0:
            ans += 1
print(ans)

Measured memory_bytes: 42476
#include <iostream>

using namespace std;

int
main(int argc, const char *argv[])
{
    int n, q;
    int S[10000], T[500];
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> S[i];
    cin >> q;
    for (int i = 0; i < q; ++i) cin >> T[i];

    int count = 0;
    for (int i = 0; i < q; ++i) {
        for (int j = 0; j < n; ++j) {
            if (S[j] == T[i]) {
                ++count;
                break;
            }
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3104
#include <stdio.h>
       
int main(void){
       
  int n;
  register int i;
  int x;

  scanf("%d",&n);
  for(i = 3;i <= n;i++){
    if(i % 3 == 0){
      printf(" %d",i);
      continue;
    }
    x = i;
    while(x > 2){
      if (x % 10 == 3){
        printf(" %d",i);
        break;
      }
      x /= 10;
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const ll M=2e5+5;
ll a[M],b[M],ord[M];
ll tim[102],ttm[102];
bool cmp(ll x,ll y)
{
	return (b[x]+1)*a[y]<a[x]*(b[y]+1);
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,T;
	cin>>n>>T;
	if(T==0)
	{
		cout<<"0\n";return 0;
	}
	std::vector<ll> v;
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		if(a[i]==0)
		{
			v.pb(b[i]);
			i--;
			n--;
		}
	}
	sort(all(v));
	if(n==0)
	{
		ll s=1;
		for(ll i=0;i<sz(v);i++)
		{
			if(s+v[i]>T)
			{
				cout<<i<<"\n";
				return 0;
			}
			s+=v[i]+1;
		}
		cout<<sz(v)<<"\n";
		return 0;
	}
	for(ll i=1;i<=n;i++)
		ord[i]=i;
	sort(ord+1,ord+n+1,cmp);
	for(ll i=1;i<=100;i++)
		tim[i]=T+1;
	tim[0]=0;
	for(ll ii=1;ii<=n;ii++)
	{
		ll i=ord[ii];
		for(ll j=0;j<=100;j++)
			ttm[j]=tim[j];
		for(ll j=0;j<100;j++)
		{
			if(tim[j]>T)
				continue;
			ll z=tim[j]+1+a[i]*(tim[j]+1)+b[i];
			ttm[j+1]=min(ttm[j+1],z);
		}
		for(ll j=0;j<=100;j++)
			tim[j]=ttm[j];
	}
	ll ans=0;
	for(ll j=0;j<=100;j++)
	{
		ll s=tim[j];
		if(s>T)
			continue;
		s++;
		ll i;
		for(i=0;i<sz(v);i++)
		{
			if(s+v[i]>T)
			{
				break;
			}
			s+=v[i]+1;
		}
		ans=max(ans,j+i);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    
    ll ans = 0;
    while (true) {
        ll s = 0;
        for (int i = 0; i < n; ++i) {
            s += a[i] / n;
            a[i] = a[i] % n - a[i] / n;
        }
        if (s == 0) break;
        for (int i = 0; i < n; ++i) {
            a[i] += s;
        }
        ans += s;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=200005;
int n,a[MAXN];
int main()
{
	n=read();for(int i=1;i<=n;i++)a[i]=read();
	if(a[1])return pr2(-1),0;for(int i=1;i<n;i++)if(a[i+1]-a[i]>1)return pr2(-1),0;
	LL ans=0;
	for(int i=1;i<=n;i++)if(a[i]>=a[i+1])ans+=a[i];
//	if(a[n]<a[n-1])ans+=a[n];
	pr2(ans);
	return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
int main () {
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0)break;
		for(i = 1;i <= H;i++){
			if(i % 2 == 1){
				for(j = 1;j <= W;j++){
					if(j % 2 == 1){
						printf("#");
					}else{
						printf(".");
					}
				}
			}
			if(i % 2 == 0){
				for(j = 1;j <= W;j++){
					if(j % 2 == 1){
						printf(".");
					}else{
						printf("#");
					}
				}
			}
				printf("\n");
		}
		printf("\n");
	}
	return 0;
}




Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    while(1){
    ll n;cin>>n;
    if(n==0)break;
    vector<ll>a(1010);
    REP(i,1,1010){
        a[i]=a[i-1]+i;
    }
    ll cnt=0;
    rep(i,n-1){
        REP(j,i+1,n){
            if(a[j]-a[i]==n)cnt++;
        }
    }
    cout<<cnt<<endl;
    }
}


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

int main() {
int N;
  cin >>N;
  bool f = false;
  for(int i=1;i<=9;i++){
   for(int j=1;j<=9;j++){
 if(N == i * j) f = true;
   }
   }
  if(f) printf("Yes");
    else printf("No");
    cout <<endl;
}

Measured memory_bytes: 256
N = int(input())

H = [int(x) for x in input().split()]

H[0] -= 1

flag = True
for i in range(1, len(H)):
	if H[i] > H[i-1]:
		H[i] -= 1
	if H[i] < H[i-1]:
		flag = False
		break

if flag:
	print('Yes')
else:
	print('No')

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

using namespace std;

int main(){
	int n;
	int temp,temp1;
	string s;
	long long cnt=0;
	std::map<string, int> m;

	cin >> n;

	for(temp=0;temp<n;temp++){
		cin >> s;
		sort(s.begin(),s.end());
		if(m[s]==0){
			m[s]++;
		}
		else{
			cnt+=m[s];
			m[s]++;
		}
	}
	cout << cnt << "\n";
}

Measured memory_bytes: 11136
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val S, T = sc.nextLine().toCharArray
    val SL = S.length
    val TL = T.length

    // dp[i][j] := Sのi番目までとTのj番目までの文字列の最長共通部分列の長さ
    // S[i] == T[j] => dp[i][j] = dp[i-1][j-1] + 1
    // i番目とj番目の文字列が異なる場合,
    // S[i] != T[j] => dp[i][j] = max(dp[i][j-1], dp[i-1][j])
    // dp[0][0] = 0
    val dp = Array.fill(SL+1, TL+1)(0)
    // では文字列情報はどのように渡すか? 更新が発生している時, 文字列が結合されている
    // 下から持ち上げられてきたとき, 文字列情報がそのまま持ち上げられている
    // なので, 文字列リテラルを保持しておく(インスタンス共有されるから足りるやろ)
    // ↑ 文字列結合がネックになってTLE
    // 移動情報を使って辿ることにする.
    // その場の文字を使った場合, c[i][j] = 0
    // [i][j-1]の文字を使った場合, c[i][j] = 1
    // [i-1][j]の文字を使った場合, c[i][j] = 2 と記録して c[SL][TL]から辿る
    val c = Array.fill(SL+1, TL+1)(-1)
    for {
      i <- 0 until SL
      j <- 0 until TL
    } if (S(i) == T(j)) {
      dp(i+1)(j+1) = dp(i)(j) + 1
      c(i+1)(j+1) = 0
    } else if (dp(i+1)(j) > dp(i)(j+1)) {
      dp(i+1)(j+1) = dp(i+1)(j)
      c(i+1)(j+1) = 1
    } else {
      dp(i+1)(j+1) = dp(i)(j+1)
      c(i+1)(j+1) = 2
    }

    // 辿る
    def printC(S: Array[Char],
               dp: Array[Array[Int]], c: Array[Array[Int]]): String = {
      def loop(i: Int, j: Int, str: List[Char]): List[Char] =
        if (!(i == 0 && j == 0)) {
          c(i)(j) match {
            case 0 => loop(i-1, j-1, S(i-1) :: str)
            case 1 => loop(i,   j-1, str)
            case 2 => loop(i-1, j,   str)
            case _ => str
          }
        } else str
      loop(SL, TL, Nil).mkString
    }

    println(printC(S, dp, c))
  }

}


Measured memory_bytes: 114120
#include<stdio.h>

int main(void)
{
    int a, b, d, r;
    double f;

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

    d = a / b;
    r = a % b;
    f = (double)a / b;

    printf("%d %d %f\n",d, r, f);

    return 0;
}


Measured memory_bytes: 2000
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>

using namespace std;

map <string,vector<int>> m;
map <int,int> l;

int main()
{
    int n;
    string s;
    int p;
    cin >> n;
    for (int i = 1;i <= n;i++){
        cin >> s >> p;
        m[s].push_back(p);
        l[p] = i;
    }
    for (auto it:m)
    {
        auto v = it.second;
        sort(v.begin(),v.end(),greater<int>());
        for (auto i:v)
        {
            cout << l[i] << endl;
        }
    }
}


Measured memory_bytes: 256
import math


def gcd(x, y):
    if x % y == 0:
        return y
    else:
        return gcd(y, x % y)


def lcm(x, y):
    return x * y // gcd(x, y)


A, B, C, D = map(int, input().split())
t = lcm(max(C, D), min(C, D))
m = (B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // t - (A - 1) // t)
print((B - A + 1) - m)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 100005
const ll INF = 1000000001;
const ll MOD = 998244353 ; //1e9+7;

vector< vector<ll> > g(N);
//vector< pair<ll, pair< ll, ll > > > g(N);
ll vis[N] = {0}, par[N] = {0}, child[N] = {0}, dp[N] = {0};

void dfs(ll v){
    vis[v] = 1;
    for(auto u: g[v]){
        if(!vis[u]){
            dfs(u);
        }
        dp[v] = max(dp[v], 1 + dp[u]);
    }
}

void solve(){
    ld d, t, s; cin >> d>> t >> s;
    if(d/t <= s) cout << "Yes\n";
    else cout << "No\n";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    //ll t;cin >> t;for(ll index=1; index<=t; index++){
        //cout << "Case #" << index << ": " ;
        solve();
    //}
    return 0;
}


Measured memory_bytes: 5424
n,m,l=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]
B=[list(map(int,input().split())) for i in range(m)]
 
for i in range(n):
  for j in range(l):
    x=0
    for k in range(m):
      x+=A[i][k]*B[k][j]
    if j==0:
      print(x, end="")
    else:
      print("", x, end="")
  print("")


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

using namespace std;
typedef long long ll;

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

int main(void){
    string s;
    char bra[] = {'(', ')', '[', ']'};
    while(getline(cin, s) && s!=".") {
        stack<char> stk;
        bool ok = true;
        rep(i, s.size()) {
            bool is_bracket = false;
            rep(j, 4) if(s[i] == bra[j]) is_bracket = true;
            if(!is_bracket) continue;
            if(stk.empty() || s[i] == '(' || s[i] == '[') stk.push(s[i]);
            else if( (stk.top() == '(' && s[i] == ')') ||
                     (stk.top() == '[' && s[i] == ']') ) stk.pop();
            else {
                ok = false;
                break;
            }
        }

        if(ok && stk.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
 
ll N,K;
vector<ll> A(200005);
vector<ll> A2(200005,0);
vector<ll> check(200005,0);

ll amari,shuu;


void loop(){
	ll shuuki=1,now=0,a;
	while(1){
		ll next = A.at(now);

		if(check.at(next)==1){
			//cout<<"next"<<next<<endl;
			//cout<<"now"<<now<<endl;
			for(int i=0;i<N;i++){
				//cout<<A2.at(i)<<" ";
				if(A2.at(i)==next){
					a=i;
					break;
				}
			}
			//cout<<"a"<<a<<" "<<"shuuki"<<shuuki<<endl;
			amari = a;
			shuu = shuuki-amari;
			return;
		}

		else{
			check.at(next)=1;
			A2.at(shuuki) = next;
			now = next;
			shuuki++;
		}
	}
}

// ll loop(ll now){
// 	ll shuuki=1;
// 	while(1){
// 		ll next = A.at(now);
// 		if(A2.at()){
// 			A2.at(shuuki) = next;
// 			return shuuki;
// 		}
// 		else{
// 			A2.at(shuuki) = next;
// 			now = next;
// 			shuuki++;
// 		}
// 	}
// }
 
int main(){
	cin>>N>>K;
	A.resize(N);
	A2.resize(N);
	check.resize(N);

	for(int i=0;i<N;i++){
		cin>>A.at(i);
		A.at(i)--;
	}

	check.at(0)=1;
	A2.at(0) = 0;
	loop();

	//cout<<"amari"<<amari<<" "<<"shuu"<<shuu<<endl;

	if(K<amari){
		cout<<A2.at(K)+1<<endl;;
	}
	else
		cout<<A2.at(amari+((K-amari)%shuu))+1<<endl;
}

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

int a[1010];
int n;

string solve(){
    set<string> S;
    for(int i = 0; i < n; i++){
        string cur;
        for(int j = i; j < n; j++){
            cur += (char)(a[j]+'0');
            if(cur.size() > 10) continue;
            S.insert(cur);
        }
    }
    for(int i = 0; i < 1e9; i++){
        string s = to_string(i);
        if(S.find(s) != S.end()) continue;
        return s;
    }
    return "";
}

int main(){
    while(cin >> n){
        rep(i,n) cin >> a[i];
        cout << solve() << endl;
    }
}

Measured memory_bytes: 4036
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K,H,W, mi1,mi2,sum;
string s;
LL ans,a;
LL alp[100000][125];
int main() {
	cin >> N;
	vector<LL> v(N);
	ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		if (v[i] > i) {
			cout << -1 << endl;
			return 0;
		}
		if (i > 0 && v[i] - v[i - 1] > 1) {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = 0; i < N-1; i++) {
		if (v[i + 1] - v[i] == 1)ans++;
		else ans += v[i+1];

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



Measured memory_bytes: 1792
import sys
from bisect import bisect_left
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        search = L[i] + L[j]
        k = bisect_left(L, search)
        ans += k - j - 1
print(ans)


Measured memory_bytes: 42844
import java.util.*;

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

	int MAX = 1000000;	
	int[] p = new int[MAX];
	for(int i=2; i<p.length; i++)p[i] = 1;
	for(int i=2; i<Math.sqrt(MAX)+1; i++){
	    for(int j=i*2; j<MAX; j+=i){
		p[j] = 0;
	    }
	}
	
	while(sc.hasNext()){
	    
	    int n = sc.nextInt();

	    int count = 0;
	    for(int i=0; i<=n; i++){
		if(p[i]==1)count++;
	    }

	    System.out.println(count);
	}
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
const int mod = 1e9 + 7;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  vi a(n), s(n + 1);
  ll res = 0;
  vvi was(1 << 20);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    s[i + 1] = s[i] ^ a[i];
    was[s[i + 1]].push_back(i + 1);
  }
  vi good;
  if (s.back() == 0) {
    ll prod = 1;
    for (int i : was[0]) if (i != 0 && i != n) prod = prod * 2 % mod;
    res += prod;
    for (int i = 1; i < was.size(); ++i) if (!was[i].empty()) good.push_back(i);
  } else {
    good.push_back(s[n]);
  }
  for (int a : good) {
    vi g, z;
    int pr = -1;
    for (int i : was[a]) {
      int it = lower_bound(was[0].begin(), was[0].end(), i) - was[0].begin();
      if (it == pr) ++g.back();
      else {
        if (pr != -1) z.push_back(it - pr);
        //else z.push_back(1);
        pr = it;
        g.push_back(1);
      }
    }
    if (a == s[n]) g.back() = 1;
    z.push_back(1);
    vi d(z.size() + 1);
    d[0] = 1;
    ll s0 = 0, s1 = 0;
    for (int i = 0; i < z.size(); ++i) {
      s0 = (s0 + d[i]) % mod;
      s1 = (s1 + s0 * g[i]) % mod;
      d[i + 1] = z[i] * s1 % mod;
//      cerr << g[i] << ' ' << z[i] << ' ' << s0 << ' ' << s1 << ' ' << d[i + 1] << endl;
    }
//    cerr << a << ' ' << d.back() << endl;
    if (a == s[n]) res += s0;
    else res += d.back();
  }
  cout << (res % mod + mod) % mod << endl;
  return 0;
}


Measured memory_bytes: 40564
f = lambda :int(input())
A = f()
B = f()
C = f()
X = f()
ans = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k == X:
                ans += 1
print(ans)

Measured memory_bytes: 3316
N = int(input())
box = [int(x) for x in input().split()]
tmp = []
for con in box:
    if con % 2 == 0:
        tmp.append(con)

flg = True
for num in tmp:
    if not ((num % 3 == 0) or (num % 5 == 0)):
        print('DENIED')
        flg = False
        break
if flg:
    print('APPROVED')

Measured memory_bytes: 3064
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=55555;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  isPrime[0]=isPrime[1]=false;
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<bool> v=sieve_of_eratosthenes();
  vector<ll> ans;
  rep(i,v.size()) if(v[i] && i%5==1) ans.push_back(i);
  rep(i,n) cout<<ans[i]<<' ';
  cout<<endl;
}

Measured memory_bytes: 256
# coding: utf-8


def main():
    hp1, atr1, hp2, atr2 = map(int, input().split())

    turn_takahashi = True
    while True:
        if turn_takahashi:
            hp2 -= atr1
        else:
            hp1 -= atr2

        if hp1 <= 0:
            return "No"
        elif hp2 <= 0:
            return "Yes"

        turn_takahashi = not turn_takahashi


print(main())


Measured memory_bytes: 9024
import java.util.*

fun main() {
    val sc = Scanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()
    val k = sc.nextInt()
    val board = Array(h){CharArray(w)}

    for(i in 0 until h) {
        board[i] = sc.next().toCharArray()
    }

    var blkCnt = 0
    for(i in 0 until h) {
        for(j in 0 until w) {
            if(board[i][j] == '#')
                ++blkCnt
        }
    }

    fun dfs(v:List<Boolean>, cnt:Int): Int {
        if(cnt == h+w) {
            val s = HashSet<Pair<Int,Int>>()
            val row = ArrayList<Int>()
            val col = ArrayList<Int>()
            for(i in 0 until h) {
                if(!v[i]) continue
                row.add(i)
                for(j in 0 until w) {
                    if(board[i][j] == '#') {
                        s.add(i to j)
                    }
                }
            }
            for(j in h until  h + w) {
                if(!v[j]) continue
                col.add(j-h)
                for(i in 0 until h) {
                    if(board[i][j-h] == '#') {
                        s.add(i to j - h)
                    }
                }
            }
            val remain = blkCnt - s.size
            if(remain == k) {
                return 1
            }
            return 0
        }
        return dfs(v.plus(true), cnt + 1) + dfs(v.plus(false), cnt + 1)
    }
    print(dfs(listOf(), 0))
}

Measured memory_bytes: 51556
import re


def solve(s, t):
    sd = s.replace('?', '.')
    sa = s.replace('?', 'a')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORABLE'
    ans = []
    for i in range(ls - lt + 1):
        if re.match(sd[i:i + lt], t) is not None:
            ans.append(sa[:i] + t + sa[i + lt:])
    if not ans:
        return 'UNRESTORABLE'
    return min(ans)


print(solve(input().strip(), input().strip()))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int N, W;
    cin >> N >> W;
    int w[N+1], v[N+1];
    FOR(i, 1, N+1) cin >> w[i] >> v[i];

    ll ret[N+1][W+1];
    REP(i, W+1) ret[0][i] = 0;

    FOR(i, 1, N+1) REP(j, W+1)
    {
        if (w[i]<=j) ret[i][j] = max(ret[i-1][j], ret[i-1][j-w[i]]+v[i]);
        else ret[i][j] = ret[i-1][j];
    }

    cout << ret[N][W] << endl;
    return 0;
}

Measured memory_bytes: 79104
#include <stdio.h>
int main(void){
    int count[4] [3] [10] = {0};
    int N, i, j, k;
    fscanf(stdin,"%d", &N);
    for(i = 0; i < N; i++){
        int b, f, r, v;
        fscanf(stdin,"%d %d %d %d", &b, &f, &r, &v);
        count[b - 1] [f - 1] [r - 1] += v;
    }
    for(i = 0; i < 4; i++){
        if(i > 0) printf("####################\n");
        for(j = 0; j < 3; j++){
            for(k = 0; k < 10; k++){
                printf(" %d", count[i] [j] [k]);
            }
            printf("\n");
        }
    }
    return 0;
}
    



Measured memory_bytes: 2140
#include<iostream>
#include<complex>
#include<array>
#include<vector>
#include<cstdio>
using namespace std;

const double EPS = 1e-10;
template<class T>
bool eq(const T& a, const T& b) {return abs(a - b) < EPS;}

typedef  complex<double> point;
// sort/unique用、setではうまく動かないので使うべからず
namespace std {
	bool operator==(const point &a, const point &b){
		return eq(a, b);
	}
	bool operator<(const point& a, const point& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const point& a, const point& b) {
	return imag(conj(a)*b);
}
double dot(const point& a, const point& b) {
	return real(conj(a)*b);
}
int ccw(point a, point b, point c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;  // counter clockwise
	if (cross(b, c) < 0)   return -1;  // clockwise
	if (dot(b, c) < 0)     return +2;  // c--a--b on line
	if (norm(b) < norm(c)) return -2;  // a--b--c on line
	return 0;  // a--c--b on line or a----bc
}

struct circle {point p; double r;};
typedef vector<point> polygon;
typedef array<point, 2> line;

point projection(const line& l, const point& p) {
	double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}

point reflection(const line& l, const point& p) {
	return p + 2. * (projection(l, p) - p);
}

int main()
{
  double x0,y0,x1,y1;
  for(;cin>>x0>>y0>>x1>>y1;)
    {
      int n;
      cin>>n;
      point p[3];
      p[0]=point(x0,y0);
      p[1]=point(x1,y1);
      const string str[]={
	"ONLINE_BACK",
	"COUNTER_CLOCKWISE",
	"ON_SEGMENT",
	"CLOCKWISE",
	"ONLINE_FRONT"

      };
      for(int i=0;i<n;i++)
	{
	  double x,y;
	  cin>>x>>y;
	  p[2]=point(x,y);
	  int ans=ccw(p[1],p[0],p[2]);
	  cout<<str[ans+2]<<endl;
	  //	  printf("%.10lf %.10lf\n",ans.real(),ans.imag());
	  //	  cout<<ans.real()<<" "<<ans.imag()<<endl;
	}
    }
}

Measured memory_bytes: 1260
while true
    h, w = gets.chomp.split.map(&:to_i)
    break if h == 0 && w == 0

    h.times{|y|
        w.times{|x|
            if y.even?
                print "#" if x.even?
                print "." if x.odd?
            else
                print "." if x.even?
                print "#" if x.odd?
            end
        }
        puts
    }
    puts
end

Measured memory_bytes: 8776
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vi A(N);
    REP(i, N) cin >> A[i];

    ll ans = 0;

    REP(i, N) FOR(j, i+1, N) {
        ans += A[i] * A[j];
    }

    print(ans);
    
}


Measured memory_bytes: 3652
#include <iostream>
#include <queue>
#define inf 1000000000

using namespace std;

struct pos{
	int sw, x, y, f;
	pos(){}
	pos(int s, int a, int b, int c){
		sw = s, x = a, y = b, f = c;
	}
};

int W, H;
char M[55][55];
int S;
int MS[10][55][55];
int sx, sy;
int dist[1024][55][55][2];
queue<pos> Q;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int bfs()
{
	for(int i = 0; i < 1024; i++){
		for(int x = 0; x < W; x++){
			for(int y = 0; y < H; y++){
				dist[i][x][y][0] = dist[i][x][y][1] = inf;
			}
		}
	}
	dist[0][sx][sy][0] = 0;
	Q.push( pos(0, sx, sy, 0) );
	
	pos v;
	int sw, f, x, y;
	int nsw, nf, nx, ny;
	char c, nc;
	while(Q.size()){
		v = Q.front(), Q.pop();
		sw = v.sw, f = v.f, x = v.x, y = v.y;
		for(int dir = 0; dir < 4; dir++){
			nx = x + dx[dir], ny = y + dy[dir];
			nc = M[nx][ny];
			if(nc == '#') continue;
			if(nc == '_' || nc == '%' || nc == '&' || (nc >= 'a' && nc <= 'j') ) nf = 0;
			else nf = 1;
			for(int i = 0; i < S; i++){
				if(sw & (1 << i) && MS[i][nx][ny]) nf = !nf;
			}
			if(nc == '|') nf = f;
			if(nc == '|' || f == nf){
				if(dist[sw][nx][ny][nf] < inf) continue;
				dist[sw][nx][ny][nf] = dist[sw][x][y][f] + 1;
				if(nc == '&') return dist[sw][nx][ny][nf];
				Q.push( pos(sw, nx, ny, nf) );
			}
		}
		c = M[x][y];
		if(c == '|'){
			if(dist[sw][x][y][!f] == inf){
				dist[sw][x][y][!f] = dist[sw][x][y][f] + 1;
				Q.push( pos(sw, x, y, !f) );
			}
		}
		if( (c >= 'a' && c <= 'j') || (c >= 'A' && c <= 'J') ){
			if(c >= 'a') c -= 'a' - 'A';
			int b = c - 'A';
			if(sw & (1 << b)) nsw = sw & ~(1<<b);
			else nsw = sw | (1<<b);
			
			nf = f;
			if(MS[b][x][y]) nf = !nf;
			
			if(dist[nsw][x][y][nf] == inf){
				dist[nsw][x][y][nf] = dist[sw][x][y][f] + 1;
				Q.push( pos(nsw, x, y, nf) );
			}
		}
	}
	return -1;
}


int main(void)
{
	cin >> W >> H;
	for(int y = 0; y < H; y++){
		for(int x = 0; x < W; x++){
			cin >> M[x][y];
			if(M[x][y] == '%') sx = x, sy = y;
		}
	}
	cin >> S;
	char tmp;
	for(int s = 0; s < S; s++){
		for(int y = 0; y < H; y++){
			for(int x = 0; x < W; x++){
				cin >> tmp;
				if(tmp == '*') MS[s][x][y] = 1;
				else MS[s][x][y] = 0;
			}
		}
	}
	
	cout << bfs() << endl;
	return 0;
}

Measured memory_bytes: 27896
import math
n = int(input())
tax_rate = 1.08
x0 = math.floor(n / tax_rate)
x1 = math.ceil(n / tax_rate)
if int(x0 * tax_rate) == n:
    print(x0)
elif int(x1 * tax_rate) == n:
    print(x1)
else:
    print(':(')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;
typedef pair<ll,ll> Pll;

int main(){
    int n,k; cin >> n >> k;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    ll ans=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i+j==0||i+j>n||i+j>k) continue;
            priority_queue<ll,vector<ll>,greater<ll>> pq;
            ll res=0;
            rep(kk,i){
                pq.push(v[kk]);
                res+=v[kk];
            }
            rep(kk,j){
                pq.push(v[n-1-kk]);
                res+=v[n-1-kk];
            }
            int cnt=k-i-j;
            while((!pq.empty())&&pq.top()<0&&cnt>0){
                res-=pq.top(); pq.pop();
                cnt--;
            }
            chmax(ans,res);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    ll a[7] = {};
    rep(i,7){
        cin >> a[i];
    }


    ll ans = 0;

    ans += a[1];

    int flag = 0;
    flag = a[0]%2 + a[3]%2 + a[4]%2;
    if(flag>=2&&a[0]>0&&a[3]>0&&a[4]>0){
        ans += 3;
        a[0]--;
        a[3]--;
        a[4]--;
    }

    ans += (a[0]/2)*2;
    ans += (a[3]/2)*2;
    ans += (a[4]/2)*2;

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


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define int long long
#define endl "\n"

const int N=1e3+5;

int n;
int a[N],b[N];
int cache[10007];

int dp(int h)
{
    if(h<=0)
        return 0;
    int &ans=cache[h];
    if(ans!=-1)
        return ans;
    ans=1e18;    
    for(int i=1;i<=n;i++)
        ans=min(ans,dp(h-a[i])+b[i]);
    return ans;
}

int32_t main()
{
    IOS;
    
    memset(cache,-1,sizeof cache);
    
    int h;
    cin>>h;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i];
        
    cout<<dp(h);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll cnt[3];
int main() {
    init();
    string S;
    cin >> S;
    rep(i,S.size()){
        cnt[S[i] - 'a']++;
    }

    ll m = min(cnt[0], min(cnt[1], cnt[2]));
    rep(i, 3) cnt[i] -= m;

    bool isok = true;
    rep(i, 3) if (cnt[i] > 1) isok = false;

    cout << (isok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

#define W 0
#define G 1
#define B 2

int n, t = 0;
int color[100], d[100], f[100];
int v[100][100];
void dfs(void);
void dfsvisit(int);

main() {
  int i, j;
  
  for(i = 0; i < 100; i++) {
    color[i] = W;
    d[i] = 0;
    f[i] = 0;
  }
  scanf("%d", &n);
  
  for(i = 0; i < n; i++) {
    scanf("%d %d", &v[i][0], &v[i][1]);
    for(j = 2; j < v[i][1] + 2; j++) {
      scanf("%d", &v[i][j]);
    }
  }
  
  dfs();

  for(i = 0; i < n; i++) {
    printf("%d %d %d\n", v[i][0], d[i], f[i]);
  }
  return 0;
}

void dfs(void) {
  int i;
  for(i = 0; i < n; i++) {
    if(color[i] == W) {
      dfsvisit(i);
    }
  }
}

void dfsvisit(int u) {
  int i;
  
  color[u] = G;
  d[u] = ++t;

  for(i = 0; i < v[u][1]; i++) {
    if(color[v[u][i + 2] - 1] == W) {
      dfsvisit(v[u][i + 2] - 1);
    }
  }
  
  color[u] = B;
  f[u] = ++t;
}

Measured memory_bytes: 636
#input
S = input()
Q = int(input())
P = [[]] * Q
for i in range(Q):
    P[i] = list(map(str, input().split()))

#output
flip = 0
cap = ""
tail = ""

for i in range(Q):
    if int(P[i][0]) == 1:
        flip += 1
    else:
        n = int(P[i][1])
        v = P[i][2]
        if flip % 2 == 0:
            if n == 1:
                cap = v + cap
            else:
                tail = tail + v
        else:
            if n == 1:
                tail = tail + v
            else:
                cap = v + cap

answer = ""
if flip % 2 == 0:
    answer = cap + S + tail
else:
    answer = tail[-1::-1] + S[-1::-1] + cap[-1::-1]

print(answer)

Measured memory_bytes: 42196