akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<queue>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stdlib.h>
#include<utility>
#include<unordered_map>
using namespace std;
#define ll long long
#define pb push_back
#define PI acos(-1)
#define INF 0x3f3f3f3f
inline int re()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
/*int a[22];
int vis[22];
int n,m;

void print(int num)
{
    for(int i=1;i<=m;i++)
    {
        if(vis[i]==1){
            num--;
            printf("%d",a[i]);
            if(num==0) puts("");
            else printf("+");
        }
    }
}
void dfs(int pos,int sum,int num)
{
    if(sum>n) return;
    if(sum==n)
    {
        print(num);
        return;
    }
    if(pos==m+1) return;
    vis[pos]=1;
    dfs(pos+1,sum+a[pos],num+1);
    vis[pos]=0;
    dfs(pos+1,sum,num);
}



int main()
{
    while(1)
    {
        cin>>n>>m;
        if(n==0&&m==0) break;
        for(int i=1;i<=m;i++)
        {
            cin>>a[i];
        }
        dfs(1,0,0);
    }
}

*/

bool cmp(int a,int b)
{
    return a>b;
}

int a[1111];
int main()
{
    ll n,k;
    cin>>n>>k;
    ll t=n%k;
    if(abs(t-k)<t) t=abs(t-k);
    cout<<t;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,q,i;
    cin>>n>>q;
    int a[q];
    for(i=0;i<q;i++)
    {
        cin>>a[i];
        n=n-a[i];
    }
    if(n<=0)
    {
        cout<<"Yes";
    }
    else
        cout<<"No";


}


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

string s;
int p, q, r;

int not_[3] = {2, 1, 0};
int and_[3][3] = {{0, 0, 0}, {0, 1, 1}, {0, 1, 2}};
int or_[3][3] = {{0, 1, 2}, {1, 1, 2}, {2, 2, 2}};

int f(int &i) {
    int t, x, y;
    char op;
    switch (s[i++]) {
        case '0':
            return 0;
        case '1':
            return 1;
        case '2':
            return 2;
        case 'P':
            return p;
        case 'Q':
            return q;
        case 'R':
            return r;
        case '-':
            return not_[f(i)];
        case '(':
            x = f(i);
            op = s[i++];
            y = f(i);
            i ++;
            return (op == '*') ? and_[x][y] : or_[x][y];
    }
}

