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


using namespace std;


const int inf = 1000000;
void dijkstra(int s, vector<int >& len, vector<vector<pair<int , int > >  > g) {
    fill(len.begin(), len.end(), inf);
    len[s] = 0;
    set<pair<int, int > > S;
    S.insert(make_pair(len[s], s));
    while(S.size()) {
        int a = S.begin()->second;
        S.erase(S.begin());
        for(auto i : g[a]) {
            if(len[a] + i.second < len[i.first]) {
                len[i.first] = len[a]+i.second;
                S.insert(make_pair(len[i.first], i.first));
            }
        }
    }
}

void testcase() {
    int k;
    cin >> k;
    vector<vector<pair<int, int >  > > graph(k+1);
    unordered_set<int > start;

    int t = 1;
    for(int i = 0; i < 2*k; ++i) {
        start.insert(t%k);
        t*=10;
        t%=k;
    }

    for(int i = 0; i <k; ++i) {
        graph[i].emplace_back((10*i)%k, 0);
        graph[i].emplace_back((i+1)%k, 1);
    }
    for(auto i : start) {
        graph[k].emplace_back(i,1);
    }

    vector<int > len(k+1);
    
    dijkstra(k, len, graph);
    cout << len[0] << endl;

}

int main() {
    int z;
    z = 1;
    while(z--) {
        testcase();
    }
}

Measured memory_bytes: 16776
#include<bits/stdc++.h>
#define MAXN 100000

using namespace std;
typedef long long ll;

int main()
{
	//freopen("t.txt","r",stdin);
	int r,d,x;
	cin>>r >>d>>x;
	for (int i=1;i<=10;i++){
		int t= r*x-d;
		cout<<t<<endl;
		x=t;
	}
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n), b(n);
  rep(i,n) cin>>a[i]>>b[i];
  ll ans=0;
  rrep(i,n){
    ll mod=(a[i]+ans)%b[i];
    if(mod==0) continue;
    ans+=b[i]-mod;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1920
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c, d[100000], e[100000], count = 0;
	char uc[100000];
	cin >> a;
	cout << 24 + (24 - a) << endl;
	return 0;
}

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

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;


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

	string s;
	cin >> s;

	int count0, count1;

	count0 = count(s.begin(), s.end(), '0');
	count1 = count(s.begin(), s.end(), '1');

	cout << min(count0, count1) * 2 << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m;
int a[1010], b;
int co[1010];

int main(){
	cin >> n >> m;
	REP(i, n)cin >> a[i];
	REP(i, m){
		cin >> b;
		REP(j, n){
			if (a[j] <= b){
				co[j]++;
				break;
			}
		}
	}
	int MAX = -1, ans;
	REP(i, n){
		if (co[i] > MAX){
			MAX = co[i];
			ans = i;
		}
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 1168
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int H, W, K;
int S[10][1000], now[10], Group[10];

int Calc(int num){
  for (int i = 0; i < H - 1; i++){
    now[i] = num % 2; num /= 2;
  }
  for (int i = 1; i < H; i++){
    Group[i] = Group[i - 1];
    if (now[i - 1]) Group[i]++;
  }
  
  return Group[H - 1];
}


int main(){
  cin >> H >> W >> K;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      char N; cin >> N;
      S[i][j] = N - '0';
    }
  }

  int ans = 1e5, all = pow(2, H - 1);
  for (int i = 0; i < all; i++){
    int now_ans = Calc(i);

    bool flag = true;
    vector <int> Now(now_ans + 1), Next(now_ans + 1);
    for (int j = 0; j < W; j++){
      for (int k = 0; k < H; k++){
        Next[Group[k]] += S[k][j];
        if (Next[Group[k]] > K) flag = false;
      }
      if (flag == false) break;

      bool next = false;
      for (int k = 0; k < Next.size(); k++){
        Now[k] += Next[k];
        if (Now[k] > K) next = true;
      }
      if (next){
        Now = Next; now_ans++;
      }
      fill(Next.begin(), Next.end(), 0);
    }

    if (flag){
      ans = min(now_ans, ans);
    }
  }
  
  cout << ans << endl;

  return 0;
}


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  int sum = 0;
  REP(i,3){
    int A;
    cin >> A;
     sum += A;
  }
  if(sum >= 22) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }
  return 0;
}

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

