akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split(' '))

ans = []

aw = []

for y in range(1, h + 1):
    ay = list(map(int, input().split(' ')))
    for x in range(1, w):
        if ay[x - 1] % 2 == 1:
            ans.append((y, x, y, x + 1))
            ay[x] += 1
    aw.append(ay[w - 1])

for y in range(1, h):
    if aw[y - 1] % 2 == 1:
        ans.append((y, w, y + 1, w))
        aw[y] += 1

print(len(ans))
for elm in ans:
    print(elm[0], elm[1], elm[2], elm[3])

Measured memory_bytes: 20384
from math import ceil

d,g = map(int,input().split())
pc = [list(map(int,input().split())) for i in range(d)]

ans = float("inf")
for bit in range(1<<d):
    sum = 0
    cnt = 0
    #残ってるやつのmaxのインデックス取得するためsetを設定
    nokori = set(range(1, d + 1))
    for i in range(d):
        if bit & (1 << i):
            sum += pc[i][0]*100*(i+1) + pc[i][1]
            cnt += pc[i][0]
            nokori.discard(i+1)
    
    if sum < g:
        use = max(nokori)
        husoku = min(ceil((g-sum)/(use*100)),pc[use-1][0])
        cnt += husoku
        sum += husoku*use*100
    
    if sum >= g:
        ans = min(cnt,ans)

print(ans)

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

map <ll, ll> mpRow, mpCol ;
pair <ll, ll> pt[300005] ;

int main()
{
    ll r, c, m, ans = 0, val, ind = 0, check = 0 ;
    cin >> r >> c >> m ;
    for (int i = 0; i < m; i++) {
        scanf("%lld %lld", &pt[i].first, &pt[i].second) ;
        mpRow[pt[i].first]++, mpCol[pt[i].second]++ ;
    }

    for (auto it = mpRow.begin(); it != mpRow.end(); it++) {
        if (it->second >= ind) {
            ind = it->second ;
            val = it->first ;
        }
    }

    for (auto it = mpCol.begin(); it != mpCol.end(); it++) {
        if (it->second >= ind) {
            ind = it->second ;
            val = it->first ;
            check = 1 ;
        }
    }
    ans += ind ;

    if (!check) {
        for (int i = 0; i < m; i++) {
            if (pt[i].first == val) {
                mpCol[pt[i].second]-- ;
            }
        }
        ind = 0 ;
        for (auto it = mpCol.begin(); it != mpCol.end(); it++) {
            ind = max(ind, it->second) ;
        }
        ans += ind ;
    }
    else {
        for (int i = 0; i < m; i++) {
            if (pt[i].second == val) {
                mpRow[pt[i].first]-- ;
            }
        }
        ind = 0 ;
        for (auto it = mpRow.begin(); it != mpRow.end(); it++) {
            ind = max(ind, it->second) ;
        }
        ans += ind ;
    }

    cout << ans ;

    return 0 ;
}


Measured memory_bytes: 45960
h, w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
up = [[0 for i in range(w)] for j in range(h)]
down = [[0 for i in range(w)] for j in range(h)]
right = [[0 for i in range(w)] for j in range(h)]
left = [[0 for i in range(w)] for j in range(h)]
for i in range(w):
    # init up
    if grid[0][i] == ".":
        up[0][i] = 1
    else:
        up[0][i] = 0
    #init down
    if grid[-1][i] == ".":
        down[-1][i] = 1
    else:
        down[-1][i] = 0
for i in range(h):
    #init right
    if grid[i][-1] == ".":
        right[i][-1] = 1
    else:
        right[i][-1] = 0
    
    #init left
    if grid[i][0] == ".":
        left[i][0] = 1
    else:
        left[i][0] = 0
for i in range(h):
    for j in range(1,w):
        if grid[i][j] == ".":
            left[i][j] = left[i][j-1] + 1
        else:
            left[i][j] = 0
for i in range(h):
    for j in range(w-2,-1,-1):
        if grid[i][j] == ".":
            right[i][j] = right[i][j+1] + 1
        else:
            right[i][j] = 0

for i in range(1,h):
    for j in range(w):
        if grid[i][j] == ".":
            up[i][j] = up[i-1][j] + 1
        else:
            up[i][j] = 0
for i in range(h-2,-1,-1):
    for j in range(w):
        if grid[i][j] == ".":
            down[i][j] = down[i+1][j] + 1
        else:
            down[i][j] = 0
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, up[i][j] + down[i][j] + left[i][j] + right[i][j] - 3)
print(ans)

Measured memory_bytes: 313352
N = int(input())
V = [0] * N
C = [0] * N
V = list(map(int, input().split()))
C = list(map(int, input().split()))

benefit = 0

for n in range(N):
    if V[n] - C[n] > 0:
        benefit += V[n] - C[n]

