akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int c(int a,int b){
	int ans=1;
	b=min(b,a-b);
	For(i,1,b){
		ans=ans*(a-i+1)/i;
	}
	return ans;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,c,d; cin>>a>>b>>c>>d;
	cout<<'L';
	For(i,b,d) cout<<'U';
	For(i,a-1,c-1) cout<<'R';
	cout<<'D';
	For(i,a,c-1) cout<<'L';
	For(i,b,d-1) cout<<'D';
	cout<<'D';
	For(i,a,c) cout<<'R';
	For(i,b-1,d-1) cout<<'U';
	cout<<"L";
	For(i,b,d-1) cout<<'D';
	For(i,a,c-1) cout<<'L';
	cout<<"\n";
	return 0;
}





























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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if((i<b && j<a) || (i>=b && j>=a)) cout << 0;
			else cout << 1;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] x = new Integer[n];
        Arrays.setAll(x, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int sum = Arrays.stream(x).mapToInt(i -> i).sum();
        int ave = (int) Math.round((double) sum / n);
        int result = 0;
        for (int i = 0; i < x.length; i++) {
            result += Math.pow((x[i] - ave), 2);
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 28628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,L;cin>>n>>L;
  lvector A(n);rep(i,n) cin>>A[i];
  ll x=-1;
  rep(i,n-1) if(A[i]+A[i+1]>=L) {x=i+1;break;}
  if(x==-1) print("Impossible");
  else {
    lvector ans;
    rep(i,x-1) ans.emplace_back(i+1);
    for(ll i=n-2;i>=x;--i) ans.emplace_back(i+1);
    ans.emplace_back(x);
    print("Possible");
    rep(i,n-1) print(ans[i]);
  }
  return 0;
}

Measured memory_bytes: 5036
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int a=sc.nextInt();
            int b=sc.nextInt();
            int c=sc.nextInt();
            if(a==-1&&b==-1&&c==-1) break;
            String s;
            if(a==-1||b==-1) s="F";
            else if(a+b>=80) s="A";
            else if(a+b>=65) s="B";
            else if(a+b>=50) s="C";
            else if(a+b>=30){
                if(c>=50) s="C";
                else s="D";
            }else s="F";
            System.out.println(s);
        }
    }
}


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

#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;

const ll INF = 1000000000000000000LL;
const int NMAX = 1e6+4;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);

string s;

signed main(){
    fast_io();
    int N;
    cin >> s;
    N = s.size();
    int K = N/2;
    char v = s[K];
    for(; K < N and s[K] == s[N-1-K] and s[K] == v; K++);
    cout << K << endl;
}


Measured memory_bytes: 512
def north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List

def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
    
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List

def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List

dice = list(map(int, input().split()))
x = str(input())
y = list(x)
for i in range(len(x)):
    if y[i] == 'N':
        dice[0:5] = north(dice)
    elif y[i] == 'W':
        dice[0:5] = west(dice)
    elif y[i] == 'S':
        dice[0:5] = south(dice)
    elif y[i] == 'E':
        dice[0:5] = east(dice)
print(dice[0])


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

namespace ABC_D
{
    class D057
    {
        static void Main(string[] args)
        {
            int[] h = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = h[0], A = h[1], B = h[2];
            List<long> v = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
            v = v.OrderByDescending(x => x).ToList();
            double ave = v.Take(A).Average();
            long mval = v[A - 1];
            int cnt = v.Count(x => x == mval);

            if (v[0] == mval) //A+1個以上選ぶのは大きい順にA個全てが同じ数の場合のみ
            {
                long count = 0;
                for(int i = A; i <= B; i++)
                {
                    if (cnt < i) break;
                    count += CombinationPascal(cnt, i);
                }
                Console.WriteLine(mval);
                Console.WriteLine(count);
            }
            else
            {
                int numC = v.Take(A).Count(x => x == mval);
                long r = CombinationPascal(cnt, numC);
                Console.WriteLine(ave.ToString("F8"));
                Console.WriteLine(r);
            }

        }

        //パスカルの三角形(O(n^2)
        public static List<long[]> PascalTriangle(int n)
        {
            List<long[]> list = new List<long[]>();
            for (int i = 0; i <= n; i++)
            {
                long[] arr = new long[i + 1];

                arr[0] = 1; arr[i] = 1;
                if (i >= 2)
                {
                    long[] arrBfr = list[i - 1];
                    for (int j = 1; j < arr.Length - 1; j++)
                    {
                        arr[j] = arrBfr[j - 1] + arrBfr[j];
                    }
                }
                list.Add(arr);
            }
            return list;
        }

        public static long CombinationPascal(int n, int r)
        {
            return PascalTriangle(n)[n][r];
        }


    }
}


Measured memory_bytes: 13652
S = str(input())
cnt1 = 0
cnt2 = 0
for i in range(len(S)):
    if S[i] == "0":
        cnt1 += 1
    else:
        cnt2 += 1

