akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {

    val (N, M) = readLine()!!.split(" ").map { it.toInt() }

    val results = (1..M).map {
        val (p, s) = readLine()!!.split(" ")
        Pair(p, s)
    }

    var penalty = 0
    var ac = 0

    val scores = mutableMapOf<String, Pair<Int, Int>>()
    results.forEach { result ->
        // scoresからキーがpのscoreを取得
        val score = scores[result.first]

        // なければscoresにpとAC or WAを登録
        if (score == null) {
            scores[result.first] = if (result.second == "WA") Pair(0, 1) else{
                ac++
                Pair(1, 0)
            }
            return@forEach
        }

        // あれば"AC"済かどうかチェック
        // AC済の場合continue
        if(score.first != 0) return@forEach

        // AC済ではない場合
        // resultがACかどうかチェック
        // ACの場合scoresのWAの回数をpenaltyに追加して、acを++して、scoresを更新
        if(result.second == "AC"){
            penalty += score.second
            ac++
            scores[result.first] = score.copy(first = score.first + 1)
            return@forEach
        }
        // WAの場合scoresのWAの回数++
        scores[result.first] = score.copy(second = score.second + 1)
    }

    println("$ac $penalty")
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

// cの小さい順に並べる
bool compare(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
    return a.first.second < b.first.second;
}

int main() {

    int n, C; cin >> n >> C;

    vector<pair<pair<int, int>, int>> tv(n);
    for (int i = 0; i < n; ++i) {
        int s, t, c; cin >> s >> t >> c;
        tv[i] = make_pair(make_pair(s, t), c);
    }

    // 区間スケジューリングの考え方でソート
    sort(tv.begin(), tv.end(), compare);

    // 終わり時間、チャンネル
    vector<pair<int, int>> rokuga;
    for (int i = 0; i < n; ++i) {
        auto p = tv[i];

        bool ok = false;
        for (auto &r : rokuga) {
            // チャンネルが同じ かつ 時間もOK
            if (p.second == r.second && p.first.first >= r.first) {
                r.first = p.first.second;
                ok = true;
                break;
            }

            // チャンネルが違う かつ 時間OK
            if (p.second != r.second && p.first.first > r.first) {
                r.second = p.second;
                r.first = p.first.second;
                ok = true;
                break;
            }
        }

        if (!ok) {
            rokuga.push_back(make_pair(p.first.second, p.second));
        }

        sort(rokuga.rbegin(), rokuga.rend());
    }

    cout << rokuga.size() << endl;
}

Measured memory_bytes: 4164
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int h, w, n;
	scanf("%d%d%d", &h, &w, &n);
	VV(int) ans;
	initvv(ans, h, w, -1);
	int y = 0, x = 0;
	for(int i = 1; i <= n; ++i){
		int a;
		scanf("%d", &a);
		for(int j = 0; j < a; ++j){
			ans[y][x] = i;
			
			if(y & 1){
				if(x == 0){ ++y; }
				else{ --x; }
			}
			else{
				if(x == w - 1){ ++y; }
				else{ ++x; }
			}
		}
	}
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			printf("%d%c", ans[i][j], j == w - 1 ? '\n' : ' ');
		}
	}
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 384
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}

int dp[3001][3001];
void solve()
{
  
  string s,t;
  cin >> s >> t;

  int l1 = sz(s) , l2 = sz(t);
  
  forf(i,1,l1+1)
  {
    forf(j,1,l2+1)
    {
      if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1]+1;
      else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    }
  }

 string an ;
 


 while(l1>0 &&l2 > 0)
 {
    if(s[l1-1] == t[l2-1])
    {
      an += s[l1-1];
      l1--;
      l2--;
    }
    else if(dp[l1-1][l2] > dp[l1][l2-1])
    {
      l1--;
    }else l2--;
 }

 rv(an);

  cout<<an;
}


int32_t main()
{
  pr_init();
  //fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 73948
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();
    let s: Vec<char> = iterator.next().unwrap().chars().collect();
    let t: Vec<char> = iterator.next().unwrap().chars().collect();

    let g = gcd(n, m);
    for i in 0..g {
        if s[n / g * i] != t[m / g * i] {
            return "-1".to_string();
        }
    }

    return (n * m / g).to_string();
}

fn gcd(mut m: usize, mut n: usize) -> usize {
    while n != 0 {
        let r = m % n;
        m = n;
        n = r;
    }
    m
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    string s;
    cin>>s;
    if(s[0]=='S'){
        cout<<"Cloudy";
    }
    else if(s[0]=='C'){
        cout<<"Rainy";
    }
    else{
        cout<<"Sunny";
      //  cout<<""
    }
}

Measured memory_bytes: 256
#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字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

