akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
int N,M;
cin>>N>>M;
//2のN乗で全てのスイッチの組み合わせを表す
int sw=1;
for(int i=0;i<N;++i){
  sw*=2;
}
//電球の設定を入力
vector<vector<int>> v(M);
int k,s;
for(int i=0;i<M;++i){
  cin>>k;
  for(int j=0;j<k;++j){
    cin>>s;
    s-=1;
    v[i].push_back(s);
  }
}


int P[M];
int p;
for(int i=0;i<M;++i){
  cin>>p;
  P[i]=p;
}


int ref[N];
int tmp;
int tmp_result;
int answer=0;
bool judge;
for(int i=0;i<sw;++i){
  tmp=i;
  judge=true;
  //スイッチのパターンを0,1に
  for(int j=0;j<N;++j){
    ref[j]=(tmp%2);
    tmp/=2;
  }
  //各電球について判定
  for(int l=0;l<M;++l){
    tmp_result=0;
    for(int m=0;m<v[l].size();++m){
      tmp_result+=ref[v[l][m]];
    }
    if(tmp_result%2!=P[l]){
      judge=false;
      break;
    }
  }
  if(judge){
    answer+=1;
  }
}
cout<<answer<<"\n";
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <cmath>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main()
{
	ll A,B,C,K;
	scanf("%lld %lld %lld %lld",&A,&B,&C,&K);
	ll x=A-B;
	if(K%2==1) x=-x;
	printf("%lld\n",x);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){ return (y != 0 ? gcd(y, x % y) : x); }
//最小公倍数
lol lcm(lol x, lol y){ return ((x * y) / gcd(max(x, y), min(x, y))); }

lol n, x[10], y[10];
long double ans = 0;

void nasu(int now, int bit, double sum){
  if(bit == (1 << n) - 1){
    ans += sum;
    //    cout << now << " " << sum << "NASU\n";
    return;
  }
  rep(i, n){
    if(!(bit & (1 << i))){
      //cout << now << " ";
      nasu(i, (bit | (1 << i)), sum + sqrt((x[now] - x[i]) * (x[now] - x[i]) + (y[i] - y[now]) * (y[i] - y[now])));
    }
  }
  return;
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cin >> n;
  lol num = 1;
  rep(i, n){
    num *= (i + 1);
    cin >> x[i] >> y[i];
  }
  rep(i, n){
    nasu(i, (1 << i), 0.0);
  }
  cout << SYOU(10) << ans / num << '\n';
  return 0;
}


Measured memory_bytes: 3860
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main()
{
	int t,p,r; char c;
	map<int,int> a;
	map<int,vector<int> > m;
	map<int,vector<int> >::reverse_iterator it;

	while(cin >> t >> c >> p, t||p)
	{
		m[p].push_back(t);
	}

	for(r=1,it=m.rbegin(); it!=m.rend(); r++,it++)
	{
		for(int i=0; i<it->second.size(); i++)
		{
			a[it->second[i]] = r;
		}
	}

	while(cin >> t)
	{
		cout << a[t] << endl;
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  ll n;
  scan(n);
  ll sum = 0;
  for (ll i = 1; i < 1000006; ++i) {
    ll j = n / i;
    if (j <= i+1) {
      break;
    }
    if (n == i * j) {
      sum += (j - 1);
    }
  }
  print(sum);

  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

int a[100005];

signed main(){
	
	int n;cin>>n;
	rep(i,n) cin>>a[i];
	
	int sum = 0;
	int ans1 = 0;
	rep(i,n)
	{
		sum += a[i];
		if(i%2==0 && sum <= 0)
		{
			ans1 += 1-sum;
			sum = 1;
		}
		
		if(i%2==1 && sum >= 0)
		{
			ans1 += sum+1;
			sum = -1;
		}
	}
	
	sum = 0;
	int ans2 = 0;
	rep(i,n)
	{
		sum += a[i];
		if(i%2==1 && sum <= 0)
		{
			ans2 += 1-sum;
			sum = 1;
		}
		
		if(i%2==0 && sum >=0)
		{
			ans2 += sum+1;
			sum = -1;
		}
	}

	cout << min(ans1,ans2) << endl;
	
}
 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    string S;
    cin >> S;
    int not_pass = 0;
    for(char c: S) {
        if (c == 'x')
            not_pass += 1;

    }
    if (not_pass >= 8)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
int main(){
int n,m;
cin >> n >> m;
vector<int> a(m,0);
for(int i = 0;i<n;i++){
    int k;
    cin >> k;
    for(int j = 0;j<k;j++){
        int f;
        cin >> f;
        f--;
        a[f]++;
    }
}
int ans = 0;
for(int i = 0;i<m;i++) if(a[i]==n) ans++;
cout << ans;

}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

LL N,a[100010];

int main(){
    cin >> N;

    if (N==1){
        cout << "YES\n";
        return 0;
    }

    LL i,sum=0;
    for (i=1; i<=N; i++) cin >> a[i],sum+=a[i];

    if (sum%(N*(N+1)/2)!=0){
        cout << "NO\n";
        return 0;
    }

    LL op=sum/(N*(N+1)/2); a[N+1]=a[1];
    LL tot=0;
    for (i=1; i<=N; i++){
        LL aux=op+a[i]-a[i+1];
        if (aux<0 || aux%N!=0){
            cout << "NO\n";
            return 0;
        }

        tot+=aux/N;
    }

    if (tot!=op) cout << "NO\n";
    else cout << "YES\n";

    return 0;
}












Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
  mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
    cout.flush();
    cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }


ll gcd (ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; }

ll primes(ll x) {
    ll ans = 0;
    for (ll d = 2; d * d <= x; ++d) {
        if (x % d == 0) ++ans;
        while (x % d == 0) {
            x /= d;
        }
    }
    ans += (x > 1);
    return ans;
}

int main() {
    cout << fixed << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);


    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    cout << (primes(g) + 1) << endl;


    print_time();
    return 0;
}