int main() {
    while (cin >> s) {
        if (s == ".") break;
        int cnt = 0;
        for (p=0; p<3; ++p)
            for (q=0; q<3; ++q)
                for (r=0; r<3; ++r) {
                    int i = 0;
                    if (f(i) == 2) cnt ++;
                }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  int ans = 1;
  for(int i=2; i<=x; i++) {
    for(int j=2; j<11; j++) {
      if(pow(i,j) > x) {
        break;
      } else if(pow(i,j) <= x && pow(i,j) > ans) {
        ans = pow(i,j);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp
//#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;




int main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> h(1000000);
  vector<ll> dp(1000000, 0);
  vector<ll> ok(1000000, 1);
  rep(i,M) cin >> h[i];
  rep(i,M){
    ok[h[i]] = 0;
  }
  dp[0] = 1;
  for(int i = 0;i <= N;i++){
    if(ok[i+1]) dp[i+1] += dp[i];
    dp[i+1] = dp[i+1]%MOD;
    if(ok[i+2]) dp[i+2] += dp[i];
    dp[i+2] = dp[i+2]%MOD;
  }
  /*
rep(i,N+1){
  cout << dp[i] << endl;
} */
  cout << dp[N]%MOD << endl;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

struct edge{ll from,to,cost;};
edge es[2222];

int main(){
  ll n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    es[i]=(edge){a,b,-c};
  }

  ll d[1111];
  fill_n(d,1111,1LL<<60);
  d[1]=0;
  
  for(int cn=0;cn<n-1;cn++){
    for(int i=0;i<m;i++){
	 ll from=es[i].from;
	 ll to=es[i].to;
	 ll cost=es[i].cost;
	 if(d[from]!=1LL<<60 && d[to]>d[from]+cost){
	   d[to]=d[from]+cost;
	 }
    }
  }

  bool neg[1111];
  fill_n(neg,1111,false);

  for(int cn=0;cn<n;cn++){
    for(int i=0;i<m;i++){
	 ll from=es[i].from;
	 ll to=es[i].to;
	 ll cost=es[i].cost;
  
	 if(d[from]==1LL<<60)continue;

	 if(d[to]>d[from]+cost){
	   d[to]=d[from]+cost;
	   neg[to]=true;
	 }

	 if(neg[from])neg[to]=true;
    }
  }
  if(neg[n])cout<<"inf"<<endl;
  else cout<<-d[n]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long f[400];
int main() {
	int n;
	f[0] = 2;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		f[i] = f[i - 1] * 2 + 2;
	}
	cout << f[n] << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    cout<<n*(n-1)/2-n/2<< endl;
    rep(i,n)for(int j=i+1;j<n;j++)if(i+j!=n-1-n%2)cout<<i+1<<" "<<j+1<<endl;
}

Measured memory_bytes: 256
from math import gcd
def solve():
  T = int(input())
  ans = ['No']*T
  for i in range(T):
    A,B,C,D = map(int, input().split())
    if A<B:
      continue
    now = A-(-(-(A-C)//B))*B
    if now<0:
      continue
    if D<B:
      continue
    if D%B==0:
      ans[i] = 'Yes'
      continue
    if C>=B:
      ans[i] = 'Yes'
      continue
    if B-gcd(D%B,B)>C:
      continue
    ans[i] = 'Yes'
  return ans
print(*solve(),sep='\n')

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

int main(void){
  int N;
  char s[101],t[101],str[201];
  int i,j,k=0;

  scanf("%d%*c",&N);
  scanf("%s%*c",s);
  scanf("%s%*c",t);

  for(i=1;i<=N;i++){
    if(strncmp(s+N-i,t,i)==0){
      k=i;
    }
  }

  printf("%d\n",2*N-k);
  return 0;
  
}


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

int main() {
  	int N;
  	cin >> N;
	vector<int> v(N);

  	for(int i = 0; i < N; i++) {
	  cin >> v.at(i);
    }
  	
  	sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
  
  	int ans;
	for(int i = 0; i < N; i++) {
     for(int j = i + 1; j < N; j++) {
       int a = v.at(i);
       int b = v.at(j);
       int m = a - b;
       for(int k = j + 1; k < N; k++) {
         if(v.at(k) > m) {
           ans++;         	
         }
       }
     }
    }
  
  	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
long long counter=0;
long long n;
cin>>n;
long long a,b;
cin>>a>>b;
if(a>b){
cout<<0<<endl;}
else if(a==b){
cout<<1<<endl;}
else if(n==1){
cout<<0<<endl;}
else if(n==2){
cout<<1<<endl;}
else{
cout<<(b*(n-1)+a)-(a*(n-1)+b)+1<<endl;}}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        List<Integer> candy = new ArrayList<Integer>(){
            {
                add(Integer.parseInt(sc.next()));
                add(Integer.parseInt(sc.next()));
                add(Integer.parseInt(sc.next()));
            }
        };
        
        Collections.sort(candy, Comparator.reverseOrder());
        
        if(candy.get(0) == candy.get(1) + candy.get(2)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21588
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    S = input()[:-1]
    if S.isupper():
        print("A")
    else:
        print("a")


if __name__ == '__main__':
    main()

Measured memory_bytes: 72668
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
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; }
using namespace std;

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

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

    rep(i,n-m+1)rep(j,n-m+1){
        bool can=true;
        rep(k,m)rep(l,m){
            if(b[k][l]!=a[i+k][j+l]){
                can=false; k=l=m;
            }
        }
        if(can){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PIE 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
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;}
using namespace std;

int main(){
  double R;
  cin>>R;
  R*=2;
  cout<<setprecision(9)<<R*PIE<<endl;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long

const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


int main() {
    int n; cin >> n;
    double t, a; cin >> t >> a;
    V<double> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    int ans = 1;
    double pre = abs(a - (t - h[0] * 0.006));
    for(int i = 1; i < n; i++){
        double tmp = t - h[i] * 0.006;
        if(abs(a - tmp) < pre){
            pre = abs(a - tmp);
            ans = i + 1;
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3756
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;

int main() {
   int n;
   string m;
   cin >> n >> m;
   int sum = 0;
   char tmp;
   int flag = 0;
  
   for(int i = 0;i<n;i++){
     
     
   //  cout << tmp << endl;
     
     if (tmp!=m[i]){
       sum = sum + 1;
       flag = 0;
     }
     
     if(flag ==0){
     tmp = m[i];
       flag = 1;
     }
     
   }
  
  cout << sum;
   
  return 0;
}

Measured memory_bytes: 3704
#!/usr/bin/env python3
from itertools import permutations


def f(i, j):
    return ((x[i] - x[j])**2 + (y[i] - y[j])**2)**0.5


n = int(input())
x = [None] * n
y = [None] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())
ans = 0
for s in permutations(range(n)):
    tmp = 0
    for i in range(n - 1):
        tmp += f(int(s[i + 1]), int(s[i]))
    ans += tmp
for i in range(n):
    ans /= i + 1
print(ans)


Measured memory_bytes: 3064
from itertools import permutations


def solve(string):
    n, a, b, c, *l = map(int, string.split())
    ans = 3000

    for _l in permutations(l):
        for i in range(1, len(l) - 1):
            for j in range(i + 1, len(l)):
                for k in range(j + 1, len(l) + 1):
                    tmp = 10 * (i - 1) + abs(a - sum(_l[:i])) + 10 * (j - i - 1) + abs(
                        b - sum(_l[i:j])) + 10 * (k - j - 1) + abs(c - sum(_l[j:k]))
                    if tmp < ans:
                        ans = tmp
    return str(ans)


if __name__ == '__main__':
    n, a, b, c = map(int, input().split())
    print(solve('{} {} {} {}\n'.format(n, a, b, c) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 73180
#include<bits/stdc++.h>
using namespace std;
#define l long
#define ll long long
#define ull unsigned long long
#define mm 1000000007
int main()
{
    int n,m;cin>>n>>m;
 ull dp[n][m];
    for(int i=0;i<n;i++)
    {for(int j=0;j<m;j++)
    {
       char c;cin>>c;
       if(c=='.'){dp[i][j]=0;}
       else{dp[i][j]=-1;}
        
    }
    }bool t=false,f=false;
    for(int i=0;i<n;i++)
    {
        if(dp[i][0]==-1){dp[i][0]=0;t=true;}
        if(!t) dp[i][0]=1;
    }
    for(int j=0;j<m;j++)
    {
        if(dp[0][j]==-1){dp[0][j]=0;f=true;}
    if(!f)dp[0][j]=1;
    }
    
    for(int i=1;i<n;i++)
    {for(int j=1;j<m;j++)
    {
        if(dp[i][j]==-1){dp[i][j]=0;continue;}
          
          dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mm;
       }
    }
    
  /*  for(int i=0;i<n;i++)
    {for(int j=0;j<m;j++)
    cout<<dp[i][j]<<" ";
    cout<<endl;
    }*/
   cout<<dp[n-1][m-1];
    
    
    
}

Measured memory_bytes: 8064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class EThreeSubstrings {
public:

    bool match(char c1, char c2) {
      return (c1 == '?' || c2 == '?' || c1 == c2);
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      string a, b, c;
      cin >> a >> b >> c;

      int A = a.size();
      int B = b.size();
      int C = c.size();

      vector<bool> ab(20000, true);
      vector<bool> bc(20000, true);
      vector<bool> ac(20000, true);

      rep(i, A) rep(j, B) {
        if (!match(a[i], b[j])) ab[i-j+10000] = false;
      }
      rep(i, A) rep(j, C) {
        if (!match(a[i], c[j])) ac[i-j+10000] = false;
      }
      rep(i, B) rep(j, C) {
        if (!match(b[i], c[j])) bc[i-j+10000] = false;
      }

      int ans = A+B+C;
      for(int i=-4000; i<=4000; i++) {
        for(int j=-4000; j<=4000; j++) {
          if (ab[i+10000] && ac[j+10000] && bc[j-i+10000]) {
            int L = min({0, i, j});
            int R = max({A, i+B, j+C});
            chmin(ans, R-L);
          }
        }
      }
      cout << ans << endl;
    }
};

signed main() {
  EThreeSubstrings solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

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

	if (s.length() != (t.length() - 1))
	{
		cout << "No\n";
		return 0;
	}
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] != t[i])
		{
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}

Measured memory_bytes: 3580
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Diagonal String
            var ans = "";

            for(int i = 0; i < 3; i++)
            {
                var c = Console.ReadLine();
                ans += c[i];
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define arr array

using namespace std;

const int e = 2e6 + 69;
const ll mod = 1e9 + 7;

ll a[e], b[e];

//beginner 1999 129


int main()
{
     int a, b, c;
     cin >> a >> b >> c;
     cout << min(min(a+b, a+c), b+c);
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#define pi 3.1415926535
int main()
{
    int n,a;
    scanf("%d",&n);
    int ans[n+1];
    memset(ans,0,(n+1)*sizeof(ans[0]));
    for(int i=0;i<n-1;i++)
    {
        scanf("%d",&a);
        ans[a]++;
    }
    for(int i=0;i<n;i++)
    printf("%d\n",ans[i+1]);
}


Measured memory_bytes: 2508
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var s = ReadLine();
            var pnum = s.Count(c => c == 'p');
            WriteLine(s.Length / 2 - pnum);
        }
    }
}

Measured memory_bytes: 26536
#include <stdio.h>

int main (void) {

	int N, A;

	scanf("%d", &N);
	scanf("%d", &A);

	N -= (int)(N / 500) * 500;

	if (N <= A) {
		printf("Yes\n");
	}else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 128
import numpy as np

N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))

A.sort()
F[::-1].sort()

sum_A = A.sum()
if sum_A <= K:
    ans = 0
else:
    high = (A * F).max()
    low = 0
    mid = (high + low) // 2
    while low < mid < high:
        if sum_A - np.minimum(A, mid // F).sum() <= K:
            high = mid
        else:
            low = mid
        mid = (high + low) // 2
    ans = high

print(ans)


Measured memory_bytes: 38612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();

	}
	static class Task{
		float n;
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			n = in.nextFloat();
			out.print((int)((180-360/n)*n));
			
		}//Solve
	}//task
	
	
	static class InputReader{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		public String next() {
			while(tokenizer == null || ! tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = -1; ++i < n;) 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 = -1; ++i < n;) a[i] = nextLong();
			return a;
		}
		public float nextFloat() {
			return Float.parseFloat(next());
		}
	}
}


Measured memory_bytes: 21332
#include <stdio.h>
#define MAX 101

int main(){
  int i,l,j,k,n,p[MAX],m[MAX][MAX];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&p[i-1]);
    scanf("%d",&p[i]);
  }

  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=1<<21;
      for(k=i;k<=j-1;k++){
	if(m[i][j]<m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])m[i][j]=m[i][j];
	else m[i][j]=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      }}}

  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2104
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#include<set>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
	int v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
int main(){
	int a = read(),b = read();
	if(a >= 10 || b >= 10) printf("-1");
	else printf("%d\n",a * b); 
	return 0;
}


Measured memory_bytes: 256
import           Control.Monad
import           Control.Applicative

main = do
    [h, w] <- map read . words <$> getLine
    sss    <- replicateM h getLine
    if existsSoloist sss w then putStrLn "No" else putStrLn "Yes"

existsSoloist sss w =
    any or
        .   zipWith2x isTarget sss
        .   foldl1 (zipWith2x (+))
        $   shifters
        <*> [map2x (fromEnum . ('#' ==)) sss]
  where
    shifters = [shiftRight, shiftLeft, shiftUp, shiftDown]
    zeros    = replicate w 0
    shiftFront x xs = x : init xs
    shiftBack x xs = tail xs ++ [x]
    shiftRight = map $ shiftFront 0
    shiftLeft  = map $ shiftBack 0
    shiftUp    = shiftBack zeros
    shiftDown  = shiftFront zeros
    isTarget c x = c == '#' && x == 0
    zipWith2x = zipWith . zipWith
    map2x     = map . map


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

int n, c, mn = 2e9, mx, md;
int main()
{
	int t;
	cin >> n >> t;
	while (n--) {
		scanf("%d", &t);
		if (t < mn) mn = t, mx = 0;
		if (t > mx) {
			mx = t;
			if (mx - mn > md) md = mx - mn, c = 0;
			if (mx - mn == md) c++;
		}
	}
    cout << c << endl;
    return 0;
}

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

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

inline void Main() {
  // code
  int a,b,c;
  cin>>a>>b>>c;

  cout << (c-a+b < 0 ? 0 : c-a+b) << endl;
}

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


Measured memory_bytes: 256
#include <stdio.h>
int main () {
  int a,b,c,d,n;
  scanf ("%d", &n);
  a = n/1000;
  b = (n-1000*a)/100;
  c = (n-1000*a-100*b)/10;
  d = n%10;
  if (a+b+c+d==7) {
    printf("%d+%d+%d+%d=7\n", a,b,c,d);
  } else if (a+b+c-d==7) {
    printf("%d+%d+%d-%d=7\n", a,b,c,d);
  } else if (a+b-c+d==7) {
    printf("%d+%d-%d+%d=7\n", a,b,c,d);
  } else if (a+b-c-d==7) {
    printf("%d+%d-%d-%d=7\n", a,b,c,d);
  } else if (a-b+c+d==7) {
    printf("%d-%d+%d+%d=7\n", a,b,c,d);
  } else if (a-b+c-d==7) {
    printf("%d-%d+%d-%d=7\n", a,b,c,d);
  } else if (a-b-c+d==7) {
    printf("%d-%d-%d+%d=7\n", a,b,c,d);
  } else if (a-b-c-d==7) {
    printf("%d-%d-%d-%d=7\n", a,b,c,d);
  }
  return 0;
}

Measured memory_bytes: 1732
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }
int calc(int s,int e,int n)
{
  int tot=0;
  for(int i=1;i<=n;i++)
  {
    int tmp=i;
    while(tmp>=10)
    {
      tmp/=10;
    }
    if(tmp==s&&(i%10)==e)tot++;
  }

  return tot;
}

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

    // ifstream fin(".in");
    // ofstream fout(".in");

    int ans=0,n;
    cin>>n;
    for(int i=1;i<=9;i++)
    {
      for(int j=1;j<=9;j++)
      {
        int to=calc(i,j,n)*calc(j,i,n);
        ans+=to;
      }
    }
cout<<ans;

    return 0;
  }


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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  int N,T;
  cin >> N >> T;
  vector<int> t(N);
  for(int i = 0; i < N; i++){
    cin >> t[i];
  }
  ll ans = 0;
  for(int i = 1; i < N; i++){
    int gap = t[i] - t[i-1];
    if(gap >= T){
      ans += T;
    }else{
      ans += gap;
    }
  }
  ans += T;
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  1000000007;
int sz[200000],zen[200000],c[200000],ans[200000];bool used[200000];
vector<int> hen[200000];
int dfssz(int a){
     
     sz[a]=1;
     for(auto&& i : hen[a])if(!sz[i])sz[a]+=dfssz(i);
     
     return sz[a];
}
void dfs(int a){
     used[a]=true;
     ans[c[a]]+=2+zen[c[a]]*(zen[c[a]]-1);
     zen[c[a]]-=sz[a];
     ans[c[a]]-=(zen[c[a]]-1)*zen[c[a]];
     int tmp=zen[c[a]];
     for(auto&& i : hen[a])if(!used[i]){
          
          ans[c[a]]-=sz[i]*(sz[i]-1);
          zen[c[a]]=sz[i];
          dfs(i);
     }
     zen[c[a]]=tmp;
     return;
}

     signed main(){
       int n;
       cin>>n;
      for(int i=0;i<n;i++){
           cin>>c[i];c[i]--;
      }
      int a,b;
      for(int i=0;i<n-1;i++){
           cin>>a>>b;a--;b--;
           hen[a].push_back(b);
           hen[b].push_back(a);
      }
      //fill(ans,ans+n,0);
      //fill(sz,sz+n,0);
      fill(zen,zen+n,n);
      dfssz(0);
       fill(used,used+n,false);
      dfs(0);
      for(int i=0;i<n;i++)cout<<ans[i]/2<<endl;

      }

        


