akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = 2e18;

signed main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<string> startStr = {"SS", "SW", "WS", "WW"};
    for (string start : startStr) {
        string save = start;
        for (int i = 1; i < N - 1; i++) {
            if (save[i] == 'S') {
                if (S[i] == 'o') {
                    save += save[i - 1];
                } else {
                    save += (save[i - 1] == 'S' ? 'W' : 'S');
                }
            } else {
                if (S[i] == 'x') {
                    save += save[i - 1];
                } else {
                    save += (save[i - 1] == 'S' ? 'W' : 'S');
                }
            }
        }
        auto check = [&](int idx) {
            int left = (idx - 1 + N) % N;
            int right = (idx + 1 + N) % N;
            if (save[idx] == 'S') {
                if (S[idx] == 'o') {
                    if (save[left] != save[right]) return false;
                } else {
                    if (save[left] == save[right]) return false;
                }
            } else {
                if (S[idx] == 'x') {
                    if (save[left] != save[right]) return false;
                } else {
                    if (save[left] == save[right]) return false;
                }
            }
            return true;
        };
        if (check(0) && check(N - 1)) {
            cout << save.substr(0, N) << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 776
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace q6
{
    class Program
    {
        static IEnumerable<long> Div(long n)
        {
            var x = 2L;
            yield return 1;
            while (true)
            {
                if ((x * x) > n)
                    break;
                if (n % x == 0)
                {
                    yield return x;
                    if ((n / x) != x)
                    {
                        yield return n/x;
                    }
                }
                x += 1;
            }
            yield return n;
        }

        static void Main(string[] args)
        {
            var N = Convert.ToInt64(Console.ReadLine());
            var cnt = 0;
            var set = new HashSet<long>();
            set.Add(1);
            foreach (var k in Div(N).Skip(1))
            {
                //Console.WriteLine($"d1 {k}");
                var n = N;
                while (n > k && n % k == 0)
                {
                    n = n / k;
                }
                if (n > k)
                    n = n % k;
                if (n == 1 || n == k)
                {
                    //Console.WriteLine($" d1 hit {k}");
                    set.Add(k);
                }
            }
            foreach (var k in Div(N - 1).Skip(1))
            {
                //Console.WriteLine($"  d2 {k}");
                //Console.WriteLine($"  d2 hit {k}");
                set.Add(k);
            }
            set.Remove(0);
            set.Remove(-1);
            set.Remove(1);
            /*
            foreach (var v in set.OrderBy(x => x))
            {
                Console.WriteLine($"res {v}");
            }
            */
            Console.WriteLine(set.Count);
        }
    }
}


Measured memory_bytes: 13524
#include<cstdio>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>

#define _USE_MATH_DEFINES
#define FORN(n) for(int i=0;i<n;i++)
#define PINT(d) printf("%d\n", d)
#define PDOUBLE(lf) printf("%lf\n", lf)
#define PSTR(s) printf("%s\n", s)
#define INF 2147483647

using namespace std;
     
main(){
    string input;
    cin >> input;
    
    stack<int> s;
    FORN(input.length()){
        switch(input[i]){
            case '0':
                s.push(0);
                break;
            case '1':
                s.push(1);
                break;
            case 'B':
                if(s.empty() == false) s.pop();
                break;
            default:
                break;
        }
    }
    
    stack<int> ans;
    int n = s.size();
    FORN(n){
        ans.push(s.top());
        s.pop();
    }
    
    FORN(n){
        cout << ans.top();
        ans.pop();
    }

    
}

Measured memory_bytes: 256
<?php
//error_reporting(0);
//$S = trim(fgets(STDIN));
list($K,$X) =  explode(" ",trim(fgets(STDIN)));
//$H =  explode(" ",trim(fgets(STDIN)));

//Xが右端
$mi = $X - $K + 1;
$mx = $X + $K;

for($i=$mi;$i<$mx;$i++) {
  $r[]=$i;
}
printf("%s\n",implode($r," "));


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

int main(){
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0;i * 4 <= n;i++) {
		if ((n - i * 4) % 7 == 0) {
			ans++;
		}
	}
	if (ans > 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    string n;
    cin >> n;
    int res = 0;
    REP(i,n.size()){
        int temp = 0;
        if(n[i]!='0'){
            REP(j,i){
                temp+=n[j]-'0';
            }
            temp+=n[i]-'0'-1;
            FOR(j,i+1,n.size()){
                temp+=9;
            }
            chmax(res,temp);
        }
    }
    int temp = 0;
    REP(i,n.size()){
        temp+=n[i]-'0';
    }
    chmax(res,temp);
    put(res);
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
#define N 200005
int n, k;
ll a[N];
bool check(int x){
	ll res=0;
	for (int i=1;i<=n;i++) res+=(a[i]-1)/x;
	return res<=k;
}
int main(){
	n=read(), k=read();
	int le=0, ri=1000000002;
	for (int i=1;i<=n;i++) a[i]=read();
	while (ri-le>1){
		int mid=(le+ri)/2;
		if (check(mid)) ri=mid;
		else le=mid;
	}
	cout<<ri<<endl;
    return 0;
}

Measured memory_bytes: 5120
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    long ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        int gcdIJ = gcd(i, j);
        for (int k = 1; k <= n; k++) {
          ans += gcd(gcdIJ, k);
        }
      }
    }
    pw.println(ans);
  }

  static int gcd(int a, int b) {
    if (a == b) {
      return a;
    }
    if (a > b) {
      return innerGcd(a, b);
    } else {
      return innerGcd(b, a);
    }
  }

  static int innerGcd(int a, int b) {
    int r = a % b;
    if (r == 0) {
      return b;
    }
    return innerGcd(b, r);
  }
}