if cnt1 < cnt2:
    print(cnt1*2)
else:
    print(cnt2*2)    

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

unsigned long long lcm(unsigned long long a, unsigned long long b)
{
    unsigned long long gcd = 0;
    unsigned long long r;

    unsigned long long p1 = a;
    unsigned long long p2 = b;

    if (p1 < p2)
    {
        unsigned long long tmp = p1;
        p1 = p2;
        p2 = tmp;
    }

    r = p1 % p2;
    while (r != 0)
    {
        p1 = p2;
        p2 = r;
        r = p1 % p2;
    }

    gcd = p2;

    a /= gcd;
    b /= gcd;
    unsigned long long tmp = a * b;
    return tmp * gcd;
}

int main()
{
    unsigned long long N;
    unsigned long long ans;

    cin >> N;

    if (N == 1)
    {
        string tmp;
        cin >> tmp;
        cout << tmp << endl;
        return 0;
    }

    unsigned long long a, b;
    cin >> a >> b;
    ans = lcm(a, b);

    for (unsigned long long i = 2; i < N; i++)
    {
        cin >> b;
        ans = lcm(ans, b);
    }

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

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


struct P
{
    int x,y,z;

    /*bool operator<(const P &a)const{
        if(x!=a.x)
        return x>a.x;
              return y>a.y;
    }*/
};

vector<int> v[2];
//bitset<4001000> b;
int a,c,i,b,k,n,d,e,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[2252];

int o[251111];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={-1,0,1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};


long long x,y,mod=1000000007;
long long z;
int j[330][111];
P u[221110];
stack<int> s;

//set<int> s;
queue<int > q;

//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p[2];
//list<int> l;
//string r1,r;
char r[115][111];
//deque<int> de;

//20921
bool as(P a,P b)
{
    return a.x<b.x;
}


int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;u[t].y=t,t++)
        scanf("%d",&u[t].x);
    sort(u+1,u+1+a,as);
    for(int t=1;t<=a;t++)
        if(t*2<=a)
    {
        o[u[t].y]=u[a/2+1].x;
    }
    else o[u[t].y]=u[a/2].x;
    for(int t=1;t<=a;t++)
        printf("%d\n",o[t]);
}


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

typedef struct {
  int par, l_ch, r_sib, depth;
} node;

#define MAX_N 100000

node T[MAX_N];
int n;

void dfs(int u, int d) {
  T[u].depth = d;
  if(T[u].r_sib != -1) dfs(T[u].r_sib, d);
  if(T[u].l_ch != -1) dfs(T[u].l_ch, d+1);
}

int main() {
  int i, j;
  {
    for(i = 0; i < MAX_N; i++) {
      T[i] = (node){-1, -1, -1, -1};
    }
  }
  {
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
      int id, k, p;
      scanf("%d %d", &id, &k);
      p = -1;
      for(j = 0; j < k; j++) {
	int c;
	scanf("%d", &c);
	if(T[id].l_ch == -1) T[id].l_ch = c;
	else T[p].r_sib = c;
	p = c;
	T[c].par = id;
      }
    }
  }
  {
    int root = -1;
    for(i = 0; i < n; i++) {
      if(T[i].par == -1) root = i;
    }

    dfs(root, 0);

    for(i = 0; i < n; i++) {
      char type[256];
      if(T[i].par == -1) strcpy(type, "root");
      else if(T[i].l_ch == -1) strcpy(type, "leaf");
      else strcpy(type, "internal node");
      printf("node %d: parent = %d, depth = %d, %s, ", i, T[i].par, T[i].depth, type);
      printf("[");
      if(T[i].l_ch != -1) {
	int p = T[i].l_ch;
	printf("%d", T[i].l_ch);
	while(T[p].r_sib != -1) {
	  printf(", %d", T[p].r_sib);
	  p = T[p].r_sib;
	}
      }
      puts("]");
    }
  }


  return 0;
}

Measured memory_bytes: 5296
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

//ford-fulkerson

//辺を表す構造体(行先,容量,逆辺(の番号))
struct edge{ll to,cap,rev;};

ll H,W;

class FordFulkerson{
public:
    V<V<edge>> G;//グラフの隣接リスト
    V<bool> used;//DFSですでに調べたかのフラグ

    explicit FordFulkerson(ll max_V){
        G.resize(max_V);
        used.resize(max_V);
    }

    //fromからtoへ容量capの辺をグラフに追加
    void add_edge(ll from,ll to,ll cap){
        G[from].push_back((edge){to,cap,(ll)G[to].size()});
        G[to].push_back((edge){from,0LL,(ll)G[from].size()-1});
    }