print(benefit)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 1e6;
int t[5][5];
ll h,a,b,c,d,e;
int ans = 1;
ll mod = 1e9+7;
bool memo[15][15] = {0};
ll func(ll x){
  ll k = 1;
  while(x>1){
    k *= x;
    k %= mod;
    x--;
  }
  return k;
}
int main(){
  ll m,n;
  cin >> n;
  vector<ll> v(n);
  for(int i=0 ; i<n ; i++){
    cin >> v[i];
  }
  vector<ll> l(n),r(n);
  l[0] = v[0];
  r[n-1] = v[n-1];
  for(int i=1 ; i<n ; i++){
    l[i] = v[i] + l[i-1];
  }
  for(int i=n-2 ; i>=0 ; i--){
    r[i] = v[i]+r[i+1];
  }
  ll mi = 1e17;
  for(int i=0 ; i+1<=n-1 ; i++){
    mi = min(mi, abs(r[i+1]-l[i]));
  }
  if(n==2) mi = abs(v[1]-v[0]);
  cout << mi << endl;
  return 0;
}


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

void cxxio() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}

int main() {
    cxxio();
    int n;
    cin>>n;
    vi xs(n);
    forn(i, n) {
        cin>>xs[i];
        int hi=i? 1+xs[i-1]:0;
        if (xs[i]>hi)
            return cout<<"-1\n", 0;
    }
    ll ans=0;
    set<int> s;
    for (int i=n-1, z=0; i>=0; i--, z--) {
        s.insert(xs[i]-z);
        while (!s.empty() && *s.begin()<=-z) s.erase(s.begin());
        ans+=s.size();
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/


int main(){
    string a,b; cin >> a >> b;

    if(a.size() == b.size()){
        if(a == b) cout << "EQUAL" << endl;
        else if(a < b) cout << "LESS" << endl;
        else cout << "GREATER" << endl;
    }
    else{
        if(a.size() < b.size()) cout << "LESS" << endl;
        else cout << "GREATER" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
long long int kaijou[300005];
void k(long long int p)
{
	long long int i;
	kaijou[0] = 1;
	for (i = 0; i < 300004; i++)
		kaijou[i + 1] = (kaijou[i] * (i + 1)) % p;
	return;
}
long long int modpow(long long int a, long long int n, long long int p)
{
	if (n < 0)
		return 0;
	long long int res = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			res = (res * a) % p;
		a = (a * a) % p;
		n /= 2;
	}
	return res;
}
long long int modcmb(long long int n, long long int r, long long int p)
{
	long long int res = kaijou[n];
	res *= modpow(kaijou[r], p - 2, p);
	res %= p;
	res *= modpow(kaijou[n - r], p - 2, p);
	res %= p;
	return res;
}
int main()
{
	long long int h, w, a, b;
	scanf("%lld %lld %lld %lld", &h, &w, &a, &b);
	long long int p = 1000000007;
	k(p);
	long long int ans = 0;
	long long int i;
	for (i = b + 1; i <= w; i++)
	{
		ans += modcmb(h - a + i - 2, i - 1, p) * modcmb(a + w - i - 1, a - 1, p);
		ans %= p;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main() {
  int n, x, m, M = 1001;
  scanf("%d %d", &n, &x);
  for(int i = 0; i < n; i++) {
    scanf("%d", &m);
    x -= m;
    if(m < M)
      M = m;
  }
  printf("%d\n", n + x / M);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=1e5+10;
int n;
char a[maxn];
int main()
{
    while(scanf("%s",a)!=EOF)
    {
        int ans=0;
        int len=strlen(a);
        for(int i=1; i<len-1; i++)
            if(a[i-1]!=a[i+1])ans++;
        if(ans==0)
        {
            printf("Second\n");
            continue;
        }
        if(a[0]!=a[len-1])printf("%s\n",len%2?"First":"Second");
        else printf("%s\n",len%2?"Second":"First");
    }
}



Measured memory_bytes: 384
<?php
fscanf(STDIN, "%d %d",$k,$s);
$result=0;
for ($i=0; $i <= $k; $i++)
{
	for ($j=0; $j <= $k; $j++)
    {
		if($s-$i-$j<=$k && $s-$i-$j>=0)
			$result++;
	}
}
printf("%d\n",$result);

Measured memory_bytes: 4604
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100001]={0};
int b[100001]={0};
bool comp(int a,int b)
{
	return a>b;
}
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
	    scanf("%d",&a[i]);
	sort(a,a+n+1);
	int k=1;
	for (int i=2;i<=n;++i)
	    if (a[i]!=a[i-1])
		{
			b[a[i-1]]=k;
			k=1;
		}
	        else k++;
	b[a[n]]=k;
	int tot=0;
	for (int i=1;i<=n;++i)
	    if ((b[a[i]]+b[a[i]-1]+b[a[i]+1])>tot) tot=b[a[i]]+b[a[i]-1]+b[a[i]+1];
	cout<<tot;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>

using namespace std;
int nen,tsuki,hi;


int main(void)
{
    while(cin>>nen>>tsuki>>hi){
        int num = nen*10000+tsuki*100+hi;
        
        if(num>=19890108){
            cout<<"heisei "<<nen-1989+1<<" "<<tsuki<<" "<<hi<<endl;
        }else if(num>=19261225){
            cout<<"showa "<<nen-1926+1<<" "<<tsuki<<" "<<hi<<endl;
        }else if(num>=19120730){
            cout<<"taisho "<<nen-1912+1<<" "<<tsuki<<" "<<hi<<endl;
        }else if(num>=18680908){
            cout<<"meiji "<<nen-1868+1<<" "<<tsuki<<" "<<hi<<endl;
        }else{
            cout<<"pre-meiji"<<endl;
        }
        
        
    }
    
}

Measured memory_bytes: 1164
import java.io.*;

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] strs = br.readLine().split(" ");
    int A = Integer.parseInt(strs[0]);
    int B = Integer.parseInt(strs[1]);
    
    System.out.print((A <= 8 && B <= 8) ? "Yay!" : ":(");
  }
}     


Measured memory_bytes: 19412
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<limits.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int IINF=INT32_MAX;
static const ll LINF=INT64_MAX;
static const ll mod=1e9+7;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};

int N,M;

int main(){
    cin>>N>>M;
    if(N%2==1){
        for(int i=1;i<=M;++i){
            cout<<i<<" "<<N-i+1<<endl;
        }
    }
    else{
        for(int i=1;i<=M;++i){
            if(N-2*i+1>2*i-1)cout<<i<<" "<<N-i+1<<endl;
            else cout<<i<<" "<<N-i<<endl;
        }
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = INT_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  string s, t;
  cin >> s >> t;
  int ans = INF;
  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    int neq = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == t[j]) neq++;
    }
    ans = min(ans, (int)t.size() - neq);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>

using namespace std;
int main()
{
	string N;
	cin >> N;

	long current = 0;
	long length = N.size();
	for (long i = 0; i < length; ++i)
	{
		char c = N.at(i);
		long val = c - '0';
		current += (val);
		current = current % 9;
	}

	if (current == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3720
H,W,K=map(int,input().split())

ans=[[0]*W for _ in range(H)]
a=0
for i in range(H):
  s=list(input())
  if "#" in s:
    a+=1
    for j in range(W):
      if s[j]==".":
        ans[i][j]=a
      else:
        ans[i][j]=a
        ind=j
        break
    for j in range(ind+1,W):
      if s[j]==".":
        ans[i][j]=a
      else:
        a+=1
        ans[i][j]=a
  else:
    if i!=0:
      for j in range(W):
        ans[i][j]=ans[i-1][j]
        
for i in reversed(range(H)):
  if ans[i][0]==0:
    for j in range(W):
      ans[i][j]=ans[i+1][j]
      
for A in ans:
  print(*A)

Measured memory_bytes: 7376
#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back
#define FILE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);


using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

void multiply(vector< vector<ll> > &a, vector< vector<ll> > &b){
    int n = a.size();
    vector< vector<ll> > c(n, vector<ll>(n, 0));

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                c[i][j]  = (c[i][j] + a[i][k] * b[k][j])%mod;
            }
        }
    }

    a = c;
}

