akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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


    string a,b;
    cin >> a >> b;

    int s = stoi(a+b);
    for(int i = (int)sqrt(s); i * i <= s;i++){
        if(i * i == s){
            cout << "Yes"<<endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

void input(int& rnMaxNum, int& rnWinPnt)
{
  cin >> rnMaxNum >> rnWinPnt;
}

double calcWinRate(int nMaxNum, int nWinPnt)
{
  double nWinRate = 0;

  for (int n = 1; n <= nMaxNum; n++)
  {
    double nOneRate = 1.0 / nMaxNum;
    int nCur = n;

    while (nCur < nWinPnt)
    {
      nOneRate /= 2;
      nCur *= 2;
    }
    nWinRate += nOneRate;
  }
  return nWinRate;
}
 
int main()
{
  int nMaxNum, nWinPnt;
  input(nMaxNum, nWinPnt);
  cout << fixed << setprecision(10) << calcWinRate(nMaxNum, nWinPnt) << endl;

  return 0;
}

Measured memory_bytes: 3756
def fun(n):
    return (n*(n+1))//2
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(len(a)):
    d[a[i]] = 0
for i in range(len(a)):
    d[a[i]] += 1
total = 0
for i in d:
    total += fun(d[i]-1)
for i in d:
    d[i] = total - (d[i] -1)
for i in range(len(a)):
    print(d[a[i]])        


Measured memory_bytes: 89276
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


struct UF
{
    long         num;
    vector<long> par;
    vector<long> rank;

    vector<ll>   val;    // sum of vtx wt
    vector<long> nedge;  // num of edges
    vector<long> nedge_c;    // num of edges counted;

    UF(long n): num(n) {
        par.resize(n);
        rank.resize(n);
        val.resize(n);
        nedge.resize(n);
        nedge_c.resize(n);
        long i;
        for(i=0; i<n; i++) {
            par[i]=i;  rank[i]=1;
            val[i]=0; nedge[i]=nedge_c[i]=0;
        }
    }
	
    long find(long x) {
        if(x==par[x]) return x;
        return par[x] = find(par[x]);
    }

    long unite(long x, long y) {
        x=find(x);
        y=find(y);
        if(x==y) return x;
        if(rank[x]<rank[y]) {
            par[x]=y;
            return y;
        }
        else {
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
            return x;
        }
    }

    bool same(long x, long y) {
        return find(x)==find(y);
    }

    long ngroup() {
        long count=0;
        long i;
        for(i=0; i<num; i++) {
            if(par[i]==i) count++;
        }
        return count;
    }
};



int main(int argc, char* argv[])
{
    long n, m;
    scanf("%ld%ld", &n, &m);

    UF uf(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%lld", &uf.val[i]);
    }

    vector<pair<long, pair<long,long> > > ee(m);   // cost,from,to
    for(i=0; i<m; i++) {
        long a,b,c;
        scanf("%ld%ld%ld", &a, &b, &c);
        ee[i] = make_pair(c, make_pair(a-1,b-1));
    }
    sort(ee.begin(), ee.end());

    vector<long> use_edge(m,0);
    for(i=0; i<m; i++) {
        long tmp0=uf.find(ee[i].second.first);
        long tmp1=uf.find(ee[i].second.second);
        ll   val = uf.val[tmp0];
        long nedge = uf.nedge[tmp0];
        long nedge_c = uf.nedge_c[tmp0];
        long tmp=tmp0;
        if( !uf.same(tmp0, tmp1) ) {
            val += uf.val[tmp1];
            nedge += uf.nedge[tmp1];
            nedge_c += uf.nedge_c[tmp1];
            tmp = uf.unite(tmp0, tmp1);
            uf.val[tmp]=val;
            uf.nedge[tmp]=nedge;
            uf.nedge_c[tmp]=nedge_c;
        }
        uf.nedge[tmp] ++;

        if(val >= ee[i].first) {
            uf.nedge_c[tmp]=uf.nedge[tmp];
        }
    }

    long sum=0;
    for(i=0; i<n; i++) {
        if(uf.find(i)==i) {
            sum = uf.nedge_c[i];
        }
    }
    printf("%ld\n", m-sum);

    return 0;
}


Measured memory_bytes: 7296
#include <cstdio>

int as[200000];

int main(){
  int N,X;
  scanf("%d %d",&N,&X);
  if(X==1||X==N*2-1){
    printf("No\n");
    return 0;
  }
  for(int i=0;i<N*2-1;i++){
    as[i]=(i+X-N+N*2-1)%(2*N-1)+1;
  }
  printf("Yes\n");
  for(int i=0;i<N*2-1;i++){
    printf("%d\n",as[i]);
  }
  return 0;
}


Measured memory_bytes: 2176
package main

import "fmt"

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)
	fmt.Println(min(a, b) + min(c, d))
}


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

using namespace std;
typedef long long ll;

int N, M, A[1010], B[1010], C[1010], D[1010], E[1010], F[1010];
int XC, X[3030], YC, Y[3030], Z[3030][3030];
bool K[3030][3030];

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

int getx(int x) { return lower_bound(X, X + XC, x) - X; }

int gety(int y) { return lower_bound(Y, Y + YC, y) - Y; }