    //増加パスをDFSで探す
    ll dfs(ll v,ll t,ll f){
        if(v==t) return f;
        used[v]=1;
        for(int i=0;i<(int)G[v].size();i++){
            edge &e=G[v][i];
            if(!used[e.to]&&e.cap>0){
                ll d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    //sからtへの最大流を求める
    ll max_flow(ll s,ll t){
        ll flow=0;
        while(true){
            rep(i,(ll)used.size()) used[i]=0;
            ll f=dfs(s,t,INF);
            if(f==0) return flow;
            flow+=f;
        }
    }
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>H>>W;
    char a[H][W];
    P S,T;
    rep(i,H) rep(j,W){
        cin>>a[i][j];
        if(a[i][j]=='S') S=make_pair(i,j);
        if(a[i][j]=='T') T=make_pair(i,j);
    }
    FordFulkerson ff(H+W+2);
    rep(i,H){
        rep(j,W){
            if(a[i][j]=='S'){
                ff.add_edge(0,i+1,INF);
                ff.add_edge(0,H+j+1,INF);
            }else if(a[i][j]=='T'){
                ff.add_edge(i+1,H+W+1,INF);
                ff.add_edge(H+j+1,H+W+1,INF);
            }else if(a[i][j]=='o'){
                ff.add_edge(i+1,H+j+1,1LL);
                ff.add_edge(H+j+1,i+1,1LL);
            }
        }
    }
    ll ans=ff.max_flow(0,H+W+1);
    if(S.ft==T.ft||S.sc==T.sc) ans=-1;
    out(ans);
}

Measured memory_bytes: 4500
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    q = int(input())
    query = [list(input().split()) for _ in range(q)]

    S = deque([s])
    flg = 1
    for i in range(q):
        if query[i][0] == "1":
            flg ^= 1
        else:
            _, f, c = query[i]
            if f == "1":
                S.appendleft(c) if flg else S.append(c)
            else:
                S.append(c) if flg else S.appendleft(c)

    print("".join(S) if flg else "".join(S)[::-1])



if __name__ == '__main__':
    resolve()


Measured memory_bytes: 33652
/* ex2_3
	kanon */

#include <stdio.h>

int main(void) {
  //与えられる値を入れる変数を宣言
  int N,A;
  
  //変数に値を入力する
  scanf("%d",&N);
  scanf("%d",&A);
  
  //N×NマスーAマス（答え）を出力
  printf("%d\n",N*N-A);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
using ll = long long;
int main()
{
    ll w, h, n;
    cin >> w >> h >> n;
    ll sx=0;
    ll sy=0;
    ll ex=w;
    ll ey=h;
    
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ll x, y, t;
        cin >> x >> y >> t;
        if (t == 1)
        {
            sx = max(sx,x);
         }
        else if (t == 2)
        {
             ex = min(ex,x);
         }
        else if (t == 3)
        {
            sy=max(sy,y);
        }
        else if (t == 4)
        {
            ey=min(ey,y);
        }
    }
   ll ans_x = ex-sx;
   ll ans_y = ey-sy;
   ans_x = ans_x<0?0:ans_x;
   ans_y = ans_y<0?0:ans_y;
    cout << ans_x*ans_y;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

// DMC

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

  vector<int> nm(n, n); // next M
  for(int i=n-2; i>=0; i--){
    if(s[i+1] == 'M') nm[i] = i+1;
    else nm[i] = nm[i+1];
  }
  vector<int> cnt(n+1, 0); // accumulation of appearance of C
  rep(i,n){
    if(s[i] == 'C') cnt[i+1] = cnt[i] + 1;
    else cnt[i+1] = cnt[i];
  }

  vector<long> cm(n,0);
  vector<long> sv(n, 0); // value for each C
  {
    rep(i,n){
      if(i>0) cm[i] = cm[i-1];
      if(s[i]=='M') cm[i]++;
      if(s[i]=='C') sv[i] = cm[i];
    }
  }
  vector<long> sva(n+1, 0); // accumulation of values of C
  rep(i,n){
    sva[i+1] = sva[i] + sv[i];
  }

  rep(_,q){
    int k;
    cin>>k;
    long ans = 0;
    rep(i,n-2){
      if(s[i] == 'D' && nm[i] < n && nm[i] < i+k-1){
        int lb = min(n, nm[i]+1), ub = min(n, i+k);
        long cs = cnt[ub] - cnt[lb];
        if(cs > 0) ans += (sva[ub] - sva[lb]) - cm[i]*cs;
        dbg(i,cs,lb,ub,cm[i],sva[ub],sva[lb],(sva[ub] - sva[lb]) - cm[i]*cs);
      }
    }
    cout << ans << endl;
  }

  return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	double r,pi = acos(-1.0);
	cin >> r;
	cout << fixed << setprecision(8) << 2*pi*r << '\n';
}

Measured memory_bytes: 3804
### constant

MAX_N = 7

### main

while line = gets
  n = line.strip.to_i

  nodes = MAX_N.times.map{false}
  nbrs = MAX_N.times.map{[]}
  start = nil

  for dmn in gets.strip.split(' ')
    ai = dmn[0].to_i
    bi = dmn[1].to_i

    start = ai
    nodes[ai] = nodes[bi] = true

    if ai != bi
      nbrs[ai] << bi
      nbrs[bi] << ai
    end
  end

  reached = MAX_N.times.map{false}
  reached[start] = true

  q = [start]

  while ! q.empty?
    u = q.shift

    for v in nbrs[u]
      if ! reached[v]
        reached[v] = true
        q << v
      end
    end
  end

  ok = true
  odd_n = 0

  for i in (0...MAX_N)
    if nodes[i] && ! reached[i]
      ok = false
      break
    end
    if (nbrs[i].length & 1) == 1
      odd_n += 1
    end
  end

  ok = false if odd_n > 2

  puts (ok ? 'Yes' : 'No')
end

Measured memory_bytes: 6132
import Data.List
import Data.Char
import Text.Printf

main = interact $ show' . solve . read'
  where
    show' xs = (unwords [showA xs, showB xs]) ++ "\n"
    showA = show . sum
    showB = show . sum . flip
    solve [] = []
    solve ([a, b]:xs) | a == b    = 1:(solve xs)
                      | a <  b    = 0:(solve xs)
                      | otherwise = 3:(solve xs)
    flip = map flipOne
      where flipOne x | x == 0 = 3
                      | x == 3 = 0
                      | otherwise = 1
    read' = map words . tail . lines :: String -> [[String]]



Measured memory_bytes: 4200
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

std::vector<int> greedy(int c, const std::string& s) {
    int i = 0;
    std::vector<int> ret;
    while (i < (int)s.length()) {
        if (s[i] == 'o') {
            ret.push_back(i);
            i += c;
        }
        ++i;
    }
    return ret;
}

void solve() {
    int n, k, c;
    std::string s;
    std::cin >> n >> k >> c >> s;

    auto fore = greedy(c, s);
    if ((int)fore.size() > k) return;

    std::reverse(s.begin(), s.end());
    auto back = greedy(c, s);

    std::reverse(back.begin(), back.end());
    for (auto& b : back) b = n - 1 - b;

    for (int i = 0; i < k; ++i) {
        if (fore[i] == back[i]) std::cout << fore[i] + 1 << std::endl;
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3468
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int top = 0;
		int answer = 0;
		for(int i = 0; i < n; i++){
			int h = sc.nextInt();
			if(top <= h){
				top = h;
				answer += 1;
			}
		}
		System.out.println(answer);
	}
}

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

int main(){
  vector<int>A(3);
  for(int i=0;i<3;i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  cout << 10*A[0]+A[1]+A[2] << endl;
}


Measured memory_bytes: 3532
n,m=map(int,input().split())
a=set(int(input()) for _ in range(m))
dp=[0]*(n+2)
dp[0]=1
for i in range(n):
    if i in a:
        continue
    dp[i+1]+=dp[i]
    dp[i+2]+=dp[i]
print(dp[n]%1000000007)

Measured memory_bytes: 462708
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		int i, j, n, q, k, counter = 1;
		try (Scanner sc = new Scanner(System.in)) {
			n = sc.nextInt();
			int[] a = new int[n + 1];
			for(i = 0; i < n; i++) {
				a[i] = sc.nextInt();
			}
			q = sc.nextInt();
			for(i = 0; i < q; i++) {
				k = sc.nextInt();
				if(Arrays.binarySearch(a, k) < 0) {
					counter = 0;
					break;
				}
			}
			System.out.println(counter);
		}
	}
}


Measured memory_bytes: 119584
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()
A = LIST()

acc = [0] * (N+1)
for i in range(N):
    acc[i+1] = (acc[i]+A[i]) % MOD

ans = 0
for i in range(N-1):
    ans += A[i] * (acc[-1]-acc[i+1])
    ans %= MOD
print(ans)


Measured memory_bytes: 31980
n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
mod = 1000000007

keisu = len(x)-1
keisu_kaisa = keisu
ans = 0
for i in range(1,n):
  #print(keisu)
  ans = ans + 1*(x[i]-x[i-1])*keisu
  keisu_kaisa = keisu_kaisa -2
  keisu = keisu +(keisu_kaisa)
  ans = ans % mod
  
keisu = len(y)-1
keisu_kaisa = keisu
ans_2 = 0
for i in range(1,m):
  ans_2 = ans_2 + ans*(y[i]-y[i-1])*keisu
  keisu_kaisa = keisu_kaisa -2
  keisu = keisu +(keisu_kaisa)
  ans_2 = ans_2 % mod  
print(ans_2)


Measured memory_bytes: 18624
#include <stdio.h>
int main(void){
  
  int r;

scanf("%d",&r);
  if(r<1200){
    printf("ABC\n");
  }
  else  if(r<2800){
      printf("ARC\n");
  }
else {
  printf("AGC\n");
}

  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] NM = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            string[] tmpA = new string[NM[0]];
            string[] tmpB = new string[NM[1]];
            for (int j = 0; j < NM[0]; j++)
            {
                tmpA[j] = Console.ReadLine();
            }
            for (int z = 0; z < NM[1]; z++)
            {
                tmpB[z] = Console.ReadLine();
            }
            //確認

            for (int x = 0; x < NM[0] - NM[1] + 1; x++)
            {
                for (int y = 0; y < NM[0] - NM[1] + 1; y++)
                {
                    Boolean flg = true;

                    for (int t = 0; t < NM[1]; t++)
                    {
                        if (tmpA[x + t].Substring(y, NM[1]) != tmpB[t])
                        {
                            flg = false;
                        }
                    }
                    if (flg)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
            }
                Console.WriteLine("No");
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);


Measured memory_bytes: 29188
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <numeric>
#include <iomanip>
#define FI first
#define SE second
#define EB emplace_back
#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 1100000000
#define LLINF 1100000000000000000LL
#define Decimal fixed << setprecision(20)
#define ALL(c) c.begin(),c.end()
#define SHOWVEC(v, sz) for(int i = 0; i < sz; i++) cerr << v[i] << ' '; cerr << endl;
#define SHOWX(x) cerr << #x << ": " << x << endl;
#define SHOWP(p) cerr << "[" << p.first << ',' << p.second << "]";

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main()
{
  int N; cin >> N;
  if (N == 1) cout << 0 << endl;
  else if (N % 2 == 0) cout << (N - 2)/2 << endl;
  else cout << (N - 2)/2 + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int c, m, n, ball, i, flag;
  scanf("%d", &c);
  while(c--){
    m = n = flag = 0;
    for(i = 0;i < 10;i++){
      scanf("%d", &ball);
      if(ball > m)
        m = ball;
      else if(ball > n)
        n = ball;
      else
        flag = 1;
    }
    printf(flag ? "NO\n":"YES\n");
  }
  return 0;
}

Measured memory_bytes: 580
using System;

class ABC_124_A
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);