Measured memory_bytes: 256
n = int(input())

ans = 0
for i in range(3):
    if str(n)[i] == "1":
        ans += 9 * pow(10, 2 - i)
    elif str(n)[i] == "9":
        ans += 1 * pow(10, 2 - i)
    else:
        ans += int(str(n)[i]) * pow(10, 2 - i)

print(ans)
print()


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

int main()
{
  int cnt = 0;
  
  char word[10];
  scanf("%s",word);

  int n;
  cin >> n;
  char str[n][10];

  for(int i = 0;i < n;i++){

      scanf("%s",str[i]);

    for(int j = 0;j < 10;j++){
      
      char *ans = strstr(str[i],word);
      
      if(ans != 0){
	cnt++;
	break;
      }
      
      for(int k = 0;k < 9;k++){
	swap(str[i][k],str[i][k+1]);
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	t=1;
	while(t--){
	long long int n;
	cin>>n;
	long long int ans=0;
	vector<long long int> divisor(n+1,0);
	for (long long int i = 1; i <= n; ++i) {  
        for (long long int j = i; j <= n; j += i)  
            divisor[j]++;;  
    } 
	for(long long int i=1;i<=n;i++){
		ans=ans+divisor[i]*i;
	}
	cout<<ans<<"\n";
	}
}

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

using namespace std;

#define fin cin
#define fout cout
//ifstream fin("x.in"); ofstream fout("x.out");

typedef long long i64;
const int nmax = 2e5;

int v[nmax + 1];
i64 s[nmax + 1];

int main() {
    fin.sync_with_stdio(false); fin.tie(); fout.tie();
    int n;
    fin >> n;

    for (int i = 1; i <= n; ++ i) {
        fin >> v[i];
        v[i] -= i;
    }

    sort(v + 1, v + n + 1);
    for (int i = 1; i <= n; ++ i)
        s[i] = s[i - 1] + v[i];

    i64 ans = 1LL << 60;
    for (int i = 1; i < n; ++ i) {
        i64 s1 = s[i], s2 = s[n] - s[i];
        int dif = (i - (n - i));

        i64 b;
        if (dif == 0)
            b = v[i];
        else
            b = (s2 - s1) / (-dif);

        if (v[i] <= b && b <= v[i + 1])
            ans = min(ans, b * dif + s2 - s1);

        -- b;
        if (v[i] <= b && b <= v[i + 1])
            ans = min(ans, b * dif + s2 - s1);

        b += 2;
        if (v[i] <= b && b <= v[i + 1])
            ans = min(ans, b * dif + s2 - s1);
    }

    for (int i = 1; i <= n; ++ i) {
        i64 s1 = s[i], s2 = s[n] - s[i];
        int dif = (i - (n - i));

        ans = min(ans, 1LL * v[i] * dif + s2 - s1);
    }

    fout << ans << "\n";
    return 0;
}


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

int main(int argc, char *argv[]) {
  int n, m;
  std::cin >> n;
  std::vector<int> t(n + 1);
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    std::cin >> t.at(i);
    sum += t.at(i);
  }
  std::cin >> m;
  for (int i = 0; i < m; ++i) {
    int p, x;
    std::cin >> p >> x;
    std::cout << sum + x - t.at(p) << std::endl;
  }
}


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

int atgc(char c){
  if(c=='A' || c=='T' || c=='G' || c=='C'){
    return 1;
  }else{
    return 0;
  }
}

int main(){
  string s;
  cin>>s;
  int count=0;
  vector<int> v;
  int c;
  for(int j=0;j<s.size();j++){
    c=j;
    int i=0;
    while(atgc(s[c])==1){
      c++;
      i++;
    }
    count=max(count,i);
  }
    cout<<count<<endl;
}

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

const long long M = 1000003;
typedef long long ll;

int inv[M], fact[M];

int qpow(long long a, int n) {
	return (n?(qpow(a*a%M, n/2)*(n%2?a:1)):1)%M;
}

int main() {
	inv[1] = 1;
	for (int i = 2; i < M; ++i)
		inv[i] = (M-inv[M%i]*(M/i)%M)%M;
	fact[0] = 1;
	for (int i = 1; i < M; ++i)
		fact[i] = (ll)fact[i-1]*i%M;

	int q, x, d, n;
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d%d", &x, &d, &n);
		if (d == 0) {
			printf("%d\n", qpow(x, n));
		}
		else {
			if (x == 0) {
				puts("0\n");
				continue;
			}
			int l = (ll)x*inv[d]%M, r = l+(n-1);
//			printf("%d %d\n", l, r);
			if (r >= M) puts("0\n");
			else printf("%lld\n", (ll)fact[r]*inv[fact[l-1]]%M*qpow(d, n)%M);
		}
	}
}


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

int n,m;
map<string,int>	c;
string a[20];
string dp[20005];

string mx(string i,string j)
{
	if(i.size()==j.size())
	{
		if(i>=j)	return i;
		else j;
	}
	if(i.size()>j.size())	return i;
	else return j;
}



int main()
{
	cin>>n>>m;
	c["1"]=2,c["2"]=5,c["3"]=5,c["4"]=4,c["5"]=5,c["6"]=6,c["7"]=3,c["8"]=7,c["9"]=6;
	for(int i=1;i<=m;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			string r=a[j];
			if(i<c[r])	continue;
			if(dp[i-c[r]]=="" && i-c[r]!=0)	continue;
			dp[i]=mx(dp[i],r+dp[i-c[r]]);
		}
	}
	cout<<dp[n]<<endl;
	
	
}