const int INF = 100100100;
int a[12][12];

int main(){
	int n,m,x;
	cin >> n >> m >> x;
	vector<int> c(n);
	rep(i,n){
		cin >> c[i];
		rep(j,m) cin >> a[i][j];
	}
	int ans = INF;
	rep(is,1<<n){
	int cost = 0;
	vector<int> d(m);
		rep(i,n){
			if(is>>i&1){
				cost += c[i];
				rep(j,m){
					d[j] += a[i][j];
				}
			}
	        bool ok = true;
				rep(j,m){
					if(d[j] < x) ok = false;
				}
				if(ok){
					ans = min(ans,cost);
				}
		}
	}
	if(ans == INF) cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 3572
H,W,N=map(int,input().split())
direc=[[0,0],[-1,0],[-2,0],[0,-1],[-1,-1],[-2,-1],[0,-2],[-1,-2],[-2,-2]]
dic={}
for i in range(N):
  h,w=map(int,input().split())
  for d in direc:
    if 1<=h+d[0]<=(H-2) and 1<=w+d[1]<=(W-2):
      l=(h+d[0],w+d[1])
      if l in dic:
        dic[l]=dic[l]+1
      else:
        dic[l]=1
A=list(dic.values())
print((H-2)*(W-2)-len(A))
for i in range(1,10):
  print(A.count(i))

Measured memory_bytes: 174260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;cin>>s;
    string ans;
    if(s=="zyxwvutsrqponmlkjihgfedcba")ans="-1";
    else if(s.size()==26){
        int idx = 24;
        char m = 'z';
        for(; idx>=0; idx--){
            if(s[idx]<s[idx+1])break;
        }
        for(int i = 25; i >idx; i--){
            if(s[i]>s[idx])m=min(m,s[i]);
        }
        ans = s.substr(0,idx)+m;


    }
    else{
        vector<bool> c(26,false);
        for(int i=0; i<s.size(); i++){
            c[s[i]-'a']=true;
        }
        int idx = 0;
        for(; idx<26; idx++){
            if(c[idx]==false)break;
        }
        ans = s + char('a'+idx);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# Aizu Online Judge. Partition
import sys

def partition(A, p, r):
    x = A[r]
    i = p-1
    for n in range (p,r):
        if A[n] <= x:
            i += 1
            A[i], A[n] = A[n], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    print(' '.join(map(str,A[:i+1])), end= ' ')
    print('[', A[i+1], ']', sep='', end='')
    if i+1 != r:
        print(' ', end='')
    print(' '.join(map(str,A[i+2:])))


n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
partition(A, 0, n-1)



Measured memory_bytes: 15604
import math
a, b = map(int, input().split())
if a % 2 == 0:
    c = int(a*12.5)
    d = c + 13
else:
    c = int(a*12.5) + 1
    d = c + 12
e = b * 10
f = e + 10
if d <= e or f <= c:
    print(-1)
else:
    print(max(c,e))

Measured memory_bytes: 3060
x,k,d= map(int,input().split())
import sys
z = abs(x) // d
if z <= k:
    y = abs(x) - d * z
    if (k- z)% 2 != 0:
        y = abs(y-d)
else:
    y = abs(x) - d * k
if x == d:
    if k % 2 == 0:
        y = x
    else:
        y = 0
print(abs(y))

Measured memory_bytes: 9192
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

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

int main(){
    ll n;
    cin>>n;
    lvec a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    ll k=gcd(a[0],a[1]);
    priority_queue<ll,vec,greater<ll>> que;
    que.push(k);
    for(int i=2;i<n;i++){
        que.push(gcd(k,a[i]));
        if(que.top()==1) break;
    }
    cout<<que.top();
}

Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

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

    int nMin = 10001;
    int nMax = 0;
    int n, temp;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> temp;
        nMin = min(nMin, temp);
        nMax = max(nMax, temp);
    }
    cout << nMax - nMin << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main()
{
   string S, T;
   cin >> S >> T;
   int ssize = S.size();
   int tsize = T.size();
   int ans = INT_MAX;
   for (int i = 0; i + tsize <= ssize; i++)
   {
      int cnt = 0;
      for (int j = 0; j < tsize; j++)
      {
         if (S[i + j] != T[j])
         {
            cnt++;
         }
      }
      ans = min(ans, cnt);
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3628
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
  std.range, std.container, std.bigint, std.ascii, std.typecons, std.format;

// }}}
// nep.scanner {{{
class Scanner {
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0) {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {
  }

  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
    str ~= s.to!(char[]).strip.split;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  int n, m;

  cin.scan(n, m);
  writeln(n * (n - 1) / 2 + m * (m - 1) / 2);
}


Measured memory_bytes: 256
// Problem : A - Payment
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define pb push_back
#define mod 1000000007
ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % mod; 
    p = (p * p) % mod; 
  
    return (y%2 == 0)? p : (x * p) % mod; 
} 
ll factorial[1000007];
void fact(ll n)
{
    memset(factorial,0,sizeof(factorial));
    factorial[0]=1;
factorial[1]=1;

    for(int i=1;i<n;i++)
    {
        factorial[i]=(factorial[i-1]*i)%mod;
    }
    
}
ll ncr(ll n,ll r)
{
    ll ans=1;
    ll i;
    ans=factorial[n];
    ll ans1=power(factorial[n-r],mod-2);
    ll ans2=power(factorial[r],mod-2);
    ans=((ans*ans1)%mod*ans2)%mod;
    return ans;
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

bool prime[100000006];
void sieve(ll n){
    memset(prime,true,sizeof(prime));
	prime[1]=false; 
    for (ll p=2;p*p<=n;p++){
        if (prime[p]){  
            for (ll i=p*p;i<=n;i+=p)
                prime[i]=false;
        }
    }
}
void bfs(vector<int> v[],int o,int n,int dp[]){
	queue<int> q;
	q.push(o);
	dp[o]=0;
	bool visited[n+1]={0};
	visited[o]=true;
	while(q.empty()==false){
		int a=q.front();
		q.pop();
		for(int i=0;i<v[a].size();i++){
			if(visited[v[a][i]]==false){
				visited[v[a][i]]=true;
				q.push(v[a][i]);
				dp[v[a][i]]=dp[a]+1;
			}
		}
	}
}
int nov[1000001];
bool visited[1000001];
int dp[1000001];
int dfs(vector<int> v[],int o)
{
    if(visited[o]==0)
    {
        visited[o]=1;
        for(int i=0;i<v[o].size();i++)
        {
            if(visited[v[o][i]]==0)
            {
            dp[v[o][i]]=dp[o]+1;
            nov[o]+=dfs(v,v[o][i]);
            }
        }
        return nov[o]+1;
    }
    else
    return 0;
}
// string s=bitset<64>(n).to_string();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll n;
	cin>>n;
	if(n%1000!=0)
	cout<<1000-n%1000;
	else
	cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 3636
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        boolean finish = false;
        int cnt = 0;
        while (!finish) {
            cnt++;
            for (int i = 0; i < n; i++) {
                if (a[i] % 2 != 0) {
                    finish = true;
                    cnt--;
                    break;
                } else {
                    a[i] = a[i] / 2;
                }
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
using namespace std;
#define LL long long

int d, n;

int main(){

	cin >> d >> n;
	if (n == 100)n++;
	if (d == 0)cout << n << endl;
	else if (d == 1)cout << n * 100 << endl;
	else cout << n * 10000 << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define ld long double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;
 
int dp[3001][3001], p[3001][3001];
pair<int, int> pr[3001][3001];
 
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	string s, t;
	cin >> s >> t;

	int n = s.size(), m = t.size();

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(s[i - 1] != t[j - 1]) dp[i][j] = 0;
			else {
				dp[i][j] = p[i - 1][j - 1] + 1;
			}
			p[i][j] = max(dp[i][j], max(p[i][j - 1], p[i - 1][j]));
			if(dp[i][j] >= max(p[pr[i - 1][j].f][pr[i - 1][j].s], p[pr[i][j - 1].f][pr[i][j - 1].s]))
				pr[i][j] = {i, j};
			else {
				if(p[pr[i - 1][j].f][pr[i - 1][j].s] >= p[pr[i][j - 1].f][pr[i][j - 1].s])
					pr[i][j] = pr[i - 1][j];
				else 
					pr[i][j] = pr[i][j - 1];
			}
		}
	}

	int mmax = 0;
	string lcs = "";
	pair<int, int> ans;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(dp[i][j] >= mmax) {
				mmax = dp[i][j];
				ans = {i, j};
			}
		}
	}
	
	while(p[ans.f][ans.s] != 0) {
		lcs += s[ans.f - 1];
		ans = pr[ans.f - 1][ans.s - 1];
	}
	reverse(lcs.begin(), lcs.end());
	cout << lcs;
}

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

int main(void){
    char days[7][3] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    char t[100];
    char today[3];
    fgets(t, 4, stdin);

    for(int i=0; i<3; i++){
        today[i] = t[i];
    }
        
    char day[3];
    for(int i=0; i<7; i++){
        int fl = 1;
        for(int j=0; j<3; j++){
            if(today[j] !=days[i][j]) fl = 0;
        }
        
        if(fl){
            printf("%d", 7-i);
            break;
        }
    }

    return 0;

}


Measured memory_bytes: 128
#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;}

signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b>=c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
  char s[4];
  cin >> s;
  if(s[0]=='R'){
    if(s[1]=='R'){
      if(s[2]=='R'){
        cout << "3";
      }else{
        cout << "2";
      }
    }else{
      cout << "1";
    }
  }else{//1日目S
    if(s[1]=='R'){
      if(s[2]=='R'){
        cout << "2";
      }else{
        cout << "1";
      }
    }else{
      if(s[2]=='R'){
        cout << "1";
      }else{
        cout << "0";
      }
    }
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);
const ll MOD = 1e9 + 7;

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

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

//素数判定
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;
    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;
}