        int sum = 0;
        for (int i = 0; i < 2; i++)
        {
            if (A > B)
            {
                sum += A;
                A--;
            }
            else
            {
                sum += B;
                B--;
            }
        }

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 13140
#include<iostream>

using namespace std;
int a;
int main(){
	int n,k;
	cin>>n>>k;
	int b[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
		if(b[i]>=k)a++;
	}
	cout<<a;
	return 0;
} 

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

struct C {
	int x, y;
} coor[52];

int n, ans;
bool visited[52];

int dfs(int idx, int p, int q)
{
	visited[idx] = true;

	for(int i = 0; i < n; i++)
	{
		int xdiff = coor[i].x - coor[idx].x;
		int ydiff = coor[i].y - coor[idx].y;

		if(xdiff == p && ydiff == q)
		{
			if(!visited[i])
				return dfs(i, p, q);
			else
				return 0;
		}
	}

	return 1;
}

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

	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> coor[i].x >> coor[i].y;
	
	ans = 1e9;
	for(int c1 = 0; c1 < n; c1++)
	{
		for(int c2 = 0; c2 < n; c2++)
		{
			int p = coor[c2].x - coor[c1].x;
			int q = coor[c2].y - coor[c1].y;

			if(p == 0 && q == 0)
				continue;

			int result = 0;
			for(int i = 0; i < n; i++)
				visited[i] = false;

			for(int i = 0; i < n; i++)
			{
				if(!visited[i])
					result += dfs(i, p, q);
			}

			ans = min(ans, result);
		}
	}