queue<pair<int, int>> Q;

void enq(int x, int y) {
    if (!K[x][y]) {
        Q.push({x, y});
        K[x][y] = 1;
    }
}

int main() {
    scanf("%d%d", &N, &M);
    for (int i = 0; i < N; i++) {
        scanf("%d%d%d", &A[i], &B[i], &C[i]);
        X[XC++] = A[i];
        X[XC++] = B[i];
        Y[YC++] = C[i];
    }
    for (int i = 0; i < M; i++) {
        scanf("%d%d%d", &D[i], &E[i], &F[i]);
        X[XC++] = D[i];
        Y[YC++] = E[i];
        Y[YC++] = F[i];
    }
    X[XC++] = -1.1e9, X[XC++] = 0, X[XC++] = 1.1e9;
    Y[YC++] = -1.1e9, Y[YC++] = 0, Y[YC++] = 1.1e9;
    sort(X, X + XC);
    XC = unique(X, X + XC) - X - 1;
    sort(Y, Y + YC);
    YC = unique(Y, Y + YC) - Y - 1;

    for (int i = 0; i < N; i++) {
        int a = getx(A[i]);
        int b = getx(B[i]);
        int c = gety(C[i]);
        for (int j = a; j < b; j++) {
            Z[j][c - 1] |= (1 << 0);
            Z[j][c] |= (1 << 2);
        }
    }
    for (int i = 0; i < M; i++) {
        int d = getx(D[i]);
        int e = gety(E[i]);
        int f = gety(F[i]);
        for (int j = e; j < f; j++) {
            Z[d - 1][j] |= (1 << 1);
            Z[d][j] |= (1 << 3);
        }
    }
    int sx = getx(0), sy = gety(0);
    for (int p = 0; p < 2; p++) for (int q = 0; q < 2; q++) enq(sx - p, sy - q);
    while (!Q.empty()) {
        int x = Q.front().first, y = Q.front().second;
        Q.pop();
        for (int k = 0; k < 4; k++) {
            if (~Z[x][y] & (1 << k)) {
                int px = x + dx[k], py = y + dy[k];
                if (px < 0 || px >= XC || py < 0 || py >= YC) continue;
                enq(px, py);
            }
        }
    }
    for (int i = 0; i < XC; i++) {
        if (K[i][0] || K[i][YC - 1]) {
            puts("INF");
            return 0;
        }
    }
    for (int i = 0; i < YC; i++) {
        if (K[0][i] || K[XC - 1][i]) {
            puts("INF");
            return 0;
        }
    }
    ll ans = 0;
    for (int i = 0; i < XC; i++) for (int j = 0; j < YC; j++) {
        if (K[i][j]) ans += 1ll * (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]);
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 45624
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from bisect import bisect_left

a, b = getList()

def koyak(a, b):
    koyak = []

    for i in range(1, int(math.sqrt(max(a, b))) + 1):
        if a % i == 0 and b % i == 0:
            koyak.append(i)

    return koyak

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

# ko = koyak(a, b)
ko = list((set(make_divisors(a)) & set(make_divisors(b))))
ko.sort()
ans = []
for k in ko:
    fl = True
    for an in ans:
        if k % an == 0 and an != 1:
            fl = False
            break
    if fl:
        ans.append(k)

# print(ko)
print(len(ans))

Measured memory_bytes: 40688
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n, K;
    scanf("%d%d", &n, &K);
    vector<int> a(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (i = K; i < n; i++) {
        if (a[i] > a[i - K]) {
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        solve();
    }
#endif
    return 0;
}


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

const int N = 1e5 + 7;
const int INF = 1e9 + 7;

string s;
int b, ans;

main(){
    cin >> s;
    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'B')
            b++;
        else
            ans += b;
    }
    cout << ans;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<math.h>
#include<stack>
#include<sstream>
#include<queue>
#include<list>
#include<iomanip>
#include<bitset>
#include<limits.h>
#include <bits/stdc++.h>
#define MOD  1000000007
#define BIG  1000000005
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define pi pair<int,int>;
typedef long long ll;
using namespace std;


int main()
{
    //freopen("input.txt", "r", stdin);
     char arr[52][52] ;
     memset(arr , '.' , sizeof arr);
     int a , b ;
     cin >> a >> b ;
     for(int i =1 ; i<=a ; i++ ){
        for(int y =1 ; y<=b ; y++){
           scanf(" %c",&arr[i][y]);
        }
     }
      for(int i =1 ; i<=a ; i++ ){
        for(int y =1 ; y<=b ; y++){
           if(arr[i][y] == '#'){
            if( (arr[i][y-1] == '.') && (arr[i][y+1]=='.') && (arr[i+1][y] =='.') && (arr[i-1][y] =='.') ){
            cout << "No"<< endl ;
            return 0 ;
            }
           }
        }
     }
     cout << "Yes" << endl ;
            return 0 ;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void
solver(double a, double b, double x)
{
    double y;
    if (x<=a*a*b/2) {
        y = x/a/b*2;
        printf("%.10Lg\n", 90.0-atanl(y/b)/M_PI*180);
    }
    else {
        y = x*2./a/a-b;
        printf("%.10Lg\n", 90.0-atanl(a/(b-y))/M_PI*180);
    }
}

int
main(int argc, char *argv[])
{
    int a, b, x;

    scanf("%d %d %d", &a, &b, &x);
    solver((double)a, (double)b, (double)x);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int gcd(int ,int);
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int max = 1;
  int i;
  max = gcd(a,b);
  printf("%d\n",max);
  return 0;
}
int gcd(int m,int n){
  int rest;
  int x = (m > n) ? m:n;
  int y = (x == m)? n:m;
  while(1){
    rest = x%y;
    if(rest ==0) return y;
    x = y;
    y = rest;
  }
}

Measured memory_bytes: 2728
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n, l;
    string s[110]; 
    string ans;

    cin >> n >> l;
    for (int i = 0; i < n; i++){
        cin >> s[i];
    }
    sort(s, s+n);

    for (int i = 0; i < n; i++){
        cout << s[i];
    }
    cout << endl;

    
    return 0;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s);

    let mut s = s.trim_right().split_whitespace();
    let a = s.next().unwrap();
    let b = s.next().unwrap();

    let a = a.parse::<usize>().unwrap();
    let b = b.parse::<usize>().unwrap();

    println!("{}", a * b / 2);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct Combination{
  const int MOD = 1e9+7;

  vector<int> fact; //　fact[i] = iの階乗
  void init(int n){
    fact.resize(n+1);
    fact[0] = fact[1] = 1;
    for(int i = 2; i <= n; i++){
      fact[i] = i * fact[i-1] % MOD;
    }
  }

  int nCr(int n, int r){ // nCr = n!/r!(n-r)!
    if(n < r) return 0;
    return fact[n] * mod_pow(fact[r]*fact[n-r]%MOD, MOD-2) % MOD;
  }

  int mod_pow(int n, int p){ // a/n ≡ a*n^(p-2) nとpは互いに素
    int r = 1;
    for(; p > 0; p >>= 1){
      if(p & 1LL) r = (r * n) % MOD;
      n = (n * n) % MOD;
    }
    return r; // r = n^p % MOD
  }

}comb;

signed main(){

  int a, b; cin >> a >> b;
  comb.init(10000);
  cout << comb.nCr(a, 2) + comb.nCr(b, 2) << endl;

  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
    int n;
    long long int sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            sum = sum + i;
        }
    }
    printf("%lld",sum);

}