Measured memory_bytes: 33404
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc045/tasks/arc061_a

int main() {
    string S; cin >> S;
    int len = S.length();

    ll ans = 0;
    for (int msk = 0; msk < 1 << (len-1); msk++) {
        ll num = S[0] - '0';

        for (int i = 0; i < len-1; i++) {
            if (1 << i & msk) {
                ans += num;
                num = 0;
            }
            num = num * 10 + (S[i+1] - '0');
        }
        ans += num;
    }

    cout << ans << "\n";

    return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n, k; cin >> n >> k;
  double ans = 0;
  for(int i = 1; i <= n; ++i) {
    double add = 1.0/n;
    int p = i;
    while(p < k) {
      p *= 2;
      add /= 2;
    }
    ans += add;
  }
  printf("%0.12f\n", ans);
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 double long double
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 endl '\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> oset;
gp_hash_table<int, int> table;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};



int freq;
int n;
int m[N];
int dpx[N];
int fac[N];
int k;

inline int mul(int a, int b) {return (a * 1ll * b) % MOD;}
inline int add(int a, int b) {a += b; if (a >= MOD)a -= MOD; a %= MOD; return a;}
inline int power(int a, int b) {int rt = 1; while (b > 0) {if (b & 1)rt = mul(rt, a); a = mul(a, a); b >>= 1;} return rt;}
inline int inv(int a) {return power(a, MOD - 2);}


