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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pii;
typedef pair<ll , ll> pll;
typedef vector <pair <int, int>> vpii;
typedef vector <vvi> _3dveci;

int main()
{
    int n, k; cin >> n >> k;
    vector <int> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    
    vector <int> state(n, INT_MAX);

    state[0] = 0;

    //forward
    for(int i = 0; i < n; i++)
    for(int j = 1; j <= k; j++)
        if(i+j < n)
        state[i + j] = min(state[i+j], state[i] + abs(a[i] - a[i+j]));

    cout << state[n-1] << endl;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

string S;

int main(void) {
    
    cin >> S;

    if (S == "AAA" || S == "BBB") {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define RALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

LL f( LL x, LL y ) {
    return x*x+y*y;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    LL d;
    cin >> n >> d;
    d*=d;
    int ans=0;
    REP(i,n) {
        LL a,b;
        cin >> a >> b;
        if ( f(a,b)<=d ) ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::pair;
#define For( i, j, k ) for( int i = j; i <= k; ++i )
const int N = 1e5 + 1;
int n;
long long ans[ N ];
pair < int, int > p[ N ];
int main( )
{
 std::ios::sync_with_stdio( false );
 cin >> n;
 For( i, 1, n )
  cin >> p[ i ].first,
  p[ i ].second = i;
 std::sort( p + 1, p + 1 + n, std::greater < pair < int, int > > ( ) );
 int top = 1, id = 0x3f3f3f3f;
 for( int i = 1; i <= n; )
 {
  while( top <= n && p[ top ].first >= p[ i ].first )
   ++top;
  id = std::min( id, p[ top - 1 ].second );
  ans[ id ] += 1LL * ( p[ top - 1 ].first - p[ top ].first ) * ( top - 1 );
  i = top;
 }
 For( i, 1, n )
  cout << ans[ i ] << '\n';
 return 0;
}

Measured memory_bytes: 5212
///
// File:  e.go
// Author: ymiyamoto
//
// Created on Thu Mar 22 21:22:19 2018
//
package main

import (
	"fmt"
)

var s1, s2 string

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

	return b
}

func main() {
	fmt.Scan(&s1)
	fmt.Scan(&s2)

	dp := make([][]int, len(s1)+1)
	for i := range dp {
		dp[i] = make([]int, len(s2)+1)
	}

	for i := range dp {
		dp[i][0] = i
	}
	for j := range dp[0] {
		dp[0][j] = j
	}

	for i := range s1 {
		for j := range s2 {
			dist := 1
			if s1[i] == s2[j] {
				dist = 0
			}
			dp[i+1][j+1] = min(dp[i][j+1]+1, min(dp[i+1][j]+1, dp[i][j]+dist))
		}
	}

	fmt.Println(dp[len(s1)][len(s2)])
}



Measured memory_bytes: 9800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<ll, ll>;
template<class T> inline bool chmax(T& a, T b) {if (a < b){a = b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if (a > b){a = b;return 1;}return 0;}
const long long LLINF = 1LL << 60;
using namespace std;

int main() {
    int n;
    cin >> n;
    map<int, int> mp1, mp2;
    int offset = 1e5;
    mp1[offset+1] = mp2[offset+1] = mp1[offset+2] = mp2[offset+2] = mp1[offset+3] = mp2[offset+3] = 0;
    rep(i, n) {
        int tmp; cin >> tmp;
        if (i%2) mp1[tmp]++;
        else mp2[tmp]++;
    }
    vector<pair<int, int>> v1, v2;
    for (auto& tmp : mp1) v1.push_back({tmp.second, tmp.first});
    for (auto& tmp : mp2) v2.push_back({tmp.second, tmp.first});
    sort(v1.rbegin(), v1.rend());
    sort(v2.rbegin(), v2.rend());
    int ans = 1e8;
    rep(i, 2) rep(j, 2) {
        if (v1[i].second == v2[j].second) continue;
        ans = min(ans, n - v1[i].first - v2[j].first);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6136
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    H, W, K = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(input().rstrip('\n'))

    ans = 0
    for i in range(2**H):
        red_h = [0] * H
        for x in range(H):
            if i >> x & 1:
                red_h[x] = 1
        for j in range(2**W):
            red_w = [0] * W
            for y in range(W):
                if j >> y & 1:
                    red_w[y] = 1
            cnt = 0
            for h in range(H):
                if red_h[h] == 1:
                    continue
                for w in range(W):
                    if grid[h][w] == "#":
                        if red_w[w] == 0:
                            cnt += 1
            if cnt == K:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69164
import java.io.*;
import java.util.*;
public class Main {
    private static MyScanner scanner;

    public static void main (String[] args){
        Main instance = new Main();
        scanner = instance.new MyScanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = scanner.nextInt();
            String S = scanner.next();
            int x = 0, max = 0;
            for (int i = 0; i < N; i++) {
                String si = S.substring(i, i+1);
                if (si.equals("I")) {
                    x++;
                } else if (si.equals("D")) {
                    x--;
                }
                if (max < x) {
                    max = x;
                }
            }
            System.out.println(max);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";

        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String line = br.readLine();
            while (line.equals("")) {
                line = br.readLine();
            }
            s = line.split(reg, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	int **p;
	int n;
	while (cin >> n && n) {
		p = new int*[n+1];
		for (int i = 0; i < n + 1; i++)
			p[i] = new int[n+1];
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				cin >> p[i][j];
				sum += p[i][j];
			}
			p[i][n] = sum;
		}
		for (int j = 0; j < n + 1; j++) {
			int sum = 0;
			for (int i = 0; i < n; i++) {
				sum += p[i][j];
			}
			p[n][j] = sum;
		}
		for (int i = 0; i < n + 1; i++) {
			for (int j = 0; j < n + 1; j++) {
				cout.width(5);
				cout << p[i][j];
			}
			cout << endl;
		}
		for (int i = 0; i < n + 1; i++)
			delete[] p[i];
		delete[] p;
	}
	return 0;
}

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

long long n;
int main(){
    scanf("%lld", &n);
    map<long long, int> dp;
    for(long long i=2;i*i<=n;i++){
        while(n%i == 0){
            dp[i]++;
            n/=i;
        }
    }
    if(n > 1) dp[n]++;
    long long ans = 0;
    for(auto i:dp){
        int cnt = i.second;
        int val = 1;
        while(cnt > 0){
            cnt -= val;
            if(cnt < 0) break;
            val++;
            ans++;
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 3792
import sys

input = sys.stdin.readline


def is_palindromic(s):
    if s[0] == s[-1] and s[1] == s[-2]:
        return True
    else:
        return False


def main():
    A, B = map(int, input().split())

    ans = 0
    for i in range(A, B + 1):
        ans += 1 if is_palindromic(str(i)) else 0

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int g[100005];
int F(int x)
{
	return g[x]==x?g[x]:g[x]=F(g[x]);
}
void U(int x,int y)
{
	g[F(x)]=F(y);
}
int n;
pair <pair<int,int>,int> a[100005];
vector <pair<int,pair<int,int> > > v;
long long ans=0;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&a[i].first.first,&a[i].first.second);
		a[i].second=i;
		g[i]=i;
	}
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
	    v.push_back(make_pair(a[i+1].first.first-a[i].first.first,
		make_pair(a[i].second,a[i+1].second)));
	for(int i=0;i<n;i++)
	    swap(a[i].first.first,a[i].first.second);
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
	    v.push_back(make_pair(a[i+1].first.first-a[i].first.first,
		make_pair(a[i].second,a[i+1].second)));
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
	{
		int k22=v[i].second.second;
		int k21=v[i].second.first;
		//cout<<v[i].first<<' '<<k21<<' '<<k22<<endl;
		int aaa=F(k21),bbb=F(k22);
		//cout<<k21<<':'<<aaa<<' '<<k22<<':'<<bbb<<endl;
		if(aaa==bbb)
		    ;
		else
	    {
	    	//cout<<aaa<<' '<<bbb<<endl;
	    	U(k21,k22);
	    	ans+=v[i].first;
	    	//cout<<v[i].first<<endl;
		}
	}	    
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6260
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

#define MAX_N 50
#define MAX_AB 1000

int dp[MAX_N][MAX_AB][MAX_AB];
int a[MAX_N], b[MAX_N], c[MAX_N];

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    REP(i, n) {
        cin >> a[i] >> b[i] >> c[i];
    }

    REP(i, MAX_N) {
        REP(j, MAX_AB) {
            REP(k, MAX_AB) {
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;

    // i までで suma, sumb になる最小の sumc
    FOR(i, 0, n) {
        REP(j, MAX_AB) {
            REP(k, MAX_AB) {
                if (dp[i][j][k] == INF) {
                    continue;
                }
                // 加えない場合
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                // 加える場合
                dp[i+1][j + a[i]][k + b[i]] = min(dp[i][j][k] + c[i], dp[i+1][j + a[i]][k + b[i]]);
            }
        }
    }

    int ans = INF;
    FOR(j, 1, MAX_AB) {
        FOR(k, 1, MAX_AB) {
            //cout << dp[i][j][k] << ' ';
            if (j*mb == k*ma) {
                ans = min(ans, dp[n][j][k]);
            }
        }
        //cout << endl;
    }
    //cout << endl;

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 195584
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x, t; cin >> x >> t;
    cout << max(0, x - t) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main(){
  ll N,K,R,S,P;
  string T;
  cin>>N>>K;
  cin>>R>>S>>P;
  cin>>T;
  ll sum=0;
  vector<bool> A(N,false);
  for(ll i=0;i<T.size();++i){
    char a=T[i];
    if(i-K>=0){
      if(A[i-K]==true&&T[i-K]==a){
        continue;
      }
    }
    A[i]=true;
    if(a=='r')sum+=P;
    else if(a=='s')sum+=R;
    else if(a=='p')sum+=S;
    //cout<<sum<<endl;
  }
  cout<<sum<<endl;
  return 0;
}


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

int main(){
  long n;
  long a[100001];
  long q;
  long long s;
  long i;
  long b,c,t;
  s = 0;
  std::cin >> n;
  for(i=0;i<100001;i++)
    a[i] = 0;
  for(i=0;i<n;i++){
    std::cin >> b;
    a[b]++;
  	s += b;
  }
  std::cin >> q;
  for(i=0;i<q;i++){
    std::cin >> b >> c;
  	t = a[b];
    a[b] = 0;
    a[c] += t;
    s += t*(c-b);
    std::cout << s << std::endl;
  }
    
}

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

int main()
{   
    int x[8];
    int y[8];
    int n;
    cin>>n;
    for (int i = 0; i < n; i++)
        cin>>x[i]>>y[i];
    double ans=0.0;
    for (int i = 0; i < n; i++)
        for (int j = i; j < n; j++){
            ans += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));

        }
    printf("%f\n", ans*2/n );

    return 0;
}

Measured memory_bytes: 256
using System;

class Untitled
{
	static void Main(string[] args)
	{
		int a = 0; 
		int b = 0;
		string[] s = Console.ReadLine().Split(' ');
		a = int.Parse(s[0]);
		b = int.Parse(s[1]);
		if (a <= 9 && b <= 9) {
			Console.WriteLine(a * b);
		} else {
			Console.WriteLine(-1);
		}
	}
}

Measured memory_bytes: 11092
#include <iostream>
#include <unordered_set> 
#include <vector>
#include <algorithm>

using namespace std;
int main() {
	    int a;
	    cin>>a;
	    unordered_set<string> s;
	    while(a--){
	        string  str;
	        cin>>str;
	        string key=str;
	        	if (!(s.find(key) != s.end())){
	        	    s.insert(str); 
	        	}
	    }
	    cout<< s.size()<<endl;
	return 0;
}

Measured memory_bytes: 17724
from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
l=len
s=sorted
print(min(C[0]-Y for C,Y in zip((s(sum((v[:max(0,l(v)-K+1)]for v in(k*s(v)for k,v in groupby(A,lambda a:a>=Y))),[]))[Q-1:]for Y in A),A)if C))

Measured memory_bytes: 67804
import java.util.Scanner;

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

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String S = sc.next();
		sc.close();

		int cnt=0,max=0;
		for(int i=0;i<n;i++) {
			if(S.substring(i, i+1).equals("I")) {
				cnt++;
				if(cnt>max)max=cnt;
			}else {
				cnt--;
			}
		}
		System.out.println(max);
	}

}


Measured memory_bytes: 22612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    private static FastReader fr = new FastReader();
    private static PrintWriter out=new PrintWriter(System.out);

    private static long pow(long a, long b, long MOD){
        if(b < 0) return 0;
        if(a == 0) return 0;
        if(b == 1) return a;
        if(b == 0) return 1;
        long v = pow(a, b/2, MOD);
        if(b % 2 == 0){
            return (v * v) % MOD;
        } else {
            return (((v * a) % MOD)*v)%MOD;
        }
    }

    public static void main(String[] args) throws IOException {
        StringBuilder sb = new StringBuilder();
        // code goes here
        long n = fr.nextInt();
        long MOD = 1000000007;

        long val = pow(10, n, MOD);
        val += 2*MOD;
        val += pow(8, n, MOD);
        val -= 2*pow(9, n, MOD);
        val %= MOD;
        sb.append(val);

        System.out.print(sb.toString());
    }

    static class FastReader{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");

        public String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long[] nextLongArray(int n) {
            long[] a=new long[n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int N, Q; string S;
    cin >> N >> S >> Q;
    
    vector<set<int>> vsi(26);
    for (int i = 0; i < S.size(); ++i) {
        vsi[S[i] - 'a'].insert(i);
    }
    for (int i = 0; i < Q; ++i) {
        int t; 
        cin >> t;
        if (t == 1) {
            int p; char c;
            cin >> p >> c; p--;
            char sc = S[p];
            vsi[sc - 'a'].erase(p);
            S[p] = c;
            vsi[c - 'a'].insert(p);
        } else {
            int l, r;
            cin >> l >> r; l--; r--;
            int ans = 0;
            for (char c = 0; c < 26; ++c) {
                auto it = vsi[c].lower_bound(l);
                if (it != vsi[c].end() && *it <= r) ans++;
            }
            cout << ans << endl;
        }
    }
}


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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

#define MAX_N 2050

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K = 0;
ll ret = 0;
ll dp[MAX_N][MAX_N];

ll f(ll x, ll y) {
  if (x < 0 || y < 1) {
    return 0;
  } else if (dp[x][y] != -1) {
    return dp[x][y];
  } else {
    ll sum = 0;
    sum += f(x-1, y);
    sum += f(x, y-1);
    sum %= MOD;
    dp[x][y] = sum;
    return sum;
  }
}

void input() {
  IN(N);
  IN(K);
  REP(i, MAX_N){
    REP(j, MAX_N){
      if (i==0 || j==1) {
        dp[i][j] = 1;
      } else if(j==0) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = -1;
      }
    }
  }
}

void solve() {
  ll ans;
  FOR(i, 1, K+1) {
    ans = f(K-i, i)*f(N-K-(i-1), i+1);
    ans %= MOD;
    PRINT(ans);
  }
}

int main(void){
  input();
  solve();
}


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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  ll x;cin>>x;
  ll t=100;
  ll cnt=0;
  while(1){
    t = t + floor(t*0.01);
    cnt++;
    if(t>=x){
      cout<<cnt<<endl;
      return 0;
    }
  }

  return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

const int INF = 1e9+7;
const int MAX = 101;
static const int WHITE = 0; // 未到達
static const int GRAY = 1; // 到達
static const int BLACK = 2; // 探索済み

// <node, cost>
vector<pair<int, int>> adj[MAX]; // 重み付き有向グラフの隣接リスト表現
int color[MAX];
int d[MAX];

void dijkstra(int s, int e) {
  // <cost, node>
  priority_queue<pair<int, int>> PQ;
  for (int i = 0; i < MAX; i++) {
    d[i] = INF;
    color[i] = 0;
  }

  d[s] = 0;
  PQ.push(make_pair(0, s));
  color[s] = GRAY;

  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = BLACK;

    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j].first;
      if (color[v] == BLACK) continue;
      if (((u == s) && (v == e)) || ((u == e) && (v == s))) continue;
      if (d[v] > d[u] + adj[u][j].second) {
        d[v] = d[u] + adj[u][j].second;
        // priority_queueはデフォルトで大きい値を優先するため-1をかける
        PQ.push(make_pair(d[v] * (-1), v));
        color[v] = GRAY;
      }
    }
  }
};

struct Edge {
  int from, to, cost;
};

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

  int n, m;
  cin >> n >> m;
  int a, b, c;
  vector<Edge> edges(m);
  rep(i, 0, m) {
    cin >> a >> b >> c;
    a--; b--;
    if (a > b) {
      swap(a, b);
    }
    adj[a].pb(make_pair(b, c));
    adj[b].pb(make_pair(a, c));
    edges[i] = Edge{a, b, c};
  }

  int ans = 0;
  for (auto e: edges) {
    int from = e.from;
    int to = e.to;
    int c = e.cost;
    dijkstra(from, to);
    int dis = d[to];
    if (dis < c) ans++;
  }

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_D
#include <iostream>
using namespace std;
int main(){
  int W,H,x,y,r;
  //W????¨????H????????????r?????????, xy???????????????
  cin >> W >> H >> x >> y >> r;
  /*
  ??????????????????????????¶
  ?????????????????§?¨? x+r > W
  ?????????????????§?¨? x-r < 0
  ?????????????????§?¨? y+r > H
  ?????????????????§?¨? y-r < 0
  */
  if(x+r > W ||x-r < 0 ||y+r > H ||y-r < 0){
    cout << "No" <<endl;
  }
  else{
      cout << "Yes" << endl;
    }
}

Measured memory_bytes: 1156
def main():
    x, y = map(int, input().split())
    b = (y - 2*x) / 2
    a = (4*x - y) / 2
    b1 = (y - 2*x) % 2
    a1 = (4*x - y) % 2
    if a1 == 0 and b1 == 0 and a >= 0 and b >= 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61924
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {

	int n, m, ans = 0;
	cin >> n >> m;
	vector<int>p(m);
	vector<vector<int>> s(m);

	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int tmp;
			cin >> tmp;
			s[i].push_back(tmp-1);
		}
	}

	for (int i = 0; i < m; i++)
		cin >> p[i];

	for (int bit = 0; bit < (1 << n); bit++) {
		vector<int>S;
		for (int i = 0; i < n; i++)
			if (bit & (1 << i))
				S.push_back(i);

		int count = 0;
		for (int i = 0; i < m; i++) {
			int tmp = 0;
			for (int j = 0; j < S.size(); j++) {
				for (int l = 0; l < s[i].size(); l++) {
					if (S[j] == s[i][l]) {
						tmp++;
						break;
					}
				}
			}
			if (tmp % 2 == p[i])
				count++;
		}
		if (count == m)
			ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        int N= sc.nextInt();
        int[] W = new int[N];
        for(int i=0;i<N;i++){
            W[i] = sc.nextInt();
        }

        int diff=100000;
        for(int i=1;i<N;i++){
            int sum1 = sum_array(W, 0, i);
            int sum2 = sum_array(W, i, N);
            if(Math.abs(sum1-sum2)<diff){
                diff=Math.abs(sum1-sum2);
            }
        }
        System.out.println(diff);

    }

    public static int sum_array(int[] array, int a, int b) {
        int result = 0;
        for(int i=a;i<b;i++){
            result += array[i];
        }
        return result;
    }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  string a,b;
  cin>>a>>b>>n>>m;
  string x;
  cin>>x;
  if(x==a)
  {
    n--;
  }
  if(x==b)
  {
    m--;
  }
  cout<<n<<" "<<m<<endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

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

	var pre string
	ans := 1
	for i := 0; i < n; i++ {
		if i == 0 {
			pre = string(s[i])
			continue
		}
		if string(s[i]) != pre {
			ans++
		}
		pre = string(s[i])
	}
	fmt.Println(ans)
}

Measured memory_bytes: 1664
bun=input()
for i in range(int(input())):
    o=input().split()
    o[1],o[2]=int(o[1]),int(o[2])
    if o[0]=='print':
        print(bun[o[1]:o[2]+1])
    elif o[0]=='reverse':
        bun_bun=bun[o[1]:o[2]+1]
        bun_bun=bun_bun[::-1]
        bun=bun.replace(bun[o[1]:o[2]+1],bun_bun)
    elif o[0]=='replace':
        bun=bun[:(o[1])]+o[3]+bun[(o[2]+1):]


Measured memory_bytes: 5616
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
f=False
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            ft=True
            if a[i+k][j:j+m] != b[k]:
                ft=False
                break
        if ft:
            f=True
            break
    if f:
        break
print('Yes' if f else 'No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */
const int MOD = 1e9 + 7;
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; }

const int MAX = 403;
ll dp[MAX][MAX];
bool visited[MAX][MAX] = {false};
ll sum[MAX] = {0};

//a_i, i in [l, r]を合体するコストの最小値
//1-indexed
ll rec(int l, int r){
  if(visited[l][r]) return dp[l][r];
  if(r==l)  return 0;
  ll ret = INF;
  FOR(i, l, r){
    ret = min(ret,rec(l,i) + rec(i+1, r));
  }
  //[l,i], [i+1,r]を合体するコストを足す
  ret += sum[r] - sum[l-1];
  visited[l][r] = true;
  return dp[l][r] = ret;
}

int main() {
  int N;  cin >> N;
  REP(i, N){
    int a;  cin >> a;
    sum[i+1] = sum[i] + a;
  }

  cout << rec(1, N) << endl;
}


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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int Maxn = 2000 * 2000 + 100;
const int Mod = 1e9 + 7;

int N, K;
int fac[Maxn], ifac[Maxn];
int Dp[2010][2010];

inline int C (int n, int m) { return (LL) fac[n] * ifac[m] % Mod * ifac[n - m] % Mod; }

inline int Pow (int a, int b)
{
	int ans = 1;
	for (int i = b; i; i >>= 1, a = (LL) a * a % Mod) if (i & 1) ans = (LL) ans * a % Mod;
	return ans;
}

inline void Init ()
{
	fac[0] = 1;
	for (int i = 1; i <= N * K; ++i) fac[i] = (LL) fac[i - 1] * i % Mod;
	ifac[N * K] = Pow (fac[N * K], Mod - 2);
	for (int i = N * K - 1; i >= 0; --i) ifac[i] = (LL) ifac[i + 1] * (i + 1) % Mod;
}

inline void Solve ()
{
	if (K == 1) { puts("1"); return ; }
	Init ();

	Dp[0][0] = 1;
	for (int i = 1; i <= N; ++i)
	{
		Dp[i][0] = 1;
		for (int j = 1; j <= i; ++j)
			Dp[i][j] = (Dp[i - 1][j] + (LL) Dp[i][j - 1] * C (N * K - i - (j - 1) * (K - 1) - 1, K - 2) % Mod) % Mod;
	}

	cout << (LL) Dp[N][N] * fac[N] % Mod << endl;
}

inline void Input ()
{
	N = read<int>(), K = read<int>();
}

int main()
{

#ifdef hk_cnyali
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}


Measured memory_bytes: 46464
#include <bits/stdc++.h>
#define inf 1000000005
#define mod 1000000007
#define eps 1e-10
#define rep(i,n) for(int i = 0; i < (n); ++i) 
#define rrep(i,n) for(int i = 1; i <= (n); ++i) 
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(a,b) for(auto& (a): (b)) 
#define all(v) (v).begin(),(v).end() 
#define sz(v) (int)(v).size() 
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define mx(x,y) x=max(x,y) 
#define mn(x,y) x=min(x,y)
#define rev(v) reverse((v).begin(),(v).end());
#define so(v) sort((v).begin(), (v).end());
#define yn {puts("Yes");}else{puts("No");}
#define fi first
#define se second
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vp = vector<P>;
using vs = vector<string>; 

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b >= c-1) {
        cout << b + c << endl;
    }
    else {
        cout<<a+b*2+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main(void){
  int m;

  cin >> m;
  for(int i=0; i<m; i++){
    int a, b, n, max = 0;

    cin >> a >> b >> n;
    for(int j=0; j<n; j++){
      int c, e; double d;

      cin >> c >> d >> e;
      if(c == 0){
        int A = a, B = 0;
        for(int k=0; k<b; k++){
          B = B + (int)(A * d);
          A = A - e;
        }

        if(max < A + B)
          max = A + B;
      } else {
        int A = a;
        for(int k=0; k<b; k++){
          A += (int)(A * d) - e;
        }

        if(max < A)
          max = A;
      }
    }

    cout << max << endl;
  }

  return 0;
}

Measured memory_bytes: 1232
s = input()
n = len(s) - 1
cnt = 0
for bit in range(1 << n):
    j = 0
    tmp = s[0]
    for i, v in enumerate(s[1:]):
        if bit & (1 << i):
            cnt += int(tmp)
            tmp = v
        else:
            tmp += v
    cnt += int(tmp)
print(cnt)

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

int main(){
    int x,n;
    cin >> x >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int a = x;
    bool flag;
    int cnt = 0;
    while(1){
        flag = true;
        rep(i,n){
            if(a == p[i]) flag = false;
        }
        if(flag) break;
        cnt++;
        a += cnt*pow(-1,cnt);
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 3924
#include <bits/stdc++.h>
#include<unordered_map>
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
	cin >> R;
	if (R < 1200)cout << "ABC";
	else if (R < 2800)cout << "ARC";
	else cout << "AGC";
}

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

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

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n;
  cin >> n;

  vector<ll> w(n);

  rep(i, n) {
    cin >> w[i];
  }

  ll ans = INF;
  REP(i, n) {
    ll sl = accumulate(w.begin(), w.begin() + i, 0);
    ll sr = accumulate(w.begin() + i, w.end(), 0);
    chmin(ans, abs(sl - sr));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int n,a[200010],cnt,ans1,ans2,f1[200010],f2[200010];
char str[200010];
int f(int x)
{
	if(x==0)return 0;
	int tmp=x,count=0;
	while(tmp)
	{
		if(tmp&1)count++;
		tmp>>=1;
	}
	return 1+f(x%count);
} 
int main()
{
	n=read();
	scanf("%s",str);
	for(int i=0;i<n;i++)a[i]=str[i]-'0',cnt+=(a[i]==1);
	if(cnt!=1)
	{
		for(int i=0;i<n;i++)ans1=(ans1*2+a[i])%(cnt-1);
	}
	for(int i=0;i<n;i++)ans2=(ans2*2+a[i])%(cnt+1); 
	f1[n-1]=1;f2[n-1]=1;
	if(cnt!=1)
	{
		for(int i=n-2;i>=0;i--)f1[i]=(f1[i+1]*2)%(cnt-1);
	}
	for(int i=n-2;i>=0;i--)f2[i]=(f2[i+1]*2)%(cnt+1);
	for(int i=0;i<n;i++)
	{
		int temp;
		if(a[i]==1)
		{
			if(cnt==1){printf("0\n");continue;}
			temp=(ans1+cnt-1-f1[i])%(cnt-1);
		}
		else temp=(ans2+f2[i])%(cnt+1);
		printf("%d\n",1+f(temp));
	}
	return 0;
}
/*
1110111001011011001110
*/


Measured memory_bytes: 5752
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
ans = 0
for i in range(k,n) :
    if t[i] == t[i-k] :
        t[i] = 'x'
for i in range(n) :
    if t[i] == 'r' :
        ans += p
    elif t[i] == 's' :
        ans += r 
    elif t[i] == 'p' :
        ans += s
print(ans)

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

int main(){
                                                                     

    int n, i, t;

    int sn = 0;

    
    cin >> n;

    t = n;


    while( t > 0 ){

           sn += ( t % 10 );

           t = t / 10;

           }


    if( n % sn == 0 ){

        cout << "Yes" << endl;

        return 0;

        }


    else cout << "No" << endl;

    return 0;

    }

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

int main(){
  int K,d;
  cin>>K;
  
  vector<long long> a(0);  
  for(int i=1;i<10;i++){
    a.push_back(i);		//配列aに1〜9までが入る
  }
  
  while(1){	//while()は()の中が真(1以外)ならループを回す，偽(0)ならループを回さない
    
    if(K<=a.size()){
      cout<<a[K-1]<<endl;	//whileのループの周回数が桁数となる
      return 0;	 			//無限ループを終わらせるためにreturnを行う
    }
    K-=a.size();	//k=k-a.size()と一緒，
    
    vector<long long> old;	//次のルンルン数をaに入れたいが，次のルンルン数を作るために前の配列が必要
    swap(old,a);		//前の配列をコピーしつつ，新しい配列を入れるためにaの要素を0個にする
    for(long long i:old){		//範囲for文
      d=i%10;
      for(int j=-1;j<2;j++){
        if(d+j<0||d+j>9){continue;}	//桁上がりあるいは桁下りを起こす
        							//continueは次のループに，breakはループ強制終了
        a.push_back(i*10+d+j);
      }
    }
  }
}
    

Measured memory_bytes: 1712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
	int N, M;
	cin >> N >> M;

	vector<int> x, y, z;
	rep(i, N) {
		int a, b, c;
		cin >> a >> b >> c;
		x.push_back(a);
		y.push_back(b);
		z.push_back(c);
	}

	int ret = 0;
	rep(a, 2) rep(b, 2) rep(c, 2) {
		int tmp = 0;
		priority_queue<int> q;
		rep(i, N) {
			int hoge = 0;
			if (a) hoge += x[i];
			else hoge -= x[i];

			if (b) hoge += y[i];
			else hoge -= y[i];

			if (c) hoge += z[i];
			else hoge -= z[i];
			q.push(hoge);
		}
		rep(i, M) {
			tmp += q.top();
			q.pop();
		}
		ret = max(ret, tmp);
	}

	cout << ret << endl;

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) V vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define V vector
#define P pair
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
#define PQ priority_queue
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<PL> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

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

  int n,m;
  cin>>n>>m;
  VL k(m),p(m);
  set<ll> s[m];
  rep(i,m){
    cin>>k[i];
    rep(j,k[i]){
      int S;
      cin>>S;
      s[i].insert(S);
    }
  }
  rep(i,m)cin>>p[i];

  int ans=0;
  for(int bit=0;bit<(1<<n);++bit){
    VL res(m,0);
    for(int show=0;show<n;++show){
      if((bit>>show)&1){
        rep(i,m){
          if(s[i].find(show+1)!=s[i].end()){
            res[i]++;
            res[i]%=2;
          }
        }
      }
    }
    ans+=(res==p);
  }
  out(ans);

  
  
  
  
  return 0;
}



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

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

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

    int ans = 0;
    int ptr = 0;
    while(ptr < n) {
        int cmp = a[ptr];
        int sum = 0;
        while(ptr < n && a[ptr] == cmp) {
            ++sum;
            ++ptr;
        }
        ans += sum%2;
    }

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

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

typedef long long LL;

const int mod=1000003;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}
int Power(int a,int k,int p=mod){int res=1;for (;k;k>>=1,smul(a,a,p)) if (k&1) smul(res,a,p);return res;}

int inv[mod+9],fac[mod+9],ifac[mod+9];

void Get_inv(){
  inv[1]=1;
  fac[0]=fac[1]=1;
  ifac[0]=ifac[1]=1;
  for (int i=2;i<mod;++i){
	inv[i]=mul(mod-mod/i,inv[mod%i]);
	fac[i]=mul(fac[i-1],i);
	ifac[i]=mul(ifac[i-1],inv[i]);
  }
}

void work(){
  Get_inv();
}

void getans(){
  int cq;
  scanf("%d",&cq);
  for (;cq--;){
	int x,d,n;
	scanf("%d%d%d",&x,&d,&n);
    if (!x) {puts("0");continue;}
	if (!d) {printf("%d\n",Power(x,n));continue;}
	smul(x,inv[d]);
	if (x+n>mod) {puts("0");continue;}
	printf("%d\n",mul(Power(d,n),mul(fac[x+n-1],ifac[x-1])));
  }
}

int main(){
  work();
  getans();
  return 0;
}

Measured memory_bytes: 15516
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 = n % 10;
        int b = n / 100;
        if (a == b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>
#define maxn 200005

using namespace std;
typedef long long ll;
char s[maxn];
int n;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == '?') s[i] = 'D';
  }
  printf("%s\n", s + 1);
  return 0;
}