Measured memory_bytes: 1736
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad
import Control.Monad.ST
import Control.Monad.Except

type ExcST s = ExceptT () (ST s)

solve :: [[Int]] -> String
solve ([valN,_]:lrds) =
  case runST $ runExceptT $ act valN lrds of
    Left _  -> "No"
    Right _ -> "Yes"

act :: Int -> [[Int]] -> ExcST s ()
act valN lrds = do
  vec <- VM.new (valN+1)
  forM_ [1 .. valN] $ \i -> VM.write vec i (i, 0)
  mapM_ (step vec) lrds

step :: VM.MVector s (Int, Int) -> [Int] -> ExcST s ()
step vec [l,r,d] = do
  (grpL, coordL) <- reGroup vec l
  (grpR, coordR) <- reGroup vec r
  if grpL == grpR
    then unless (coordL + d == coordR) (throwError ())
    else VM.write vec grpR (grpL, coordL + d - coordR)

reGroup :: VM.MVector s (Int, Int) -> Int -> ExcST s (Int, Int)
reGroup vec x = VM.read vec x >>= sub
  where sub (grp, coord) 
          | x == grp  = return (grp, coord)
          | otherwise = do
              (newGrp, newCoord) <- reGroup vec grp
              let newXVal = (newGrp, newCoord + coord)
              VM.write vec x newXVal
              return newXVal

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

main :: IO ()
main = putStrLn . solve . map bsReadInts . B.lines =<< B.getContents


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

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

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  vector<int> odd;
  for (int i = 1; i <= n; i += 2) {
    odd.push_back(i);
  }

  int res = 0;
  for (int num : odd) {
    int count = 0;
    for (int i = 1; i <= num; ++i) {
      if (num % i == 0) ++count;
    }
    if (count == 8) ++res;
  }
  cout << res << endl;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[100010],cnt[2];
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
bool check(){
	cnt[0]=cnt[1]=0;
	for(int i=1;i<=n;i++)
		cnt[a[i]&1]++;
	if(cnt[0]&1)
		return 1;
	if(cnt[1]>1)
		return 0;
	if(a[1]==1)
		return 0;
	int d=(a[1]-=(a[1]&1));
	for(int i=2;i<=n;i++){
		if(a[i]==1)
			return 0;
		d=gcd(d,a[i]-=(a[i]&1));
	}
	for(int i=1;i<=n;i++)
		a[i]/=d;
	return !check();
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i);
	puts(check()?"First":"Second");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int a[10],b[10],fac[10],n;
int calc(int a[],int l){
	if(l>=n)return 0;
	for(int i=l+1;i<n;i++)if(a[i]>a[l])a[i]--;
	return a[l]*fac[n-l-1]+calc(a,l+1);
}
int main(){
	scanf("%d",&n);
	fac[0]=1;for(int i=1;i<10;i++)fac[i]=fac[i-1]*i;
	for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=0;i<n;i++)scanf("%d",b+i);
	printf("%d",abs(calc(a,0)-calc(b,0)));
	return 0;
}

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

