akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    map<string,string> mp;
    mp["Sunny"]="Cloudy";
    mp["Cloudy"]="Rainy";
    mp["Rainy"]="Sunny";

    string s;
    cin>>s;
    cout<<mp[s]<<"\n";




}
// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3592
N, T = map(int, input().split())
c = []
t = []
for i in range(N):
    s = input().split()
    c.append(int(s[0]))
    t.append(int(s[1]))
cnt = 0
min = 1001
for i in range(N):
    if t[i] <= T:
        cnt += 1
        if c[i] < min:
            min = c[i]
if cnt > 0:
    print(min)
else:
    print('TLE')


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

int main(){
    string S;
    cin >>S;
    if((S.at(2)==S.at(3))&(S.at(4)==S.at(5))){
        cout <<"Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }
}

Measured memory_bytes: 256
n= int(input())
a=list(map(int,input().split()))

tmp = [0]*(n+1)
for i in a:
    tmp[i] += 1
ans = 0
for i in tmp:
    ans += i*(i-1)//2

for k in range(n):
    num = a[k]
    if tmp[num] == 0:
        print(ans)
        continue
    num = tmp[num]
    print(ans - num*(num-1)//2 + (num-1)*(num-2)//2)

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

namespace ProconLib{

    //struct graph_t
    //  requirement
    //      int to;


    template<class graph_t>
    std::vector<int> TopologicalSort(const graph_t &g){
        int n=g.size();
        std::vector<int> res(n);
        std::vector<int> in(n);
        for(int i=0;i<n;i++) for(auto e:g[i]) in[e.to]++;

        std::queue<int> que;
        for(int i=0;i<n;i++) if(in[i]==0) que.push(i);

        int id=0;
        while(!que.empty()){
            int v=que.front(); que.pop();
            res[id++]=v;
            for(auto e:g[v]){
                in[e.to]--;
                if(in[e.to]==0) que.push(e.to);
            }
        }
        if(id!=n){
            throw std::runtime_error("Given graph is not DAG.");
        }
        return res;
    };

    template<typename graph_t>
    bool isDAG(const graph_t& g){
        try{
            TopologicalSort(g);
            return true;
        }catch(std::runtime_error e){
            return false;
        }
    }
    
};

using namespace std;
using namespace ProconLib;

struct Edge{
    int to;
};

using Edges=vector<Edge>;
using Graph=vector<Edges>;
int main(){
    int n,m;
    cin>>n>>m;
    Graph g(n);
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        g[u].push_back({v});
    }

    auto res=TopologicalSort(g);
    for(auto v:res)cout<<v<<endl;
    return 0;
}


Measured memory_bytes: 3688
instr = input()
strx = instr.split()
D = int(strx[0])
T = int(strx[1])
S = int(strx[2])

if D <= T*S:
 print( "Yes")
else:
 print( "No")
 

#print(strx[0])
#print(strx[1])
#print(strx[2])

Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
struct state{
  int bit,p,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};
#define INF (1<<26)
 
int n;
string t[20];
int cost[20][20];
int id[20][20];
 
void calc(int a,int b){
  string A=t[a],B=t[b];
  int as=A.size(),bs=B.size();
  int i,j;
     
  for(i=0;i<as;i++){
    bool flg=true;
    for(j=0;j<bs&&i+j<as;j++){
      if(A[i+j]!=B[j]){
        flg=false;
        break;
      }
    }
     
    if(flg){
      cost[a][b]=bs-j;
      if(cost[a][b]==0)id[a][b]=a;
      else id[a][b]=b;
      return;
    }
  }
   
  cost[a][b]=bs;
  id[a][b]=b;
}
 
int d[(1<<14)][20];
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++)cin>>t[i];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(i!=j){
          calc(i,j);
          //cout<<t[i]<<' '<<t[j]<<endl;
          //cout<<cost[i][j]<<' '<<id[i][j]<<endl;
          //cout<<endl;
        }
      }
    }
 
    for(int i=0;i<(1<<14);i++)
      for(int j=0;j<20;j++)
        d[i][j]=INF;
    priority_queue<state> Q;
    for(int i=0;i<n;i++){
      state s;
      s.bit=(1<<i);
      s.cost=t[i].size();
      s.p=i;
      d[s.bit][s.p]=s.cost;
      Q.push(s);
    }
    while(!Q.empty()){
      state s=Q.top();Q.pop();
      if(s.cost>d[s.bit][s.p])continue;
      if(s.bit==(1<<n)-1){
        cout<<s.cost<<endl;
        break;
      }
      int S=s.bit;
      for(int i=0;i<n;i++){
        if(S>>i&1)continue;
        int nbit=S+(1<<i);
        int ncost=s.cost+cost[s.p][i];
        int to=id[s.p][i];
        if(ncost<d[nbit][to]){
          d[nbit][to]=ncost;
          Q.push((state){nbit,to,ncost});
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 6544
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m,k;
PLL a[200010];
ll tac[450];
ll len;
ll res;
int main()
{
	scanf("%lld%lld%lld",&n,&m,&k);
	len=(ll)sqrt(n);
	for (int i=0;i<n;i++) scanf("%lld%lld",&a[i].Fst,&a[i].Snd);
	sort(a,a+n);
	for (int i=0;i<n;i++)
	{
		if (a[i].Snd-tac[i/len]<=0) continue;
		ll t=(a[i].Snd-tac[i/len]+k-1)/k;
		//cout <<t<<" "<<a[i].Snd-tac[i/len]<<" "<<i<<" ##\n";
		res+=t;
		ll ix=lower_bound(a,a+n,MP(a[i].Fst,0ll))-a;
		ll iy=upper_bound(a,a+n,MP(a[i].Fst+m*2,(ll)1e9))-a;
		iy--;
		//cout <<i<<" "<<ix<<" "<<iy<<" "<<t<<" ##\n";
		ll xi=ix/len,yi=iy/len;
		ix%=len,iy%=len;
		if (xi==yi)
		{
			for (int j=ix;j<=iy;j++) a[xi*len+j].Snd-=k*t;
			continue;
		}
		for (int j=ix;j<len;j++) a[xi*len+j].Snd-=k*t;
		for (int j=0;j<=iy;j++) a[yi*len+j].Snd-=k*t;
		for (int j=xi+1;j<yi;j++) tac[j]+=k*t;
	}
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  int zero = 0;
  int M = 0;
  int total = 0;
  int hiku = 1000000000000;
  for( int i = 0; i < N; i++ ){
    cin >> A.at(i);
    if( A.at(i) == 0 ) zero++;
    else if( A.at(i) < 0 ){
      M++;
    }
    if( abs(A.at(i)) < hiku ) hiku = abs(A.at(i));
    total += abs(A.at(i));
  }
  
  if( M % 2 == 0 ){
    cout << total << endl;
  }else{
    cout << total - hiku*2 << endl;
  }
}

Measured memory_bytes: 1152
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;


void main() {
    int n; scan(n);
    auto a = readln.split.to!(int[]);
    auto b = readln.split.to!(int[]);

    auto bk = new int[][][](30, 2, 0);

    foreach (i ; 0 .. 30) {
        foreach (bj ; b) {
            int bl = bj & ((1<<i) - 1);
            bk[i][(bj >> i) & 1] ~= bl;
        }

        bk[i][0].sort();
        bk[i][1].sort();
    }

    int ans;

    foreach (k ; 0 .. 30) {
        long cnt;

        foreach (ai ; a) {
            int al = ai & ((1<<k) - 1);

            int sw = (ai >> k) & 1;
            int ub = (1 << k) - al;
            cnt += bk[k][1-sw].assumeSorted.lowerBound(ub).length.to!int;
            cnt += bk[k][sw].length.to!int - bk[k][sw].assumeSorted.lowerBound(ub).length.to!int;
        }

        ans ^= ((cnt & 1) << k);
    }

    writeln(ans);
}








void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 51880
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

int main(){
	int x;
	cin>>x;
	cout<<x*x*x<<endl;
}



Measured memory_bytes: 3116
import java.util.*;

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

		int n = sc.nextInt(); int m = sc.nextInt(); int l = sc.nextInt();
		int[][] row = new int[n][m];
		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
				row[i][j] = sc.nextInt();
			}
		}
		int[][] column = new int[m][l];
		for (int i=0; i<m; i++) {
			for (int j=0; j<l; j++) {
				column[i][j] = sc.nextInt();
			}
		}
		
		long[][] ans = calcMatrix(row, column, "*");
		
		for (int i=0; i<n; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j<l; j++) {
				sb.append((j==0?"":" ")+(ans[i][j]));
			}
			System.out.println(sb);
		}
		
	}

	static long[][] calcMatrix(int[][] row, int[][] column, String operator) {
		//計算が正常におこなえない行・列を受け取った場合のエラー処理は施してません

		int rowH = row.length; int rowW = row[0].length;
		int columnH = column.length; int columnW = column[0].length;
		long[][] result = null;

		if (operator.equals("+") || operator.equals("-")) {
			result = new long[rowH][rowW];
		}
		else if (operator.equals("-")) {
			result = new long[rowH][rowW];
		}
		else if (operator.equals("*")) {
			result = new long[rowH][columnW];
			for (int i=0; i<rowH; i++) {
				for (int j=0; j<columnW; j++) {
					long sum = 0;
					for (int k=0; k<rowW; k++) {
						sum += row[i][k] * column[k][j];
					}
					result[i][j] = sum;
				}
			}
		}
		return result;
		
	}

}