int ncr(int n, int r)
{
    if (r > n)return 0;
    int x = fac[n] * inv(fac[n - r]);
    x %= MOD;
    x = x * inv(fac[r]);
    x %= MOD;
    return x;
}

int dp[N];

void check()
{

    rfor(i, n, 1)
    {

        dp[i] = power(dpx[i], k);
        for (int j = 2 * i ; j <= n ; j += i)
        {
            dp[i] = dp[i] - dp[j] + MOD;
            dp[i] %= MOD;
        }
    }
}




void solve()
{
    cin >> k >> n;
    forn(i, 1, n)
    {
        int a;
        a = i;
        m[a]++;
    }
    n = 0;
    forn(i, 0, N - 1)
    {
        n += m[i];
    }
    //cout << n << "\n";
    //dpx[1] = n;

    forn(i, 1, N - 1)
    {
        for (int j = i ; j < N ; j += i)
            dpx[i] += m[j];
    }





    check();

    int ans = 0;
    forn(i, 1, n)
    {
        //cout << dp[i] << " ";
        ans = add(ans, mul(dp[i], i));
    }
    //nl;
    cout << ans;



}


signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin>>t;
    fac[0] = 1;
    forn(i, 1, N - 1)fac[i] = (fac[i - 1] * i) % MOD;
    while (t--)
    {
        solve();
        nl;
    }



    return 0;

}