ll power(vector< vector<ll> > &a, ll p){
    int n= a.size();
    vector< vector<ll> > res(n, vector<ll>(n, 0));
    fr(i,n)res[i][i] = 1;

    while(p){
        if(p&1)multiply(res, a);
        multiply(a, a);
        p >>= 1;
    }

    a = res;

}

int main(){
    inp_out_work

    int n;
    ll k;
    cin>>n>>k;

    vector< vector<ll> > a(n, vector<ll>(n));

    fr(i,n)fr(j,n)cin>>a[i][j];

    power(a, k);

    ll ans = 0;

    fr(i,n)fr(j,n){
        ans += a[i][j];
        if(ans > mod)ans -= mod;
    }

    cout<< ans << endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, t, a[200005];
vector< ll > adj[100005];
#define ari for( int i = 0 ; i < n ; i++ ) cin >> a[i];
#define ginp for( int i = 0 ; i < m ; i++ ){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u);}
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first
#define mp make_pair
ll mod = 1e9 + 7;
void printar(vector< ll > ar, ll l, ll r){
	for(int i = l ; i < r ; i++)
		cout << ar[i] << " ";
	cout << endl;
}

ll fast(){
	ll temp = 1, exp = 1e9 + 5, pow = 2;
	while( exp > 0 ){
		if( exp % 2 )
			temp = (temp * pow) % mod;
		exp /= 2;
		pow = (pow * pow) % mod; 
	}
	return temp;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    ari;
    ll sum = 0, sq = 0;
    for(int i = 0 ; i < n ; i++){
    	sum += a[i];
    	sum %= mod;
    	sq += (a[i] * a[i]) % mod;
    	sq %= mod;
    }
    ll ans = (((sum * sum) % mod - sq) + mod) % mod;
    ans = (ans * fast()) % mod;
    cout << ans << endl;
	return(0);
}

Measured memory_bytes: 7528
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 2e5+1;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll p = 29;

int main(){

    FASTIO;
    PRECISION; 

    int k,n;
    cin>>k>>n;
    int ans = 0;

    vector<int>arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    for(int i=0;i+1<n;i++){
        ans = max(arr[i+1]-arr[i],ans);
    }

    ans = max(ans,arr[0]+k-arr[n-1]);

    cout<<k-ans<<"\n";
}

Measured memory_bytes: 1024
////D
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[2019],ans;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string str;
	cin>>str;
	a[0]=1;
	ll t=0,cnt=1;
	for(int idx=str.length()-1;idx>=0;idx--){
		t=(t+cnt*(str[idx]-'0')%2019)%2019;
		//cout<<t<<endl;
		ans+=a[t];
		a[t]++;
		cnt=cnt*10%2019;
	}
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 3764
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
li = [a, b, c, d, e]
new = []
mini = 10
for i in range(len(li)):
    if li[i] % 10 == 0:
        new.append(li[i])
    else:
        new.append(li[i] // 10 * 10 + 10)
        if mini > li[i] % 10:
            mini = li[i] % 10
# print(new)
print(sum(new)-(10-mini))


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

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();

        string Sunny = "Sunny";
        string Cloudy = "Cloudy";
        string Rainy = "Rainy";

        if(S == Sunny)
        {
            Console.WriteLine(Cloudy);
        }
        else if(S == Cloudy)
        {
            Console.WriteLine(Rainy);
        }else if(S == Rainy)
        {
            Console.WriteLine(Sunny);
        }
    }
}

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