Measured memory_bytes: 29252
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  int mx, g;
  rep(i, n){
    int in;
    cin >> in;
    if(i == 0){
      mx = g = in;
    }else{
      mx = max(mx, in);
      g = __gcd(g, in);
    }
  }
  if(mx >= k && k % g == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    int x,a,b; cin >> x >> a >> b;
    cout << (x-a) % b << endl;
}

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

long long calc(int X){
  int ans =0;
  while(X>0){
    ans+=X%10;
    X/=10;
  }
  return ans;
}

int main(){
  int N;cin>>N;
  long long res=1LL<<60;
  for (long long i =1;i<N;++i){
    long long j=N-i;
    long long tmp=calc(i)+calc(j);
    res = min(res,tmp);
  }
  cout<<res<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
  int a, b, c,tmp;
  scanf("%d %d %d",&a,&b,&c);
  if( a > b ){
    tmp = b;
    b = a;
    a = tmp;
  }
  if( a > c ){
    tmp = c;
    c = a;
    a = tmp;
  }
  if( b > c ){
    tmp = c;
    c = b;
    b = tmp;
  }

  printf("%d %d %d\n",a ,b, c);
  return 0;
  
}

Measured memory_bytes: 1804
/*
ID: techiah1
PROG: test
LANG: C++
*/
#define _CRT_SECURE_NO_WARNINGS
#pragma _attribute_((optimize("-O2")))
#pragma comment(linker, "/STACK:102400000,102400000")

#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <sstream>
#include <time.h>
#include <iomanip>

//#define Local

using namespace std;

int res[110][110];
int h, w, n;
int i = 0, j = 0;
bool flg = 0;