	cout << (n == 1 ? 1 : ans) << '\n';
}

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

int main() {
	int A[8];
	int n = 0;
	while (n < 8) {
		cin >> A[n];
		n++;
	}
	int M = A[0] + A[1] + A[2] + A[3];
	int N = A[4] + A[5] + A[6] + A[7];
	if (M > N) {
		cout << M << endl;
	}
	else {
		cout << N << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
#include <stdio.h>
#include <stdlib.h>

int num (int n, int a[]) {
  int count=0;
  
  for (int i=0; i<n-1; i++) {
	for(int j=i; j<n; j++)
      if (a[i]>a[j])
		count++;
    count *= n-i-1;
  }
  return count;
}


int main (void) {
  int N;
  int p[8],q[8];
  int P,Q;
  
  scanf("%d", &N);
  for (int i=0; i<N; i++){
    scanf("%d", &p[i]);
  }
  for (int i=0; i<N; i++){
    scanf("%d", &q[i]);
  }
  
  P = num(N,p);
  Q = num(N,q);
  
  if(P>=Q)
    printf("%d", P-Q);
  else 
    printf("%d", Q-P);
  
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<k;i++)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;

}

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

int exp(int a, int n) {
  if(n > 0) return exp(a, n-1)*a;
  else if(n == 0) return (int)1;
}

int main() {
  int a; 
  cin >> a;
  int ans = 0;
  ans = exp(a, 3) + exp(a, 2) + exp(a, 1);
  cout << ans << endl;
}
  
  

Measured memory_bytes: 3568
#define _CRT_SECURE_NO_WARNINGS

#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#include <numeric>
#include <set>
#include <queue>
#include <deque>
#include <array>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <map>
#include <functional>
#include <bitset>
#include <complex>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s, t;
	cin >> s >> t;
	int n = sz(s);
	int m = sz(t);
	vector<vi> dp(n + 1, vi(m + 1, 0));
	vector<vi> pr(n + 1, vi(m + 1, -1)); // 0 means i-- 1 means j-- 2 means i-- j-- -1 means stop
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (dp[i + 1][j + 1] <= dp[i][j + 1]) {
				dp[i + 1][j + 1] = dp[i][j + 1];
				pr[i + 1][j + 1] = 0;
			}
			if (dp[i + 1][j + 1] <= dp[i + 1][j]) {
				dp[i + 1][j + 1] = dp[i + 1][j];
				pr[i + 1][j + 1] = 1;
			}
			if (s[i] == t[j] && dp[i + 1][j + 1] <= 1 + dp[i][j]) {
				dp[i + 1][j + 1] = 1 + dp[i][j];
				pr[i + 1][j + 1] = 2;
			}
		}
	}
	string ans;
	int i = n, j = m;
	while (pr[i][j] != -1) {
		if (pr[i][j] == 0) {
			i--;
		}
		else if (pr[i][j] == 1) {
			j--;
		}
		else {
			i--;
			j--;
			ans.pb(s[i]);
		}
	}
	reverse(all(ans));
	cout << ans;
}


Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e5;