Measured memory_bytes: 3848
S = input()
T = input()

s = len(S)
t = len(T)

ans = 10**9

for i in range(s - t + 1):
    tmp = 0
    for j in range(t):
        if S[i + j] != T[j]:
            tmp += 1

    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 8988
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)

int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  
  int64_t MIN=n;
  int64_t count=0;
  rep(i,n){
    cin >> a[i];
    if(a[i]<=MIN){
      count++;
      MIN = a[i];
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll a;
    double b;
    cin >> a >> b;
    ll c = (ll)round(b * 100);
    cout << a * c / 100;
}


Measured memory_bytes: 3692
n, x = map(int, input().split())
b = 1
p = 1
for i in range(n):
    b = 2 * b + 3
    p = 2 * p + 1
x -= 1
b -= 1
ans = 0
while True:
    if x == 0:
        if b == 0:
            ans += 1
        break
    elif x == b:
        ans += p
        break
    elif x == b // 2:
        ans += p // 2 + 1
        break
    elif 0 < x < b // 2:
        x -= 1
    else:
        x -= b // 2 + 1
        ans += p // 2 + 1
    b = (b - 3) // 2
    p = (p - 1) // 2
print(ans)


Measured memory_bytes: 9016
#include <bits/stdc++.h>
using namespace std;
#define FOR(x,to) for(x=0;x<(to);x++)

int main()
{
    long int n,m,i;cin>>n>>m;
    vector<pair<long int,long int>> ab(n);
    FOR(i,n){cin >> ab[i].first>>ab[i].second;}
    sort(ab.begin(),ab.end());
    long int ans=0,res=m,k=0;
    while (res>0) {
        ans+=ab[k].first*min(res,ab[k].second);
        res-=ab[k].second;
        k++;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
int i,j,k,n,m,l,a[100][100],b[100][100];
long int s;
scanf("%d%d%d",&n,&m,&l);


for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&a[i][j]);


for(i=0;i<m;i++)
for(j=0;j<l;j++)
scanf("%d",&b[i][j]);


for(i=0;i<n;i++)
for(j=0;j<l;j++){
s = 0;
for(k=0;k<m;k++)
s += a[i][k] * b[k][j] ;
printf("%ld", s);
if(j+1 == l)
printf("\n");
else
printf(" ");
}

return 0;
}


Measured memory_bytes: 2112
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
	int n,count;
	bool num[1000000];
	while( scanf("%d",&n) != EOF ){
		for(int i=2;i<=n;i++){
			num[i]=true;
		}
		count = 0;
		for(int i=2;i<=sqrt(n);i++){
			if(num[i]){
				for(int j=i;j<=n;j+=i){
					num[j]=false;
				}
				 count++;
			}
		}
		for(int i=2;i<=n;i++){
			count += num[i];
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 3648