using namespace std;


void reverse(string &s,int a,int b)
{
    int i=a;
    int j=b;
    while(i<=j)
    {
        char ch=s[i];
        s[i]=s[j];
        s[j]=ch;
        i++;
        j--;
    }

}

void replace(string &s,int a,int b,string s1)
{
    int k=0;
    for(int i=a;i<=b;i++)
        s[i]=s1[k++];
}

int main()
{
//    freopen("in.txt","r",stdin);

    int n;
    string s;
    cin>>s;
    cin>>n;
    while(n--)
    {
        string con;
        cin>>con;
        if(con=="replace")
        {
            int a,b;
            string re;
            cin>>a>>b>>re;
            if(b-a+1==re.length())
            replace(s,a,b,re);
//            cout<<s<<endl;
        }
        else if(con=="reverse")
        {
            int a,b;
            cin>>a>>b;
            reverse(s,a,b);
//            cout<<s<<endl;

        }
        else if(con=="print")
        {
            int a,b;
            cin>>a>>b;
            for(int i=a; i<=b; i++)
                cout<<s[i];

            cout<<endl;
//            cout<<s<<endl;

        }
    }
}



Measured memory_bytes: 3212
N, M = map(int, input().split())
H = [i for i in map(int, input().split())]
path = [set() for _ in range(N+1)]

for i in range(M):
    A, B = map(int, input().split())
    path[A].add(B)
    path[B].add(A)

ans = 0
for n, i in enumerate(path):
    if len(i) == 0:
        ans += 1
        continue
    # print(i, n)
    if all([H[n-1] > H[j-1] for j in i]):
        ans += 1


ans -= 1
# 0の分引く
print(ans)


Measured memory_bytes: 112004
#include <stdio.h>

int main(void)
{
    int i, j, w, h;

    while(1){

        scanf("%d %d", &h, &w);

        if (h == 0 && w == 0)
            break;
        
        for (i = 0; i < w; ++i)
            printf("#");

        printf("\n");

        for (i = 0; i < h - 2; ++i){
            printf("#");
            for (j = 0; j < w -2; ++j)
                printf(".");
            printf("#");
            printf("\n");

        }

        for (i = 0; i < w; ++i)
            printf("#");

        printf("\n\n");
        

    }

    return 0;

}