ll partnum[50][3100];

void partition(ll a){
  
  for(ll i = 0; i < 50; i++){
    for(ll j = 0; j < 3100; j++){
     partnum[i][j] = 0LL;}
    }
  
   partnum[0][0] = 1LL;

   for(ll i = 0; i <= a; i++){ partnum[1][i] = 1LL;}
   
 for(ll i = 2; i < 50; i++){
    for(ll j = 0; j < 3100; j++){
      ll res = 0LL;
      res += partnum[i-1][j];
      
    if( j-i >= 0){
      res += partnum[i][j-i];
      if( j-a-i >= 0){
        res -= partnum[i-1][j-a-i];
      }
    }
      res = (mod*mod+res)%mod;
      
      partnum[i][j] = res;
    }
  }
}
  
  
  
int main(){
 ll N,M,S;
  while( cin >> N >> M >> S){
    if( !N && !M && !S){ break;}
    
    ll res = N*N;
    M = M-res;
    S = S -(res*(res+1))/2;
    N = res;
    
    partition(M);
   
    cout << partnum[N][S] << endl;
  }
  
  return 0;
}


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

const int INF = 1e5;

vector<vector<int> > ld, sd, dp;
int N, M, R;
vector<int> z;

int dfs(int n, int fune) {	
	if ( n == R-1 ) return 0;
	if ( dp[n][fune] >= 0 ) return dp[n][fune];

	int ret = dfs(n+1, fune)+ld[z[n]][z[n+1]];
	for ( int i = 0; i < N; i++ ) {
		ret = min(ret, dfs(n+1, i)+ld[z[n]][fune]+sd[fune][i]+ld[i][z[n+1]]);							
	}

	
	return dp[n][fune] = ret;	
}

int main() {
	while ( cin >> N >> M, N ) {
		ld = vector<vector<int> >(N+1, vector<int>(N+1, INF));
		sd = vector<vector<int> >(N+1, vector<int>(N+1, INF));
		for ( int i = 0; i < N; i++ ) ld[i][i] = sd[i][i] = 0;
		
		for ( int i = 0; i < M; i++ ) {
			int x, y, t;
			char sl;
			cin >> x >> y >> t >> sl;
			x--; y--;
			if ( sl == 'L' ) ld[x][y] = ld[y][x] = t;
			else sd[x][y] = sd[y][x] = t;			
		}

		for ( int i = 0; i < N; i++ )
			for  ( int j = 0; j < N; j++ )
				for ( int k = 0; k < N; k++ ) {
					ld[j][k] = min(ld[j][k], ld[j][i]+ld[i][k]);
					sd[j][k] = min(sd[j][k], sd[j][i]+sd[i][k]);
				}
		
		cin >> R;
		z = vector<int>(R);
		for ( int i = 0; i < R; i++ ) {
			cin >> z[i];
			z[i]--;
		}
		
		dp = vector<vector<int> >(R+1, vector<int>(N+1, -1));
		cout << dfs(0, z[0]) << endl;
	}
	
	return 0;
}