int main(){
    long long int n,i,j,d=1,ans;
    cin>>n;
    for(i=2;i<=(int)sqrt(n);i++){
        if(n%i==0){d=i;}
    }
    ans=d+n/d-2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	string s;
	cin>>s;
	bool flag=true;
	string s2=s;
	reverse(s2.begin(),s2.end());
	if(s!=s2)
	flag=false;
	n=s.length();
	string str=s.substr(0,(n-1)/2);
	s2=str;
	reverse(s2.begin(),s2.end());
	if(str!=s2)
	flag=false;
	str="";
	for(i=(n+3)/2-1;i<n;i++)
	str+=s[i];
	s2=str;
	reverse(s2.begin(),s2.end());
	if(str!=s2)
	flag=false;
	if(flag)
	cout<<"Yes";
	else cout<<"No";
}

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

int main() {
  
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> color(0);
  
  color.push_back(a);
  
  if(a != b){
    color.push_back(b);
  }
  
  if(b != c && a != c){
    color.push_back(c);
  }
  
  cout << color.size() << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if(a < b && b < c){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> count(n+1);
    int start,end;
    for(int i=0;i<m;i++){
        cin >> start >> end;
        count.at(start-1) +=1;
        count.at(end-1) +=1;
    }
    for (int j=0;j<n;j++){
        cout << count.at(j) << endl;
    }

}

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

const int mod = 1e9 + 7;

int main() {
	int n, m;
	cin >> n >> m;
	vector <vector<char>> matrix(n, vector<char>(m, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> matrix[i][j];
		}
	}

	vector<vector<int>> dp(n, vector<int>(m, 0));

	dp[0][0] = (matrix[0][0] == '#' ? 0 : 1);

	for (int i = 1; i < m; i++) {
		dp[0][i] = (matrix[0][i] == '#' ? 0 : dp[0][i - 1] == 0 ? 0 : 1);
	}

	for (int i = 1; i < n; i++) {
		dp[i][0] = (matrix[i][0] == '#' ? 0 : dp[i - 1][0] == 0 ? 0 : 1);
	}

	for (int i = 1; i < n; i++) {
		for (int j = 1; j < m; j++) {
			if (matrix[i][j] == '#') dp[i][j] = 0;
			else dp[i][j] += dp[i - 1][j] + dp[i][j - 1];
			dp[i][j] %= mod;
		}
	}

	cout << dp[n - 1][m - 1];
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#ifndef bhartiya
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif


typedef long long ll;
typedef pair<ll, ll> pll;
typedef gp_hash_table<long long, long long> umap;
typedef tree<int, null_type, less<int>, rb_tree_tag,
		tree_order_statistics_node_update> oset;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;

#define inf 200000000000000ll
#define mod 1000000007ll
#define eps 1e-7
#define PI 3.1415926535897932385
// #define PI acos(-1)

#define pb push_back
#define bitc  __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) memset(ar, val, sizeof(ar))

#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; return 0;
#else
#define endl '\n'
#define trace(...)
#define end_routine() return 0;
#endif

mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
inline bool equals(double a, double b) {return fabs(a - b) < 1e-9;}
ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }

const ll maxn = 500005;

void solve(){
    ll n,k; cin>>n>>k;
    if(k> (n-1)*(n-2)/2){
        cout<<-1;
        return;
    }
    ll v = (n-1)*(n-2)/2;
    vll ans;
    rep(i,n-1){
        ans.pb(mp(i+1, n));
    }
    ll st = 1, end = 2;
    while(k != v){
        v--;
        ans.pb(mp(st, end));
        if(end == n-1){
            st++;
            end = st+1;
        }
        else{
            end++;
        }
    }
    cout<<ans.size()<<endl;
    rep(i,ans.size()){
        cout<<ans[i].ff<<" "<<ans[i].ss<<endl;
    }
}

int main() 
{ 
	ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(10); //cout<<fixed;
    cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    solve();
    end_routine();
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

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

//--------------------



int main() {

  int n;
  cin >> n;
  int p[n];
  rep(i, n) cin >> p[i];

  int cnt = 0;
  for(int i=0; i<=n-3; ++i) {
    if(p[i+1]>p[i]&&p[i+1]<p[i+2]) ++cnt;
    else if(p[i+1]>p[i+2]&&p[i+1]<p[i]) ++cnt;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	X,Y,Z := sc.i(),sc.i(),sc.i()
	fmt.Printf("%d %d %d\n", Z,X,Y)
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


Measured memory_bytes: 1776
using System;
using static System.Console;
using static System.Math;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            WriteLine(N % 2 == 0 ? N / 2 : N / 2 + 1);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int solve(){
    int n; cin >> n;
    vint a(n); rep(i,n){
        cin >> a[i];
        --a[i];
    }
    
    vector<ll> v(n,0);
    rep(i,n){
        ++v[a[i]];
    }

    ll sum = 0;
    rep(i,n){
        sum += v[i]*(v[i]-1)/2;
    }
    rep(i,n){
        cout << sum - v[a[i]]*(v[a[i]]-1)/2 + (v[a[i]]-1)*(v[a[i]]-2)/2 << endl;
    }

    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


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


bool isN(vector<int> a, int n){
  bool flg=true;
  if(n==0)return false;
  for(int i=0; i<(int)a.size(); i++)if(a[i]%n!=0){flg=false; break;}
  return flg;
}

int main(){

  int n;
  vector<int> a(2),ans(0);

  cin >> n;
  for(int i=0; i<2; i++)cin>>a[i];
  if(n==3){
    a.resize(3); cin>>a[2];
  }

  sort(a.begin(),a.end());

  if(isN(a,a[0])==true)ans.push_back(a[0]);

  for(int i=1; i<=a[0]/2; i++){
    if(isN(a,i)==true){
      ans.push_back(i);
      if(i!=a[0]/2 && isN(a,a[0]-i)==true)
	ans.push_back(a[0]-i);
    }
  }

  sort(ans.begin(),ans.end());
  //reverse(ans.begin(),ans.end());

  for(int i=0; i<(int)ans.size(); i++)cout << ans[i] << endl; 

  return 0;
}

Measured memory_bytes: 1220
//#include<iostream>
//#include<vector>
//using namespace std;
//typedef long long ll;
//
//int main() {
//	ll n, min = 10000000000, max = -10000000000,r;
//
//	cin >> n;
//	for (int i = 0; i < n; i++) {
//		cin >> r;
//		if (max < r - min)max = r - min;
//				if (min > r)min = r;
//
//
//	}
//
//
//	cout << max << endl;
//
//}

//2回目

#include<iostream>
#include<vector>
typedef long long ll;

using namespace std;

int main() {

	ll n,r;
	ll min = 10000000000;
	ll max = -10000000000;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >>r;
		if(max < r - min)max = r - min;
		if ( min > r)min = r;
		
	}
	cout << max  << endl;

	return 0;

}





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

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

using bigint = boost::multiprecision::cpp_int;
using decfloat = boost::multiprecision::cpp_dec_float_50;

int main() {
  in(ll, n, k);
  vector<bigint> a(n);
  rep(i, n) cin >> a[i];
  for (int i = k; i < n; ++i) {
    if (a[i] > a[i - k]) {
      out("Yes");
    } else {
      out("No");
    }
  }
}


Measured memory_bytes: 9548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,1,-1};
vector<string> field;
int dist[21][21];
int H,W;
int ans = -1;

void bfs(int sx,int sy){
  memset(dist,-1,sizeof(dist));
  if(field[sx][sy]=='#') return;
  dist[sx][sy] = 0;
  queue<pii> que;
  que.push(make_pair(sx,sy));
  
  while(!que.empty()){
    pii P = que.front(); que.pop();
    int xx = P.first; int yy = P.second;
    for(int i=0;i<4;i++){
      int nx = xx + dx[i];
      int ny = yy + dy[i];
      if(nx<0||nx>=H||ny<0||ny>=W) continue;
      if(field[nx][ny]=='#') continue;
      if(dist[nx][ny]==-1||dist[nx][ny]>dist[xx][yy]+1){
        dist[nx][ny] = dist[xx][yy]+1;
        que.push(make_pair(nx,ny));
      }
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        ans = max(ans,dist[i][j]);
      }
    }
  }
}
int main(){
  cin >> H >> W;
  field.resize(H);
  for(int i=0;i<H;i++){
    cin >> field[i];
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      bfs(i,j);
    }
  }
  cout << ans << endl;
 
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;
const double PI = (acos(-1));
const long long MOD = pow(10, 9) + 7;
long long kaizyou(int N);
long long POW(int J);

int main()
{
    string s;
    cin >> s;

    set<char> c;
    int sum=0;
    const int N=4;
    int num[4] = {};

    for(int i=0; i<N-1; i++)
    {
        for(int j= i+1; j<N; j++)
        {
            if(s[i] == s[j])
            {
                c.insert(s[i]);
                num[i]++;
                sum++;
            }
        }
    }

    bool judge = true;
    int test=0;
    
    for(int i=0; i<N-1; i++)
    {
        if(s[i] > 1)
        {
            judge = false;
        }

    }

    if(c.size() == 2 && sum == 2 )
    {
        if(sum = 2)
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 3528
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        String n = scanner.next();
        int number = 0;
        int carry = 0;
        for (int i = n.length() - 1; i >= 0; --i) {
            int current = Integer.valueOf(n.charAt(i)) - '0' + carry;
         //   System.out.print("current: " + current);
            if (current > 5) {
                carry = 1;
                number += 10 - current;
            } else if (current == 5) {
                if (i >= 1 && Integer.valueOf(n.charAt(i - 1)) - '0' >= 5) {
                    carry = 1;
                } else {
                    carry = 0;
                }
                number += current;
            } else {
                carry = 0;
                number += current;
            }
        //    System.out.println(" number: " + number);
        }
        if (carry > 0) {
            number += carry;
        }
        System.out.println(number);
    }
}


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


int main()
{
  vector<int> num(26);
  char ch;
  
  while(cin >> ch){
    if(('A'<=ch&&ch<='Z')||('a'<=ch&&ch<='z'))
    {
      num[tolower(ch)-'a']++;
    }
  }
  
  for(int i=0;i<26;i++){
    printf("%c : %d\n", 'a'+i, num[i]);
  }
  
  return 0;
}


Measured memory_bytes: 3140
#include<stdio.h>

void visit(int);
int map[101][101];
int f[101],d[101],color[101],time,n;
int main()
{
  int i,j,v,vv,m;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    color[i]=0;
    for(j=0;j<n;j++){
      map[i][j]=0;
    }
  }
  time=0;
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&m);
    for(j=0;j<m;j++){
      scanf("%d",&vv);
      map[v-1][vv-1]=1;
    }
  }
  for(i=0;i<n;i++){
    if(color[i]==0)visit(i);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}