//       g++ -g c.cpp ; ./a.out


Measured memory_bytes: 21032
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <complex>
#include <vector>
#include <random>
using namespace std;

#define SZ(x) ((int)x.size())
#define sqr(x) ((x) * (x))
const double PI = acos(-1.0);
const double EPS = 1e-8;
typedef complex<double> point;
inline int dcmp(double x) { return (x > EPS) - (x < -EPS); }
inline double cross(const point &a, const point &b) { return (conj(a) * b).imag(); }
inline double dot(const point &a, const point &b) { return (conj(a) * b).real(); }
inline double cross(const point &a, const point &b, const point &c) { return cross(b - a, c - a); }
inline double dot(const point &a, const point &b, const point &c) { return dot(b - a, c - a); }
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct circle {
  point p;
  double r;
  circle(const point &p, double r): p(p), r(r) {}
  circle() {}
};

circle calc(vector<point> &a, int n, vector<point> &b) {
  circle ret;
  if (SZ(b) == 3) {
    double tmp = 2 * cross(b[0], b[1], b[2]);
    ret.r = abs(b[1] - b[2]) * abs(b[0] - b[1]) * abs(b[0] - b[2]) / abs(tmp);
    double C = sqr(abs(b[0] - b[1]));
    double B = sqr(abs(b[0] - b[2]));
    ret.p = point(b[0].real() - ((b[1] - b[0]).imag() * B - (b[2] - b[0]).imag() * C) / tmp,
                  b[0].imag() + ((b[1] - b[0]).real() * B - (b[2] - b[0]).real() * C) / tmp);
    return ret;
  }
  if (SZ(b) == 2) ret = circle((b[0] + b[1]) / 2.0, abs(b[0] - b[1]) / 2);
  else if (SZ(b) == 1) ret = circle(b[0], 0);
  else ret = circle(point(0, 0), -1); // empty circle!
  for (int i = 0; i < n; ++i) {
    if (abs(ret.p - a[i]) <= ret.r) continue;
    b.push_back(a[i]);
    ret = calc(a, i, b);
    b.pop_back();
  }
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<point> a;
  for (int i = 0; i < n; ++i) {
    double x, y;
    scanf("%lf %lf", &x, &y);
    a.push_back(point(x, y));
  }
  vector<point> b;
  std::shuffle(a.begin(), a.end(), mrand);
  circle c = calc(a, SZ(a), b);
  printf("%.10f\n", c.r);
  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
const int FACT_SIZE=1111111;
int fact[FACT_SIZE];
int inv[FACT_SIZE];
struct fact_exec{
    fact_exec(){
        fact[0]=1;
        for(int i=1;i<FACT_SIZE;i++)fact[i]=fact[i-1]*i%mod;
        inv[FACT_SIZE-1]=mpow(fact[FACT_SIZE-1],mod-2);
        for(int i=FACT_SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    }
}factexec;
int nCk(int n,int k){
    if(n<0|k<0||k>n)return 0;
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int nPk(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*inv[n-k]%mod;
}


int dp[2][1<<19];
int MSB[1<<19];

int dir[22][22];
int N,M,K;

signed main(){
    memset(dir,-1,sizeof(dir));

    rep(i,1<<19){
        MSB[i]=-1;
        for(int j=0;j<19;j++)if(i>>j&1)MSB[i]=j;
    }

    cin>>N>>M>>K;N--;
    rep(i,K){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        dir[a][b]=c;
    }

    dp[0][0]=1;
    int t=0;
    rep(i,M){
        rep(j,N){

            rep(k,1<<N){
                int nk=k;
                if(MSB[k]>=j)nk^=1<<MSB[k];
                nk<<=1;
                nk++;
                if(dir[i][j]!=0)add(dp[1-t][nk],dp[t][k]);

                nk=k;
                nk<<=1;
                if((~nk>>N&1)&&dir[i][j]!=1)add(dp[1-t][nk],dp[t][k]);

                dp[t][k]=0;
            }
            t=1-t;
        }
    }

    cout<<accumulate(dp[t],dp[t]+(1<<N),0ll)%mod<<endl;
    return 0;
}


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

string S,T;

bool check(int i){
    for(int j=0;j<T.length();j++){
        if(S[i+j] != T[j] && S[i+j] !='?' )return false;
    }
    return true;
}

int main(void){
    cin >> S >> T;
    for(int i=S.length()-T.length();i>=0;i--){
        if(check(i)){
            for(int j=0;j<T.length();j++)S[i+j] = T[j];
            for(int j=0;j<S.length();j++)if(S[j] =='?')S[j] = 'a';
            cout << S << endl;
            return 0;
        }   
    }
    cout <<"UNRESTORABLE"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PRINT(s) cout << s << endl;
#define FOR(i, n) for (int i = 0; i < (n); i++)

int main() {

    int n, k;
    cin >> n >> k;
    vector<long long> H(n);
    FOR(i, n) {
        cin >> H[i];
    }
    vector<long long> dp(n, LLONG_MAX);
    
    FOR(i, n) {
        if (i == 0) { 
            dp[0] = 0;
            continue;
        }
        int maxStep = min(i, k);
        for (int j = maxStep; j > 0; j--) {
            dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]));
        }
    }
    
    PRINT(dp[n - 1]);
}


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

int main() {
  int l, r;
  cin >> l >> r;

  if (l <= 0 && 0 <= r) {
    cout << "Zero" << endl;
  } else {
    if (l > 0) {
      cout << "Positive" << endl;
    } else {
      cout << (r - l & 1 ? "Positive" : "Negative") << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())

    if n == 0:
        break

    ans = []

    for count_a in range(1, n + 1):
        for count_b in range(1 + count_a, n + 1):
            for count_c in range(1 + count_b, n + 1):
                if count_a == count_b or count_b == count_c or count_a == count_c:
                    continue

                if count_a + count_b + count_c == x:
                    ans.append([count_a, count_b, count_c])
    # print(ans)
    # 6通り出ちゃうから
    # print(ans)
    print(int(len(ans)))



Measured memory_bytes: 5608
n = int(input())
a = input().split()
a = [int(m) for m in a]

ans = 0
while True:
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] = a[i] // 2
            if i == n - 1:
                ans += 1
        else:
            print(ans)
            exit()

Measured memory_bytes: 3060
import java.util.Scanner;


public class Main {

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

		int N = scanner.nextInt();
		int aMax=0;
		int bMax=0;
		int cMax=0;

		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[N];

		for(int i=0;i<N;i++) {
			a[i] = scanner.nextInt();
			b[i] = scanner.nextInt();
			c[i] = scanner.nextInt();
		}

		aMax = a[0];
		bMax = b[0];
		cMax = c[0];

		for(int i=1;i<N;i++){
			//i-1のデータを退避させる．
			int aTemp = aMax;
			int bTemp = bMax;
			int cTemp = cMax;

			aMax = a[i] + Math.max(bTemp, cTemp);
			bMax = b[i] + Math.max(aTemp, cTemp);
			cMax = c[i] + Math.max(aTemp, bTemp);
//			System.out.println(i + "日目にaを選んだ時の最大幸せ指数:" + aMax);
//			System.out.println(i + "日目にbを選んだ時の最大幸せ指数:" + bMax);
//			System.out.println(i + "日目にcを選んだ時の最大幸せ指数:" + cMax);
		}

		//Math.max で最大値比較
		System.out.println(Math.max(aMax, Math.max(bMax, cMax)));
		scanner.close();
	}

}

Measured memory_bytes: 92348
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n,m;
    cin >> n >> m;
    if(n>1&&m>1){
        print((n-2)*(m-2));
    }else{
        if(n==1&&m==1){
            print(1);
        }else if(n==1){
            print(m-2);
        }else{
            print(n-2);
        }
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

double n, m, d;

double power(double x, int y) {
    if (y == 1) return x;
    ll p = power(x, y >> 1);
    if (y & 1) return p * p * x;
    else return p * p;
}

int main() {
    cin >> n >> m >> d;
    double ans = (m - 1) / n;
    if (d != 0) {
        ans *= 2 * (n - d) / n;
    }

    cout.precision(10);
    cout << showpoint << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int h1, m1, h2, m2, k;
  std::cin >> h1 >> m1 >> h2 >> m2 >> k;
  m1 += h1 * 60;
  m2 += h2 * 60;
  std::cout << std::abs(m2 - m1) - k << std::endl;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

int gcd(int a, int b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

int lcm(int a, int b) { //最小公倍数
  return a * b / gcd(a, b);
}


int main()
{
  ll n;
  cin>>n;
  cout<<(ll)sqrt(n)*(ll)sqrt(n)<<endl;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();


int main(){

  int a,b;
  cin >> a >> b;

  if (a%2==0||b%2==0)
    cout << "Even" << endl;
    else
      cout << "Odd" << endl;

}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc106/tasks/abc106_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int_fast32_t i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int_fast32_t i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

// 約数の個数
template <int_fast64_t max_N> struct Prime {
    int cnt[max_N] = {0};
    constexpr Prime() : cnt() {
        for (int_fast64_t i = 1; i < max_N; ++i) {
            for (int_fast64_t j = i; j < max_N; j += i)
                cnt[j]++;
        }
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    // １の倍数＋２の倍数＋３の倍数＋・・・
    constexpr auto d = Prime<65535>();
    int ans = 0;
    for (int i = 105; i <= N; i += 2) {
        ans += (d.cnt[i] == 8);
    }
    cout << ans << endl;
    return 0;
}


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

int main(void) {
  int N;
  int *A, *B;
  int sum = 0;
  (void)scanf("%d", &N);
  A = (int*)malloc(sizeof(int) * (N + 2));
  B = (int*)malloc(sizeof(int) * (N + 1));
  A[0] = A[N+1] = 0;
  for (int i = 1; i <= N; i++) {
    (void)scanf("%d", &A[i]);
  }
  for (int i = 0; i <= N; i++) {
    B[i] = abs(A[i+1] - A[i]);
  }

  for (int i = 0; i <= N; i++) {
    sum += B[i];
  }
  for (int i = 0; i < N; i++) {
    printf("%d\n", sum - B[i] - B[i+1] + abs(A[i+2]-A[i]));
  }

  return 0;
}


Measured memory_bytes: 1920