ll f(ll a){
    if(a <= 0) return 0;

    if(a%4 == 3) return 0;
    else {
        ll ans = 0;
        for(int i=0; i<a%4+1; i++) ans ^= a-i;
        return ans;
    }
}

int main(){
    ll a, b; cin >> a >> b;
    cout << (f(b)^f(a-1)) << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  int i = nextInt();
  cout << (N - i + 1) << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include <cmath>
#include <limits>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int A, B;
	cin >> A >> B;
	if (A <= 9 && B <= 9)cout << A * B;
	else cout << "-1";
}

Measured memory_bytes: 256
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;
for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}

Measured memory_bytes: 2488
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

vector<int> g[100100];

int dfs(int s,int p){
    int k=0;
    for(int r:g[s]){
        if(r!=p){
            k^=(1+dfs(r,s));
        }
    }
    return k;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
    for(int i=0;i<n-1;i++){
        int x,y; cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    if(dfs(0,-1)){
        cout << "Alice" << endl;
    }
    else{
        cout << "Bob" << endl;
    }
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
map<ii, int> mp;
int N, M, K;
ii v[MAX];
ll ans[10];

bool check(int i, int j) {
    return (i >= 1 && i <= N && j >= 1 && j <= M);
}

void calc(int x, int y) {
    int cnt = 0;
    REP(i, -1, 1) REP(j, -1, 1) {
        if(!check(x+i, y+j)) return;
        if(mp.count(mk(x+i, y+j))) cnt++;
    }
    ans[0]--; ans[cnt]++;
}

void calc() {
    map<ii, bool> vis;
    rep(k, 0, K)
        REP(i, -1, 1) REP(j, -1, 1) {
            if(!vis[mk(v[k].F+i, v[k].S+j)])
                calc(v[k].F+i, v[k].S+j);
            vis[mk(v[k].F+i, v[k].S+j)] = 1;
        }
}

int main() {
    int a, b;
    cin >> N >> M >> K;
    rep(i, 0, K) {
        cin >> a >> b;
        mp[mk(a, b)] = 1;
        v[i] = mk(a, b);
    }
    calc();
    ans[0] += 1LL*(N-2)*(M-2);
    REP(i, 0, 9) printf("%lld\n", ans[i]);
    return 0;
}


Measured memory_bytes: 66940
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

int main(int, char**) {
    ios_base::sync_with_stdio(0); cin.tie(NULL);

    int A, B, C;
    cin >> A >> B >> C;

    if ((A == B && B != C) || (A == C && C != B) || (B == C && A != B))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdlib>
#include<string>
#include<unordered_map>
#include<vector>
#include<list>
#include<map>
#include<set>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=200000+5;
const int MAX_M=100000+5;
const int INF=0x7fffffff;
const int inf=1000000000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
char s[MAX_N];
int main()
{
    int n;
    cin>>n;
    scanf("%s",s);
    int i,j;
    int len=strlen(s);
    i=0;
    j=len-1;
    int ans=0;
    for(i=0; i<j; i++)
    {
        if(s[i]=='W')
        {
            while(j>i&&s[j]=='W')
            {
                j--;
            }
            if(j!=i)
            {
                s[j]='W';
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}


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

void solve()
{
	ll n; cin >> n;
	ll arr[n];
	ll wxor = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i];
		wxor = (wxor ^ arr[i]);
	}
	for (auto x : arr)
	{
		cout << (x ^ wxor) << ' ';
	}
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll t = 1; //cin >> t;
	while (t--)
		solve();
	return 0;
}



Measured memory_bytes: 5200
// D - Road to Millionaire
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	int N; cin>>N;
	vector<int> A(N+1, 0);
	rp(i, 1, N+1) cin>>A[i];
	vector<ll> dp_stock(N+1, 0);
	vector<ll> dp_yen(N+1, 0);
	dp_yen[0] = 1000;
	rp(day, 1, N+1){
		dp_stock[day] = max(dp_stock[day-1], dp_yen[day-1]/A[day]);
		ll sell = dp_yen[day-1] + dp_stock[day-1] * (A[day] - A[day-1]);
		dp_yen[day] = max(dp_yen[day-1], sell);
	}
	cout<< dp_yen[N] <<endl;
}


Measured memory_bytes: 3572
N = int(input())
li = list(map(int,input().split()))

A = [0,0,0]
for i in range(N):
    if li[i] % 2 != 0:
        A[0] += 1
    elif li[i] % 2 == 0 and li[i] % 4 != 0:
        A[1] += 1
    elif li[i] % 2 == 0 and li[i] % 4 == 0:
        A[2] += 1

if A[1] == 0:
    if A[2]+1 < A[0]:
        print("No")
    else:
        print("Yes")
else:
    if A[2] < A[0]:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 14252
a, b = input().split()

result = ''
if(a == 'H' and b == 'H'):
  result = 'H'
elif(a == 'H' and b == 'D'):
  result = 'D'
elif(a == 'D' and b == 'H'):
  result = 'D'
elif(a == 'D' and b == 'D'):
  result = 'H'

print(result)


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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int N,K;
    string S;
    cin>>N>>S>>K;
    char c = S[K-1];
    rep(i,N){
        if(S[i]!=c){
            S[i] = '*';
        }
    }

    cout<<S<<endl;
}

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

#define PROBLEM_NUMBER 3

int main(){
  string input;
  cin >> input;
  bool isGood = false;
  // 1~3と2~4文字目が同じ文字であるか判定
  for (int i = 0; i < 2; i++)
  {
    string tmpStr = input.substr(i, PROBLEM_NUMBER);
    if(count(tmpStr.cbegin(), tmpStr.cend(), input[i]) == 3)
    {
      isGood = true;
    }
  }
  // 出力
  if (isGood == true)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int intcat(int, int);

int main(){
  int A, B, C;
  int a[3];
  int i, result;

  scanf("%d %d %d", &a[0], &a[1], &a[2]);

  if(a[1]<=a[0] && a[2]<=a[0]){
    A=a[0];
    if(a[1]<=a[2]){
      B=a[2];
      C=a[1];
    }else{
      B=a[1];
      C=a[2];
    }
  }else if(a[0]<=a[1] && a[2]<=a[1]){
    A=a[1];
    if(a[0]<=a[2]){
      B=a[2];
      C=a[0];
    }else{
      B=a[0];
      C=a[2];
    }
  }else{
    A=a[2];
    if(a[0]<=a[1]){
      B=a[1];
      C=a[0];
    }else{
      B=a[0];
      C=a[1];
    }
  }

  result=intcat(A,B);
  printf("%d\n", result+C);

  return 0;
}

int intcat(int a, int b){
  int connect;
  char buf[256];

  sprintf(buf, "%d%d", a, b);
  sscanf(buf, "%d", &connect);
  return(connect);
}
   

Measured memory_bytes: 128
#include<cstdio>
using namespace std;
const int maxn=100000 + 7;
int a[maxn];
int main(){
    int n,num,k;
    scanf("%d%d",&n,&k);
    if(n==k){
        printf("1\n");
        return 0;
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]==1) num=i;
    }
    int f=(num-1)%(k-1);
    int l=(n-num)%(k-1);
    int ans=0;
    if(f+l!=0) ans++;
    ans+=(num-1)/(k-1)+(n-num)/(k-1);
    if(f+l>k-1)
    ans++; 
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  int cnt=0;
  string s;
  cin>>a>>b>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='-')cnt++;
  }
  for(int i=0;i<s.size();i++){
    if(s[i]=='-'){
      if(a==i&&cnt==1){
	cout<<"Yes"<<endl;
	return(0);
      }
    }
  }
  cout<<"No"<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    int x,y;cin>>x>>y;
	cout<<abs(abs(x)-abs(y))+((x<0&&y<0)||(x>=0&&y>=0)?(x>=y)*2:1)+(y?0:-1)<<endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;