void visit(int u)
{
  int i;
  color[u]=1;
  d[u]=++time;
  for(i=0;i<n;i++){
    if(map[u][i]==1){
      if(color[i]==0)visit(i);
  
    }
  }
  color[u]=2;
  f[u]=++time;
}

Measured memory_bytes: 636
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
LL SUM = 1LL << 60;
int n, m;
void slove(int a, int b){
	LL sum1, sum2, sum3;
	for(int i = 1; i <= a / 2; i++){
		sum1 = 1LL * i * b;
		sum2 = 1LL * (a - i) * (b / 2);
		sum3 = 1LL * (a - i) * (b - b / 2);
		if(sum1 < sum2) swap(sum1, sum2);
		if(sum1 < sum3) swap(sum1, sum3);
		if(sum2 < sum3) swap(sum2, sum3);
		SUM = min(SUM, sum1 - sum3);
	}
}
int main(){
	scanf("%d%d", &n, &m);
	if(n % 3 == 0 || m % 3 == 0)SUM = 0;
        else SUM = min(n, m);
	slove(n, m);
	slove(m, n);
	printf("%lld\n", SUM);
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n=Integer.parseInt(br.readLine());
		String[] str=br.readLine().split(" ");
		int[] S=new int[n];
		for(int i=0;i<n;i++)
			S[i]=Integer.parseInt(str[i]);
		
		int q=Integer.parseInt(br.readLine());
		str=br.readLine().split(" ");
		int[] T=new int[q];
		for(int i=0;i<q;i++)
			T[i]=Integer.parseInt(str[i]);
		
		System.out.println(method(S,T));
		

	}
	static int method(int[] s,int[] t){
		if(s.length<t.length){
			int[] tmp=s;
			s=t;
			t=tmp;
		}
		int count=0;
		for(int i=0;i<t.length;i++){
			for(int j=0;j<s.length;j++){
				if(t[i]==s[j]){count++;break;}
				
				
			}
		}
		
		return count;
	}

}