void solve() {
    ll x; cin >> x;
    ll ans = 0;
    ans += (x/11)*2;
    x %= 11;
    if(x){
        if(x <= 6) ans++;
        else ans += 2;
    }
    cout << ans << endl;
}

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

    solve();
    return 0;
}


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

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define double long double
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int n,m,k;
    cin>>n>>m>>k;int s=0,x=0;
    VI ar(n);VI re;
    for(int i=0;i<n;i++)
    cin>>ar[i];
    for(int j=0;j<m;j++)
    {int x;
    cin>>x;
    s+=x;re.pb(s);
    }
    s=0;int ans=0;
    int mn=LB(all(re),k+1)-re.begin();
    ans=mn;
    for(int i=0;i<n;i++)
    {   s+=ar[i];
        int k1=k-s;
        if(k1<0)break;
        
        int mn=LB(all(re),k1+1)-re.begin();
        
        ans=max(ans,mn+i+1);
    }
    cout<<ans<<endl;
}


return 0;
}





Measured memory_bytes: 6892
#include <cstdio>
#include <iostream>
#include <cstring>

int main() {
	char a,b;
	std::cin >> a >> a;
	std::cin >> a >> b;
	if(a != b) return std::puts("No"), 0;
	std::cin >> a >> b;
	if(a != b) std::puts("No");
	else std::puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int sum=0,su=0,ans=INT_MAX,au;
  int arr[n];
  for(int i=0;i<n;i++)
  {cin>>arr[i];sum+=arr[i];}
  for(int i=0;i<n;i++)
  {
    su+=arr[i];
    au=sum-su;
    ans=min(ans,abs(au-su));
  }
  cout<<ans;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main() {
    int h, w; cin >> h >> w;
    vector<vector<char>> pass(h+1, vector<char>(w+1, '.'));
    int cnt = 0;
    rep(i, h){
        string s; cin >> s;
        rep(j, w){
            pass[i][j] = s[j];
            if(s[j] == '#')cnt++;
        }
    }
    
    int y = 0, x = 0; //現在地
    while(true){
        cnt--;
        if(pass[y+1][x] == '.' && pass[y][x+1] == '.') break;
        if(pass[y+1][x] == '#') y++;
        else x++;
    }

    if(cnt == 0) cout << "Possible" << ln;
    else cout << "Impossible" << ln;
}


Measured memory_bytes: 256
def dot(a,b):return a[0]*b[0] + a[1]*b[1]
def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def isOn(a,b):
    if cross(a,b) == 0:
        if dot(a,b) < 0 or dot(a,a) < dot(b,b) : return False
        else : return True
    else : 
        return False

q = int(input())
for i in range(q):
    x0,y0,x1,y1,x2,y2,x3,y3 = [int(i) for i in input().split()]
    a = [x1-x0,y1-y0]
    b = [x2-x0,y2-y0]
    c = [x3-x0,y3-y0]
    d = [x3-x2,y3-y2]
    e = [x0-x2,y0-y2]
    f = [x1-x2,y1-y2]
    if isOn(a,b) or isOn(a,c):
        print(1)
    elif cross(a,b) == 0 and cross(a,c) == 0:
        if ( not isOn(c,a) and isOn(b,a)) or (isOn(c,a) and not isOn(b,a)) :
            print(1)
        else:
            print(0)
    elif cross(a,b) * cross(a,c) > 0 :
        print(0)
    elif cross(d,e) * cross(d,f) > 0 :
        print(0)
    else :
        print(1)

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

int main(){
    int N;
    long A[100005];
    long long Anum = 0;

    cin >> N;
    for(int n=1;n<=N;n++){
        cin >> A[n];
        if(n%2 == 1){
            Anum += A[n];
        }
        else{
            Anum -= A[n];
        }
    }

    for(int n=1;n<=N;n++){
        cout << Anum;
        if(n != N) cout << " ";
        Anum = -1*Anum + 2*A[n];
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	ll n;
  cin>>n; n;
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i]; a[i];
  }
	vector<ll> sum(n+1);
	rep(i,n) sum[i+1]=sum[i]+a[i];
	ll re=sum.back();
	rep(i,n) MN(re,abs(sum[i]-(sum.back()-sum[i])));
	cout<<re NL;
	return 0;
}


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

