akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using P = pair <int,int>; //to, cost
using WeightedGraph = vector<vector <P>>; //to cost
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int n, x; cin>>n>>x;
    vector <int> a(n);
    rep(i,n) cin>>a[i]; 
    int ans = 0;
    for(int i=0;i<n-1;i++){
        if(a[i] + a[i+1] > x){
            if(a[i] <= x){
                ans += (a[i] + a[i+1] - x);
                a[i+1] = x - a[i];
            }else{
                ans += a[i+1] + a[i] - x;
                a[i+1] = 0;
            }
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
from sys import stdin
INF = float("inf")#無限大の設定1
IINF = 10 ** 18#無限大の設定2
MOD = 10 ** 9 + 7#まれに用いるmodを予め設定しておく
a,b = map(int, stdin.readline().rstrip().split())

def gcd(a,b):#greatest common divisor
    while b:a,b=b,a%b
    return a
def lcm(a,b):#least common multiple
    return a*b//gcd(a,b)

print(lcm(a,b))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H;
  char mas[10][5];
  while( cin >> H, H){
    for(int i = 0; i < H; i++){
      for(int j = 0; j < 5; j++){
        cin >> mas[i][j];
      }
    }

    int ret = 0;
    bool changed = true;

    for(int foo = 0; foo < 10; foo++){
      
      for(int q = 0; q < 10; q++){
        for(int i = H - 1; i > 0; i--){
          for(int j = 0; j < 5; j++){
            if(mas[i][j] == '*'){
              swap(mas[i][j],mas[i - 1][j]); //上から持ってくる
            }
          }
        }
      }

      for(int i = 0; i < H; i++){
        char prev = mas[i][0];
        int cnt = 0;
        for(int j = 0; j < 5; j++){
          if(mas[i][j] == '*'){
            cnt = 0;
            continue;
          }
          if(mas[i][j] != prev){
            prev = mas[i][j];
            cnt = 0;
          }
          cnt++;
          if(cnt == 3){
            ret += (mas[i][j] - '0') * 3;
            for(int k = j, l = 0; l < cnt; l++, k--){
              mas[i][k] = '*';
            }
          } else if(cnt > 3){
            ret += (mas[i][j] - '0');
            mas[i][j] = '*';
          }
        }
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define clt(x) 63-__builtin_clzll(x)
#define bct(x) __builtin_popcountll(x)
#define all(v) (v).begin(),(v).end()
#define pi pair<ll,ll>
#define vi vector<ll>
#define vpi vector<pair<ll,ll>>
#define maxq priority_queue<ll>
#define minq priority_queue<ll,vector<ll>, greater<ll>>
#define cont continue;
#define reto return 0;
#define sz size()
#define spmod 1116295198451
#define mod 1000000007
#define md 998244353 
#define N 1000009
//typedef tree<int,null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> //pbds;

ll a[N],p[N+10];
bool f[N];
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll i=2,j,d,x;
  while(i<=N)
  {
    if(p[i]==0)
    {
      j=i;
      while(j<=N)
      {
        p[j]=i;
        j+=i;
      }
    }
    i++;
  }
  ll n,g;
  cin>>n;
  i=0;
  while(i<n)
  {
    cin>>a[i];
    if(i==0)
      g=a[i];
    else
      g=__gcd(a[i],g);
    i++;
  }
  if(g!=1)
  {
    deb("not coprime");
    return 0;
  }
  i=0;
  while(i<n)
  {
    x=a[i];
    while(x!=1)
    {
      d=p[x];
      if(f[d])
      {
        deb("setwise coprime")
        return 0;
      }
      f[d]=1;
      while(x%d==0)
      {
        x/=d;
      }
    }
    i++;
  }
  deb("pairwise coprime")
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

void solve(long long A, long long P) {
    P += A * 3;
    cout << P / 2 << endl;
}

int main() {
    long long A;
    scanf("%lld", &A);
    long long P;
    scanf("%lld", &P);
    solve(A, P);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define PRINT(mpr) printf(#mpr "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
    int n, k;
    long long MIN = 10000000000;
    cin >> n >> k;
    vector<long long> a(n);
    REP(i, n) cin >> a[i];
    sort(all(a));
    
    REP(i, n-k+1){
        MIN = min(MIN, a[i+k-1]-a[i]);
    }
    cout << MIN << endl;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007LL;

int main() {
	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int a = x2 - x1;
	int b = y2 - y1;
	swap(a, b);
	a *= -1;
	int x3 = x2 + a, y3 = y2 + b;
	swap(a, b);
	a *= -1;
	int x4 = x3 + a, y4 = y3 + b;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
const  long long INF = 1LL << 60;
typedef unsigned long long ll;
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;
}



int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

map<ll,ll> mp;

auto findFactors(ll num){
	
    ll i;
    while (num % 2 == 0){ // 偶数の素数は2のみ
        if(mp.count(2)){
			mp[2] = mp[2] + 1;
		}
		else{
			mp[2] = 1;
		}
        num /= 2;
    }
    for (i = 3; i <= num; i++){ // 他の素数で割っていく
        while (num % i == 0){
			if(mp.count(i)){
			mp[i] = mp[i] + 1;
		}
		else{
			mp[i] = 1;
		}
            num /= i;
        }
    }
    return 0;
}

int main(){ 
int N,M; cin >> N >> M;
vector<pair<int, int>> c(M);//配列の宣言
for(int i = 0; i < M; i++){
  int a,b;
  cin >> a >> b;
  c[i] = make_pair(a,b);//配列型のpairに代入
}
sort(all(c));
set<int> s;
set<int> t;

rep(i,M){
	if(c[i].first == 1){
		if(!s.count(c[i].second)){
			s.insert(c[i].second);
		}
	}
	else if(c[i].second == N){
		if(! t.count(c[i].first)){
			t.insert(c[i].first);
		}
	}
}
bool ok = false;
for(auto u: s){
	if(t.count(u)) {
		ok = true;
	}

}
if(ok) cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;

}

Measured memory_bytes: 11136
#include <iostream>
#include <limits>

using namespace std;

const int MAX_N = 1001;
const int MAX_H = 10001;

// dp[i][j] is the minimum cost to decrease the monster's health by j
// if ibis can cast i kinds of spells from 1 to i
int a[MAX_N], b[MAX_N], dp[MAX_H];

int main()
{
    int h, n;
    cin >> h >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
    }
    const int INF = numeric_limits<int>::max();
    for(int j = 0; j <= h; ++j) dp[j] = INF;
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < h; ++j){
            if(dp[j] == INF) continue;
            dp[min(j + a[i], h)] = min(dp[min(j + a[i], h)], dp[j] + b[i]);
        }
    }
    cout << dp[h] << "\n";
}

Measured memory_bytes: 256
N = int(input())
s = input()
cnt=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a=s.find(str(i))
            if a==-1:
                continue
            b=s[a+1:].find(str(j))
            if b==-1:
                continue
            b+=a+1
            c=s[b+1:].find(str(k))
            if c==-1:
                continue
            cnt+=1

print(cnt)


Measured memory_bytes: 72388
#include <stdio.h>
int main() {
  int N, i;
  int count = 0;
  scanf("%d", &N);
  int p[N];
  int q[N];
  scanf("%d", &p[0]);
  for(i = 1; i < N; ++i){
    scanf("%d", &p[i]);
    if (p[i] < p[i - 1]) {
      if (count == 0) {
        q[count] = i - 1;
      } else {
        q[count] = i;
      }
      ++count;
    }
  }
  
  if (count == 1 || count > 2) {
    printf("NO");
  }
  else if (count == 2) {
    int temp, cou;
    cou = 1;
    temp = p[q[0]];
    p[q[0]] = p[q[1]];
    p[q[1]] = temp;
    for (i = 1; i < N; ++i) {
      if (p[i] < p[i - 1]) {
        printf("NO");
        break;
      }
      ++cou;
    }
    if (cou == N) {
      printf("YES");
    }
  } else {
    printf("YES");
  }
  return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut x: Vec<i32> = (0..n).map(|_| read()).collect();
    let mut sum = vec![std::i32::MAX; 200];

    x.sort();

    for i in x[0]..x[n - 1] + 1 {
        sum[i as usize] = 0;
        for j in 0..n {
            sum[i as usize] += (i - x[j]) * (i - x[j]);
        }
    }

    println!("{}", sum.iter().min().unwrap());
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int multiply = a * b;
		String out;
		if (multiply % 2 == 0) {
			out = "Even";
		} else {
			out = "Odd";
		}
		System.out.println(out);
	}

}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N, Q; cin >> N >> Q;
    int v, w;
    if (N == 1) {
        rep(i, Q) {
            cin >> v >> w;
            cout << v << '\n';
        }
        return 0;
    }
    rep(i, Q) {
        cin >> v >> w;
        while (v != w) {
            if (v > w) v = (v + N - 2) / N;
            else w = (w + N - 2) / N;
        }
        cout << v << '\n';
    }
    return 0;
}

Measured memory_bytes: 1280
// Undone
#include <bits/stdc++.h>
using namespace std;
signed main() {
  int N;
  while (cin >> N, N) {
    int ans = (N == 1) ? 0 : 1;
    for (int i = 2; i*i < N; i++) {
      if (N % i == 0) {
        ans += i + N/i;
      }
      if (ans > N) break;
    }
    if (ans == N) {
      cout << "perfect number" << endl;
    } else if (ans > N) {
      cout << "abundant number" << endl;
    } else if (ans < N) {
      cout << "deficient number" << endl;
    }
  }
}




Measured memory_bytes: 3008
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <stack>
#define mp make_pair
#define MIN(a,b) (a>b?b:a)
#define rank rankk
//#define MAX(a,b) (a>b?a:b)
typedef long long ll;
typedef unsigned long long ull;
const int MAX=4e5+5;
const int INF=2147483647;
const int B=1024;//桶的大小
const double M=4e18;
using namespace std;
const int MOD=1e9+7;
typedef pair<int,int> pii;
ll n,a,b;
ll big,small;
int main()
{
    scanf("%lld%lld%lld",&n,&a,&b);
    big=b*(n-1)+a;
    small=a*(n-1)+b;
    if(big-small+1<=0)
        printf("0\n");
    else
    printf("%lld\n",big-small+1);
    return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long long N; cin >> N;
	for(long long i = 1; i <= 3500; i++) {
		for(long long j = 1; j <= 3500; j++) {
			if(  4 * i * j - N * i - N * j >= 1 && (N * i * j) % (4 * i * j - N * i - N * j) == 0){
				cout << i << " " << j << " " << (N * i * j) / (4 * i * j - N * i - N * j) << endl;
				return 0;
			}
		}
	}
	
	return 0;                                              
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000

int main(void){
  long n,m;
  cin>>n>>m;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(m);
  vector<int> d(m);

  r(i,n)cin>>a.at(i)>>b.at(i);
  r(i,m)cin>>c.at(i)>>d.at(i);
  long min=INF,num;
  r(i,n){
    num=-1;min=INF;
    r(j,m){
        long dis=abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j));
        if(dis<min){
          min=dis;

          num=j+1;

        }
      }
    cout<<num<<endl;
  }
  return 0;
}


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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/




signed main()
{
	int n; cin >> n;
	vector<int> a(30, INF);
	vector<string>  s(n);
	for(int i = 0, i_len = (int)n; i < i_len; ++i){
		cin >> s[i];
	}

	for(int i = 0; i < n; ++i){
		vector<int> b(30, 0);
		for(auto c: s[i]){
			b[c -'a']++;
		}
		for(int i = 0; i < 26; ++i){
			a[i] = min(a[i], b[i]);
		}
	}

	string ans{};
	for(int i = 0; i < 26; ++i){
		ans+=string(a[i], 'a'+i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 8)
N = int(input())
graph = [[] * N for _ in range(N)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append([b, c])
    graph[b].append([a, c])
    
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

depth = [0] * N
def dfs(v, p, d):
    depth[v] = d
    for new_v_list in graph[v]:
        new_v = new_v_list[0]
        if new_v == p:
            continue
        dfs(new_v, v, d + new_v_list[1])

dfs(K-1, -1, 0)
for i in range(Q):
    print(depth[xy[i][0] - 1] + depth[xy[i][1] - 1])

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

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int H,W,A,B; cin >> H >> W >> A >> B;
  rep(h, H){
    rep(w, W){
      if(0 <= h && h < B && 0 <= w && w < A) std::cout << 1;
      else if(B <= h && h < H && A <= w && w < W) std::cout << 1;
      else std::cout << 0;
    }
    std::cout << '\n';
  }
}


Measured memory_bytes: 1280
from collections import deque

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

graph = [[] for _ in range(N * N)]
ins = [0] * (N * N)

for i, nodes in enumerate(A):
    for j1, j2 in zip(nodes[:-1], nodes[1:]):
        n1 = max(i, j1 - 1) * N + min(i, j1 - 1)
        n2 = max(i, j2 - 1) * N + min(i, j2 - 1)
        graph[n1].append(n2)
        ins[n2] += 1

visited = [False] * (N * N)
for i in range(N):
    visited[N * i + i] = True

que = deque()
for i, v in enumerate(ins):
    if v == 0:
        que.append((i, 1))

dist = [0] * (N * N)
while que:
    cur, d = que.popleft()
    
    visited[cur] = True
    dist[cur] = d
    for v in graph[cur]:
        if visited[v]:
            continue
            
        ins[v] -= 1
        if ins[v] == 0:
            que.append((v, d + 1))

print(max(dist) if all(visited) else -1)


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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    ll n, k;
    cin >> n >> k;

    ll ans = k;
    rep(i, n-1){
        ans *= k-1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int n, m;
    cin >> n >> m;
    vector<pair<pair<int, int>, int>> city(m);
    auto c = 0;
    for(auto & in : city){
        cin >> in.first.first >> in.first.second;
        in.second = c++;
    }
    sort(city.begin(), city.end());
    auto city_flg = 0;
    auto city_number = 0;
    vector<string> ans(m);
    for(auto &x : city){
        if(city_flg != x.first.first){
            city_number = 1;
        }
        stringstream ss;
        ss << setw(6) << setfill('0') << x.first.first << setw(6) << setfill('0') << city_number++;
        ans[x.second] = ss.str();
        city_flg = x.first.first;
    }
    for(const auto & x : ans){
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 9472
#include <iostream>
#include <vector>

using namespace std;

int main(void){
  int n;
  cin >> n;
  vector<int> b(n);

  for (int i = 0; i < n; i++)
    cin >> b[i];


  int check = 0;
  for (int i = 0; i < n; i++){
    for (int j = i; j < n; j++){
      int ok = 1;
      int t = b[i];
      b[i] = b[j];
      b[j] = t;

      for (int k = 0; k < n-1; k++){
        if (b[k] > b[k+1])
          ok = 0;
      }
      t = b[i];
      b[i] = b[j];
      b[j] = t;

      if (ok)
        check = 1;
    }
  }


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

Measured memory_bytes: 384
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>

using namespace std;

int gcd(int a,int b)
{
     return b ? gcd(b,a%b) : a;
}

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	set<int> s;
	for(int i=0;i<n;i++)  scanf("%d",&a[i]);
	int gc=gcd(a[0],a[1]);
	for(int i=2;i<n;i++)	gc=gcd(gc,a[i]);
	if(gc!=1)
	{
		cout<<"not coprime"<<endl;
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]==1)	continue;
		for(int j=1;j*j<=a[i];j++)
		{
			if(a[i]%j==0)
			{
				if((j!=1 && s.count(j)) || s.count(a[i]/j))
				{
					cout<<"setwise coprime"<<endl;
					return 0;
				}
				s.insert(j);
				s.insert(a[i]/j);
			}
		}
	}
	cout<<"pairwise coprime"<<endl;
	return 0;
}

Measured memory_bytes: 7292
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

# t = int(stdin.readline())
# for _ in range(t):
# n, m = map(int, stdin.readline().split())
# nums = list(map(int, stdin.readline().split()))
# n = int(input())
# if n%10 in [2, 4, 5, 7, 9]:
#     print('hon')
# elif n%10 in [0, 1, 6, 8]:
#     print('pon')
# else:
#     print('bon')

k = int(input())
s = input()

ans = s[:k] + ('...' if len(s) > k else '')
print(ans)

Measured memory_bytes: 77172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    while(n--){
        int x; cin >> x;
        ans += 2 * min(x, (k-x));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// ProblemURL : https://atcoder.jp/contests/agc023/tasks/agc023_a
// ---------------------------------------------
package main

import "fmt"

func comb(n, r int64) int64 {
	if n < 0 || r < 0 || r > n {
		return 0
	}
	if r > n-r {
		r = n - r
	}
	x := int64(1)
	for i := int64(0); i < r; i++ {
		x *= (n - i)
		x /= (i + 1)
	}
	return x
}

func main() {
	var n int64
	fmt.Scan(&n)
	as := make([]int64, n)
	for i := range as {
		fmt.Scan(&as[i])
	}

	cs := make([]int64, n+1)
	for i := range as {
		cs[i+1] = cs[i] + as[i]
	}

	m := make(map[int64]int64, n+1)
	for _, x := range cs {
		m[x]++
	}

	ans := int64(0)
	for _, count := range m {
		ans += comb(count, 2)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 11264
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();
        int d = 0;
        if(a==b){
            if(a<c){
                d = 1;
            }
        }
        else if(a==c){
            if(a<b){
                d = 1;
            }
        }
        else if(c==b){
            if(c<a){
                d = 1;
            }
        }
        
        if(d==1){
            System.out.println("YES"); 
        }
        else{
            System.out.println("NO"); 
        }
        scan.close();
    }
}

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

int main()
{
	int n, m;
	while(cin>>n>>m){
		if(!n&&!m) break;
		queue<int> q;
		for(int i=1; i<=n; i++) q.push(i);
		while(q.size()!=1){
			for(int i=1; i<m; i++){
				int tmp =q.front();
				q.pop();
				q.push(tmp);
			}
			q.pop();
		}
		cout << q.front() << endl;
	}
	return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100;
const int mod = 1000000007;

int lis(vector<int> arr){
    vector<int> dp(arr.size(), inf);
    for(auto e: arr){
        dp[distance(dp.begin(), lower_bound(dp.begin(), dp.end(), e))] = e;
    }
    int i = 0; while(i < dp.size() && dp[i] < inf) i++;
    return i;
}

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

    int n; cin >> n;
    vector<int> arr; 
    
    rep(i,0,n){
        int t; cin >> t; arr.push_back(t);
    }

    cout << lis(arr) << endl;



}


Measured memory_bytes: 5248
#include <stdio.h>
int main() {
	while(1){
		int h,m,i,j;
		scanf("%d %d",&h,&m);
		if(h == 0 && m == 0) break;
		for(i=0;i<h;i++){
			if(i%2 == 0){
				for(j=0;j<(m/2);j++)printf("#.");
				if(m%2 != 0)printf("#");
			}
			else{
				for(j=0;j<(m/2);j++)printf(".#");
				if(m%2 != 0)printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>  
using namespace std;
 
map<string, bool> memo;
 
bool parse(string s) {
  if(memo.find(s) != memo.end()) return memo[s];
  if(s == "") return 1;
  int const size = s.size();
  if(s[0] != 'm' || s[size-1] != 'w') return memo[s] = 0;
    
  bool ok = 0;
  for(int i=1; i<size; i++) {
    if(s[i] == 'e') {
      if(parse(s.substr(1, i-1))
	 && parse(s.substr(i+1, size-i-2))
      ) return memo[s] = 1;
    }
  }
  return memo[s] = 0;
}
  
string checker(string s) {
  return parse(s) ? "Cat" : "Rabbit"; 
}
  
int main() {
  string s; cin >> s;
    
  cout << checker(s) << endl;
    
  return 0;
}
/*
以下は無駄なことしてて2秒くらいかかるコード
bool parse(string s) {
  if(memo.find(s) != memo.end()) return memo[s];
  if(s == "") return true;
  int const size = s.size();
    
  bool ok = 0;
  for(int i=1; i<size; i++) {
    if(s[i] == 'e') {
      string temp;
      string t = "m";
      if(i-1>=0) {
        if(parse(temp = s.substr(1, i-1))) t+=temp;
        else continue;
      }
      t += "e";
      if(size-i-2>=0) {
        if(parse(temp = s.substr(i+1, size-i-2))) t+=temp;
        else continue;
      }
      t +="w";
      ok |= s == t;
    }
  }
  return memo[s] = ok;
}
*/ 

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

int main(){
    string s;
    cin>>s;
    string t;
    rep(i,s.size()){
        if(i%2==0) t += s[i];
    }
    cout << t << endl;
}


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

using namespace std;

int findLoc(long long ppl, const vector<int> &vals) {
	for (auto e: vals) {
		ppl = ppl - (ppl % e);
		if (ppl < 2) break;
	}
	if (ppl > 2) return 1;
	else if (ppl == 2) return 0;
	else return -1;
}

void solve(long long ppl, const vector<int> &vals) {
	// int worst = ppl;
	// int best = ppl;

	auto l = ppl;
	auto r = 0x7FFFFFFFFFFF;
	while (l <= r) {
		auto mid = (l+r)/2;
		auto where = findLoc(mid, vals);
		if (where == 1) {
			r = mid-1;
		} else if (where == 0) {
			l = mid+1;
		}
	}
	auto best = (l+r)/2;

	l = 2;
	r = ppl;
	while (l <= r) {
		auto mid = (l+r)/2;
		auto where = findLoc(mid, vals);
		if (where == 0) {
			r = mid-1;
		} else if (where == -1) {
			l = mid+1;
		}
	}
	auto worst = 1 + ((l+r)/2);
	cout << worst << ' ' << best;
}

int main() {
	int K;
	cin >> K;
	vector<int> vals(K);
	for (auto &v: vals) {
		cin >> v;
	}
	long long l = 2;
	long long r = 0x7FFFFFFFFFFF;
	while (l <= r) {
		auto mid = (l+r)/2;
		auto where = findLoc(mid, vals);
		if (where == 1) {
			r = mid-1;
		} else if (where == -1) {
			l = mid+1;
		} else {
			solve(mid, vals);
			return 0;
		}
	}
	cout << -1;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int a, b;
	char s;
	
	scanf("%d", &a);
	
	while (1){
		scanf(" %c ", &s);
		
		if (s == '='){
			break;
		}
		scanf("%d", &b);
		
		if (s == '*'){
			a *= b;
		}
		else if (s == '/'){
			a /= b;
		}
		else if (s == '+'){
			a += b;
		}
		else if (s == '-'){
			a -= b;
		}
	}
	
	printf("%d\n", a);
	
	return (0);
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;
int main(void){
    // Here your code !

int n;

while(cin>>n){
    int count=0;

for(int a=0;a<=9;a++){
for(int b=0;b<=9;b++){
    for(int c=0;c<=9;c++){
        for(int d=0;d<=9;d++){
         if(a+b+c+d==n) count++;
        }}}}
cout<<count<<endl;
}

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N;
string s;

void rec(int i, int k) {
  if (i == N) {
    cout << s << endl;
    return;
  }

  for (int j = 0; j < (int)(k); ++j) {
    s[i] = char(j + 'a');
    rec(i + 1, max(k, j + 2));
  }
}

int main() {
  cin >> N;
  s.resize(N, ' ');
  s[0] = 'a';
  rec(1, 2);
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<Int> ans;
    int q; cin>>q;
    for(int i=0; i<q; i++){
        string a,b; cin>>a;
        if(a=="0"){
            cin>>b;
            Int x=stoll(b);
            ans.emplace_back(x);
        } 
        else if(a=="1"){
            cin>>b;
            Int p =stoll(b);
            cout<<ans[p]<<endl;
        }
        else{
            ans.pop_back();
        }
    }
    return 0;
}


Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;
    int k;
    cin>>n>>k;

    ll min=0,max=0;

    rep(i,0,k)
    {
        min+=i;
    }
    for(i=n;i>n-k;i--)max+=i;
    j=i;
    ll ans=0;
    ans+=max-min+1;

    rep(i,k,n+1)
    {
        min+=i;
        max+=j;
        j--;
        ans+=max-min+1;
        ans%=mod;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3648
N = int(input())
data = []

for i in range(N):
    x, y, h = map(int, input().split())
    data.append([x, y, h])

data = sorted(data, key=lambda x: x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        flag = True
        H = data[0][2] + abs(data[0][0]-cx) + abs(data[0][1]-cy)
        for i in range(1, len(data)):
            if not max(H - abs(data[i][0]-cx) - abs(data[i][1]-cy), 0) == data[i][2]:
                flag = False
                break

        if flag:
            print(cx, cy, H)
            exit()


Measured memory_bytes: 3064
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))
    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    return dfs(i + 1, f + s[i + 1]) + \
           dfs(i + 1, f + "+" + s[i + 1])
s = input()
n = len(s)
print(dfs(0, s[0]))

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int M=1000000;
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int m=in.nextInt();
			int cost[][]=new int[n][n];
			int mincost[]=new int[n];//頂点iへの辺の最小コスト
			boolean use[]=new boolean[n];//頂点iが部分全域木に含まれているか
			int total=0;//answer
			for(int i=0;i<n;i++)
				Arrays.fill(cost[i], M);
			Arrays.fill(mincost, M);
			Arrays.fill(use, false);
			for(int i=0;i<n;i++)
				cost[i][i]=0;
			for(int i=0;i<m;i++)
			{
				String str[]=in.next().split(",");
				int s=Integer.valueOf(str[0]);
				int t=Integer.valueOf(str[1]);
				int c=Integer.valueOf(str[2]);
				cost[s][t]=c;
				cost[t][s]=c;
			}
			mincost[0]=0;
			for(;;)
			{
				int v=-1;//追加する頂点				
				for(int j=0;j<n;j++)//追加する頂点を探す
					if(!use[j]&&(v==-1||mincost[v]>mincost[j]))
						v=j;
				if(v==-1) //全ての頂点を選んだ
					break;
				if(mincost[v]!=0)
					total+=((mincost[v]/100)-1);
				use[v]=true;
				for(int j=0;j<n;j++)//追加した頂点と繋がっている辺を調べ最小コストを更新
				{
					if(!use[j]&&mincost[j]>cost[v][j])
						mincost[j]=cost[v][j];
				}
			}
			System.out.println(total);
		}
	}
}

Measured memory_bytes: 13000
/*
    	Name:
    	Author: xiaruize
    	Date:
    */
     
    #include<algorithm>
    #include<bitset>
    #include<cctype>
    #include<cerrno>
    #include<clocale>
    #include<cmath>
    #include<complex>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<ctime>
    #include<deque>
    #include<exception>
    #include<fstream>
    #include<functional>
    #include<limits>
    #include<list>
    #include<map>
    #include<iomanip>
    #include<ios>
    #include<iosfwd>
    #include<iostream>
    #include<queue>
    #include<set>
    #include<sstream>
    #include<stack>
    #include<stdexcept>
    #include<streambuf>
    #include<string>
    #include<utility>
    #include<vector>
    #include<cwchar>
    #include<cwctype>
    using namespace std;
    #define ull unsigned long long
    #define MOD 1000000007
    #define ALL(a) (a).begin(), (a).end()
    #define forn(i, n) for (int i = 0; i < int(n); i++)
    #define ll long long
    #define form(i,j,n) for(int i=int(j);i<=int(n);i++)
    #define pb push_back
    #define mk make_pair
    #define pii pair<int,int>
    #define pis pair<int,string>
    #define sec second
    #define sz(a) int((a).size())
     
    inline int read()
    {
        char ch=getchar();
        int x=0,f=1;
        while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
        return x*f;
    }
    #define int ll
    int a[200005];
    int dp[200005];
    int sum[200005];
     
    signed main()
    {
     	ios::sync_with_stdio(false);
    	cin.tie(0);
     	//freopen(".in","r",stdin);
    	//freopen(".out","w",stdout);
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>a[i];
    		if(i!=1)
    			sum[i]=sum[i-2]+a[i];
    		else
    			sum[1]=a[1];
    	}
    	for(int i=2;i<=n;i++)
    	{
    		if(i%2)
    			dp[i]=max(dp[i-2]+a[i],dp[i-1]);
    		else
    			dp[i]=max(dp[i-2]+a[i],sum[i-1]);
    	}
    	cout<<dp[n]<<endl;
    	return 0;
    }

Measured memory_bytes: 8348
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
// numeric_limits<ll>::max()
// cout << setprecision(20) << double << endl;

int main(void)
{
    ll r, D, x;
    cin >> r >> D >> x;
    for (ll i = 0; (i < 10); ++i) {
        x = r*x-D;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N, L = map(int, input().split())
A = list(map(int, input().split()))
l = max_2 = A[0] + A[1]
idx = 0
for i in range(N-2):
  l += A[i+2] - A[i]
  if l > max_2:
    max_2 = l
    idx = i + 1

if max_2 < L:
  print('Impossible')
else:
  print('Possible')
  for i in range(1, idx + 1):
    print(i)
  for i in range(N-1, idx, -1):
    print(i)

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

int A, B, C;

int dfs(int a, int b, int c, vector<int> &l, int idx, int cost) {
        if (idx == l.size()) {
                if (a == 0 || b == 0 || c == 0) {
                        return 1000000000;
                }
                int h = cost + abs(A - a) + abs(B - b) + abs(C - c) - 30;
                return h;
        }
        int res = 1000000000;

        res = min(res, dfs(a,          b,          c,          l, idx + 1, cost));
        res = min(res, dfs(a + l[idx], b,          c,          l, idx + 1, cost + 10));
        res = min(res, dfs(a,          b + l[idx], c,          l, idx + 1, cost + 10));
        res = min(res, dfs(a,          b,          c + l[idx], l, idx + 1, cost + 10));

        return res;
}

int main() {
        int N;
        cin >> N >> A >> B >> C;
        vector<int> l(N);
        for(int i = 0; i < N; ++i) {
                cin >> l[i];
        }
        int res = dfs(0, 0, 0, l, 0, 0);
        cout << res << endl;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using std::cin;
using std::cout;
using std::endl;

char encode(char c, int n) {
	char ret = c;
	for (int i = 0; i < n; i++) {

		if (ret == 'a') {
			ret = 'Z';
		}
		else if (ret == 'A') {
			ret = 'z';
		}
		else {
			ret -= 1;
		}
	}
	return ret;
}

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

	while (n != 0) {
		std::vector<int> k(n);
		std::string str;
		for (int i = 0; i < n; i++) {
			cin >> k[i];
		}
		
		cin >> str;

		for (int i = 0; i < str.length(); i++) {
			cout << encode(str[i], k[i%n]);
		}
		cout << endl;

		cin >> n;
	}

	return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N , M , C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for(int i = 0; i < M; i++) cin >> B[i];
  int counter = 0;
  
  for(int i = 0; i < N; i++){
    vector<int> A(M);
    int T = 0;
    for(int j = 0; j < M; j++){
      cin >> A[j];
      T += A[j] * B[j];
    }
    T += C;
    if(T > 0) counter++;
  }
  cout << counter;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;

const int maxn=1000010;
const int inf=0x3f3f3f3f;

ll n;
ll dp[maxn];
ll a[maxn];
ll k;
int main()
{
    gbtb;
    cin>>n>>k;
    repd(i,1,n)
    {
        cin>>a[i];
    }
    dp[1]=0;
    dp[0]=0;
    repd(i,2,n)
    {
        dp[i]=inf;
    }
    repd(i,2,n)
    {
        for(int j=i-1;j>=max(1ll,i-k);j--)
        {
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    cout<<dp[n];
    return 0;
}

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

using namespace std;

const int max_n = 5, inf = 1000111222;

int n = 4, a[max_n][max_n];
vector<int> v;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        a[u][v] = 1;
        a[v][u] = 1;
    }
    for (int i = 1; i <= n; ++i) {
        v.push_back(i);
    }
    do {
        bool ok = true;
        for (int i = 0; i + 1 < v.size(); ++i) {
            if (!a[v[i]][v[i + 1]]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << "YES" << endl;
            return 0;
        }
    } while (next_permutation(v.begin(), v.end()));
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
for i in range(1, 3501):
    for j in range(i, 3501):
        a = i * j
        b = i + j
        if not 4 * a == n * b:
            k = (n * a) / (4 * a - n * b)
            if k % 1 == 0 and k > 0:
                print(i, j, int(k))
                exit()

Measured memory_bytes: 40684
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o B.exe B.cpp 
Execute: ./B
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	int n; 
	cin >> n; 
	int d[n][2]; 
	for(int i = 0; i < n; i++) 
		cin >> d[i][0] >> d[i][1]; 
		
	bool answer = false; 
	for(int i = 2; i < n; i++) {
		if(	d[i][0] == d[i][1] && 
			d[i-1][0] == d[i-1][1] && 
			d[i-2][0] == d[i-2][1]) {
			answer = true;
		}
	}
	
	if(answer) {
		cout << "Yes" << endl; 
	} else {
		cout << "No" << endl; 
	}
	
	return 0; 
} 


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll h,w,m[405][405],dx[4]={1,0,-1,0},dy[4]={0,1,0,-1},n,ans;
vector<int>g[160005];
bool vis[160005];
ll od,ev;
void dfs(int v){
    vis[v]=true;
    if((v/w+v%w)%2)od++;
    else ev++;
    for(int i=0;i<g[v].size();i++){
        int u=g[v][i];
        if(vis[u])continue;
        dfs(u);
    }
}
int main(void){
    cin>>h>>w;
    n=h*w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c;
            scanf(" %c",&c);
            if(c=='#')m[i][j]=1;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int k=0;k<4;k++){
                int y=i+dy[k],x=j+dx[k];
                if(x>=0&&x<w&&y>=0&&y<h&&m[i][j]!=m[y][x]){
                    g[y*w+x].PB(i*w+j);
                    g[i*w+j].PB(y*w+x);
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        if(!vis[i]){
            od=0;
            ev=0;
            dfs(i);
            ans+=od*ev;
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 17920
print('1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.split(', ')[int(input())-1])


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

ll N, K;
int nxt[70][220000];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> nxt[0][i];

	for (int i = 1; i <= 60; i++)
		for (int j = 1; j <= N; j++)
			nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];

	int pos = 1;
	for (int i = 0; K; i++) {
		if (K & 1) pos = nxt[i][pos];
		K /= 2;
	}
	cout << pos << '\n';
	return 0;
}

Measured memory_bytes: 51532
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		String tmp = in.readLine();
		int N = Integer.parseInt(tmp);

		tmp = in.readLine();

		String[] Ws = tmp.split(" ");

		int max = Integer.parseInt(Ws[0]);
		int Hi ;

		int count =1;
		for(int i=1;i<N;i++){
			Hi = Integer.parseInt(Ws[i]);
			if(max <= Hi){
				max = Hi;
				count++;
			}
		}

		System.out.print(count);

	}


}


Measured memory_bytes: 23252
import sys

K = int(input())


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


if K % 2 == 0 or K % 5 == 0:
    print("-1")
    sys.exit()

x = 1
for i in range(1, 1000000):
    if (x * 7) % K == 0:
        print(i)
        sys.exit()
    x = (x + pow(10,i,K))%K

print("-1")
sys.exit()

Measured memory_bytes: 63636
n=int(input())  #数値入力 「N」だけの入力のとき
#n=2
a=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#a = [100, 1, 1]
b=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#b=[1,100]
ans = 0

for i in range(n):
    if a[i]>=b[i]:
        ans+=b[i]
        a[i]-=b[i]
        b[i]=0
    else:
        ans+=a[i]
        b[i]-=a[i]
        a[i]=0
    if a[i+1]>=b[i]:
        ans+=b[i]
        a[i+1]-=b[i]
        b[i]=0
    else:
        ans+=a[i+1]
        b[i]-=a[i]
        a[i+1]=0
print(ans)

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

flg = None
cur = a[0]
cnt = 1

for v in a[1:]:
  if v > cur:
    if flg is None:
      flg = True
    if not flg:
      flg = None
      cnt += 1
  if v < cur:
    if flg is None:
      flg = False
    if flg:
      cnt += 1
      flg = None
  cur = v
print(cnt)

Measured memory_bytes: 14100