Measured memory_bytes: 23340
#include <iostream>
using namespace std;
int msort(int n[],int l,int r)
{
        if(l+1==r) return 0;

        int m=(l+r)/2;
        msort(n,l,m);
        msort(n,m,r);

        int t[r-l];
        for(int i=0;i<r-l;i++) t[i]=n[l+i];

        int a=0,b=m-l;
        for(int i=l;i<r;i++){
                if(a==m-l) n[i]=t[b++];
                else if(b==r-l) n[i]=t[a++];
                else{
                        if(t[a]>t[b]) n[i]=t[b++];
                        else n[i]=t[a++];
                }
        }
        return 0;
}

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

        int x[n],t[n];
        for(int i=0;i<n;i++){
                cin >> x[i];
                t[i]=x[i];
        }
        msort(t,0,n);

        int m1,m2;
        m1=t[n/2];
        m2=t[n/2-1];
        for(int i=0;i<n;i++){
                if(x[i]<m1) cout << m1 << endl;
                else cout << m2 << endl;
        }

        return 0;
}


Measured memory_bytes: 4480
#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 mod 1000000007
using namespace std;
typedef long long ll;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

signed main(){
    V<double> x(2),y(2);
    rep(i,2) cin>>x[i]>>y[i];
    int q;
    cin>>q;
    while(q--){
        double a,b;
        cin>>a>>b;
        double t=((x[0]-x[1])*(x[0]-a)+(y[0]-y[1])*(y[0]-b))/(pow(x[1]-x[0],2)+pow(y[1]-y[0],2));
        double xx=x[0]+t*(x[1]-x[0]);
        double yy=y[0]+t*(y[1]-y[0]);
        cout<<fixed<<setprecision(10)<<xx<<' '<<yy<<endl;
    }
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
//#pragma warning( disable : 4996 )
#define ll long long
#define pb push_back
#define endl '\n'
#define fastIO cin.tie( 0 );ios_base::sync_with_stdio( false )
#define pii pair<int, int>
#define eps 1e-13
#define N 200005

using namespace std;

int n, white = 0, tmpWhite = 0;
string s;

inline void init()
{
    cin >> n >> s;

    for ( int i = 0; i < n; ++i ) {
        if ( s[i] == '.' )
            ++white;
    }
    int ans = n - white;
    for ( int i = 0; i < n; ++i ) {
        ans = min( ans, i - tmpWhite + white - tmpWhite );
        if ( s[i] == '.' )
            ++tmpWhite;
    }
    cout << ans;
}

inline void solve()
{
    cout << endl;
}

int main()
{
    fastIO;
    init();
    solve();

    return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#define LL long long int 
#define LD long double
#define PI 3.14159265358979323846
#define MOD ((LL)1e9+7)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const LL N=1e5+10;
vector<LL>A(N),dp(N);
vector<bool>f(N);
LL n;


LL DP(LL I)
{
	if(f[I])return dp[I];
	if(I==1)dp[I]=0;
	else if(I==2)dp[I]=abs(A[1]-A[2]);
	else
	{
		dp[I]=min(DP(I-1)+abs(A[I-1]-A[I]),DP(I-2)+abs(A[I]-A[I-2]));
	}
	f[I]=true;
	return dp[I];
	
}

int main()
{
	IOS
	cin>>n;
	for(LL i=1;i<=n;i++)cin>>A[i];
	cout<<DP(n)<<endl;
	
}
			
				
			
	
	
	
			
		



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

int main()
{
	char s[5];
	int a=0;
	for(int i=1;i<=4;i++)
	{
		scanf("%c",&s[i]);
		if(s[i]==43)
		a=a+1;
		if(s[i]==45)
		a=a-1;
	}
	cout<<a;
}

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

int main(){
	int r,d,x;
	cin >> r >> d >>x;
	rep(i,10){
		cout << r*x - d << endl;
		x = r*x - d;
	}
}

// cout << fixed << setprecision(15) <<  << endl;

Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int s[366][26];
int main() {

	int d;
	cin >> d;
	int c[26];
	int i, j, j2;
	for (i = 0; i < 26; i++) {
		cin >> c[i];
	}

	for (i = 0; i < d; i++) {
		for (j = 0; j < 26; j++) {
			cin >> s[i][j];
		}
	}
	int last[26];
	for (i = 0; i < 26; i++) {
		last[i] = 0;
	}
	int jmax, jindex, jindex2;
	for (i = 1; i <= d; i++) {

		jmax = 0;
		jindex = -1;
		jindex2 = -1;
		/*for (j = 0; j < 26; j++) {
			if (c[j] *(i - last[j]) > jmax) {
				jmax = c[j] *(i - last[j]);
				jindex = j;
			}
			else if (c[j] *(i - last[j]) == jmax) {
				if (s[i - 1][j] > s[i - 1][jindex]) {
					jindex = j;
				}
			}
		}*/
		for (j = 0; j < 26; j++) {
			for (j2 = 0; j2 < 26; j2++) {
				if (j != j2) {
					if (s[i - 1][j] + 3 * c[j] * (i - last[j]) + s[i][j2] + 3 * c[j2] * (i + 1 - last[j2]) > jmax) {
						jmax = s[i - 1][j] + 3 * c[j] * (i - last[j]) + s[i][j2] + 3 * c[j2] * (i + 1 - last[j2]);
						jindex = j;
						jindex2 = j2;
					}
				}
				else {
					if (s[i - 1][j] + 3 * c[j] * (i - last[j]) + s[i][j2] + 3 * c[j2] > jmax) {
						jmax = s[i - 1][j] + 3 * c[j] * (i - last[j]) + s[i][j2] + 3 * c[j2];
						jindex = j;
						jindex2 = j2;
					}
				}
			}
		}
		/*for (j = 0; j < 26; j++) {
			if (s[i - 1][j] + 15 * c[j] * (i - last[j]) >= jmax) {
				jmax = s[i - 1][j] + 15 * c[j] * (i - last[j]);
				jindex = j;
			}
		}*/
		last[jindex] = i;
		cout << jindex + 1 << endl;
		


	}
	return 0;


}

Measured memory_bytes: 3676
#include <stdio.h>
#include <string.h>
#include <math.h>

long calc(char *exp) {
    long tmp=0, ret=0;
    for (int i=0; i<strlen(exp); i++) {
        if (exp[i] != '+')
            tmp *= 10, tmp += exp[i]-'0';
        else 
            ret += tmp, tmp=0;
    }
    return ret+tmp;
}

int main() {
    char s[11] = {};
    scanf("%s", s);
    int len = strlen(s);
    long ans = 0;
    for (int i=0; i<powl(2, len-1); i++) {
        char dst[24]={};
        int k=0;
        for (int t=0 ; t<len; t++, k++) {
            if (i & (1 << (t-1)))
                dst[k++] = '+';
            dst[k] = s[t];
        }
        dst[k] = '\0';
        ans += calc(dst);
    }
    printf("%ld\n", ans);
}

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

using namespace std;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
  int Q;
  int maxN = 50000+10;
  cin >> Q;
  vector<vector<int>> lr(Q, vector<int>(2));
  for(int i=0;i<Q;++i){
    cin >> lr[i][0] >> lr[i][1];
  }
  
  vector<int> sum(maxN);
  for(int i=0;i<maxN;++i){
    if(i==0){
      sum[i] = 0;
    }else{
      if(IsPrime(2*i+1) && IsPrime(i+1)){
        sum[i] = sum[i-1] + 1;
      }else{
        sum[i] = sum[i-1];
      }
    }
  }
  
  for(int i=0;i<Q;++i){
    if(lr[i][0]==1){
      cout << sum[(lr[i][1]-1)/2] <<endl;
    }else{
      cout << sum[(lr[i][1]-1)/2]-sum[(lr[i][0]-1)/2-1] <<endl;
    }
  }
}

Measured memory_bytes: 6272
#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 bpc[1 << 21];
int dp[1 << 21];
int dp_new[1 << 21];

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	const int mod = 1e9 + 7;
	int n;
	cin >> n;
	for (int u = 1; u < (1 << n); u++) {
		bpc[u] = 1 + bpc[u & (u - 1)];
	}
	vector<vector<bool>> edge(n, vector<bool>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int x;
			cin >> x;
			edge[i][j] = x;
		}
	}
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		memset(dp_new, 0, sizeof(dp_new));
		for (int mask = 0; mask < (1 << n); mask++) {
			if (bpc[mask] != i) continue;
			for (int j = 0; j < n; j++) {
				if (edge[i][j] && !(mask >> j & 1)) {
					int to = mask | (1 << j);
					dp_new[to] += dp[mask];
					if (dp_new[to] >= mod) {
						dp_new[to] -= mod;
					}
				}
			}
		}
		memcpy(dp, dp_new, sizeof(dp));
	}
	cout << dp[(1 << n) - 1];
	//cout << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 24832
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    if op == "?":
        break
    elif op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    else:
        print(a//b)


Measured memory_bytes: 5596
# 解説見たつもりだけどまだWA
# https://atcoder.jp/contests/abc173/submissions/15052457
import sys
input = sys.stdin.readline

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
p = 10 ** 9 + 7
A.sort(key = lambda x : abs(x)) # 絶対値小→大
A_zpos = [a for a in A if a >= 0]
A_neg = [a for a in A if a < 0]

# 非負にできるか判定
nneg_en = False
if A_zpos:
    if K == N:
        if len(A_neg) % 2 == 0:
            nneg_en = True
    else:
        nneg_en = True
else:
    if K % 2 == 0:
        nneg_en = True


if nneg_en: # 非負にできる
    if K % 2 == 1:
        ans = A_zpos.pop() # 一番大きい正の数を確保
        K -= 1
    else:
        ans = 1

    while K > 0:
        # 2個ずつ取る
        next_zpos = -1 if len(A_zpos) < 2 else A_zpos[-1] * A_zpos[-2]
        next_neg = -1 if len(A_neg) < 2 else A_neg[-1] * A_neg[-2]
        if next_zpos >= next_neg:
            ans = ans * A_zpos.pop() * A_zpos.pop() % p
        else:
            ans = ans * A_neg.pop() * A_neg.pop() % p
        K -= 2
else:
    ans = 1
    for i in range(K):
        ans = ans * A[i] % p

print(ans)

Measured memory_bytes: 31748
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String fm[] = sc.nextLine().split("\\+|=");
			int init = 0;
			if (fm[0].charAt(0) == 'X' && fm[0].length() > 1
					|| fm[1].charAt(0) == 'X' && fm[1].length() > 1
					|| fm[2].charAt(0) == 'X' && fm[2].length() > 1) {
				init = 1;
			}
			for (int i = init; i < 10; i++) {
//				System.out.println(Long.parseLong(fm[0].replace('X',
//						(char) (i + '0')))
//						+ "+"
//						+ Long.parseLong(fm[1].replace('X', (char) (i + '0')))
//						+ "="
//						+ Long.parseLong(fm[2].replace('X', (char) (i + '0'))));
				if (((new BigInteger(fm[0].replace('X', (char) (i + '0'))))
						.add(new BigInteger(fm[1]
								.replace('X', (char) (i + '0')))))
						.equals(new BigInteger((fm[2].replace('X',
								(char) (i + '0')))))) {
					System.out.println(i);
					break;
				} else if (i == 9)
					System.out.println("NA");
			}
		}
	}
}

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