Measured memory_bytes: 5000
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<ll,pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main(){
    ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n)cin >> a[i];
	ll g = a[0];
	REP(i, n-1)g = __gcd(g, a[i]);
	if(g == 1){
		map<int, int> mp;
		rep(t, n){
			int now = a[t];
			for (int i = 2; i * i <= now; i++) {
				if(now % i == 0)mp[i]++;
				while (now % i == 0) {
					now /= i;
				}
			}
			if (now != 1) mp[now]++;
		}
		bool ans = true;
		for(auto x : mp)if(x.second > 1)ans = false;
		if(ans)cout << "pairwise coprime" << endl;
		else cout << "setwise coprime" << endl;
	}else{
		cout << "not coprime" << endl;
	}
} 


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll a,b,c;cin>>a>>b>>c;
  ll count=0;
  rep(i,a,b+1){
    if(c%i==0)count++;
  }

  out(count);

  return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
using namespace std;
ll knapSack(ll W, ll wt[], ll val[], ll n)
{
   ll i, w;
   ll K[n+1][W+1];

   // Build table K[][] in bottom up manner
   for (i = 0; i <= n; i++)
   {
       for (w = 0; w <= W; w++)
       {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }

   return K[n][W];
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> n >> c;
    ll wt[n], val[n];
    for(i = 0; i < n; i++){
        cin >> wt[i] >> val[i];
    }
    cout << knapSack(c,wt,val,n);


    return 0;
}


Measured memory_bytes: 79232
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n,k;
    cin>>n>>k;
    int64_t ans=k*pow(k-1,n-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    int n; cin >> n;
    string s; cin >> s;
    rep(i,s.length()) {
        s[i] = (s[i] - 'A' + n) % 26 + 'A';
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 1e5+5;
const int K = 3;
int f[nax][K];

int valq(char t) {
	if (t == 'p') return 0;
	if (t == 'r') return 1;
	// if (t == 's')
		return 2;
}

bool beats(int x, int y) {
	return ((x + 1) % K) == y;
}

int main() {
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vi val(3);
	cin >> val[1] >> val[2] >> val[0];
	string t;
	cin >> t;
	int res = 0;
	rep(i, 0, k) {
		int lastValue = - 1;
		rep(j, 0, K) {
			f[i][j] = val[j] * beats(j, valq(t[i]));
			// printf("f[%d][%d] = %d\n", i, j, f[i][j]);
			lastValue = max(lastValue, f[i][j]);
		}
		for (int q = i + k; q < n; q += k) {
			rep(j, 0, K) {
				int myValue = val[j] * beats(j, valq(t[q]));
				rep(lastj, 0, K) {
					if (j == lastj) {
						continue ;
					}
					f[q][j] = max(f[q][j], f[q - k][lastj] + myValue);
				}
				lastValue = max(lastValue, f[q][j]);
				// cout << imie(q) imie(j) imie(f[q][j]) << endl;
			}
		}
		res += lastValue;
	}
	cout << res << endl;
}

Measured memory_bytes: 1616
"use strict";

const main = arg => {
    const N = arg.split("\n")[0];
    const S = arg.split("\n")[1].split("");
    const scores = [];
    const letter = new Set(S);
    
    for(let i=1 ; i<N ; i++) {
        let cnt   = 0;
        let left  = S.slice(0, i);
        let right = S.slice(i, N);
        
        letter.forEach(value=> {
           if(left.indexOf(value) !== -1 && right.indexOf(value) !== -1 ) {
               cnt++;
           }
        });
        
        scores.push(cnt);
    }
    
    console.log(Math.max(...scores));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7880
// 17.07.2017


# include <iostream>


using namespace std;

int a, b;
bool ok;

int main ()
{
   cin >> a >> b;

   ok = ( a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 );

   if ( ok )
      cout << "Possible";
   else
      cout << "Impossible";

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF					INT_MAX
#define LLINF					LLONG_MAX
#define DEBUG					false
 
typedef long long				ll;
typedef pair <int, int> ii;

int main() {
	
	int n;
	cin >> n;
	
	vector<int>a(n);
	rep(i, n) cin >> a[i];
	SORT(a);
	
	double ans = 0;
	
	for(int i  = n - 1; i > 0 ; i--){//C, D
		int bunnbo = a[i] - a[i - 1];
		int bunnsi;
		if(i == n - 1) bunnsi = a[n - 3] + a[n - 4];
		else if (i == n - 2) bunnsi = a[n - 1] + a[n - 4];
		else bunnsi = a[n - 1] + a[n - 2];
		ans = max(ans, (double)(1.0 * bunnsi / bunnbo ));
	}
	
	printf("%.6lf\n", ans);
	
	
	return 0;
}

Measured memory_bytes: 3296
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int a[15][15];
signed main(void)
{
	while(true) {
		string s;
		cin >> s;
		if(s == "#") break;

		int y = 0, x = 0;
		REP(i, s.size()) {
			int tmp;
			if('1' <= s[i] && s[i] <= '9') tmp = s[i]-'0';
			else if(s[i] == 'b') {tmp = 0; a[y][x] = 1; x++;}
			else {y++; x=0; continue;}
			while(tmp--) {a[y][x] = 0; x++;}
			//cout << i << " " << x << " " << y << endl;
		}

		int b, c, d, e;
		cin >> b >> c >> d >> e;
		a[b-1][c-1] = 0;
		a[d-1][e-1] = 1;

		/*REP(i, y+1) {
			REP(j, x) {
				cout << a[i][j] << " ";
			}
			cout << endl;
		}*/

		string ans = "";
		REP(i, y+1) {
			int cnt = 0;
			REP(j, x) {
				if(a[i][j]) {
					if(cnt != 0) ans += (char)('0' + cnt);
					ans += 'b';
					cnt = 0;
				}	else {
					cnt++;
				}
			}
			if(cnt != 0) ans += (char)('0' + cnt);
			if(i != y) ans += '/';
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=3e3+5;
int dp[N][N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	string s1,s2,ans="";
	cin>>s1>>s2;
	int n=s1.size(),m=s2.size();
	rep(i,1,n+1) rep(j,1,m+1) {
		dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		if (s1[i-1]==s2[j-1]) dp[i][j]=dp[i-1][j-1]+1;
	}
	int x=n,y=m;
	while (x&&y) {
		if (s1[x-1]==s2[y-1]) {
			ans+=s1[x-1];
			--x,--y;
		}
		else dp[x-1][y]>dp[x][y-1]?--x:--y;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<"\n";
}


Measured memory_bytes: 35456
H,W = map(int,input().split())
A = [list(map(int, input().split(' '))) for i in range(H)]
A = [[A[i][j] % 2 for j in range(W)] for i in range(H)]
Ainv = []
for i in range(H):
    if i % 2 == 0:
        Ainv.append(A[i])
    else:
        Ainv.append(A[i][::-1])
flg = 0
pls = []
for i in range(H):
    for j in range(W):
        if Ainv[i][j] == 1:
            flg += 1
            if i % 2 == 0:
                pls.append([i+1,j+1])
            else:
                pls.append([i+1,W-j])
ans = []
for i in range(1,len(pls),2):
    goal = pls[i]
    start = pls[i-1]
    while start != goal:
        ps0 = start[0]
        ps1 = start[1]
        if start[0] % 2 != 0:
            if start[1] < W:
                start[1] += 1
            else:
                start = [start[0]+1,W]
        else:
            if start[1] > 1:
                start[1] -= 1
            else:
                start = [start[0]+1,1]
        ans.append([ps0,ps1,start[0],start[1]])

print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 58684
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
int[] a=new int[m];
int[] b=new int[m];
int[] road=new int[n+1];
    for (int i = 0; i < m; i++) {
        a[i]=Integer.parseInt(sc.next());
        b[i]=Integer.parseInt(sc.next());
        road[a[i]]++;
        road[b[i]]++;
    }
    for (int i =1; i <= n; i++) {
        out.println(road[i]);
    }
}
}

Measured memory_bytes: 21972
table_prime_numbers = [True for _ in range(10 ** 5)]
table_2017_numbers = [False for _ in range(10 ** 5)]
table_2017_numbers_acm = [0 for _ in range(10 ** 5)]

def init_tables():
  table_prime_numbers[0] = table_prime_numbers[1] = False
  for i in range(2, 10 ** 5):
    if table_prime_numbers[i]:
      for j in range(i * 2, 10 ** 5, i):
        table_prime_numbers[j] = False
        
  for i in range(2, 10 ** 5):
    if table_prime_numbers[i]:
      if (i * 2 - 1 < 10 ** 5) and table_prime_numbers[i * 2 - 1]:
        table_2017_numbers[i * 2 - 1] = True
  
  for i in range(2, 10 ** 5):
    table_2017_numbers_acm[i] = table_2017_numbers_acm[i - 1] + int(table_2017_numbers[i])
      
  return

def cumul(n):
  return table_2017_numbers_acm[n]

def result(l, r):
  return cumul(r) - cumul(l - 1)

def main():
  q = int(input())
  
  for _ in range(q):
    l, r = map(int, input().split())
    print(result(l, r))

  return

if __name__ == "__main__":
  init_tables()
  main()


Measured memory_bytes: 8088
using namespace std;

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int N = 2e5 + 5;
int ans = 0, q = 0;

int lover[N];
void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &lover[i + 1]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i == lover[lover[i]] && lover[i] > i)
            ans++;
    }
    cout << ans;
}

int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        if (0) {
            freopen("weapons.in", "r", stdin);
            freopen("weapons.out", "w", stdout);
        }
    #endif

    solve();

    #ifdef _DEBUG27_
        cout << endl << "Time: " << clock() / 1000.0 << " ms";
    #endif
    return 0;
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


Measured memory_bytes: 640