int d[100001];

int64_t solve(const int N, const int L){
	int64_t score = 0;
	
	map<int,int> mp;

	for(int x=1; x<=N; ++x){
		int pos;
		cin >> pos;
		cin >> mp[pos];
	}

	int x=1;
	for(auto e: mp){
		int pos = e.first;
		d[x] = e.second;
		score += (pos - x) * (d[x]==0?1:-1);
		++x;
	}

	int64_t best = score;
	for(int x=N,l=L; x>0; --x,--l){
		score += (l - x) * (d[x]==0?-1:1);
		best = max(best, score);
	}
	return best;
}

int main(){
	int N,L;
	cin>>N>>L;
	cout<<solve(N,L)<<endl;
}



Measured memory_bytes: 8156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    string S;
    cin >> S;
    ll N = S.size();
    ll cnt=0;
    rep(i,N){
        cnt += S[i] - '0';
    }
    cout << ((cnt%9==0)?"Yes":"No") << endl;
}

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

map<char,int>mp;
char str[101][101];

int main()
{   int i, j, n, m, k, num2=0, z=0, e;
    cin>>n>>m;
    for(i=0; i<n; i++)
        for(j= 0 ; j<m ;j++)
            { cin>>str[i][j]; mp[str[i][j]]++;}


    for(i=0; i<n; i++)
        for(j= 0 ; j<m ;j++){
             k = mp[str[i][j]];
            if(k!=0){
                if(k%4!=0&&k%2==0)num2++;
                else if(k%2!=0) z++;
                mp[str[i][j]]=0;
            }
        }
        if(n%2==0)e=n; else e=m;

      if(n%2==0&&m%2==0)  if(num2==0&&z==0) {cout<<"Yes"<<endl;return 0;}


      if(abs(n-m)%2==1)
            {if(num2<=e/2&&z==0) {cout<<"Yes"<<endl;return 0;}}


      if(n%2==1&&m%2==1)
       {

           if(num2<=(m+n-2)/2&&z==1) {cout<<"Yes"<<endl; return 0;}
           }

      cout<<"No"<<endl;


    return 0;
}














Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr ll INF = 1LL << 60;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    sort(A.rbegin(),A.rend());
    // n+1 C k > nCk
    ll K = A[0] / 2;
    ll t = INF, ans = 0;
    rep(i,1,N) if(chmin(t,abs(A[i]-K))) ans = A[i];
    cout << A[0] << " " << ans << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include<math.h>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define    ll   long long int