#define N 1100

char s[N], t[N];

int main() {
    int n, i;
    scanf("%s", s);
    scanf("%s", t);
    n = strlen(s);
    for (i = n - 1; i >= 0; --i) {
        int flag = 1;
        for (int j = 0; j < n; ++j) {
            if (s[(i + j) % n] != t[j]) flag = 0;
        }
        if (flag) break;
    }
    if (i < 0) puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,L,R;
vl a;

int main(){
	cin>>n>>R>>L;
	a=vl(n);
	for(auto &i:a) cin>>i;
	if(L<R){
		swap(L,R);
		reverse(a.begin(),a.end());
		for(int i=0;i<n;i++) a[i]=n-a[i]+1;
	}
	vl dp(n+1,INF);
	dp[0]=0;
	for(int i=0;i<n;i++){
		ll x=a[i];
		vl DP(n+1,INF);
		DP[0]=0;
		for(int j=0;j<x;j++) DP[x]=min(DP[x],dp[j]);
		for(int j=0;j<=n;j++) if(j!=x) DP[j]=dp[j]+(j<x?R:L);
		dp=DP;
	}
	ll res=INF;
	for(int i=0;i<=n;i++) res=min(res,dp[i]);
	cout<<res<<endl;
}

Measured memory_bytes: 512