void paint(int num, int tim)
{
	for (i; i < h;)
	{
		if (flg)
		{
			for (j; j >= 0 && tim; j--)
			{
				res[i][j] = num;
				tim--;
			}
			if (j < 0)
			{
				i++;
				j++;
				flg = !flg;
			}

		}
		else
		{
			for (j; j < w&&tim; j++)
			{
				res[i][j] = num;
				tim--;
			}
			if (j == w)
			{
				i++;
				j--;
				flg = !flg;
			}

		}
		if (!tim)
			break;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input1.txt", "r", stdin);
	//freopen("output1.txt", "w", stdout);


	cin >> h >> w >> n;
	i = 0;
	j = 0;
	for (int a = 1; a <= n; a++)
	{
		int tmp;
		cin >> tmp;
		paint(a, tmp);
	}

	for (int a = 0; a < h; a++)
	{
		for (int b = 0; b < w; b++)
			cout << res[a][b] << " ";
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int main()
{
    int H,W;
    cin>>H>>W;
    vector<bool> through(H*W,true);
    int blackNum=0;
    for (int i=0; i<H; ++i) {
        string str;
        cin>>str;
        for (int j=0; j<W; j++) {
            if(str[j]=='#'){
                through[i*W+j]=false;
                blackNum++;
            }
        }
    }
    
    queue<int> q;
    q.push(0);
    through[0]=false;
    vector<int> dist(H*W,0);
    while(!q.empty())
    {
        int n = q.front();
        if(n==H*W-1){
            cout<<H*W-blackNum-dist[n]-1<<endl;
            return 0;
        }
        if(n%W-1>=0&&through[n-1]){
            through[n-1]=false;
            q.push(n-1);
            dist[n-1] = dist[n]+1;
        }
        if(n%W+1<W&&through[n+1]){
            through[n+1]=false;
            q.push(n+1);
            dist[n+1]=dist[n]+1;
        }
        if(n-W>=0&&through[n-W]){
            through[n-W]=false;
            q.push(n-W);
            dist[n-W]=dist[n]+1;
        }
        if(n+W<H*W&&through[n+W]){
            through[n+W]=false;
            q.push(n+W);
            dist[n+W]=dist[n]+1;
        }
        through[n]=false;
        q.pop();
    }
    
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashSet;
fn main() {
    input! {
        N: usize,
        ab: [(usize1, usize1); N-1],
    }
    let mut edges = Vec::with_capacity(N);
    for _ in 0..N {
        edges.push(vec![]);
    }
    for &(a, b) in &ab {
        edges[a].push(b);
        edges[b].push(a);
    }
    use std::collections::{VecDeque, HashSet};
    let mut queue = VecDeque::new();
    let mut visited = HashSet::new();
    let mut d_from_zero = vec![0; N];
    queue.push_back((0, 0));

    while let Some((cur, dist)) = queue.pop_front() {
        if visited.contains(&cur) {
            continue;
        }
        d_from_zero[cur] = dist;
        visited.insert(cur);

        for &to in &edges[cur] {
            queue.push_back((to, dist + 1));
        }
    }

    let mut queue = VecDeque::new();
    let mut visited = HashSet::new();
    queue.push_back((N - 1, 0));
    let mut s_cnt = 0;

    while let Some((cur, dist)) = queue.pop_front() {
        if visited.contains(&cur) {
            continue;
        }

        visited.insert(cur);
        if dist < d_from_zero[cur] {
            s_cnt += 1;
        }

        for &to in &edges[cur] {
            queue.push_back((to, dist + 1));
        }
    }

    let f_cnt = N - s_cnt;

    println!("{}", if f_cnt > s_cnt {"Fennec"} else {"Snuke"});
}



Measured memory_bytes: 23624
#include <iostream>
using namespace std;
int main(){
int n;
int b;
int c;
int d;
int e;
while(cin >>n){
if(n==0){break;}
int a[n];
b=0;
while(b<n){
cin >>a[b];
b=b+1;}
d=a[0];
b=0;
while(b<n){
e=0;
c=b;
while(c<n){
e=e+a[c];
if(e>d){d=e;}
c=c+1;}
b=b+1;}
cout <<d<<endl;}}

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

using namespace std;

int n;

int solve(int l, int r, vector <int> &h) {
	if (l > r) {
		return 0;
	}
	if (l == r) {
		return h[l];
	}
	int ind = l;
	for (int i = l; i <= r; i++) {
		if (h[ind] > h[i]) {
			ind = i;
		}
	}
	int total = h[ind];
	for (int i = l; i <= r; i++) {
		h[i] -= total;
	}
	total += solve(l, ind - 1, h) + solve(ind + 1, r, h);
	return total;
}

int main() {
	cin >> n;
	vector <int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	cout << solve(0, n - 1, h);
	return 0;
}


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


using ll = long long;
const int MaxN = 2e5+10;
int n, d, a;
vector<pair<int, int>> vxh;


void solve()
{
    queue<pair<int, ll>> q;
    ll ans = 0;
    ll c = 0;

    sort(vxh.begin(), vxh.end());
    for (const auto &e : vxh) {
        while (!q.empty() && q.front().first < e.first) {
            c -= q.front().second;
            q.pop();
        }
        ll v = (e.second + a - 1) / a - c;
        if (v <= 0) continue;
        c += v;
        ans += v;
        q.emplace(e.first + 2*d, v);
    }
    cout << ans << endl;
}


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

    cin >> n >> d >> a;
    int xi, hi;
    for (int i = 0; i < n; i++) {
        cin >> xi >> hi;
        vxh.emplace_back(xi, hi);
    }
    solve();
    return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#include <string.h>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15


int main(){

   // ios_base::sync_with_stdio(0);

  int Tests=1;
  //cin>>Tests;

  while(Tests--){
     //cout<<"enter value of the n"<<endl;
   int n;
   cin>>n;

    cout<<(1000-n%1000)%1000<<endl;
  }

return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
int N,M;
vector<int> vt[1010], ans, tmp;

void bfs(int start){
    queue<int> que;
    que.push(start);
    vector<int> pre(1010, -1);
    while(!que.empty()){
        int now=que.front(); que.pop();
        for(auto v:vt[now]){
            if(v==start){
                tmp=vector<int>();
                tmp.push_back(start+1);
                while(now!=start){
                    tmp.push_back(now+1);
                    now=pre[now];
                }
                if(ans.size()>tmp.size() || ans.size()==0) swap(ans, tmp);
                return;
            }
            if(pre[v]>=0) continue;
            pre[v]=now;
            que.push(v);
        }
    }
}

int main()
{
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        vt[a].push_back(b);
    }
    for(int i=0; i<N; i++) bfs(i);
    
    if(ans.size()==0) cout << -1 << endl;
    else{
        cout << ans.size() << endl;
        for(int i=0; i<ans.size(); i++){
            cout << ans[ans.size()-1-i] << endl;
        }
    }



    return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
    int N, K;
    int l;
    int v[100];

    cin >> N >> K;

    int i = 0;
    while(cin >> l) {
        v[i] = l;
        i++;
    }

    int sum = 0;
    for (int i = 0; i < N; i++) {
        if ((K - v[i]) <= v[i]) {
            sum += (K - v[i]) * 2;
        } else {
            sum += v[i] * 2;
        }
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
s1=[]
for i in range(n):
    s=input()
    s1.append(s)
s1.sort()
s2=sorted(list(set(s1)))
s3=[0]*(len(s2))
cnt=0
for i in range(n):
    if s2[cnt]==s1[i]:
        s3[cnt]+=1
    else:
        cnt+=1
        s3[cnt]+=1
max=max(s3)
for i in range(len(s3)):
    if max==s3[i]:
        print(s2[i])


Measured memory_bytes: 91864
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    // 深さ優先探索 ?
    // 10^9*10^9 -> TLE,MLE(grid)
    public static void Main(string[] args)
    {
        var HWN = Console.ReadLine().SplittedStringToInt32List();
        var H = HWN[0];
        var W = HWN[1];
        var N = HWN[2];

        var ls = new Dictionary<string,int>();

        for (int i = 0; i < N; i++)
        {
            var ab = Console.ReadLine().SplittedStringToInt32List();
            var a = ab[0];
            var b = ab[1];
            for (int j = 0; j < 3; j++)
            {
                for (int k = 0; k < 3; k++)
                {
                    var x = a - j;
                    var y = b - k;
                    if (x + 2 > H || y+ 2 > W || x <= 0 || y <= 0)
                    {

                    }
                    else
                    {
                        var key = $"{a-j}:{b-k}";
                        if (ls.ContainsKey(key))
                            ls[key]++;
                        else
                            ls.Add(key, 1);
                    }
                }
            }
        }
        var dic = new Dictionary<int, int>();
        for (int i = 1; i < 10; i++)
        {
            dic.Add(i, 0);
        }
        foreach (var item in ls.Values)
        {
            dic[item]++;
        }
        var sum = dic.ToList().Sum(x => x.Value);
        Console.WriteLine((BigInteger)(H-2)*(BigInteger)(W-2)-sum);
        foreach (var item in dic)
        {
            Console.WriteLine(item.Value);
        }

        Console.ReadLine();
    }


    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();

    public const int INF = int.MaxValue / 2;
    #endregion
}


Measured memory_bytes: 104588
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
    string[] str=Console.ReadLine().Split(' ');
      string[] dis=str.Distinct().ToArray();
      if(dis.Length==3){
        Console.WriteLine("Three");
      }else{
        Console.WriteLine("Four");
      }
    }
    
  }

}


Measured memory_bytes: 28228
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

const ll INF=1e18;

int main() {
    int N,M;
    cin>>N>>M;
    vector<pair<pair<int,int>,ll>> lines(M);
    rep(i,M){
        cin>>lines.at(i).first.first>>lines.at(i).first.second>>lines.at(i).second;
    }
    sort(lines.begin(),lines.end());
    set<pair<ll,int>> min;
    set<pair<int,ll>> del;
    min.insert({0,1});
    del.insert({1,0});
    del.insert({N,INF});
    rep(i,M){
        pair<int,ll> x=*begin(del);
        while(x.first<lines.at(i).first.first){
            del.erase(x);
            pair<ll,int> y;
            y.first=x.second;
            y.second=x.first;
            min.erase(y);
            //if(del.empty()){cout<<-1<<endl;return 0;}
            x=*begin(del);
        }
        if(min.empty()){cout<<-1<<endl;return 0;}
        pair<ll,int> v=*begin(min);
        v.second=lines.at(i).first.second;
        v.first+=lines.at(i).second;
        min.insert(v);
        pair<int,ll> u;
        u.first=v.second;
        u.second=v.first;
        del.insert(u);
    }
    pair<int,ll> z=*begin(del);
    while(z.first<N){
//cout<<z.first<<" "<<z.second<<endl;
        del.erase(z);
        z=*begin(del);
    }
    if(z.second>=1e18){cout<<-1<<endl;return 0;}
    cout<<z.second<<endl;
    return 0;
}

Measured memory_bytes: 8704
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<pair<long long, long long>> p;
	for (auto i = 0; i < N; ++i)
	{
		long long x, y;
		cin >> x >> y;
		p.push_back(make_pair(x, y));
	}

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

	auto result = LLONG_MAX;
	for (auto i = 0; i <= N - K; ++i)
	{
		for (auto j = i + K - 1; j < N; ++j)
		{
			vector<long long> temp;
			for (auto k = i; k <= j; ++k)
			{
				temp.push_back(p[k].second);
			}

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

			auto x = p[j].first - p[i].first;
			for (auto k = 0; k <= temp.size() - K; ++k)
			{
				auto y = temp[k + K - 1] - temp[k];
				result = min(result, x * y);
			}
		}
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, C] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    if A < B and A < C and C < B:
        print "Yes"
        return
    if B < A and A > C and B < C:
        print "Yes"
        return
    print "No"



if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
//n种颜色，每种颜色k个球排成一列，将每种颜色最左边的球涂白，求最终状态数
#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
const int MAX=3e3+5;
const int mod=1e9+7;
int n,k;
int inv[MAX*MAX],fac[MAX*MAX],facinv[MAX*MAX],dp[MAX][MAX];    //已经放了i个白球和j种颜色的球，当前空格放白色或一种新颜色：dp[i][j]=dp[i-1][j]+dp[
inline void pre(){
    fac[0]=facinv[0]=1;
    inv[1]=fac[1]=facinv[1]=1;
    for(int i=2;i<MAX*MAX;i++){
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        fac[i]=fac[i-1]*i%mod;
        facinv[i]=facinv[i-1]*inv[i]%mod;
    }
}
inline int C(int x,int y){
    return (fac[x]*facinv[y]%mod)*facinv[x-y]%mod;
}
signed main(){
    scanf("%lld %lld",&n,&k);
    if(k==1){
        printf("1\n");
        return 0;
    }
    pre();
    for(int i=1;i<=n;i++){
        dp[i][0]=1;
        for(int j=1;j<=i;j++){
            dp[i][j]=dp[i-1][j]+(dp[i][j-1]*C(n*k-i-(j-1)*(k-1)-1,k-2)%mod)*(n-j+1)%mod;    //从后面空格中选k-2个放当前颜色，枚举当前颜色
            dp[i][j]%=mod;
        }
    }
    printf("%lld",dp[n][n]);
    return 0;
}


Measured memory_bytes: 239008
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

struct edge{
  ll to;
  ll cost;
};

int solve() {
  ll n;
  cin >> n;
  vector<ll> p(n);
  for(ll i = 0;i < n;i++){
      cin >> p[i];
  }
  ll ans = 0;
  ll r,l;
  for(ll i = 0;i < n - 1;i++){
      if(i + 1 == p[i]){
          ll tmp = p[i];
          p[i] = p[i + 1];
          p[i + 1] = tmp;
          ans++;
      }
  }
  if(p[n - 1] == n){
      ans++;
      ll tmp = p[n - 2];
      p[n - 2] = p[n - 1];
      p[n - 1] = tmp;
  }
  cout << ans << endl;
  return 0;
}


int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 1024
from collections import Counter

H,W=map(int,input().split())
a=[]
for i in range(H):
    a.extend(input())

v=list(Counter(a).values())
# print(v) #DB

f=True
if H%2==0 and W%2==0:    
    for e in v:
        if e%4!=0:
            f=False
            break
elif H%2==0 and W%2==1:
    q=0
    for e in v:
        if e%2!=0:
            f=False
            break
        elif e%4!=0:
            q+=1
            if q>H//2:
                f=False
                break
elif H%2==1 and W%2==0:
    q=0
    for e in v:
        if e%2!=0:
            f=False
            break
        elif e%4!=0:
            q+=1
            if q>W//2:
                f=False
                break
elif H%2==1 and W%2==1:
    p,q=0,0
    for e in v:
        if e%4==1:
            p+=1
            if p>1:
                f=False
                break
        elif e%4==3:
            f=False
            break
        elif e%4!=0:
            q+=1
            if q>(H-1)//2+(W-1)//2:
                f=False
                break
    if p==0:
        f=False

print('Yes' if f else 'No')

Measured memory_bytes: 39664
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int n;cin >> n;
    string s;cin >> s;
    int ans=0;
    for(int i=1;i<n;i++){
        int cnt=0;
        for(char c='a';c<='z';c++){
            bool left=false,right=false;
            
            for(int j=0;j<i;j++){
                if(s[j]==c){
                    left=true;
                }
            }
            for(int j=i;j<n;j++){
                if(s[j]==c){
                    right=true;
                }
            }
            if(left&&right){
                cnt++;
            }
            if(ans<cnt){
                ans=cnt;
            }
        }
    }
    cout << ans << endl;
    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 int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll a[n], i;
    for(i = 0; i < n; i++) {
    	cin >> a[i];
    }
    ll maxi = a[0], ans = 0;
    for(i = 1; i < n; i++) {
    	if(maxi >= a[i]) {
    		ans += maxi - a[i];
    	}
    	maxi = max(maxi, a[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 5208
Q = int(input())
mod = 10**6+3
arr = []
for i in range(Q):
    x, d, n = map(int, input().split())
    arr.append([x, d, n])

P = [1]*(mod+1)
for i in range(mod):
    P[i+1] = P[i]*(i+1)%mod

def rev(a):
    return pow(a,mod-2,mod)

def f(x, d, n):
    if d == 0:
        return pow(x, n, mod)
    else:
        d_r = rev(d)
        if d_r * x % mod == 0:
            return 0
        elif (d_r*x%mod+n-1) >= mod:
            return 0
        else:
            return (P[d_r*x%mod+n-1] * rev(P[d_r*x%mod-1])%mod)*pow(d,n,mod)%mod

for i in range(Q):
    print(f(arr[i][0], arr[i][1], arr[i][2]))


Measured memory_bytes: 63184
import java.io.*;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) throws IOException {

        ArrayList<Integer> num = new ArrayList<>();
        int x = 0;
        int a = 1;
        int data;

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

        do {

            data = Integer.parseInt(br.readLine());
            if (data == 0) {
                break;
            }
            num.add(data);

        } while (data != 0);

        
        for (int i = 0; i < num.size(); i++) {
            System.out.println("Case " + a + ": " + num.get(i));
            a++;
        }
    }

}

Measured memory_bytes: 32320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;



int main(){
    int h,w;
    cin >> h >> w;

    int sx,sy,gx,gy;
    cin >> sy >> sx >> gy >> gx;
    sx--;sy--;gx--;gy--;

    pair<int,int> s = make_pair(sx,sy), g = make_pair(gx,gy); 
    vector<vector<int>> ans(h,vector<int>(w,mod));
    string sur[h];

    for(int i = 0; i < h; i++) cin >> sur[i];

    auto inout = [&](int x,int y){
        if(0 <= x && x < w && 0 <= y && y < h) return true;
        else return false;
    };

    auto add = [&](pair<int,int> now,int dx,int dy){
        pair<int,int> ret = make_pair(now.first+dx,now.second+dy);
        return ret;
    };

    auto answer = [&](pair<int,int> now){
        if(now == g){
            cout << ans[now.second][now.first] << endl;
            return true;
        } else return false;
    };

    queue<pair<int,int>> p,q;
    map<pair<int,int>,bool> seen;

    

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

    p.push(s);
    seen[s] = true;
    ans[s.second][s.first] = 0;

    int can = 0;

    for(int l = 0; l <= h*w; l++){
        while(!p.empty()){
            pair<int,int> now = p.front();
            p.pop();
            for(int i = 0; i < 4; i++){
                pair<int,int> nxt = add(now,dx[i],dy[i]);
                if(inout(nxt.first,nxt.second)){
                    if(sur[nxt.second][nxt.first] == '.' && !seen[nxt]){
                        ans[nxt.second][nxt.first] = can;
                        seen[nxt] = true;
                        if(answer(nxt)) return 0;
                        p.push(nxt);
                    } else q.push(now);
                }
            }
        }
        can++;
        while(!q.empty()){
            pair<int,int> now = q.front();
            q.pop();
            for(int i = -2; i < 3; i++){
                for(int j = -2; j < 3; j++){
                    pair<int,int> nxt = make_pair(now.first+i,now.second+j);
                    if(inout(nxt.first,nxt.second)){
                        if(sur[nxt.second][nxt.first] == '.' && !seen[nxt]){
                            ans[nxt.second][nxt.first] = can;
                            seen[nxt] = true;
                            p.push(nxt);
                            if(answer(nxt)) return 0;
                        }
                    }
                }
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 35760
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> v;
    for (int i = 0; i < n; i++) {
        string s;
        int p;
        cin >> s >> p;
        v.emplace_back(s, -p, i + 1);
    }
    sort(v.begin(), v.end());

    for (auto x:v)cout << get<2>(x) << endl;
    return 0;
}

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

using namespace std;
string s;

int main(){
  cin>>s;
  int ans=0,cnt=0;
  for (int i=0; i<3; i++){
    if (s[i]=='R') cnt++;
    else ans=max(ans, cnt), cnt=0;
  }
  if (cnt) ans=max(ans, cnt);
  cout<<ans;
}


Measured memory_bytes: 3528
#include<stdio.h>
#define compile 0
#define LENGTH 21
void func_init(char str[]);
void func_reverse(char str[]);
main()
{
	char str[LENGTH];
	func_init(str);
	//scanf("%s", str);
	gets(str);
	func_reverse(str);
	return 0;
}
void func_init(char str[])
{
	int i = 0;
	while(i < LENGTH)
	{
		str[i] = 0x00;
		i++;
	}
}
void func_reverse(char str[])
{
	int i = 0;
	while(str[i + 1] != 0x00)
	{
		i++;
#if compile == 1
		printf("i = %d\n", i);
		printf("acii code of str[%d] = 0x%x\n", i, str[i]);
#endif
	}
	while(i >= 0)
	{
		if(i == 0)
		{
			printf("%c\n", str[i]);
		}
		else
		{
			printf("%c", str[i]);
		}
		i--;
	}
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<cmath>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
using namespace std;

int main()
{
int n,i=0,j=0; cin >> n; int a[n];
for(int x=0;x<n;x++) cin>>a[x];
for(int x = 0; x < n; x++)
{
  i++;
  if(a[j]==2) break;
  j= a[j]-1;
}
if(i<n) cout <<i<< endl;
else cout << -1 << endl;
return 0;
}


Measured memory_bytes: 3960
var str = String((readLine()!).sorted())

  let a = str.index(str.startIndex, offsetBy: 0)
  let b = str.index(str.startIndex, offsetBy: 1)
  let c = str.index(str.startIndex, offsetBy: 2)
  let d = str.index(str.startIndex, offsetBy: 3)
  
  if str [a]==str [b] && str [b] != str[c] && str [c]==str[d] {
    print("Yes")
  }
  else {
    print("No")
  }

Measured memory_bytes: 7844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if((10*b+c)%4==0) cout<<"YES" <<endl;
  else cout <<"NO" <<endl;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                ans += 1
print(ans)

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

int main(){
  int a,b,c,n,counter=0;
  std::cin >> a>>b>>c>>n;
  for (int i = 0; i <=3000; i++) {
    /* code */
    for (int j = 0; j <=3000 ; j++) {
      /* code */
      if((n-i*a-j*b)>=0&&(n-i*a-j*b)%c==0)counter++;
    }
  }
  std::cout << counter << std::endl;
}

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

bool isRectangleInside(int width, int height, int x, int y, int r) {
    if (x - r < 0) {
        return false;
    }
    if (x + r > width) {
        return false;
    }
    if (y - r < 0) {
        return false;
    }
    if (y + r > height) {
        return false;
    }

    return true;
}

int main() {
    int width, height, x, y,
        r;  // width|height:長方形の幅|高さ, x|y|r:円のx座標|y座標|半径
    cin >> width >> height >> x >> y >> r;

    // x軸,y軸 双方において範囲内であればYesを，そうでなければNoを出力
    if (isRectangleInside(width, height, x, y, r)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>

using namespace std;

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

int main() {

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

    int A[N];
    REP(i, N){
        scanf("%d", &A[i]);
    }

    sort(A, A + N);

    int ans = 1;

    REP(i, N-1){
        if (A[i] != A[i+1]) {
            ans += 1;
        }
    }

    printf("%d\n", ans);
}


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>;
ll dp[55][55][2505] = {0};
int main() {
    ll N, A; cin >> N >> A;
    vector<ll> x(N+1);
    rep(i, N) cin >> x[i+1];
    dp[0][0][0] = 1;
    for(ll j=1;j<=N;j++) {
        for(ll k=0;k<=N;k++) {
            for(ll s=0;s<=N*50;s++) {
                if(s < x[j])
                dp[j][k][s] = dp[j-1][k][s];
                else if(k>=1 && s >= x[j])
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]];
                else
                dp[j][k][s] = 0;
            }
        }
    }
    ll ans = 0;
    for(int k=1;k<=N;k++) ans+=dp[N][k][k*A];
    cout << ans;
}


Measured memory_bytes: 54400