#define    py   printf("Yes\n")
#define    pn   printf("No\n")
#define    in   cin>>
using namespace std;

int main()
{
  int n,a,b;
  in n>>a>>b;
  string ans;
  bool flag=false;
  for(int i=0;i<1000;i++)
  {
    if(i*n>=a&&i*n<=b)flag=true;
  }
  if(flag==true)cout<<"OK"<<endl;
  else cout<<"NG"<<endl;

}


Measured memory_bytes: 3624
num_line=input().rstrip().split(" ")

num=int(num_line[0])
firstpoint=int(num_line[1])
times=int(num_line[2])

pointlist=[0 for i in range(num)]
#print(pointlist)

for i in range(times):
    win=int(input())-1
    pointlist[win]+=1

#print(pointlist)
for i in range(num):
    if pointlist[i]>=times-firstpoint+1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4684
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
	public static void main (String[] args) throws java.lang.Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    int n = Integer.parseInt(br.readLine());
	    while(n-->0){
	        String line = br.readLine();
	        line = line.replaceAll("Hoshino","Hoshina");
	        System.out.println(line);
	    }
	}
}

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

#include <atcoder/all>
using namespace atcoder;

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> grid(n);
    rep(i,n) {
        cin >> grid[i];
    }
    mf_graph<int> g(n*m+2);
    int s = n*m;
    int t = n*m+1;
    vector<P> d;
    d.push_back(P(0,1));
    d.push_back(P(0,-1));
    d.push_back(P(1,0));
    d.push_back(P(-1,0));
    rep(i,n) {
        rep(j,m) {
            if (grid[i][j] == '#') continue;
            int p = i*m+j;
            if ((i+j)%2 == 0) {
                rep(k,4) {
                    int ni = i+d[k].first;
                    int nj = j+d[k].second;
                    if (0 <= ni && ni < n && 0 <= nj && nj < m) {
                        if (grid[ni][nj] == '.') {
                            int np = ni*m+nj;
                            //cout << "*" << endl;
                            //cout << p << " " << np << endl;
                            //cout << i << "," << j << endl;
                            //cout << ni << "," << nj << endl;
                            g.add_edge(p, np, 1);
                        }
                    }
                }
            }
            if ((i+j)%2 == 0) {
                g.add_edge(s, p, 1);
            } else {
                g.add_edge(p, t, 1);
            }
        }
    }
    cout << g.flow(s, t) << endl;
    auto edges = g.edges();
    for (auto e: edges) {
        if (e.from == s || e.to == t || e.flow == 0) continue;
        int x1 = e.from / m;
        int y1 = e.from % m;
        int x2 = e.to / m;
        int y2 = e.to % m;
        if (x1 == x2+1) {
            grid[x2][y2] = 'v';
            grid[x1][y1] = '^';
        } else if (x1 == x2-1) {
            grid[x1][y1] = 'v';
            grid[x2][y2] = '^';           
        } else if (y1 == y2+1) {
            grid[x1][y1] = '<';
            grid[x2][y2] = '>';           
        } else {
            grid[x1][y1] = '>';
            grid[x2][y2] = '<';
        }
    }
    rep(i,n) {
        cout << grid[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5436
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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;
}
long long dp[101][100001];
int main() {

  cout << fixed << setprecision(10);
  int n,w;
  cin >> n >> w;
  vector<int> weight(n,0);
  vector<int> value(n,0);
  rep(i,n){
    cin >> weight.at(i) >> value.at(i);
  }


  rep(i,n){
    for(int sum_w=0;sum_w<=w; sum_w++){
      if(sum_w-weight[i]>=0){
        chmax(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i]);
      }
      chmax(dp[i+1][sum_w],dp[i][sum_w]);
    }
  }

  cout << dp[n][w] << endl;


}