Measured memory_bytes: 36264
#include<stdio.h>
#include<math.h>

#define N 100000

int isprime(int);

int main(){

  int num[N];
  int n,a,b,i,j;
  int count = 0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
  }

  for(i=0;i<n;i++){
    a=num[i];
    b=isprime(a);
    if(b==1) count++;
   }

  printf("%d\n",count); 

  return 0;
  
}

int isprime(int x){

  int i;

  if(x==2) return 1;
  if(x<2 || x%2==0) return 0;

  i=3;
  
    while(i<=sqrt(x)){

      if(x%i==0) return 0;
      i=i+2;
      
    }

  return 1;

}



Measured memory_bytes: 2108
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int A[110];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, N) cin >> A[i];

    rep(i, N) {
        if (A[i] % 2 == 0) {
            if (A[i] % 3 == 0 || A[i] % 5 == 0) {

            } else{
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;


    return 0;
}


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

int abs(int x){
    if(x<0)
        return x*(-1);
    else
        return x;
}


int main(void){
    int x1,x2,x3,x4,y1,y2,y3,y4;

    cin>>x1>>y1>>x2>>y2;

    x4=x1-(y2-y1);
    y4=y1+(x2-x1);

    x3=x2+(y1-y2);
    y3=y2-(x1-x2);

    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
    return 0;

}

Measured memory_bytes: 256
from copy import deepcopy
def main():
    N = int( input())
    if N == 1:
        print('a')
        return
    ANS = [(1, 'a')]
    a = ord('a')
    for i in range(N-1):
        G = deepcopy(ANS)
        ANS = []
        for c, t in G:
            for j in range(c):
                ANS.append((c,t+chr(a+j)))
            ANS.append((c+1, t+chr(a+c)))
    ANS = [ t[1] for t in ANS]
    print('\n'.join(ANS))
if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll from;
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = (ll)pow(10,7);
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a;
vl s;
/******* define variable end *******/
ll binary_search(ll x){
	ll i = 0, j = n - 1;
	while(j >= i){
		ll m = floor((i + j) / 2);
		if(a[m] == x){
			return m;
		}else if(a[m] > x){
			j = m - 1;
		}else{
			i = m + 1;
		}
	}
	return -1;
}

int solve() {
	cin >> n;
	RES(a, n);
	REP(i, n){
		cin >> a[i];
	}
	sort(ALL(a));
	ll ans = 0;
	FOR(i,1, n){
		ans += a[n - i/2 - 1];
	}
	cout << ans << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 4804
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    // ABC129-D, 1080, 
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i, h) {
        cin >> s[i];
    }
    vector<vector<int>> hor(h, vector<int>(w, 0));
    vector<vector<int>> ver = hor;
    rep(i, h) {
        int start = 0;
        int num = 0;
        char old = '.';
        rep(j, w) {
            if (old == '#' && s[i][j] == '.') {
                start = j;
                num++;
            }
            else if (old == '.' && s[i][j] == '.') num++;
            else if (old == '#' && s[i][j] == '#') continue;
            else {
                int k = j - 1;
                while (start <= k) {
                    hor[i][k] = num;
                    k--;
                }
                num = 0;
            }
            old = s[i][j];
        }
        if (old == '.') {
            int k = w - 1;
            while (start <= k) {
                hor[i][k] = num;
                k--;
            }
        }
    }
    rep(j, w) {
        int start = 0;
        int num = 0;
        char old = '.';
        rep(i, h) {
            if (old == '#' && s[i][j] == '.') {
                start = i;
                num++;
            }
            else if (old == '.' && s[i][j] == '.') num++;
            else if (old == '#' && s[i][j] == '#') continue;
            else {
                int k = i - 1;
                while (start <= k) {
                    ver[k][j] = num;
                    k--;
                }
                num = 0;
            }
            old = s[i][j];
        }
        if (old == '.') {
            int k = h - 1;
            while (start <= k) {
                ver[k][j] = num;
                k--;
            }
        }
    }
    int ans = 0;
    rep(i, h) rep(j, w) {
        ans = max(ans, hor[i][j] + ver[i][j]);
    }
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 42476
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp(x,y) std::make_pair(x,y)
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int N;
int a[200010],b[200010];
std::vector<int> edge[200010];
bool f[200010];
int temp;
void add_edge(int from,int to){
  edge[from].push_back(to);
  edge[to].push_back(from);  
}
int far_away(int s){
  fill(f,0);
  temp=0;
  int res;
  std::priority_queue<pi,std::vector<pi>,std::greater<pi> > q;  
  q.push(mp(0,s));
  while(!q.empty()){
    pi p=q.top();q.pop();
    int F=p.first,S=p.second;
    f[S]=true;
    int es=edge[S].size();
    rep(i,es){
      int e=edge[S][i];
      if(!f[e]){
	q.push(mp(F+1,e));
	if(temp<=F+1){
	  temp=F+1;
	  res=e;
	}
      }
    }
  }
  return res;
}
int diameter(){
  far_away(far_away(0));
  return temp+1;
}
void solve(){
  rep(i,N-1){
    add_edge(a[i],b[i]);
  }
  int L=diameter();
  //  prin(L);
  if(L%3==2) prin("Second");
  else prin("First");
}
int main(){
  cin>>N;
  rep(i,N-1){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
  }
  solve();
  return 0;
}


Measured memory_bytes: 17364
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define N_MAX 1000
#define M_MAX 1000
#define INF 10000000
#define SMAP(a, b) ((a)!=(b))&&((a)^=((b)^=((a)^= (b))))

typedef unsigned long long ull;

int d[M_MAX];
int n, m;

int i, j, k;

char s[N_MAX + 1];

int e[M_MAX][2];

void deb(){
	return;
}

void solve(){
	if (n > 0) {
		puts("Positive");
	} else if (m >= 0) {
		puts("Zero");
	} else switch ((m - n) & 1) {
	case 0:
		puts("Negative");
		break;
	case 1:
		puts("Positive");
		break;
	}
	return;
}

int main (void) {
	scanf("%d%d", &n, &m);

	solve();
	return 0;
}




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

int main(){
  int H, W;
  cin >> H >> W;
  cout << string(W+2, '#') << endl;
  for (int i=0; i<H; i++){
    string s;
    cin >> s;
    cout << '#'+s+'#' << endl;
  }
  cout << string(W+2, '#') << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, long long> pii;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
const int MOD = 1000000007;
const int oo = 1000000001;
const int N = 100011;
const int MX = 19;
const int PRE = 0;
const int NXT = 1;

int n , p[N];

int main() {
	//freopen("input.txt", "r", stdin);
	cin >> n;
	int cnt = 0;
	for(int i = 1 ; i <= n ; i++)cin >> p[i];
	for (int i = 2; i <= n; ++i){
		if(p[i-1]==(i-1) && p[i] == i){
			swap(p[i-1],p[i]);
			++cnt;
		}
	}
	for (int i = 1; i <= n; ++i){
		if(p[i] == i)++cnt;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
class Fenwick:
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (n + 1)
    
    def getsum(self, i):
        ret = 0
        i += 1
        while(i > 0):
            ret += self.BIT[i]
            i -= i & -i
        return ret
    
    def add(self, i, x):
        i += 1
        while(i <= self.n):
            self.BIT[i] += x
            i += i & -i

N, Q = map(int, input().split())
A = list(map(int, input().split()))
bit = Fenwick(N)
for i in range(N):
    bit.add(i, A[i])

for q in range(Q):
    t, a, b = map(int, input().split())
    if t == 0:
        bit.add(a, b)
    else:
        print(bit.getsum(b - 1) - bit.getsum(a - 1))

Measured memory_bytes: 132156
package main

import (
	"fmt"
	"sort"
)

var s string
var K int

func main() {
	fmt.Scanf("%s", &s)
	fmt.Scanf("%d", &K)

	ss := []rune(s)

	set := make(map[string]struct{})
	for i := 0; i < len(ss); i++ {
		for j := i; j < i+K && j < len(ss); j++ {
			set[string(ss[i:j+1])] = struct{}{}
		}
	}

	strs := make([]string, 0, K*len(ss))

	for k := range set {
		strs = append(strs, k)
	}

	sort.Strings(strs)

	fmt.Println(strs[K-1])
}


Measured memory_bytes: 2432
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        int valid = int.MaxValue / 2;
        int invalid = 0;
        while (valid - invalid > 1)
        {
            var mid = (valid + invalid) / 2;

            if (a.Sum(x => (x + mid - 1) / mid) <= k + n) valid = mid;
            else invalid = mid;
        }
        Console.WriteLine(valid);
    }
}

Measured memory_bytes: 45712
#include<stdio.h>

int n;

typedef struct node{
  long int key;
  long int parent;
  long int left;
  long int right;
}Node;

int parent(i){
  if(i==1) return -1;
  else return i/2;
}

int left(i){
  if(2*i > n) return -1;
  else return 2*i;
}

int right(i){
  if(2*i+1 > n) return -1;
  else return 2*i+1;
}
	       

int main(){

  int i;
  scanf("%d",&n);

  Node H[n+1];

  for(i=1;i<=n;i++){
    scanf("%d",&H[i].key);
    H[i].parent = H[i].left = H[i].right = -1;
  }

  for(i=1;i<=n;i++){
    if(parent(i)!=-1) H[i].parent = H[parent(i)].key;
    if(left(i)!=-1) H[i].left = H[left(i)].key;
    if(right(i)!=-1) H[i].right = H[right(i)].key;
  }

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,H[i].key);
    if(H[i].parent!=-1) printf("parent key = %d, ",H[i].parent);
    if(H[i].left!=-1) printf("left key = %d, ",H[i].left);
    if(H[i].right!=-1) printf("right key = %d, ",H[i].right);
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2040
def dfs(n,N,s):
    L=[]
    if n==N:
        return s
    alps='abcdefghijklmnopqrstuvwxyz'
    
    for alp in alps[:len(set(list(s)))+1]:
        out=dfs(n+1,N,s+alp)
        if n+1==N:
            L.append(out)
        else:
            L+=out
    return L

def main():
    import sys
    import math
    N=int(sys.stdin.readline())

    for s in dfs(0,N,''):
        print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 13076
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n,k;
	cin >> n >> k;
	vector<int> v(n);
	for(int i = 0;i < n;i++)cin >> v[i];

	ll ans = 0;
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= n;j++){
			int now_cnt = k;
			if(i + j > n || i + j > k)continue;
			priority_queue<int,vector<int>,greater<int>> q;
			ll sum = 0;
			for(int l = 0;l < i;l++){
				sum += v[l];
				q.push(v[l]);
			}
			for(int l = 0;l < j;l++){
				sum += v[n-1-l];
				q.push(v[n-1-l]);
			}
			now_cnt -= (i+j);
			while(q.size() && q.top() < 0 && now_cnt > 0){
				sum -= q.top();
				q.pop();
				now_cnt--;
			}
			ans = max(ans,sum);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vi a(n);
    for(ll i=0;i<n;i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    lf ans=0;
    ans=a[0];
    for(ll i=1;i<n;i++)
    {
        ans=(ans+a[i])/2.0;
    }
    printf("%.6Lf\n",ans);
}


Measured memory_bytes: 256
use proconio::input;
use im_rc::HashMap;

#[proconio::fastout]
fn main() {
    input! {
    S:[String],
    }
    let freq = S.iter().fold(HashMap::new(), |mut acc, s| {
        *acc.entry(s).or_insert(0) += 1;
        acc
    });
    println!("AC x {}", freq.get(&"AC".to_string()).unwrap_or(&0));
    println!("WA x {}", freq.get(&"WA".to_string()).unwrap_or(&0));
    println!("TLE x {}", freq.get(&"TLE".to_string()).unwrap_or(&0));
    println!("RE x {}", freq.get(&"RE".to_string()).unwrap_or(&0));
}


Measured memory_bytes: 7772
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

const ll MOD = INF + 7;



int main(){
    string s;
    int k;
    vector<string>que;
    cin >> s >> k;
    rep(i, s.size()){
        REP(j, 1, k){
            if(i + j > s.size())break;
            que.push_back(s.substr(i, j));
        }
    }

    sort(ALL(que));
    string par = "-1";
    int cnt = 0;
    for(string q : que){
        if(par == q){
            continue;
        }
        par = q;
        cnt++;
        if(cnt == k){
            cout << q << endl;
            return 0;
        }
    }

}

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

int main(){

    int n,m;
    cin >> n >> m;
    vector<vector<int>> a(1e+5+1);
    ll ans=0L;
    rep(i,n){
        int aa,b;
        cin >> aa >> b;
        a[aa].push_back(b);
    }
    vector<int> bb;
    for(int i=1;i<=m;i++){
        if(a[i].size()!=0) {
            rep(j, a[i].size()) {
                bb.push_back(a[i][j]);
            }
            sort(bb.begin(),bb.end());
        }
        if(bb.size()!=0){
            ans+=bb.back();
            bb.pop_back();
        }
    }
//    rep(i,bb.size()){
//        cout << bb[i] << endl;
//    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> t(n+1), a(n+1), b(n+1);
  t[0] = a[0] = b[0] = 0;
  FOR(i, 1, n+1){
    cin >> t[i] >> a[i] >> b[i];
  }
  REP(i, n){
    int diff = abs(a[i+1] - a[i] + b[i+1] - b[i]);
    int time = t[i+1] - t[i];
    if (diff > time or diff % 2 != time % 2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 4492
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fs first
#define sc second
#define mp make_pair
using namespace std;
typedef double D;
typedef pair<D,int> pii;

int main(){
  int h,w;
  char f[999][999];
  scanf("%d%d",&h,&w); getchar();

  rep(i,h){rep(j,w)f[i][j] = getchar();getchar();}

  vector<pii> v;
  rep(i,h)rep(j,w){
    if( i==0?f[i][j]=='#':f[i][j]!=f[i-1][j] ){
      v.push_back(mp((D)(h-i)/j,-1));
      v.push_back(mp((D)(h-i)/(j+1),1));
    }
    if( j==w-1?f[i][j]=='#':f[i][j]!=f[i][j+1] ){
      v.push_back(mp((D)(h-i)/(j+1),-1));
      v.push_back(mp((D)(h-i-1)/(j+1),1));
    }
  }

  int res = 0, tmp = 0;
  sort(v.begin(),v.end());
  rep(i,v.size())res = max(res,tmp += v[i].sc);
  cout << (res+3)/2 << endl;
}

Measured memory_bytes: 19384
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    string S; cin >> S;
    int count=0,maxcount=0;
    rep(i,S.size()){
        if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T'){
            count += 1;
            maxcount = max(maxcount,count);
        }else{
            count = 0;
        }
    }
    cout << maxcount << endl;

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    string devide[4] = {"dream", "dreamer", "erase","eraser"};
    for (int i=0; i<4; i++) {
        reverse(devide[i].begin(), devide[i].end());
    }

    bool can = true;
    for (int i=0; i<s.size();){
        bool can2 = false;
        for (int j=0; j<4; j++){
            string d = devide[j];
            if (s.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2) {
            can = false;
            break;
        }
    }
    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]

v_even = []
v_odd = []
for i in range(n):
    v_even.append(v[i]) if i % 2 == 0 else v_odd.append(v[i])

even_cnt = Counter(v_even).most_common() + [(0, 0)]
odd_cnt = Counter(v_odd).most_common() + [(0, 0)]

if even_cnt[0][0] != odd_cnt[0][0]:
    print(n//2 - even_cnt[0][1] + n//2 - odd_cnt[0][1])
else:
    print(min(n//2 - even_cnt[0][1] + n//2 - odd_cnt[1][1], n//2 - even_cnt[1][1] + n//2 - odd_cnt[0][1]))


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

int main(void){
  int n;
  cin>>n;
  while(n--){
    int y,m,d;
    unsigned long long days = 0;
    cin>>y>>m>>d;
    // year
    for(int i = 1; i < y ; i ++){
      if(0==i%3){
	days += 200;
      }else{
	days += (19 + 20) * 5;
      }
    }
    // month
    if(y%3!=0){// hutuu year is  150 days
      // big is 20 days , small is 19
      for(int i = 0 ; i < m-1 ; i ++){
	if(i%2==0){ // big
	  days += 20;
	}else{ // small 
	  days += 19;
	}
      }
    }else{ // %3 year is 200 days
      // big 
      days += 20 * (m-1);
    }
    
    cout<<196471 - days - d<<endl;
  }

}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    string A, B, C;
    cin >> A >> B >> C;

    cout << 'A' << B[0] << 'C' << endl;
    return 0;
}

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

int main()
{
    long long int  n;
    cin>>n;
    long long int a[n+1];
    long long int  b[n+1];
    a[0]=0;
    for(long long int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(long long int i=0;i<=n;i++)
    {
      if(i==0 || i==1) b[i]=0;
      if(i==2)
       b[i]= abs(a[i-1]-a[i]);
        if(i>2)
            b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));

          }
          cout<<b[n];
    return 0;}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define FREE 1
#define NOT_FREE -1

bool X[N][N];
int row[N],col[N],dneg[N*2-1],dpos[N*2-1];

void initialize(){
  int i;
  for(i=0;i<N;i++) {row[i] = FREE,col[i] = FREE;}
  for(i=0;i<N*2-1;i++) {dneg[i] = FREE;dpos[i]=FREE;}
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
	if(row[i] != j) return;
      }
    }
  }
  for(int i = 0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j){
	printf("Q");
      }else{
	printf(".");
      }
    }
    printf("\n");
  }
}
void recursive(int i){
  int j;
  if(i==N){
    printBoard();return;
  }

  for(j=0;j<N;j++){
    if(NOT_FREE == col[j] ||
       NOT_FREE == dpos[i+j] ||
       NOT_FREE == dneg[i-j+N-1]) continue;
    row[i] = j;col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;

    recursive(i+1);

    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

int main(){
  int i,j,k;
  initialize();

  for(i = 0;i<N;i++){
    for(j=0;j<N;j++){
      X[i][j] = false;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    int r,c;
    scanf("%d%d",&r,&c);
    X[r][c] = true;
  }

  recursive(0);
  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int r;
  cin >> r;
  cout << r * r << endl;
  return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
const ll INF = 1<<30;

int main(){
    int N; cin >> N;
    int a=0;
    for(int i=1;i<=N;i++){
        if(i%2 == 1)a++;
    }
    double res = (double)a/(double)N;
    cout << fixed << setprecision(7) << res << endl;
}

Measured memory_bytes: 256
class SegmentTree:
    def __init__(self, a, mode='min'):
        self.mode = mode
        if self.mode == 'min':
            self.padding = float('inf')
        elif mode == 'max':
            self.padding = -float('inf')
        elif mode == 'sum':
            self.padding = 0
        
        n = len(a)
        self.N = 2 ** (n-1).bit_length()
        self.data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-n)
        for i in range(2*self.N-2, 0, -2):
            self.data[(i-1)//2] = self._segfunc(*[self.data[i], self.data[i-1]])
    
    def _segfunc(self, *v_list):
        if self.mode == 'min':
            return min(v_list)
        elif self.mode == 'max':
            return max(v_list)
        elif self.mode == 'sum':
            return sum(v_list)
    
    def update(self, idx, x):
        idx = self.N - 1 + idx
        self.data[idx] = x
        while idx:
            idx = (idx-1) // 2
            self.data[idx] = self._segfunc(
                *[self.data[2*idx+1], self.data[2*idx+2]]
            )
    
    def search(self, i, j):
        # [i, j)の区間の最小値を求める
        idx1 = self.N-1+i
        idx2 = self.N-1+j-1
        result = self.padding
        while idx1 + 1 < idx2:
            if idx1&1 == 0: # idx1が偶数
                result = self._segfunc(*[result, self.data[idx1]])
            if idx2&1 == 1: # idx2が奇数
                result = self._segfunc(*[result, self.data[idx2]])
                idx2 -= 1
            
            idx1 //= 2
            idx2 = (idx2 - 1)//2
        
        if idx1 == idx2:
            result = self._segfunc(result, self.data[idx1])
        else: # idx1 + 1 == idx2
            result = self._segfunc(*[result, self.data[idx1], self.data[idx2]])
        
        return result


N = int(input())
H = list(map(int, input().split()))
A = list(map(int, input().split()))

dp = [0] * (N+1)
st = SegmentTree(dp, mode='max')

ans = 0
for h, a in zip(H, A):
  M = st.search(0, h)
  st.update(h, M + a)

print(st.search(0, N+1))

Measured memory_bytes: 121596
#途中の箇所はs>tに変更可

s=input()
t=input()

s=sorted(s)
t=sorted(t,reverse=True)
#s=xy, t=yxa

if t[0:len(s)] == s:
    if len(t)>len(s):
        print("Yes")
        exit()
    else:
        print("No")
        exit()

len_s=0
for ss in s:
    for tt in t :
        if ss==tt:
            len_s+=1
            if len_s==len(s):
                print("No")
                exit()
        elif ss < tt: 
            print("Yes")
            exit()

print("No")

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

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/*** Loops ***/
#define ffit(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)
#define ff1(i,a,b) for(ll i = a; i <b; i++)
#define ff2(i,a,b) for(ll i = b-1; i >= a; i--)
#define ff3(i,a,b,m) for(ll i = a; i <=b; i+=m)
#define ipar(ar,n) ll ar[n]; ff1(i,0,n) cin>>ar[i];
#define opar(ar,n) ff1(i,0,n) cout<<ar[i]<<" ";
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define forIn(arr, num) for(ll i = 0; i < num; i++) sc1(arr[i]);
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) sc1(arr[i]);
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/
#define mood 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 15

/*** STLs ***/
#define rsz(x...) resize(x)
#define ins(x...) insert(x)
#define ft() front()
#define bk() back()
#define eb(x...) emplace_back(x)
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))
#define MIN3(n1,n2,n3) min(n1,min(n2,n3))
#define MIN4(n1,n2,n3,n4) min(n1,min(n2,min(n3,n4)))
#define MAX3(n1,n2,n3) max(n1,max(n2,n3))
#define MAX4(n1,n2,n3,n4) max(n1,max(n2,max(n3,n4)))
#define endl " \n"

/*** STLs ***/
typedef vector <ll> vll;
#define vvll vector<vll>
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll, ll> > vpll;

///vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of 10 rows and 20 columns, with value 500.

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtgrt(v) sort(all(v), greater<ll>())
#define prsrt greater<pair<int,int>>()
/*** Some Prints ***/
#define q2(n) (n%2)==0
#define ip(n) ll n; cin>>n;
#define en cout << '\n';
#define no cout << "No" << '\n'
#define yes cout << "Yes" << '\n'
#define case cout << "Case " << t++ << ": ";
#define ps(x,y)         fixed<<setprecision(y)<<x
#define inf             1e18
#define debug(x) cout << '>' << #x << ':' << x << endl;
//const ll N = 1e6 + 9;
#define w(x)             ll x; cin>>x; while(x--)

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ip(n);ip(m);
    if(m>=n) cout<<"unsafe";
    else cout<<"safe";
return 0;
}









Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (const auto& vv : v) {
    for (const auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0); cin.tie(0);

  int k; cin >> k;
  if (k % 2 == 0 || k % 10 == 5) {
    cout << -1 << endl;
    return 0;
  }
  if (k == 7) {
    cout << 1 << endl;
    return 0;
  }
  k *= 9;
  int ans = 1;
  for (int cur = 70 % k; cur != 7; cur = cur * 10 % k) ++ans;
  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 3624
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	class line {
		double x1, x2;
		double y1, y2;

		line(int x1, int y1, int x2, int y2) {
			this.x1 = x1;
			this.x2 = x2;
			this.y1 = y1;
			this.y2 = y2;
		}

		line(line a) {
			x1 = a.x1;
			x2 = a.x2;
			y1 = a.y1;
			y2 = a.y2;
		}

		void shift(double x, double y) {
			x1 -= x;
			x2 -= x;
			y1 -= y;
			y2 -= y;
		}

		void rot(double x, double y) {
			line t = new line(this);

			y1 = t.x1 * y - t.y1 * x;

			y2 = t.x2 * y - t.y2 * x;
		}

		boolean cross(line tar) {
			line t = new line(this);
			line r = new line(tar);

			r.shift(t.x1, t.y1);
			t.shift(t.x1, t.y1);

			r.rot(t.x2, t.y2);
			if (r.y1 * r.y2 < 0) {
				return true;
			}
			return false;
		}
	}

	void run() {
		int n = sc.nextInt();
		for (int z = 0; z < n; z++) {
			int x[] = new int[5];
			int y[] = new int[5];

			for (int i = 0; i < 5; i++) {
				x[i] = sc.nextInt();
				y[i] = sc.nextInt();
			}

			line[] tri = new line[3];
			for (int i = 0; i < 3; i++) {
				int j = i % 3;
				int k = (i + 1) % 3;
				tri[i] = new line(x[j], y[j], x[k], y[k]);
			}
			line tar = new line(x[3], y[3], x[4], y[4]);

			int cross = 0;
			for (int i = 0; i < 3; i++) {
				if (tri[i].cross(tar)) {
					if (tar.cross(tri[i])) {
						cross++;
					}
				}
			}
			System.out.println(
					(cross == 1 ? "OK" : "NG"));
		}

	}

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

Measured memory_bytes: 12000
N = int(input())
S = input()
ans = 0
a = [0] * 26
for i in range(N):
    a[ord(S[i])-ord('a')] += 1

b = [0] * 26
for i in range(N):
    a[ord(S[i])-ord('a')] -= 1
    b[ord(S[i])-ord('a')] += 1
    cnt = 0
    for j in range(26):
        if a[j]*b[j]>0:
            cnt += 1
    ans = max(ans,cnt)
print(ans)


Measured memory_bytes: 9164
"""
author : halo2halo
date : 22, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c = map(int, readline().split())
print(max(10*a+b+c,a+10*b+c,a+b+10*c))


Measured memory_bytes: 2940
def main():
    n,k = map(int,input().split(" "))
    r,s,p = map(int,input().split(" "))
    Ts = list(input())
    flags = [True]*(n)
    ks = {"r":0, "s":0, "p":0}
    for i in range(k,n):
        if Ts[i]==Ts[i-k] and flags[i-k]:
            ks[Ts[i]]+=1
            flags[i] = False

    sum = (Ts.count("r")-ks["r"])*p+(Ts.count("s")-ks["s"])*r+(Ts.count("p")-ks["p"])*s

    print(sum)
main()

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

int main() {
    int n,m,k; cin >> n >> m >> k;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=m; j++){
            if(i*(m-j)+j*(n-i)==k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3672
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){


	char s1,s2,s3;

	int total=700;

	cin>>s1>>s2>>s3;

	if(s1=='o'){
		total+=100;
	}
	if(s2=='o'){
		total+=100;
	}
	if(s3=='o'){
		total+=100;
	}

	cout<<total<<endl;

	return 0;
}


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

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

int n, k;
vector<int> a;

int solve() {
    int sum = 0, prev_sum = 0;
    for (int i = 0; i < k; i++) {
        prev_sum += a[i];
    }
    int max_sum = prev_sum;
    for (int i = 1; i + k - 1 < n; i++) {
        sum = prev_sum - a[i-1] + a[i+k-1];
        if (max_sum < sum) max_sum = sum;
        prev_sum = sum;
    }
    return max_sum;
}

int main() {
    while (cin >> n >> k) {
        if (n == 0 && k == 0) break;
        a.clear();
        repeat(n, i) {
            int _a; cin >> _a;
            a.push_back(_a);
        }
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 1400
import sys
N,M=map(int,input().split())

scdic={}
for i in range(M):
  s,c=map(int,input().split())
  if s in scdic and scdic[s]!=c:
    print(-1)
    sys.exit()
  else:
    scdic[s]=c
    
#print(scdic)
if N==1:
  if 1 in scdic:
    print(scdic[1])
    sys.exit()
  else:
    print(0)
    sys.exit()
elif N==2:
  answer=0
  if 1 in scdic:
    if scdic[1]==0:
      print(-1)
      sys.exit()
    else:
      answer+=10*scdic[1]
  else:
    answer+=10
  if 2 in scdic:
    answer+=scdic[2]
elif N==3:
  answer=0
  if 1 in scdic:
    if scdic[1]==0:
      print(-1)
      sys.exit()
    else:
      answer+=100*scdic[1]
  else:
    answer+=100
  if 2 in scdic:
    answer+=10*scdic[2]
  if 3 in scdic:
    answer+=scdic[3]

print(answer)

Measured memory_bytes: 3064
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)

    N, Q = map(int, input().split())
    G = [set() for _ in range(N)]
    cnt = [0]*N
    visited = [0]*N

    for _ in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].add(b)
        G[b].add(a)

    for _ in range(Q):
        node, x = map(int, input().split())
        node -= 1
        cnt[node] += x

    visited[0]=1
    st = [0]
    while st:
        v = st.pop()
        for u in G[v]:
            if visited[u]:
                continue
            visited[u] = 1
            cnt[u] += cnt[v]
            st.append(u)    

    print(*cnt)

if __name__ == '__main__':
    main()



Measured memory_bytes: 80672