const long MOD = 1000000007;


int main() {long N;
cin >> N;
string ans = "";
long k = 0;

if(N == 0) ans = '0';
while(N != 0){
    long tmp = k+1;
    long two = 2;
    long tmp2 = pow(two, tmp);
    if(N % tmp2 != 0){
        ans = '1' + ans;
        N = N - pow(-2, k);
    }
    else ans = '0' + ans;
    k++;
}
show(ans);

  return 0;
 
}



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

class UnionFind{
public:
    vector<int> tree;

    void init(){
        for(int i = 0;i < tree.size();i++){
            tree[i] = -1;
        }
        return;
    }

    UnionFind(int n){
        n++;
        tree.resize(n);
        init();
        return;
    }

    int root(int i){
        if(tree[i] < 0) return i;
        return tree[i] = root(tree[i]);
    }

    bool unite(int i, int j){
        i = root(i);
        j = root(j);
        if(i == j) return false;

        tree[i] += tree[j];
        tree[j] = i;
        return true;
    }

    int size(int i){
        return -tree[root(i)];
    }

    bool same(int i, int j){
        return root(i) == root(j);
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    int a[100], b[100];
    for(int i = 0;i < m;i++){
        cin >> a[i] >> b[i];
    }

    int ans = 0;
    for(int i = 0;i < m;i++){
        UnionFind uf(n);
        for(int j = 0;j < m;j++){
            if(i != j){
                uf.unite(a[j], b[j]);
            }
        }

        if(uf.size(1) != n){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}








Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
long long a , b;
long long k;
long long intersect(long long a , long long b , long long l , long long r){
    return max(0LL , min(r , b) - max(l , a) + 1LL);
}
long long getor(long long l , long long r){
    long long res = 0;
    for(int i = 0 ; i < 60 ; ++i){
        if((l | (1LL << i)) <= r){
            res |= 1LL << i;
        }
    }
    return res;
}
int main(){
    cin >> a >> b;
    if(a == b){
        cout << 1 << endl;
        return 0;
    }
    for(int i = 60 ; i >= 0 ; --i){
        if(((a >> i) & 1) != ((b >> i) & 1)){
            k = 1LL << i;
            break;
        }
        a &= ~(1LL << i);
        b &= ~(1LL << i);
    }
    long long ans = 0;
    ans += k - a;
    long long r = getor(k , b);
    ans += (r - k + 1);
    ans += k - a;
    ans -= intersect(k + a , k + k - 1 , k , r);
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
k = sum(a)
All = k*(1/(4*m))
count = 0
for i in range(n):
    if a[i] < All:
        pass
    else:
        count+=1
if count >= m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
n =int(input())
t,a =map(int,input().split())
h = list(map(int,input().split()))
ans = 0
near = 10000
for i in range(n):
    if abs(t-h[i]*0.006 - a) < near:
        ans = i
        near = abs(t-h[i]*0.006-a)
print(ans+1)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    int n, a;
    cin >> n >> a;

    ll x[n];
    rep(i,  n){
        cin >> x[i];
        x[i] -= a;
    }

    ll dp[n+1][2*a*n+1] = {};
    dp[0][n*a] = 1;
    rep(i, n)rep(j, 2*a*n){
        if(j - x[i] < 0 || j - x[i] > 2*a*n){
            dp[i+1][j+1] = dp[i][j+1];
        }
        else dp[i+1][j+1] = dp[i][j+1] + dp[i][j+1-x[i]];
    }

    cout << dp[n][a*n] - 1 << endl;
}


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

int GCD(int m, int n){
	int t;
	if (n > m){ t = n; n = m; m = t; }

	while (n != 0){
		t = n;
		n = m%n;
		m = t;
	}
	return m;
}


int main(){
	int x, y;
	cin >> x >> y;

	cout << GCD(x, y) << endl;
}

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

using namespace std;

int main(){
  int n,h,w; cin >> n >> h >> w;
  vector<int> x(n);
  for(int i=0;i<n;++i) cin >> x[i];
  vector<int> used(n*w);
  for(int i=0;i<n;++i) {
    for(int j=0;j<w+x[i];++j) {
      if(i&1) {
        if(j<x[i]) used[(i+1)*w-j-1]--;
        else used[(i+1)*w-j-1]++;
      } else {
        if(j<x[i]) used[i*w+j]--;
        else used[i*w+j]++;
      }
    }
  }
  int ans=0;
  for(int i=0;i<n*w;++i)
    if(used[i]<0) ans++;
  cout << ans*h << endl;
  
  return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

template<long long mod>
class modint{
private:
  long long num;
  long long extgcd(long long a, long long b, long long&x, long long&y)const {
    long long d = a;
    if(b != 0){d = extgcd(b, a%b, y, x);  y -= (a/b) * x;}
    else{x = 1; y = 0;}
    return d;
  }
  long long modinverse()const{
    long long x, y;
    extgcd(num, mod, x, y);
    return (mod + x%mod)%mod;
  }
public:
  modint():num(0){}
  modint(const long long x):num((x < 0?(x+mod):x)%mod ){}
  friend modint operator+(const modint&a, const modint&b)
  {    return modint(a.num + b.num);  }
  friend modint operator-(const modint&a, const modint&b)
  {    return modint(a.num - b.num);  }
  friend modint operator*(const modint&a, const modint&b)
  {    return modint(a.num * b.num);  }
  friend modint operator/(const modint&a, const modint&b)
  {    return modint(a*b.modinverse());  }
  modint& operator+=(const modint&b)
  {    return (*this) = (*this) + b;  }
  modint& operator-=(const modint&b)
  {    return (*this) = (*this) - b;  }
  modint& operator*=(const modint&b)
  {    return (*this) = (*this) * b;  }
  modint& operator/=(const modint&b)
  {    return (*this) = (*this) / b;  }
  modint& operator++()
  {    (*this)+=1; return (*this);  }
  modint& operator--()
  {    (*this)-=1; return (*this);  }
  modint operator++(int){
    modint tmp(*this);
    ++(*this);
    return tmp;
  }
  modint operator--(int){
    modint tmp(*this);
    --(*this);
    return tmp;
  }    
  modint pow(unsigned long long i){
    if(i == 0) return 1;
    if(i & 1){
      return (*this) * (this->pow(i-1));
    }
    modint<mod>hpow = (this->pow(i>>1));
    return hpow * hpow;
  }
  friend ostream& operator<<(ostream&os, const modint&a){
    os << a.num;
    return os;
  }
  friend istream& operator>>(istream&is, modint&a){
    long long x; is >> x;
    a = x;
    return is;
  }
};

using mint = modint<1000000007>;

mint kai(int s, int e){
  mint ret = 1;
  for(int i = s; i <= e; ++i)ret *= i;
  return ret;
}

mint Comb(int x, int y){
  int z = x - y;
  if(z < y) swap(z,y);
  return kai(z+1,x)/kai(1,y);
}

int main(){
  unsigned n,a,b; cin >> n >> a >> b;
  mint two = 2;
  mint sum = two.pow(n)-1;  
  mint an = Comb(n,a);
  mint bn = Comb(n,b);
  cout << sum - an - bn << endl;
  return 0;
}


Measured memory_bytes: 256
//write for s26

#include<bits/stdc++.h>
using namespace std;
long long a[100010];
int main() {
	unsigned long long ans=1;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		if(a[i]==0) {
			cout<<0<<endl;
			return 0;
		}
	}
	for(int i=1;i<=n;i++) {
		if(log10(ans)+log10(a[i])>18) {
			cout<<-1<<endl;
			return 0;
		}
		if(ans*a[i]>1000000000000000000) {
			cout<<-1<<endl;
			return 0;
		}
		ans*=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
#define error(args...) { vector<string> _debug = split(#args, ',');err(begin(_debug), args);}

vector<string> split(const string& s, char c){
	vector<string> v;stringstream ss(s);string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {cerr << endl;}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a,Args... args){
cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << " ",err(++it, args...);
}

char s[310][310];

const int limit = 610;
char tmp[limit][limit];
int csum[limit][limit];

int solve(int n, int offset,int all){
	int ofr = 0, ofc = 0;
	if(offset > 0) ofr = offset;
	if(offset < 0) ofc = -offset;

	rep(i,2*n)rep(j,2*n) tmp[i][j] = s[(i + ofr) % n][(j + ofc) % n];

	rep(i,2*n)rep(j,2*n) csum[i][j] = (tmp[i][j] == tmp[j][i]);

	rep(i,2*n)rep(j,2*n){
		if(i-1>=0) csum[i][j] += csum[i-1][j];
		if(j-1>=0) csum[i][j] += csum[i][j-1];
		if(i-1>=0 and j-1>=0) csum[i][j] -= csum[i-1][j-1];
	}

	int ret = 0;
	rep(i,all){
		int cnt = csum[i + n - 1][i + n - 1];
		if(i - 1 >= 0) cnt -= csum[i - 1][i + n - 1];
		if(i - 1 >= 0) cnt -= csum[i + n - 1][i - 1];
		if(i - 1 >= 0) cnt += csum[i - 1][i - 1];
		if(cnt == n * n) ret++;
	}

	//error(n,offset,all,ret);

	return ret;
}


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

	rep(i,n)rep(j,n) cin >> s[i][j];

	int ans = 0;
	for(int i = - n + 1; i <= n - 1; ++i){
		ans += solve(n, i, n - abs(i));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
#include<string.h>
#define INF 200000000
#define min(x,y) ((x>y)?y:x)
int main(){
	int i,j,k,n,m,c[105][105],t[105][105],v[105],u[105],a,b,x,y;
	FILE *fp;
	//fp=fopen("test.txt","r");
	fp=stdin;
	while(1){
		fscanf(fp,"%d%d",&n,&m);
		if(n==0 && m==0)break;
		for(i=1;i<=m;i++)for(j=1;j<=m;j++)c[i][j]=t[i][j]=INF;
		for(i=0;i<n;i++){
			fscanf(fp,"%d%d%d%d",&a,&b,&x,&y);
			c[a][b]=c[b][a]=x;
			t[a][b]=t[b][a]=y;
		}
		fscanf(fp,"%d",&k);
		for(i=0;i<k;i++){
			fscanf(fp,"%d%d%d",&a,&b,&x);
			for(j=1;j<=m;j++)v[j]=INF;
			memset(u,-1,sizeof(u));
			v[a]=0;
			while(1){
				y=-1;
				for(j=1;j<=m;j++){
					if(u[j]==-1 && (y==-1 || v[j]<v[y]))y=j;
				}
				if(y==-1)break;
				u[y]=0;
				for(j=1;j<=m;j++){
					if(x==0)v[j]=min(v[j],v[y]+c[y][j]);
					else v[j]=min(v[j],v[y]+t[y][j]);
				}
			}
			printf("%d\n",v[b]);
		}
	}
	fclose(fp);
	return 0;
}

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

int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int wake = h1*60 + m1;
    int sleep = h2*60 + m2;
    int ans = sleep - wake - k;
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;
import java.util.stream.*;
import java.util.function.*;

public class Main {
    
    public static void main(String[] args) throws Exception {
        System.out.println(new Main().solve());
    }
    
    // パラメタ渡しもちゃんとクラス作るのも面倒なので手抜き
    // 必要な値はここで全部取ってしまう
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    String s = sc.next();
    char[] c = s.toCharArray();
    
    int solve() {
        
        // ベタにやると n * n
        // メモ化する？
        // 一旦連続数を記録して
        // でも10101010...みたいなのはどうする？ 最大連続数をもっとく？
        
        // 1だけの区間と0だけの区間が最大 k 回連続する区間を探す
        // 区間連続数が最大でない区間が一番多い可能性もある？ 11110101011110
        // 先頭からカウントして数を記録
        // 次は次のブロックかカウントして数を記録　前回より多ければ残す　以下同様？
        
        // List<Integer> countList = countList();
        int[] countArray = countArray();
        
        // c[0] の値と countList の偶奇でどっちのブロックかはわかる
        // index偶数が逆立ち
        boolean oddHandstand = c[0] == '0';
        // 端が逆立ちなら奇数番目を反転させる
        // 端が絡まなければ必ず 1 と 1 で挟まれる区間になるので最大 k * 2 + 1 区間の和が最大になるもの
        // 片方が端の場合は 最大 k * 2
        // 両端が1の場合は n が答えになる
        
        // 端が0の時は0からそこもチェック
        // 他は1始まりのみでよい
        
        int max = 0;
        int current = 0;
        int nextIndex = 0;
    
        for(int i = 0; i < countArray.length; i++) {
            int nextSize = nextIndex + (k * 2 + 1);
            // 端かどうかで +1 が変わる
            if(i == 0 && oddHandstand) {
                nextSize--;
            }
            if(nextSize > countArray.length) {
                nextSize = countArray.length;
            }
            for(int j = nextIndex; j < nextSize; j++) {
                current += countArray[j];
            }
            if(current > max) {
                max = current;
            }
            current = 0;
            nextIndex += 2;
            if(i == 0 && oddHandstand) {
                nextIndex--;
            }
        }
        
        return max;
    }
    
    int[] countArray() {
        List<Integer> countList = new ArrayList<>();
        // 最初を入れておく　気持ち悪いが
        char tmp = c[0];
        int tmpCount = 1;
        for(int i = 1; i < c.length; i++) {
            if(c[i] == tmp) {
                tmpCount++;
            } else {
                tmp = c[i];
                countList.add(tmpCount);
                tmpCount = 1;
            }
        }
        // 末尾処理
        countList.add(tmpCount);
        
        int[] countArray = new int[countList.size()];
        for(int i = 0, size = countList.size(); i < size; i++) {
            countArray[i] = countList.get(i);
        }
        
        // System.out.println(countList);
        
        return countArray;
    }
    
}


Measured memory_bytes: 28632
def div(n):
  ret=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      ret.append(i)
      if i!=n//i:
        ret.append(n//i)
  return ret

n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
s=sum(arr)
ans=1
d=div(s)
for val in d:
  arr=sorted(arr,key=lambda x:x%val)
  parr=[]
  narr=[]
  for num in arr:
    narr.append(num%val)
    parr.append(val-num%val)
  for i in range(n-1):
    parr[i+1]+=parr[i]
    narr[i+1]+=narr[i]
  for i in range(n-1):
    ncnt=narr[i]
    pcnt=parr[-1]-parr[i]
    if ncnt!=pcnt:
      continue
    else:
      if pcnt<=k:
        ans=max(ans,val)
print(ans)

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

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

using namespace std;
using vint = std::vector<int>;

int main() {
	int N;
	int j, i;

	cin >> N;

	if (N / 10 == 9 || N - N / 10 * 10 == 9) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int x,y;
    while (1){
        scanf("%d %d",&x,&y);
        if (x==0 && y==0) break;
        if (x<y){
            printf("%d %d\n",x,y);
        } else {
            printf("%d %d\n",y,x);
        }
    }
    return 0;
}        


Measured memory_bytes: 2076
N,L=map(int,input().split())
origin=(2*L+N-1)*N/2
D=[]
A=[]
for i in range(1,N+1):
  answer=(2*L+N-1)*N/2-(L+i-1)
  difference=abs(origin-answer)
  A.append(int(answer))
  D.append(difference)
print(A[D.index(min(D))])

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

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

fn main() {
    let s: String;
    let mut cnt = 0;
    s = read();
    for si in s.as_str().chars() {
        if si == '1' {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


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

int main()
{
  int H, W;
  cin >> H >> W;
  string str;
  for(int i = 0; i < H; i++)
  {
    for(int j = 0; j < W; j++)
    {
      cin >> str;
      if(str == "snuke")
      {
        cout << (char)(j + 0x41) << i + 1 << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

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

        String[] values = scanner.nextLine().split(" ");
        int n = Integer.parseInt(values[0]);
        int limit = Integer.parseInt(values[1]);

        Queue<Process> queue = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            queue.add(new Process(scanner.nextLine().split(" ")));
        }

        int elapsedTime = 0;
        while (!queue.isEmpty()) {
            Process process = queue.poll();
            int processTime = Math.min(process.reamingTime, limit);
            process.reamingTime -= processTime;
            elapsedTime += processTime;
            if (process.reamingTime == 0) {
                System.out.println(process.processName + " " + Integer.toString(elapsedTime));
            } else {
                queue.add(process);
            }
        }

    }

    private static class Process {
        String processName;
        int reamingTime;

        Process(String[] data) {
            processName = data[0];
            reamingTime = Integer.parseInt(data[1]);
        }

    }
}



Measured memory_bytes: 106136
import java.util.Scanner;

/**
 * https://abc072.contest.atcoder.jp/tasks/arc082_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] a = new int[N];
		for(int i=0; i<N; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		
		int ans = 0;
		for(int i=0; i<N-1; i++){
			if(a[i]==i+1){
				a[i] = a[i+1];
				a[i+1] = i+1;
				ans++;
			}
		}
		if(a[N-1]==N) ans++;
		System.out.println(ans);
		
	}

}

Measured memory_bytes: 48028
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toInt()}
    var cnt = a.count{it < 0}
    val ans = a.map{Math.abs(it.toLong())}.sum()
    val mi = a.map{Math.abs(it)}.reduce{i1, i2 -> Math.min(i1, i2)}
    println(if(cnt % 2 == 1) ans - mi * 2 else ans)
}


Measured memory_bytes: 61712
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

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

    int s = 0, m = n;
    while(m >= 1) {
        s += m%10;
        m /= 10;
    }
    if (n%s==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input_text = scanner.nextLine();
        int N = Integer.parseInt(input_text);
        HashMap<String, Integer> map = new HashMap<>();
        int maximum = 0;
        for(int i = 0; i < N; i++) {
            input_text = scanner.nextLine();
            if(!map.containsKey(input_text)) map.put(input_text, 0);
            int val = map.get(input_text) + 1;
            if (maximum < val) {
                maximum = val;
            }
            map.put(input_text, val);
        }

        List<String> array = new ArrayList<>();
        for(String key : map.keySet()) {
            if(map.get(key) >= maximum) {
                array.add(key);
            }
        }
        
        Collections.sort(array);
        for(String d : array) {
            System.out.println(d);
        }
        scanner.close();
    }

}

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

using namespace std;

const int dh[4]={0, 1, 0, -1};
const int dw[4]={1, 0, -1, 0};

int main() {
    int H, W;
    cin >> H >> W;
    
    int N;
    cin >> N;
    
    int curh=0, curw=0;
    int curd=0;
    vector<vector<int> > ans(H, vector<int>(W, -1));
    for(int n=0; n<N; n++) {
        int a;
        cin >> a;
        for(int j=0; j<a; j++) {
            ans[curh][curw] = n+1;
            int nxh=curh+dh[curd];
            int nxw=curw+dw[curd];

            if(nxh<0 || nxh>=H || nxw<0 || nxw>=W) {
                curd++;
            } else if(ans[nxh][nxw]!=-1) {
                curd++;
            }
            curd %= 4;
            curh += dh[curd];
            curw += dw[curd];
        }
    }
    
    for(int h=0; h<H; h++) {
        for(int w=0; w<W; w++) {
            cout << ans[h][w] << " ";
        }
        cout << endl;
    }


    return 0;
    
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
int n,x[101],y[101],h[101],X,Y,H,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {scanf("%d%d%d",&x[i],&y[i],&h[i]);if(h[i]) {H=h[i];Y=y[i];X=x[i];}}
	for(int i=0;i<=100;++i) {
		for(int j=0;j<=100;++j) {
			ans=H+abs(X-i)+abs(Y-j);
			bool flag=false;
			for(int k=1;k<=n;++k) if((ans-abs(i-x[k])-abs(j-y[k])!=h[k]&&ans-abs(i-x[k])-abs(j-y[k])>=0)||(ans-abs(i-x[k])-abs(j-y[k])<0&&h[k]!=0))
			{flag=true;break;}
			if(!flag) {printf("%d %d %d\n",i,j,ans);return 0;}
		}
	}
	return 0;
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

const int N = 2e3 + 5;

int L[N];

int main(){
    fIO

    int n;
    cin >> n;

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

    sort(L, L + n);

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int req = L[i] + L[j];

            int idx = lower_bound(L, L + n, req) - L;
            ans += idx - j - 1;
        }
    }
    cout << ans;
}








Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long ans = sc.nextLong() - 1;
    long p = 2;
    for(int i = 1; i < n; i++) {
      long a = sc.nextLong();
      if(a == p) {
        p++;
      } else {
        long r = (a % p);
        if(r == 0) {
          if(a > p) {
            ans++;
            a -= (p + 1);
            r = (a % p);
            ans += ((a - r) / p);
          }
        } else {
          ans += ((a - r) / p);
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 49012
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

int now,n;


bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


int main(){
  int ans=0;
  cin >> n;
  
  vector<pair<int, int> > pairs(n);
  REP(i,n) cin>>pairs[i].first>>pairs[i].second;
  sort(pairs.begin(),pairs.end(), compare_by_b);
  ll time=0LL;
  REP(i,n){
    time+=(ll)pairs[i].first;
    if (pairs[i].second<time)ans=1;

  }

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


  //cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&a!=c)
    cout<<"Yes";
    else if(a==c&&a!=b)
    cout<<"Yes";
    else if(b==c&&a!=b)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
M = 10 ** 9 + 7
 
x, y = map(int, input().split())
 
r = 0
if (x + y) % 3 == 0:
  a, b = (2 * y - x) // 3, (2 * x - y ) // 3
  if a >= 0 <= b:
    f = [1]
    for i in range(1, a + b + 1):
      f.append(f[-1] * i % M)
    r = f[a + b] * pow(f[a] * f[b], M - 2, M) % M
print(r)

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

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

const int N=1007;
const ll mod=1e9+7;

int n,m;
int dp[N][N];
string s[N];

int main(){
	n=input(),m=input();
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}

	dp[1][1]=1;

	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j-1]=='#') continue;
			if(s[i][j-1]=='.')
				dp[i][j]+=dp[i][j-1],
				dp[i][j]%=mod;
			if(s[i-1][j-1]=='.')
				dp[i][j]+=dp[i-1][j],
				dp[i][j]%=mod;
		}
	}

	printf("%d\n",dp[n][m]);
}

Measured memory_bytes: 5248
from heapq import heappush, heappop
inf = float('inf')
mod = 10**9 + 7

# ダイクストラ法 計算量O(ElogV)
# [引数]: 隣接リスト, 始点
class Dijkstra:
    def __init__(self, to:list, start:int):
        self.N = len(to)
        self.to = [s[:] for s in to]
        self.start = start
        self.dist = [inf] * self.N
        self.dist[start] = 0
        # cnt : 最短経路の数
        self.cnt = [0] * self.N
        self.cnt[start] = 1
        self.pq = [(self.dist[start], start)]

    # distを更新
    def update(self) -> None:
        while self.pq:
            _, v = heappop(self.pq)
            for nv, w in self.to[v]:
                if self.dist[nv] > self.dist[v] + w:
                    self.dist[nv] = self.dist[v] + w
                    heappush(self.pq, (self.dist[nv], nv))
                if self.dist[nv] == self.dist[v] + w:
                    self.cnt[nv] += self.cnt[v]
                    self.cnt[nv] %= mod

N, M = map(int,input().split())
to = [[] for _ in range(3*N)]
for _ in range(M):
    u, v = map(int,input().split())
    u -= 1; v -= 1
    for i in range(3):
        nu = 3*u + i
        nv = 3*v + (i + 1) % 3
        to[nu].append((nv, 1))
S, T = map(int,input().split())
S -= 1; T -= 1

DI = Dijkstra(to, 3*S)
DI.update()

ans = DI.dist[3*T]
if ans == inf:
    ans = -1
else:
    ans //= 3
print(ans)

Measured memory_bytes: 112052
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  long long x;
  cin >> x;

  long long ans=0;
  ans=(x+11-1)/11*2;
  if(x<=ans/2*11-5)  ans--;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	long long res = 0;
	int cur_height;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (i == 0)
		{
			cur_height = a;
			continue;
		}
		if (a <= cur_height)
			res += cur_height - a;
		else
			cur_height = a;
	}
	cout << res << endl;
}

Measured memory_bytes: 3624
inp=input().split(" ")
N=int(inp[0])
A=int(inp[1])
x=list(map(int, input().split(" ")))
y=[x[i]-A for i in range(N)]
y=[0]+y
X=max(x)
dp=[[0 for i in range(2*N*X+1)] for j in range(N+1)]
for j in range(N+1):
    for t in range(2*N*X+1):
        if j==0 and t==N*X:
            dp[j][t]=1
        elif j>=1 and (t-y[j]<0 or t-y[j]>2*X*N):
            dp[j][t]=dp[j-1][t]
        elif j>=1 and 0<=t-y[j] and t-y[j]<=2*N*X:
            dp[j][t]=dp[j-1][t]+dp[j-1][t-y[j]]
        else:
            dp[j][t]=0
print(dp[N][N*X]-1)

Measured memory_bytes: 5740