Measured memory_bytes: 78336
import java.util.*;

public class Main{
	public static void main(String[] args) {
	 Scanner sc = new Scanner(System.in);
     int input1 = sc.nextInt();
     int input2 = sc.nextInt();
     
     if(input1 <= input2) {
      System.out.println("unsafe");
     } else {
      System.out.println("safe");
     }
     
    }
}

Measured memory_bytes: 35772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<ll> a(n),b(n),c(m),d(m);
	rep(i,n){
		cin>>a[i]>>b[i];
	}
	rep(i,m){
		cin>>c[i]>>d[i];
	}
	rep(i,n){
		ll ans,now=inf;
		rep(j,m){
			if(now<=abs(a[i]-c[j])+abs(b[i]-d[j])) continue;
			now=abs(a[i]-c[j])+abs(b[i]-d[j]);
			ans=j+1;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define ARRIN(a, n) REP(i, n) cin>>a[i];
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n, m;
  cin>>n>>m;
  int a[n+1];
  MEMSET(a, n+1, 0);
  LL dp[n+1];
  MEMSET(dp, n+1, (LL)0);
  int b;
  REP(i, m){
    cin>>b;
    a[b]=1;
  }

  if(n==1){
    cout<<1<<endl;
    return 0;
  }
  dp[0]=1;
  for(int i=1; i<n+1; ++i){
    if(a[i]==1) continue;
    if(a[i-1]==0) {dp[i] += dp[i-1]; dp[i]%=MOD;}
    if(i-2>-1) if(a[i-2]==0) {dp[i] += dp[i-2]; dp[i]%=MOD;}
  }

  cout<<dp[n]<<endl;

  return 0;
}


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

int main()
{
  long n1, n2;
  int ans = 0;
  while(cin >> n1 >> n2){
    long sum = n1 + n2;
    ans = 0;
    while(sum > 0){
      sum /= 10;
      ans++;
    }
    ans = (n1 == 0 & n2 == 0) ? 1 : ans;
    cout << ans << endl;
  }
}
    

Measured memory_bytes: 1160
import collections

N = int(input())
A_list = list(map(int, input().split(' ')))
count_dict = collections.Counter(A_list)

sum_ = 0
for count in count_dict.values():
  sum_ += (count**2 - count) // 2

for A in A_list:
  print(sum_ - count_dict[A] + 1)

Measured memory_bytes: 86684
import java.util.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] candles = new int[n];
		for (int i = 0; i < n; i++) {
			candles[i] = sc.nextInt();
		}
		int min = Integer.MAX_VALUE;
		for (int i = 0; i + k - 1 < n; i++) {
			int x = candles[i + k - 1] - candles[i] + start(candles[i + k - 1], candles[i]);
			if (min > x) {
				min = x;
			}
		}
		System.out.println(min);
	}
	
	public static int start(int x, int y) {
		if (x < 0) {
			x = -x;
		}
		if (y < 0) {
			y = -y;
		}
		if (x < y) {
			return x;
		} else {
			return y;
		}
	}
}