Measured memory_bytes: 54492
#include <bits/stdc++.h>
using namespace std;
int s;
int main()
{
    string a;
    cin>>a;
    if(a[0]!='C')
    {
        s++;
    }
    if(a[1]!='O')
    {
        s++;
    }
    if(a[2]!='D')
    {
        s++;
    }
    if(a[3]!='E')
    {
        s++;
    }
    if(a[4]!='F')
    {
        s++;
    }
    if(a[5]!='E')
    {
        s++;
    }
    if(a[6]!='S')
    {
        s++;
    }
    if(a[7]!='T')
    {
        s++;
    }
    if(a[8]!='I')
    {
        s++;
    }
    if(a[9]!='V')
    {
        s++;
    }
    if(a[10]!='A')
    {
        s++;
    }
    if(a[11]!='L')
    {
        s++;
    }
    if(a[12]!='2')
    {
        s++;
    }
    if(a[13]!='0')
    {
        s++;
    }
    if(a[14]!='1')
    {
        s++;
    }
    if(a[15]!='6')
    {
        s++;
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_B
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 2000000000000
#define MAX_V 2000

ll D[MAX_V][MAX_V];
int V,E;

void warshall_floyd(){
    int i,j,k;
    for(k=0;k<V;k++){
        for(i=0;i<V;i++){
            for(j=0;j<V;j++){
                D[i][j]=min(D[i][j],D[i][k]+D[k][j]);
            }
        }
    }
}

int main(){
    int i,j;
    ll s,t,d,dall=0;
    bool flg=false;
    cin>>V>>E;
    for(i=0;i<V;i++){
        for(j=0;j<V;j++){
            if(i==j)D[i][j]=0;
            else D[i][j]=INF;
        }
    }
    for(i=0;i<E;i++){
        cin>>s>>t>>d;
        D[s][t]=d;
        if(d>=0)dall+=d;
    }

    warshall_floyd();

    //rからだどりつける負の閉路があるか判定
    for(i=0;i<V;i++){
        if(D[i][i]<0){
            flg=true;
            break;
        }
    }

    if(flg){
        cout<<"NEGATIVE CYCLE\n";
    }else{
        for(i=0;i<V;i++){
            if(D[i][0]>dall)cout<<"INF";
            else cout<<D[i][0];
            for(j=1;j<V;j++){
                if(D[i][j]>dall)cout<<" INF";
                else cout<<" "<<D[i][j];
            }
            cout<<"\n";
        }
    }
}


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

const int INF = 1 << 30;

int grid[11][11];

void solve(int d, int w) {
    for (int i = 0; i < d; i++) {
        for (int j = 0; j < w; j++) cin >> grid[i][j];
    }
    int ans = 0;
    for (int i = 0; i < d; i++) {
        for (int j = 0; j < w; j++) {
            for (int tate = 3; tate <= d - i; tate++) {
                for (int yoko = 3; yoko <= w - j; yoko++) {
                    int min_h = INF;
                    for (int k = i; k < i + tate; k++) {
                        min_h = min(min_h, grid[k][j]);
                        min_h = min(min_h, grid[k][j + yoko - 1]);
                    }
                    for (int k = j; k < j + yoko; k++) {
                        min_h = min(min_h, grid[i][k]);
                        min_h = min(min_h, grid[i + tate - 1][k]);
                    }
                    bool is_ok = true;
                    int now_ans = 0;
                    for (int k = i + 1; k < i + tate - 1; k++) {
                        for (int l = j + 1; l < j + yoko - 1; l++) {
                            if (min_h <= grid[k][l]) {
                                is_ok = false;
                                break;
                            }
                            now_ans += min_h - grid[k][l];
                        }
                        if (!is_ok) break;
                    }
                    if (!is_ok) continue;
                    ans = max(ans, now_ans);
                }
            }
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D, W;
    while (true) {
        cin >> D >> W;
        if (D == 0 && W == 0) break;
        solve(D, W);
    }
    return 0;
}


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

def count_digit(n):
    cnt = 1
    while True:
        n = n // 10
        if n == 0:
            break
        else:
            cnt += 1
    return cnt

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        # nを合う数字で割り切れたら、その割った数と商をリストに追加する。
        # nが平方数のとき、同じ数字が2回追加されてしまうので3行したのif文がある
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

divs_list = make_divisors(N)

min_f = 12
len_d = len(divs_list)
for i in range(len_d):
    if i > len_d-i:
        break
    cnt = max(count_digit(divs_list[i]),count_digit(divs_list[len_d-i-1]))
    if min_f > cnt:
        min_f = cnt
print(cnt)

Measured memory_bytes: 39536
#include "bits/stdc++.h"
using namespace std;
vector<vector<int> > x;
int main()
{
    int n,d;
    int i,j,k;
    int cnt=0,tmp=0,tmpp;
    scanf("%d %d",&n,&d);
    x.resize(n);
    for(i=0;i<n;i++)
    {
        x[i].resize(d);
        for(j=0;j<d;j++)
        {
            scanf("%d",&x[i][j]);
        }
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            for(k=0;k<d;k++)
            {
                tmp+=((x[i][k]-x[j][k])*(x[i][k]-x[j][k]));
            }
            tmpp=(int)sqrt(tmp);
            if(tmpp*tmpp==tmp)
            {
                cnt++;
            }
            tmp=tmpp=0;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pii> v(n);
  rep(i, n){
    int a,b;
    cin >> a >> b;
    v[i] = make_pair(b, a);
  }
  sort(v.begin(), v.end());
  ll tot = 0;
  rep(i, n){
    tot += v[i].second;
    if(tot > v[i].first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main (void)
{
    long long a;
    long long b;
    long long c;
    long long d;
    long long bd;
    long long bc;
    long long ad;
    long long ac;
    long long ans;

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

    bd = b * d;
    bc = b * c;
    ad = a * d;
    ac = a * c;

    ans = bd;
    if(ans < bc){
        ans = bc;
    }
    if(ans < ad){
        ans = ad;
    }
    if(ans < ac){
        ans = ac;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		long N = Long.parseLong(scan.next());
		long A = Long.parseLong(scan.next());
		long B = Long.parseLong(scan.next());
		scan.close();

		long total = A + B;

		long shou = N / total;
		long amari = N % total;

		long AA = shou * A;
		if (amari <= A) {
			AA += amari;
		} else {
			AA += A;
		}

		System.out.println(AA);

	}

}

Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) lower_bound(all(v),k)-v.begin()
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=100100100100;
const int mod=1000000007;
int main(){
   int n,k;cin>>n>>k;
   vi v(n);
   rep(i,n)cin>>v[i];
   vi dp(n,inf);
   dp[0]=0;
   REP(i,1,n){
      REP(j,1,k+1){
         if(i-j<0)break;
         chmin(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
      }
   }
   cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

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

        int march[] = new int[5];
        for (int i = 0; i < n; i++) {
            String str = sc.next();
            char ch = str.charAt(0);
            switch(ch) {
            case 'M' :
                march[0]++;
                break;
            case 'A' :
                march[1]++;
                break;
            case 'R' :
                march[2]++;
                break;
            case 'C' :
                march[3]++;
                break;
            case 'H' :
                march[4]++;
                break;
            }
        }
//        for (int i = 0; i < 5; i++) {
//            System.out.println(march[i]);
//        }

//        System.out.println("---------------------------------");

        long ans = 0;

        for (int i = 0; i <= 2; i++) {
            for (int j = i+1; j <=3 ; j++) {
                for (int k = j+1; k <=4 ; k++) {
                    ans += count(march[i], march[j], march[k]);
//                    System.out.println(i + "/"+ j + "/" + k + ":" + count(march[i], march[j], march[k]));
                }
            }
        }

        System.out.println(ans);
        sc.close();
    }

    static long count(long a, long b, long c) {
        return a * b * c;
    }

}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S,T;

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>S;
	
	FORR(c,S) {
		if(c=='B' && T.size()) T.pop_back();
		else if(c!='B') T.push_back(c);
	}
	cout<<T<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
package main

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

type As [][]int

func (a As) Len() int {
    return len(a)
}

func (a As) Swap(i, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a As) Less(i, j int) bool {
    return a[i][1] < a[j][1]
}

func main() {
    var n int
    fmt.Scan(&n)

    ws := make(As, n)
    var sc = bufio.NewScanner(os.Stdin)
    for i := 0; i < n; i++ {
        sc.Scan()
        ss := strings.Split(sc.Text(), " ")
        a, _ := strconv.Atoi(ss[0])
        b, _ := strconv.Atoi(ss[1])
        ws[i] = []int{a, b}
    }
    sort.Sort(ws)

    var ng bool
    var sum int
    for i := range ws {
        sum += ws[i][0]
        if sum > ws[i][1] {
            ng = true
        }
    }
    if ng {
        fmt.Println("No")
    } else {
        fmt.Println("Yes")
    }
}


Measured memory_bytes: 12032
import java.util.Scanner;

class B {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int A = sc.nextInt();
        final int B = sc.nextInt();
        int cA = 0, cB = 0, cC = 0;
        for (int i = 0; i < N; i++) {
            final int P = sc.nextInt();
            if (P <= A)
                cA++;
            else if (P <= B)
                cB++;
            else
                cC++;
        }
        System.out.println(Math.min(cA, Math.min(cB, cC)));
    }
}
public class Main {
    public static void main(String... args) {
        B.main();
    }
}


Measured memory_bytes: 22740
x, n = map(int, input().split())
p = set(map(int, input().split()))
min_d = 103
ans = 103
for i in range(102):
    if i in p:
        continue
    d = abs(x - i)
    if d < min_d:
        min_d = d
        ans = i
print(ans)


Measured memory_bytes: 9120
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define debug(x) cerr << #x << ": " << (x) << endl
#define debug2(x, y) cerr << #x << ": " << (x) << " " << #y << ": " << y << endl;
#define int long long
using namespace std;
using II = pair<int, int>;
using VII = vector<II>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;

signed main() {
  int N, K; cin >> N >> K;
  VI a(N);
  VI acc(N);
  REP (i, N) {
    int p;
    cin >> p;
    acc[i] = (i == 0 ? 0 : acc[i - 1]) + p;
  }
  VI xs;
  REP (i, N) {
    REPI (j, i, N) {
      int p;
      p = acc[j] - (i == 0 ? 0 : acc[i - 1]);
      xs.push_back(p);
    }
  }
  assert(xs.size() == N * (N + 1) / 2);
  int M = xs.size();
  vector<bool> use(xs.size(), true);
  int ans = 0;
  for (int i = 40; i >= 0; i--) {
    int num = 0;
    REP (j, M) {
      if (!use[j]) continue;
      if (xs[j] & (1ll << i)) {
        num++;
      }
    }
    if (num < K) continue;
    ans += 1ll << i;
    REP (j, M) {
      if (!(xs[j] & (1ll << i))) use[j] = false;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6000
s = input()
flag=1

cnt = 0
for i in s[2:-1]:
    if i == "C":
        cnt += 1
if s[0] != "A":
    flag = 0
else:
    if cnt != 1:
        flag = 0
    else:
        for i in range(len(s)):
            if s[i] == "A" or s[i] == "C":
                pass
            else:
                if s[i].isupper() == True:
                    flag = 0
if flag:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>

#define MAX 20000
using namespace std;



int main(){
  int a[MAX];
  int N=3;
  // std::cin >> N;
  for(int i=0;i<N;i++){
    std::cin >> a[i];
  }

  for(int i=1;i<N;i++){
    int v=a[i];
    int j=i-1;
    while(j>=0&&a[j]>v){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
  }

  for(int i=0;i<N-1;i++){
    std::cout << a[i] <<" ";
  }
  std::cout << a[N-1] << '\n';
  



}

Measured memory_bytes: 3100
# abc101_b.py
# https://atcoder.jp/contests/abc101/tasks/abc101_b

# B - Digit Sums /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 整数 nに対して，n を十進法で表したときの各桁の和を S(n) で表すことにします． たとえば，S(101)=1+0+1=2です．

# 整数 Nが与えられたとき，N が S(N)で割り切れるかどうかを判定してください．

# 制約
#     1≤N≤109

# 入力
# 入力は以下の形式で標準入力から与えられる．
# N

# 出力
# Nが S(N)で割り切れるなら Yes を，割り切れないなら No を出力せよ．

# 入力例 1
# 12

# 出力例 1
# Yes

# この入力では N=12です． S(12)=1+2=3 なので，N は S(N)で割り切れます．

# 入力例 2
# 101

# 出力例 2
# No

# S(101)=1+0+1=2なので，N は S(N)で割り切れません．

# 入力例 3
# 999999999

# 出力例 3
# Yes


def calculation(lines):
    line = lines[0]
    n = 0
    for i in range(len(line)):
        n += int(line[i])
    if int(line) % n == 0:
        result = 'Yes'
    else:
        result = 'No'
    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['12']
        lines_export = ['Yes']
    if pattern == 2:
        lines_input = ['101']
        lines_export = ['No']
    if pattern == 3:
        lines_input = ['999999999']
        lines_export = ['Yes']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9240
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

const int MAX = 1e6;
long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(ll n, ll k){
  ll tmp = 1;
  for(ll i = 0; i < k; i++) {
    tmp *= (n-i);
    tmp %= MOD;
  }
  tmp *= finv[k];
  tmp %= MOD;
  return tmp;
}

ll myPow(ll x, ll n){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % MOD, n / 2);
  else
    return x * myPow(x, n - 1) % MOD;
}



int main(){
  ll n, a, b; cin >> n >> a >> b;
  ll ans = myPow(2LL, n) - 1;
  COMinit();
  ans = ans - (COM(n, a) + COM(n, b));
  ans %= MOD;
  while(ans < 0){
    ans += MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 23680
import sys
f = sys.stdin


def paintout0(islands, x, y):
    if 0 <= x <12 and 0 <= y <12 and islands[y][x]:
        islands[y][x] = 0
        paintout0(islands,x + 1,y)
        paintout0(islands,x,y + 1)
        paintout0(islands,x -1,y)
        paintout0(islands,x,y -1)

while True:
    islands = [[int(c) for c in f.readline().strip()] for _ in range(12)]
    cnt =0
    for y in range(len(islands)):
        for x in range(len(islands[0])):
            if islands[y][x]:
                cnt += 1
                paintout0(islands,x,y)
    print(cnt)
    
    if not f.readline():
        break

Measured memory_bytes: 6724
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int n; cin >> n;
        vi a(n);
        int tot_pos = 1;
        int ev = 1;
        rep(i,n){
            cin >> a[i];
            tot_pos*=3;
            if(a[i]%2==0)ev*=2;
        }
        cout<<tot_pos - ev<<endl;


return 0;
}




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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N;
    cin >> N;
    int t = INT_MAX, p, cnt = 0;
    for (int i=0; i<N; ++i) {
        cin >> p;
        if (t >= p) {
            t = p;
            cnt ++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 2e5 + 10, inf = 1e9 + 1;
int dis[N], mark[N], n, m, mn, mx;
vector<pair<int, int> > gr[N];
void dfs(int v) {
	mark[v] = 1;
	for (auto p : gr[v]) {
		int u = p.first, w = p.second;
		if (mark[u]) {
			if (dis[u] != dis[v] + w) {
				cout << "No";
				exit(0);
			}
		}
		else {
			dis[u] = dis[v] + w;
			dfs(u);
		}
	}
	return;
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		gr[x].push_back({y, w});
		gr[y].push_back({x, -w});
	}
	for (int i = 0; i < n; i++) {
		if (!mark[i]) {
			mn = mx = 0;
			dfs(i);
			if (mx - mx > inf) {
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 11392
#include<bits/stdc++.h>
#define pb push_back
#define int long long
//#define M 998244353
#define M 1000000007
using namespace std;
const int inf=4e18;
const int MX=100;
const int MN=-100;
const double pi=3.14159265358979;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n,i;cin>>n;
	string s,t,o;cin>>s>>t;
	for(i=0;i<n;i++)
	{
		o.pb(s[i]);o.pb(t[i]);
	}
	cout<<o<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n+1];
        for (int i = 1; i <= n; i++) {
            int t1 = i*i;
            if(n < t1)break;
            for (int j = 1; j <= n; j++) {
                int t2 = j*j + i*j + t1;
                if(n < t2)break;
                for (int k = 1; k <= n; k++) {
                    int t3 = k*k + i*k + j*k + t2;
                    if(n < t3)break;
                    a[t3]++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= n; i++) {
            sb.append(a[i] + "\n");
        }
        System.out.print(sb.toString());
        sc.close();

    }

}


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 1010;;

char S[MAX][MAX];
int D[MAX][MAX];

int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);

	FOR (i, 0, n)
	{
		scanf("%s", S[i]);
	}

	queue<PII> q;

	FILL(D, -1);

	FOR (i, 0, n)
	{
		FOR (j, 0, m)
		{
			if (S[i][j] == 'S') q.push(MP(i, j)), D[i][j] = 0;
		}
	}

	while(SZ(q))
	{
		int x = q.front().first;
		int y = q.front().second;

		q.pop();

		FOR (i, 0, 4)
		{
			int x1 = x + dx[i];
			int y1 = y + dy[i];

			if (x1 < 0 || y1 < 0 || x1 >= n || y1 >= m) continue;
			if (D[x1][y1] != -1) continue;
			if (S[x1][y1] == '#') continue;
			D[x1][y1] = D[x][y] + 1;
			q.push(MP(x1, y1));
		}

	}

	int mn = INF;

	FOR (i, 0, n)
	{
		FOR (j, 0, m)
		{
			if (D[i][j] < 0) continue;
			if (D[i][j] > k) continue;

			int cur = min(i, n - i - 1);
			cur = min(cur, j);
			cur = min(cur, m - j - 1);

			mn = min(mn, cur);
		}
	}

	int res = 1;
	res += (mn + k-1) / k;

	cout<<res<<endl;

}


Measured memory_bytes: 5120
let range start stop =
  let rec loop n acc =
    if n >= start then
      loop (n-1) (n :: acc)
    else
      acc
  in
  loop stop []

let check num =
  let rec include3 = function
    | 0 -> None
    | x when x mod 10 = 3 -> Some num
    | x -> include3 (x / 10)
  in
  if num mod 3 = 0 then
    Some num
  else
    include3 num

let filter_option xs =
  let f a x = match x with Some x -> x :: a | None -> a in
  List.rev (List.fold_left f [] xs)

let make n = range 1 n |> List.map check |> filter_option

let format ns = ns |>
                List.map string_of_int |>
                List.map ((^) " ") |>
                String.concat ""

let () =
  let n = read_int () in
  print_endline (format (make n))

Measured memory_bytes: 4052
#include <iostream>
#include <list>

#define T_CT 1
#define T_NC 2

using namespace std;

typedef struct
{
	int count;
	int type;
} bulk;

int N,M,P,Q,R;
list<bulk> S;
bulk tb;

bulk* makebulk(int count,int type)
{
	tb.count = count;
	tb.type = type;
	return &tb;
}

void shuffle(int x,int y)
{
	int sum = 0;
	int countv = 0;
	auto endi = S.end();
	auto sfront = S.begin();
	while(true)
	{
		sfront = S.begin();
		if(sum + sfront->count <= x)
		{
			S.push_back(*sfront);
			sum += sfront->count;
			S.pop_front();
			countv++;
		}
		else
		{
			if(sum != x)
			{
				sfront->count -= x - sum;
				S.push_back(*makebulk(x-sum,sfront->type));
				countv++;
			}
			break;
		}
	}
	sum = 0;
	for(int i = 0;i < countv;i++)
	{
		endi--;
	}
	while(true)
	{
		sfront = S.begin();
		if(sum + sfront->count <= y-x)
		{
			S.insert(endi,*sfront);
			sum += sfront->count;
			S.pop_front();
		}
		else
		{
			if(sum != y-x)
			{
				sfront->count -= (y-x) - sum;
				S.insert(endi,*makebulk((y-x)-sum,sfront->type));
				endi++;
			}
			break;
		}
	}
	/*
	for(auto it = S.begin();it < S.end()-1;it++)
	{
		if(it->type == (it+1)->type)
		{
			it->count += (it+1)->count;
			S.erase(it+1);
			it--;
		}
	}
	*/
}

int main(void)
{
	while(true)
	{
		cin >> N;
		if(N == 0)
			exit(0);
		cin >> M >> P >> Q >> R;
		S.clear();
		S.push_back(*makebulk(R,T_CT));
		S.push_back(*makebulk(N-R,T_NC));
		int a,b;
		for(int i = 0;i < M;i++)
		{
			cin >> a >> b;
			shuffle(a,b);
		}
		int sum = 0;
		auto sfront = S.begin();
		while(true)
		{
			sfront = S.begin();
			if(sum + sfront->count <= P-1)
			{
				sum += sfront->count;
				S.pop_front();
			}
			else
			{
				if(sum != P-1)
				{
					sfront->count -= (P-1)-sum;
				}
				break;
			}
		}
		sum = 0;
		int count = (Q - P) + 1;
		int result = 0;
		while(true)
		{
			sfront = S.begin();
			if(sum + sfront->count <= count)
			{
				if(sfront->type == T_CT)
				{
					result += sfront->count;
				}
				sum += sfront->count;
				S.pop_front();
			}
			else
			{
				if(sum != count)
				{
					if(sfront->type == T_CT)
					{
						result += count - sum;
					}
				}
				break;
			}
		}
		cout << result << endl;
	}
}

Measured memory_bytes: 3228
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

const int MAX = 300;

int main(){
  int S, D, M;
  while(cin >> S >> D >> M){
    int dp[100][MAX + 1] = {};
    REP(i, S){
      int K;
      cin >> K;
      while(K--){
        int w, p;
        cin >> w >> p;
        for(int y = MAX; y >= 0; y--){
          if(y - p >= 0) dp[i][y] = max(dp[i][y], dp[i][y - p] + w);
        }
      }
    }
    int ans[MAX + 1] = {};
    REP(i, D){
      int f; cin >> f;
      for(int j = MAX; j >= 0; j--){
        for(int k = 0; j - k >= 0; k++){
          ans[j] = max(ans[j], ans[j - k] + dp[f][k]);
        }
      }
    }
    while(M > 0 && ans[M] == ans[M - 1]) M--;
    printf("%d %d\n", ans[M], M);
  }
  return 0;
}

Measured memory_bytes: 1268
N=int(input())
h=list(map(int,input().split()))
dp=[0]
cost=[]
for i in range(1,N):
    cost=[]
    cost.append(abs(h[i]-h[i-1])+dp[i-1])
    if i>=2:
        cost.append(abs(h[i]-h[i-2])+dp[i-2])
    dp.append(min(cost))
print(dp[N-1])

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


int main() {
  int N;
  cin >> N;
 vector<int> X(N);
  for(int i=0;i<N;i++) cin >>X[i];
  bool f= true;
  sort(X.begin(),X.end());
for(int i=0;i<N-1;i++){
 if(X[i] == X[i+1]) f= false; 
}

  if(f )cout<<"YES"<<endl;
  else cout <<"NO" <<endl;
}

Measured memory_bytes: 1024
from collections import deque
import sys
readline = sys.stdin.readline
write= sys.stdout.write

N = int(readline())
s0 = map(int, readline().split())
s1 = map(int, readline().split())
st0 = []; st1 = []
que = deque()
q = next(s1, None)
j = -1
ans = []
for v in s0:
    while st1 and st1[-1] != j:
        ans.append(st1.pop())
    st1.append(v)

    st0.append(v)
    j = v
    while st0 and st0[-1] == q:
        j = st0.pop()
        q = next(s1, None)
while st1:
    ans.append(st1.pop())
print(*ans)



Measured memory_bytes: 6004
a = [[0 for i in range(3)] for j in range(3)]
for i in range(3):
    a[i] = [int(j) for j in input().split()]

n = int(input())
b = [0] * n
for i in range(n):
    b[i] = int(input())


for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = 0

f = 0
for i in range(3):
    if sum(a[i]) == 0:
        f = 1
        break

for i in range(3):
    tmp = 0
    for j in range(3):
        tmp += a[j][i]
    if tmp == 0:
        f = 1
        break

if a[0][0] + a[1][1] + a[2][2] == 0:
    f = 1
if a[0][2] + a[1][1] + a[2][0] == 0:
    f = 1

if f == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
package main
 
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func main(){
    for {
        x := nextInt()
        y := nextInt()
        if x == 0 && y == 0{
            break
        }
        if x > y {
            fmt.Printf("%v %v\n", y, x)
        } else {
            fmt.Printf("%v %v\n", x, y)
        }
    } 
}
 
/* templates */
 
func Max(a ...int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r < a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Min(a ...int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r > a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Sum(a []int) (r int) {
    for i := range a {
        r += a[i]
    }
    return r
}
 
func Abs(a float64) float64 {
    if a < 0 {
        return -a
    }
    return a
}
 
type Pair struct {
    a, b int
}
 
type Pairs []Pair
 
func (p Pairs) Len() int {
    return len(p)
}
 
func (p Pairs) Swap(i, j int) {
    p[i], p[j] = p[j], p[i]
}
 
func (p Pairs) Less(i, j int) bool {
    return p[i].b < p[j].b
}
 
var nextReader func() string
 
func init() {
    nextReader = NewScanner()
}
 
func NewScanner() func() string {
    r := bufio.NewScanner(os.Stdin)
    r.Buffer(make([]byte, 1024), int(1e+11))
    r.Split(bufio.ScanWords)
    return func() string {
        r.Scan()
        return r.Text()
    }
}
 
func nextString() string {
    return nextReader()
}
 
func nextInt64() int64 {
    v, _ := strconv.ParseInt(nextReader(), 10, 64)
    return v
}
 
func nextInt() int {
    v, _ := strconv.Atoi(nextReader())
    return v
}
 
func nextInts(n int) []int {
    r := make([]int, n)
    for i := 0; i < n; i++ {
        r[i] = nextInt()
    }
    return r
}
 
func nextFloat64() float64 {
    f, _ := strconv.ParseFloat(nextReader(), 64)
    return f
}


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

int main(void) {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long ans = LONG_LONG_MAX;
  for (int i = -100; i <= 100; i++) {
    long long sum = 0;
    for (int j = 0; j < N; j++) sum += (a[j] - i) * (a[j] - i);
    ans = min(ans, sum);
  }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int[] A = new int[N];
        int count=0;
        int num=1;
        for (int i=0; i<N; i++){
            A[i]=sc.nextInt();
            if(A[i]==num){
                num++;
            }else{
                count++;
            }
        }
        if(count>=N){
            count=-1;
        }
        System.out.println(count);

    }
}


Measured memory_bytes: 60620
#include<bits/stdc++.h>
using namespace std;
int n,k,curk;
struct data{
    int a,b;
};
vector<data> ans;
int chk[103][103];
int main(){
    int i,j;
    scanf("%d %d",&n,&k);
    curk=(n-1)*(n-2)/2-k;
    if(curk<0){
        printf("-1");
        return 0;
    }
    for(i=2;i<=n;i++){
        ans.push_back({1,i});
    }
    for(i=2;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(!curk) goto pr;
            ans.push_back({i,j});
            curk--;
        }
    }
    pr:
    printf("%d\n",ans.size());
    for(data t : ans){
        printf("%d %d\n",t.a,t.b);
    }
    return 0;
}


Measured memory_bytes: 384
//#pragma GCC optimize("O3,unroll-loops")
//#pragma loop_opt(on)
#include <bits/stdc++.h>
//#include <bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 998244353;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    int n;
	cin >> n;
  	cout << (n-1)/2+1 << endl;

}


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

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

using namespace std;

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

	int ans=1e9;
	rep(S,1<<n){
		int res=1;
		rep(i,n) res=(S>>i&1?res*2:res+k);
		ans=min(ans,res);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [int(input()) for  _ in range(N)]
S.sort()
ans = sum(S)
if ans % 10 == 0:
    for i in S:
        if i % 10 != 0:
            ans -= i
            break
if ans % 10 == 0:
    ans = 0
print(ans)

Measured memory_bytes: 3060