Measured memory_bytes: 2032
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
int main() {
  int N; cin >> N;
  // vector<pair<int, int> > G[10001];
  map<int, vector<pair<int, int> > > G;
  for (int i = 0; i < N-1; i++) {
    int u, v, w; cin >> u >> v >> w;
    u--; v--; w %= 2;
    G[u].push_back(make_pair(v, w));
    G[v].push_back(make_pair(u, w));
  }
  queue<pair<int, int>> Q;
  Q.push(make_pair(0, 0));
  int color[100001] = {0};
  int checked[100001] = {0};
  while (Q.size()) {
    pair<int, int> p = Q.front(); Q.pop();
    checked[p.first]++;

    if (p.second % 2) color[p.first] = 1;
    for (int i = 0; i < G[p.first].size(); i++) {
      pair<int, int> n = G[p.first][i];
      if (checked[n.first]) {
        continue;
      }
      Q.push(make_pair(n.first, p.second + n.second));
    }
  }
  for (int i = 0; i < N; i++) {
    cout << color[i] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 12672
n,k,c=map(int,input().split())
s=input()

available=[]
for i in range(n):
    if s[i]=="o":
        available.append(i)

#左側から〇を数える
left=[0]*n
rest=0
cnt=0

for i in range(n):
    if s[i]=="o" and i>=rest:
        cnt+=1
        left[i]=cnt
        rest=i+c+1
    else:
        left[i]=cnt

#右側から〇を数える
right=[0]*n
rest=n-1
cnt=0

for i in range(n-1,-1,-1):
    if s[i]=="o" and i<=rest:
        cnt+=1
        right[i]=cnt
        rest=i-c-1
    else:
        right[i]=cnt

#-1日目、n+1日目がエラーにならないように0を足す        
for i in ([left,right]):
    i.insert(0,0)
    i.append(0)

ans=[]

for i in range(1,n+1):
    a=left[i-1]+right[i+1]
    if a<k:
        ans.append(i)
    
for j in ans:
    print(j)


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

int main() {
    int a,b,ans;
    //string trg;
    //string tmp;
    
    cin >> a >> b ;

    if(a>12){
        ans = b;
    }else if(a > 5){
        ans = b/2;
    }else{
        ans = 0;
    }

    cout << ans;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

var (
	n, k int
)

func main() {
	fmt.Scan(&n, &k)
	ls := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&ls[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(ls)))

	fmt.Println(sum(0, ls[0:k]))
}

func sum(x int, ls []int) int {
	if len(ls) == 0 {
		return x
	}

	return sum(x+ls[0], ls[1:])
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    ll n;
    cin>>n;
    int ans=0;
    int p=sqrt(n);
    for(ll i=p;i>=1;i--)
    {
        if(n%i==0)
        {
            ans=max(n/i,i);
            break;
        }
    }
    string s=to_string(ans);
    cout<<s.length();

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
const int maxx = 1e5+5 ;
vector < int > g[maxx+5],p(maxx+5),vis(maxx+5,0);
int temp=1;
void bfs()
{
    queue < int > q ;
    q.push(1);
    vis[1]=1;
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        for(auto v : g[u])
        {
           if(vis[v]==0)
           {
               p[v]=u;
               vis[v]=1;
               q.push(v);
               temp++;
           }
        }
    }
}
int main()
{
    int q,n;
    cin >> n >>  q ;
    while(q--)
    {
        int u,v;
        cin >> u >> v ;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    bfs();
    if(temp==n){cout << "Yes" << endl;}
    else{cout << "No" << endl;return 0;}
    for(int i=2;i<=n;i++)
    {
        cout << p[i] << endl;
    }
    return 0 ;
}

Measured memory_bytes: 10664
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1, 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
template <class T> long long mod_factorial(T N, const int mod) {
    long long ans = 1;
    for (int i = 0; i < N; i++) {
        ans *= (i + 1);
        ans %= mod;
    }
    return ans;
}

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

    int N, M;
    cin >> N >> M;
    if (1 < abs(N - M)) {
        print(0);
        return 0;
    }

    int time = 2 - abs(N - M);
    ll ans   = mod_factorial(N, MOD7) * mod_factorial(M, MOD7);
    MOD(ans);
    ans *= time;
    MOD(ans);
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#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()
const int INF = 100100100;
typedef long long ll;
 
int main() {
   int n;
   string s;
   cin >> n >> s;
   string a=s.substr(0,n/2), b=s.substr(n/2,n/2);
   if(n%2==0 && a==b)
   cout << "Yes" << endl;
   else 
   cout << "No" << endl;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

int main(void){
    int n, m;
    cin >> n >> m;
    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
//#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
double pi = acos(-1) ;
ll z =  1000000007 ;
ll inf = 6000000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll min(ll a , ll b){if(a < b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return ((2*i) + 2) ;}
void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
//__builtin_popcount(n) -> returns number of set bits in n

void solve()
{
	ll n , k ;
	cin >> n >> k ;
	k-- ;
	vector<pair<ll ,ll> > v ;
	ll mini = (k*(k+1))/2 ;
	ll maxi = 0 ;
	fo(i , k+1)
		maxi += (n - i) ;
	ll ans = 0 ;
	//cout << "mini = " << mini << " maxi = " << maxi << endl ;	
	for(ll i = k ; i <= n ; i++)
	{
		//cout << "mini = " << mini << " maxi = " << maxi << endl ;	
		ans += ((maxi - mini)+1) ;
		mini += i+1 ;
		maxi += (n - (i+1)) ;
		
	}
	//ans++ ;
	cout << ans%z << endl ;
	return ;
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif*/
    
    ll t ;
    //cin >> t ;
    t = 1 ;

    while(t--)
    {
        solve() ;
    }
    //cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
    return 0;
}

Measured memory_bytes: 3640
import Data.Function (on)

sn::Int->Int
sn n = n + 1

div' = (/) `on` fromIntegral

main = do
  [n, k] <- map read . words <$> getLine::IO[Int]
  pn <- map read . words <$> getLine
  let snn = scanl (+) 0 $ map sn pn
  print $ div' (maximum $ zipWith subtract snn (drop k snn)) 2

Measured memory_bytes: 77180
#include <stdio.h>

int main(void) {
	int h[10] = {0};
	int i, j, x;
	for(i = 0; i < 10; i++){
		scanf("%d", &h[i]);
	}
	for(i = 0; i < 9; i++){
		for(j = i+1; j < 10; j++){
			if(h[i] < h[j]){
				x = h[i];
				h[i] = h[j];
				h[j] = x;
			}
		}
	}
	for(i = 0; i < 3; i++){
		printf("%d\n", h[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <assert.h>
typedef int64_t ll;
typedef uint64_t ull;
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (200001)
#define MOD (1000000007)

int main(void)
{
    ll a,b;
    scanf("%ld %ld",&a,&b);

    printf("%ld\n", max(0,a-(b*2)));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,minv=1e9+7;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=100;i++){
		int tot=0;
		for(int j=1;j<=n;j++) tot+=(fabs(a[j]-i)*fabs(a[j]-i));
		minv=min(tot,minv);
	}
	cout<<minv<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            String line = sc.next();
            char c = line.charAt(0);
            int b = sc.nextInt();
            if(c == '+'){
                System.out.println(a+b);
            }
            else if(c == '-'){
                System.out.println(a-b);
            }
            else if(c == '*'){
                System.out.println(a*b);
            }
            else if(c == '/'){
                System.out.println(a/b);
            }
            else{
                break;
            }
        }
    }
}


Measured memory_bytes: 26312
N, K = map(int, input().split())
S = list(input())
 
p = 0
while K > 0 and p < len(S):
	now = S[p]
	p += 1
	if p >= len(S):
		break
	while now == S[p]:
		p += 1
		if p >= len(S):
			break
			
	if p >= len(S):
		break
	q = p + 1
	if q >= len(S):
		if S[p] == "R":
			S[p] = "L"
		else:
			S[p] = "R"
		break
	while S[p] == S[q]:
		q += 1
		if q >= len(S):
			break
	while p < q:
		if S[p] == "R":
			S[p] = "L"
		else:
			S[p] = "R"
		p += 1
		if p >= len(S):
			break
	K -= 1
 
ret = 0;
for x in range(len(S)-1):
	if S[x] == S[x + 1]:
		ret += 1
print(ret)



Measured memory_bytes: 4084
// https://atcoder.jp/contests/abc163/tasks/abc163_e

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1
 
#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define getBit(S, j) ((S & ( 1 << j )) >> j)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<*it.F<<' '<<*it.S<<'\t';  cout<<endl;
#define printn(x)   for(auto it=x.begin();it!=x.end();it++) cout<<*it<<endl;
#define in(x,n)   for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
 
#define vi vector<int>
#define vll vector<ll>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<ii>
#define viii vector<pair<ii,int>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)

int n=2001;
pair<int,ll> arr[2001];
ll dp[2001][2001];

bool desc(pair<int,ll> a,pair<int,ll> b)
{
    return (a.S>b.S);
}
ll solve(int l, int r)
{
    if(dp[l][r]!=-1)
        return dp[l][r];
    
    if(l==r)
        return 1ll*abs(arr[n].F-l)*arr[n].S;

    ll res= max(solve(l+1,r)+1ll*abs(arr[n-r+l].F - l)*arr[n-r+l].S,solve(l,r-1)+1ll*abs(arr[n-r+l].F - r)*arr[n-r+l].S);
    dp[l][r]=res;

    return res;
    
}

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

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        arr[i]=mp(i,x);
    }
    sort(arr+1,arr+n+1,desc);
    MSET(dp,-1);
    cout<<solve(1,n);
    

    return 0;
}


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

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff         first
  #define  ss         second
  #define  pb         push_back
  #define  all(x)     (x).begin(), (x).end()
  #define  rep(i,a,b) for(ll i=a ; i<b ; ++i)
  #define  D(x)       cout << #x << " - " << x << endl;
  #define  IOS        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D2(x)      cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  D2p(x)      cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)    fixed<<setprecision(y)<<x

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll MAX_N = 1e6+4;
  void solve(){
     int l,r,d;
     cin >> l >> r >> d;
     int cnt=0;
     for(int i=l;i<=r;i++){
       if(i%d==0)cnt++;
     }
     cout << cnt;
  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3800
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int mod=1e9+7;
int C[5000][5000];
void comp()
{
	for(int i=0;i<5000;i++)
	{
		C[i][0]=1;
	}
	for(int i=1;i<5000;i++)
		for(int j=1;j<5000;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	int n,k;
	cin>>n>>k;

	comp();
	//cout<<C[2][1]*C[3][2]<<"\n";
	for(int i=1;i<=k;i++)
	{
		//cout<<k-1<<" "<<i-1<<" "<<n-k+i<<" "<<i<<"\n";
		cout<<(C[k-1][i-1]*C[n-k+1][i])%mod<<"\n";
	}


}

Measured memory_bytes: 198928
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = 0;
        while((n = sc.nextInt()) != 0){
            double[] s = new double[n];
            double sum = 0.0;
            for(int i = 0; i < n; i++){
                s[i] = sc.nextDouble();
                sum += s[i];
            }
            double m = sum / n;
            double ssd = 0.0;
            for(int i = 0; i < n; i++){
                ssd += (s[i] - m) * (s[i] - m);
            }
            double sd = Math.sqrt(ssd / n);
            System.out.println(sd);
        }
    }
}



Measured memory_bytes: 40252
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  sort(a.begin(), a.end());
  cout << a[n - 1] - a[0] << endl;

  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    long long N, K;
    cin >> N >> K;
    vector<vector<int>> A(62, vector<int>(N));
    REP(i, N){
        cin >> A[0][i];
        A[0][i]--;
    }
    for(int i=1; i<62; i++){
        for(int j=0; j<N; j++){
            int k0 = A[i-1][j];
            int k1 = A[i-1][k0];
            A[i][j] = k1;
        }
    }
    int cur = 0;
    for(int i=62; i>=0; i--){
        if(K&(1LL<<i)){
            cur = A[i][cur];
        }
    }
    cout << cur + 1 << endl;
    return 0;
}

Measured memory_bytes: 52624
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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(){
    ll N,sum=0,a=0,ans=INF*3;
    cin>>N;
    ll A[N];
    for(ll i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    for(ll i=0;i<N-1;i++){
        a+=A[i];
        ans=min(ans,abs(sum-2*a));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int L, R;
  cin >> L >> R;
  int m = 2019;
  vector<int> cnt(m);
  for (int i = L; i <= R && i - L <= 3 * m; ++i) {
    cnt[i % m]++;
  }
  int ret = m;
  for (int i = 0; i < m; ++i) {
    if (!cnt[i]) continue;
    if (cnt[i] >= 2) ret = min(i * i % m, ret);
    for (int j = i + 1; j < m; ++j) {
      if (!cnt[j]) continue;
      ret = min(i * j % m, ret);
    }
  }
  printf("%d\n", ret);
  return 0;
}


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

const int N = 1e5;
int sz[N+100],par[N+100],ans[N+100];
vector<int>g[N+100];
int find(int a)
{
	if(par[a]==a){
		return a;
	}
	return par[a] = find(par[a]);
}
void unionSet(int a,int b)
{
	a = find(a);
	b = find(b);
	//printf("%d %d\n",a,b);
	if(a!=b)
	{
		if(sz[a]>sz[b]){
			sz[a] += sz[b];
			par[b] = par[a];
		}
		else{
			sz[b] += sz[a];
			par[a] = par[b];
		}
	}
}
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		par[i] = i;
		sz[i] = 1;
	}
	for(int i=1;i<=m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		unionSet(a,b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(int i=1;i<=n;i++){
		sort(g[i].begin(),g[i].end());
		ans[i] = sz[find(i)]-g[i].size();
	}
	for(int i=1;i<=k;i++){
		int c,d;
		scanf("%d%d",&c,&d);
		if(!binary_search(g[c].begin(),g[c].end(),d)){
			if(find(c)==find(d)){
				ans[c]--;
				ans[d]--;
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d ",ans[i]-1);
	}
	printf("\n");
}


Measured memory_bytes: 10292
#include<stdio.h>
int main(void){
  int d[3] = {0};
  int i;
  int h = 0;
  char S[3];
  scanf("%s",&S);
  for(i = 0;i < 3;i++){
 	 if(S[i] == 'a'){
       if(d[0] == 0){
         h += 1;
         d[0] = 1;
       }
     }
    else if(S[i] == 'b'){
       if(d[1] == 0){
         h += 1;
         d[1] = 1;
       }
     }
    else if(S[i] == 'c'){
       if(d[2] == 0){
         h += 1;
         d[2] = 1;
       }
     }
  }
  if(h == 3)printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
import sys
def input():
	return sys.stdin.readline()[:-1]

n = int(input())
d = []
M, m = 0, 10**30
M_of_m, m_of_M = 0, 10**30
for _ in range(n):
	x, y = map(int, input().split())
	g, l = max(x, y), min(x, y)
	d.append([l, g])
	M = max(M, g)
	m = min(m, l)
	M_of_m = max(M_of_m, l)
	m_of_M = min(m_of_M, g)
ans1 = (M - m_of_M) * (M_of_m - m)

M_other, m_other = M_of_m, m
m_reversed = 10**30
gap = M_other - m_other
d.sort(key=min)
for i in range(n-1):
	M_other = max(M_other, d[i][1])
	m_reversed = min(m_reversed, d[i][1])
	m_other = min(m_reversed, d[i+1][0])
	gap = min(gap, M_other - m_other)
M_other = max(M_other, d[n-1][1])
m_reversed = min(m_reversed, d[i][1])
gap = min(gap, M_other - m_reversed)
ans2 = (M - m) * gap

#print(ans1, ans2)
print(min(ans1, ans2))

Measured memory_bytes: 40036
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
template <typename X>
struct Edge{
  int from;
  int to;
  X cost;

  Edge() = default;

  Edge(int from, int to, X cost = 1) : from(from), to(to), cost(cost) {}
};

template <typename X>
class Graph{
private:
  int n;
  int m;
  vector<vector<Edge<X>>> edge;
  vector<vector<X>> d;
  X inf = 1e+17;
  
public:
  Graph(int n) : n(n) {
    edge.resize(n);
  }

  Graph(int n, int m, vector<int> a, vector<int> b, vector<X> c) : n(n), m(m){
    edge.resize(n);
    rep(i,m) {
      add_edge(a[i], b[i], c[i]);
      add_edge(b[i], a[i], c[i]);
    }
  }

  void add_edge(int from, int to, X cost = 1) {
    edge[from].emplace_back(from, to, cost);
  }

  void dijkstra(int s) {
    d.resize(n);
    d[s].resize(n ,inf);
    d[s][s] = 0;
    using pi = pair<X, int>;    
    //    auto compare = [](pi a, pi b) { return a.second < b.second; };
    priority_queue<pi, vector<pi>, greater<pi>> pq;
    pq.emplace(0, s);
    while( !pq.empty() ) {
      pi p = pq.top(); pq.pop();
      int v = p.second; // 頂点
      X dist = p.first; // s->vの最短距離
      if(d[s][v] < dist) continue;
      for(auto w: edge[v]) {
	if(chmin(d[s][w.to], d[s][v] + w.cost)) {
	  pq.emplace(d[s][w.to], w.to);
	}
      }
    }
  }

  X get_d(int u, int v) { return d[u][v]; }
  X get_inf() { return inf; }
  
};

int main()
{
  int n,m,s,t;cin >> n >> m >> s >> t;
  s--; t--;
  vector<int> u(m), v(m);
  vector<ll> a(m), b(m);
  rep(i,m) {
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--; v[i]--;
  }

  Graph<ll> gpen(n, m, u, v, a);
  Graph<ll> gpsn(n, m, u, v, b);

  gpen.dijkstra(s);
  gpsn.dijkstra(t);

  vector<ll> res(n);
  rep(i,n) {
    res[i] = gpen.get_d(s, i) + gpsn.get_d(t, i);
  }

  ll M = 1e+15;
  ll tmp = M;
  vector<ll> ans(n);
  for(int i = n - 1;i >= 0;--i) {
    tmp = min(tmp, res[i]);
    ans[i] = M - tmp;
  }

  rep(i,n) cout << ans[i] << "\n";
  
  
  return 0;
}


Measured memory_bytes: 26976
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (b - a == c - b) {
    printf("YES\n");
  }
  else {
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int s;
  cin >> s;

  int ab, cd;
  ab = s/100;
  cd = s%100;
  bool flag1 = false;
  bool flag2 = false;
  if(1 <= ab && ab <= 12) flag1 = true;
  if(1 <= cd && cd <= 12) flag2 = true;

  if(flag1 == false && flag2 == true)cout<<"YYMM"<<endl;
  else if(flag1 == true && flag2 == false)cout<<"MMYY"<<endl;
  else if(flag1 == true && flag2 == true)cout<<"AMBIGUOUS"<<endl;
  else if(flag1 == false && flag2 == false)cout<<"NA"<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int a[100010];

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	int ans = 0;
	for(int i = 0; i <= n; i++) {
		ans += abs(a[i] - a[(i + 1) % (n + 1)]);
	}
	for(int i = 1; i <= n; i++) {
		int res = ans;
		res -= abs(a[i] - a[i - 1]);
		res -= abs(a[i] - a[(i + 1) % (n + 1)]);
		res += abs(a[i - 1] - a[(i + 1) % (n + 1)]);
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
	char b;
	cin >> b;
	if(b == 'A'){
		cout << 'T' << endl;
	}else if(b == 'T'){
		cout << 'A' << endl;
	}else if(b == 'G'){
		cout << 'C' << endl;
	}else if(b == 'C'){
		cout << 'G' << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll x=k;
    while(a>=b&&x>0)
    {
        b*=2;
        x--;
    }
    while(b>=c&&x>0)
    {
        c*=2;
        x--;
    }
    if(c>b&&b>a)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3644