Measured memory_bytes: 50052
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int value(string s) {
    int v = s[1] - '0';
    return v;
}

char key(string s) {
    char c = s[0];
    return c;
}

vector<string> bubbleSort(vector<string> A, int N) {
    for (int i = 0; i < N - 1; i++) {
        for (int j = N - 1; j > i; j--) {
            if (value(A[j]) < value(A[j - 1]))
                swap(A[j], A[j - 1]);
        }
    }

    return A;
}

vector<string> SelectionSort(vector<string> A, int N) {
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (value(A[j]) < value(A[minj]))
                minj = j;
        }
        swap(A[minj], A[i]);
    }

    return A;
}

bool isStable(vector<string> sortedA1, vector<string> sortedA2, int N) {
    rep(i, N) {
        if (key(sortedA1[i]) != key(sortedA2[i]))
            return false;
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    vector<string> A(N);
    rep(i, N) { cin >> A[i]; }

    vector<string> sortedA1 = bubbleSort(A, N);
    vector<string> sortedA2 = SelectionSort(A, N);
    rep(i, N - 1) { cout << sortedA1[i] << " "; }
    cout << sortedA1[N - 1] << endl;
    cout << "Stable" << endl;
    rep(i, N - 1) { cout << sortedA2[i] << " "; }
    cout << sortedA2[N - 1] << endl;
    if (isStable(sortedA1, sortedA2, N))
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
inline void io()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}
map<int, int>dislike;
bool check(int n)
{
    while (n > 0)
    {
        if (dislike[n % 10])
            return 0;
        n /= 10;
    }
    return 1;
}
int main()
{
    io();
    int k;
    int n;
    cin >> n >> k;
    for (int i = 0, x; i < k; ++i) {
        cin >> x;
        dislike[x]++;
    }
    while (!check(n))
    {
        n++;
    }
    cout << n << '\n';
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main( int argc, char *argv[] ) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n, k;
	cin >> n >> k;
	n %= k;
	n = min(abs(n-k), n);
	cout << n << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    string S;
    cin >> S;
    ll K;
    cin >> K;
    VC test(S.size()*2);
    rep(i,S.size()){
        test.at(i)=S.at(i);
    }
    for(int i=S.size(); i<S.size()*2; i++){
        test.at(i)=S.at(i-S.size());
    }
    ll sum=0;
    
    ll count=1;
    bool judge=true;
    rep(i,S.size()-1){
        if(S.at(i)!=S.at(i+1)){
            judge=false;
        }
    }
    if(judge){
        cout << S.size()*K/2 << endl;
        return 0;
    }

    rep(i,test.size()-1){
        if(test.at(i)==test.at(i+1)){
            count++;
            if(i==test.size()-2){
                sum+=count/2;
            }
            continue;
        }
        else{
            sum+=count/2;
        }
        count=1;
    }
    ll first_point=0;
    ll count_2=1;
    rep(i,S.size()-1){
        if(S.at(i)==S.at(i+1)){
            count_2++;
            if(i==S.size()-2){
                first_point+=count_2/2;
            }
            continue;
        }
        else{
            first_point+=count_2/2;
        }
        count_2=1;
    }
    ll dif=sum-first_point;
    cout << first_point+(K-1)*dif << endl;
}


Measured memory_bytes: 256
from itertools import accumulate,chain
from collections import Counter

MOD = 2019

S = input()

memo = [None]*len(S)
x = 1
for i,c in enumerate(reversed(S)):
    memo[i] = x*int(c)%MOD
    x = (10*x)%MOD

acc = tuple(chain((0,), accumulate(memo, lambda x,y: (x+y)%MOD)))

print(sum(c*(c-1)//2 for c in Counter(acc).values()))


Measured memory_bytes: 24324