akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;

int w,h;
int c[50][50];
int dx[8] = {-1,-1,-1,0,0,1,1,1};
int dy[8] = {-1,0,1,-1,1,-1,0,1};

void dfs(int x,int y)
{
    c[x][y] = 0;
    for(int i = 0; i < 8; i++){
        int nx = x + dx[i] , ny = y + dy[i];
        if(0 <= nx && nx < w && 0 <= ny && ny < h && c[nx][ny] == 1){
            dfs(nx,ny);
        }
    }
    return;
}


int main()
{
    while(true){
        int ans = 0;
        cin >> h >> w;
        if(w == 0 && h == 0){
            break;
        }
        for(int i = 0; i < w; i++){
            for(int j = 0; j < h; j++){
                cin >> c[i][j];
            }
        }
        for(int i = 0; i < w; i++){
            for(int j = 0; j < h; j++){
                if(c[i][j] == 1){
                    dfs(i,j);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
}


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

#define INF int(1e9)

int n, m, ans;
int c[21], memo[50001];

int solve(int v) {
    //cout << "called v = " << v << endl;

    if (v < 0) return INF;
    if (v == 0) return 0;
    if (memo[v] != INF) return memo[v];

    int ret = INF, tmp;

    for (int i = 0; i < m; ++i) {
        tmp = solve(v - c[i]) + 1;
        //cout << v << " " << c[i] << ", " << tmp << endl;
        ret = min(ret, tmp);
    }

    return memo[v] = ret;
}

int main() {
    cin >> n >> m;
    fill(memo, memo + 50001, INF);
    for (int i = 0; i < m; ++i) cin >> c[i];

    ans = solve(n);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5624
import numpy as np

N, K = [int(i) for i in input().split()]
P = [int(p) for p in input().split()]

max = 0
sum = 0
for i in range(N):
    sum += P[i]
    if i >= K:
        sum -= P[i-K]
    if max < sum:
        max = sum
print((max+K)/2)

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

using namespace std;
int main(){
    string s;
    cin>>s;
    int st,c;
    st=s.find('A');
    for(int i=st;i<s.size();i++){
        if(s[i]=='Z')
            c=i-st+1;
    }
    cout<<c<<endl;
}

Measured memory_bytes: 640
e=(0..gets.to_i).map{[]}
a=$<.map{|s|!s.split.map{|v|e[v.to_i]+=[$.-2]}}
e.map{|e|i=0
u={}
e.reject{|j|u[x=a[j]]=x}.map{|j|0while u[a[j]=i+=1]}}
p a.max,*a

Measured memory_bytes: 160968
L,R = map(int,input().split())
ans = set()
mini = 2019
if (R-L) >= 2019:
  print(0)
else:  
  for i in range(L,R+1):
    ans.add(i%2019)
  
  for i in ans:
    for j in ans:
      if (i*j)%2019 < mini and i != j:
        mini = (i*j)%2019
  print(mini)
      

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N; cin >> N;
  ll sum = 0;
  rep(i, N) {
    char c; cin >> c;
    ll x; cin >> x;
    if(c == '(') sum += x;
    if(c == ')') sum -= x;
    if(sum < 0) {
      cout << "NO\n";
      exit(0);
    }
  }
  
  cout << (sum == 0 ? "YES" : "NO") << endl;
  
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

int main() {
	string s; cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100

int graph[100][100];

int main(){

  int i, j, num, inum, jnum, line;

  scanf("%d", &num);

  for(i = 0; i < num; i++){

    for(j = 0; j < num; j++){

      graph[i][j] = 0;

    }

    scanf("%d %d", &inum, &jnum);

    for(j = 0; j < jnum; j++){

      scanf("%d", &line);

      graph[inum - 1][line - 1] = 1;

    }

  }

  for(i = 0; i < num; i++){

    for(j = 0; j < (num - 1); j++){

      printf("%d ", graph[i][j]);

    }

    printf("%d\n", graph[i][j]);

  }


  return 0;

}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
char ch[200010];
int main(){
	int n,ans=0;
	scanf("%d\n",&n);
	for(int i=1;i<=n;i++)
		scanf("%c",&ch[i]);
	for(int i=1,j=n;i<j;){
		while(ch[i]=='R'&&i<=n)i++;
		while(ch[j]=='W'&&j>=1)j--;
		if(i>=j)break;
		swap(ch[i],ch[j]);
		ans++,i++,j--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define int long long
using P = pair<int,int>;

const int mod = 1000000007;
class mint {
  long long x;
  public:
  mint(long long x=0) : x((x%mod+mod)%mod) {}
  mint operator-() const {
    return mint(-x);
  }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const  mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint& a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res/=a;
  }

  friend ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
  }
};
mint c[4005][4005];
void init(){
  c[0][0] = 1;
  for(int i = 0;i <= 4000;i++){
    for(int j = 0;j <= i;j++){
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}

mint comb(int n,int k){
  return c[n][k];
}

/*mint f2(int n,int k){
  return comb(n+k-1,k-1);
}*/

/*mint f(int n,int k){
  if(n < k) return 0;
  if(n == 0 && k == 0) return 1;
  return f2(n-k,k);
}*/

signed main(){
  init();
  int n,k;
  cin >> n >> k;
  for(int i = 1;i <=k;i++){
    mint blue = comb(n-k+1,i);
    mint red = comb(k-1,i-1);
    mint ans = blue*red;
    cout << ans << endl;
  }
}

Measured memory_bytes: 125568
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int n,d; cin >> n >> d;
	int c=2*d+1;
	if(n%c==0) {
		cout << n/c << endl;
		return 0;
	}
	cout << (n/c)+1 << endl;
}

Measured memory_bytes: 3556
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
a = inl()
print("YES" if n == len(set(a)) else "NO")

Measured memory_bytes: 30876
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>
#define mod 1000000007
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  if(!b) return a;
  ll t;
  while(b) t = a % b, a = b, b = t;
  return a;
}

ll mul(ll a, ll b) {
  return a * b % mod;
}

ll mpow(ll a, ll b) {
  ll ans = 1;
  while(b) {
    if(b & 1) ans = mul(ans, a);
    a = mul(a, a), b >>= 1;
  }
  return ans;
}

int main(void) {
  ll i, j, k, n, a, b, t, z = 0, now = 1, ans, cnt = 1;
  scanf("%lld", &n);
  vector< pair<ll, ll> > vec, p;
  pair<ll, ll> pt;
  for(i = 0; i < n; ++i) {
    scanf("%lld%lld", &a, &b);
    t = gcd(a, b);
    if(t) a /= t, b /= t;
    else {
      z++;
      continue;
    }
    if(b < 0) a *= -1, b *= -1;
    if(!b && a < 0) a = 1;
    vec.push_back(make_pair(a, b));
  }
  sort(vec.begin(), vec.end());
  n = vec.size();
  ans = mpow(2, n) - 1 + z;
  ans %= mod;
  if(vec[n - 1].first > 0) for(i = 0; i < n && vec[i].first <= 0; ++i) {
    if(vec[i] == vec[i + 1]) cnt++;
    else {
      pt = make_pair(vec[i].second, -vec[i].first);
      t = upper_bound(vec.begin(), vec.end(), pt) - lower_bound(vec.begin(), vec.end(), pt);
      if(t) p.push_back(make_pair(cnt, t));
      cnt = 1;
    }
  }
  t = n;
  for(i = 0; i < p.size(); ++i) {
    t -= p[i].first + p[i].second;
    ans += mod - mul(now, mul(mpow(2, p[i].first) - 1, mul(mpow(2, p[i].second) - 1, mpow(2, t))));
    now = mul(now, mpow(2, p[i].first) + mpow(2, p[i].second) - 1);
    ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	string T;
	cin >> T;
	int len = T.length();
	rep(i,len) {
		if(T[i] == '?') T[i] = 'D';
	}
	cout << T << endl;
	int cnt = 0;
	rep(i,len) {
		if(T[i] == 'D') cnt++;
		if(i == len-1) continue;
		if(T[i] == 'P' && T[i+1] == 'D') cnt++;
	}

  return 0;
}


Measured memory_bytes: 3756
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int k,s; cin >> k >> s;
    int ans = 0;
    REP(i,k+1) REP(j,k+1) if(0<=s-i-j && s-i-j<=k) ans++;
    out(ans);

    return 0;
}

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



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

   long n,a[100010],ans=0; 
   cin >> n;
   int p=0; 
   rep(i,0,n) {
   	cin >> a[i];
   	if(a[i]<0) a[i]*=-1,p++;
   	ans+=a[i];
   }
   sort(a,a+n);
   if(p%2) ans-=2*a[0];
   cout << ans << endl;
}



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


using namespace std;

int main () {
  int W,H,N;
  cin>>W>>H>>N;
  
  vector<vector<int>> vec(N,vector<int>(3));
  for (int i=0;i<N;i++) {
    for (int j=0;j<3;j++) {
      cin>>vec.at(i).at(j);
    }
  }
  
  int a=0,b=W,c=0,d=H;
  for (int i=0;i<N;i++) {
    if (vec.at(i).at(2) == 1&&a<vec.at(i).at(0)) {
      a = vec.at(i).at(0);
    }
    else if (vec.at(i).at(2) == 2&&b>vec.at(i).at(0)) {
      b = vec.at(i).at(0);
    }
    else if (vec.at(i).at(2) == 3&&c<vec.at(i).at(1)) {
      c = vec.at(i).at(1);
    }
    else if (vec.at(i).at(2) == 4&&d>vec.at(i).at(1)){
      d = vec.at(i).at(1);
    }
  }
  if (b-a<=0 || d-c<=0) cout<<0<<endl;
  else cout<<(W-a-(W-b))*(H-c-(H-d))<<endl;
    
}


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

using namespace std;

void Com(int *a,int *b){
	if((*a) > (*b)){
		int x = (*a);
		(*a) = (*b);
		(*b) = x;
	}
}
int main(){
	int a,b,c;
	cin >> a;
	cin >> b;
	cin >> c;
	Com(&a,&b);
	Com(&b,&c);
	Com(&a,&b);
	cout << a << " " << b << " "  << c <<endl;
	return 0;
}

Measured memory_bytes: 1164
import numpy as np
N,M,C = map(int,input().split())
B = np.array(list(map(int,input().split())),dtype=np.int).reshape((M,1))
A = np.empty((N,M),dtype=np.int)
for i in range(N):
    A[i] = list(map(int,input().split()))

AB = np.dot(A,B)
ans = len(np.where(AB+C > 0)[0])

print(ans)

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

int main() {
    int n, a; scanf("%d%d", &n, &a);
    // N = 500 * x + a
    // N が500の倍数＋余りがA　の金額であれば支払える（？）
    if (n % 500 <= a) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 1e5+1;
int n,a[N],pre[N];
int	bit[2*N];
void update(int x)	{for(int i=x;i<2*N;i+=i&-i)	bit[i]++;	}
int find(int x)		{int res=0;for(int i=x;i>0;i-=i&-i)	res+=bit[i];return res;	}
bool check(int med)
{
	int i;pre[0]=0;
	for(i=1;i<=n;i++)
	{
		if(a[i]>=med)	pre[i]=pre[i-1]+1;
		else			pre[i]=pre[i-1]-1;
	}
	for(i=0;i<2*N;i++)	bit[i]=0;
	ll cnt=0ll;
	for(i=0;i<=n;i++)
	{
		cnt += (ll)find(pre[i]+N);
		update(pre[i]+N);
	}
	if(cnt>=1ll*n*(n+1)/4)		return true;
	return false;
}
int main()
{
	int i,l=1,r=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		r=max(r,a[i]);
	}
	int ans;
	while(l<=r)
	{
		int mid=(l+r)/2;
		bool e = check(mid);
		if(e==true)
		{
			ans=mid;
			l=mid+1;
		}
		else	r=mid-1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 5284
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;

class Program
{
    //static int maxVal = 1000000 + 1;
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        Dictionary<string, int> map = new Dictionary<string, int>();
        int max = 1;
        for (int i = 0; i < n; i++)
        {
            string s = Console.ReadLine();
            if (!map.ContainsKey(s))
            {
                map.Add(s, 1);
            }
            else
            {
                map[s]++;
                if (map[s] > max) max = map[s];
            }
        }
        //var ans = map.Where(v => v.Value == max).OrderBy(v => v.Key);
        var ans = map.Where(v => v.Value == max).Select(v => v.Key).ToArray();
        Array.Sort(ans,cmp);
        foreach (var ele in ans) Console.WriteLine(ele);

    }

    static int cmp(string a, string b)
    {
        for (var i = 0; i < Math.Min(a.Length, b.Length); i++)
            if (a[i] < b[i]) return -1;
            else if (a[i] > b[i]) return 1;
        if (a.Length == b.Length) return 0;
        if (a.Length > b.Length) return 1;
        else return -1;
    }

}

Measured memory_bytes: 50208
S=input()
N=len(S)
mod= 998244353

FACT=[1]
for i in range(1,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
    else:
        return 0

R=0
B=0

RB=[[0,0]]*N

for i in range(N):
    s=S[i]
    if s=="0":
        R+=2
    elif s=="1":
        R+=1
        B+=1
    else:
        B+=2
    RB[i]=[R,B]

DP=[0]*(R+1)
DP[0]=1

for i in range(N):
    NDP=[0]*(R+1)
    red,blue=RB[i]
    for r in range(R+1):
        if DP[r]==0:
            continue
        if r+1<=red:
            NDP[r+1]+=DP[r]
        if i-r+1<=blue:
            NDP[r]+=DP[r]
    DP=NDP


ANS=0
for r in range(R+1):
    red=R-r
    blue=B-(N-r)

    ANS=ANS+DP[r]*Combi(red+blue,blue)
    ANS%=mod
print(ANS)

Measured memory_bytes: 25824
#include <bits/stdc++.h>
#define ll long long
const long double PI=acos(-1);
using namespace std;
void fast() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
bool p(int a,int b)
{
    return a>b;
}
int modpow(int a,int b,int c)
{
    if(b==0)
        return 1%c;
    int u = modpow(a,b/2,c);
    u=(u*u)%c;
    if(b&1)
        u=(u*a)%c;
    return u;
}
bool cmp(const pair<ll,ll>&q,const pair<ll,ll>&f)
{
    return q.second>f.second;
}
ll prime(ll x)
{
    if(x<2)
    {
        return false;
    }
    else
    {
        for(int i=2;i*i<=x;i++)
        {
            if(x%i==0)
            {
                return false;
            }
        }
        return true;
    }
}

int main() {
    fast();
    string x;
    cin>>x;
    if(x[x.length()-1]=='s')
        cout<<x+"es"<<endl;
    else
        cout<<x+"s"<<endl;
}

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

int main(){
    ll n,x,m,ans=0,gap,j=0;
    cin>>n>>x>>m;
    //ll k=x;
    queue<ll> que;
    vector<bool> vis(m+10,false);
    bool check=false;
    vis[x]=true;
    que.push(x);
    ans+=x;
    rep(i,n-1){
        x=(x*x)%m;
        que.push(x);
        if(vis[x]){
            gap=x;
            j=i;
            //cout<<i+2<<endl;
            check=true;
            break;
        }
        vis[x]=true;
        ans+=x;
    }
    if(!check){
        cout<<ans<<endl;
        return 0;
    }
    else{
        ans=0;
        ll t=0;
        //ループに入る前
        while(que.front()!=gap){
            ans+=que.front();
            que.pop();
            j--;
            t++;
        }
        //cout<<ans<<endl;
        ll jj=j;
        ll roo=0;
        //ループの中身の合計
        //cout<<endl;
        while(jj){
            jj--;
            //cout<<que.front()<<endl;
            roo+=que.front();
            que.push(que.front());
            que.pop();
        }
        //cout<<roo<<endl;
        //ループの中身（ans）
        n-=t;
        que.pop();
        if(j!=0){
            ans+=roo*(n/j);
            j=n%j;
            for(int i=0;i<j;i++){
                ans+=que.front();
                que.pop();
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    ll r, D, x;
    cin >> r >> D >> x;
    rep(i, 10) {
        x = r * x - D;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
h, w, d = map(int, input().split())
A = []

for _ in range(h):
    line = list(map(int, input().split()))
    A.append(line)

num_to_xy = [[0, 0] for i in range(h*w + 1)]

for y in range(h):
    for x in range(w):
        num = A[y][x]
        num_to_xy[num] = [x, y]

costs = [[] for i in range(d+1)]
for mod in range(1, d+1):
    num = mod
    sx, sy = num_to_xy[num]
    cost = 0
    while num <= h*w:
        nx, ny = num_to_xy[num]
        cost += abs(nx-sx) + abs(ny-sy)
        costs[mod].append(cost)
        num += d
        sx, sy = nx, ny

q = int(input())

for _ in range(q):
    l, r = map(int, input().split())
    mod = l % d
    if mod == 0:
        mod = d
    idx = (l-mod) // d
    step = (r-l) // d

    res = costs[mod][idx+step] - costs[mod][idx]
    print(res)

Measured memory_bytes: 27100
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

struct Event {
  int time, type;
  Event(int type, int time): type(type), time(time){;}
  bool operator<(const Event &rhs) const {
    if (time == rhs.time)
      return type < rhs.type;
    else
      return time < rhs.time;
  }
};

int main()
{
  int N;
  while (cin >> N && N) {
    vector<Event> vec;
    for (int i = 0; i < N; i++) {
      int h, m, s, b, e;
      scanf("%d:%d:%d", &h, &m, &s);
      vec.push_back(Event(0, h * 60 * 60 + m * 60 + s));
      scanf("%d:%d:%d", &h, &m, &s);
      vec.push_back(Event(1, h * 60 * 60 + m * 60 + s - 1));
    }

    sort(vec.begin(), vec.end());
    int ans = 0, cnt = 0;
    for (int i = 0; i < vec.size(); i++) {
      Event e = vec[i];
      if (e.type == 0)
        cnt++;
      else
        cnt--;
      ans = max(ans, cnt);
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1180
#j-i=Ai+Aj(j>i)
#j-Aj=Ai+i

#Lj=Ri=X
from bisect import bisect_left

def main():
    N=int(input())
    A=list(map(int,input().split()))

    L={}
    R={}

    res=0

    for i in range(N):
        l=(i+1)-A[i]
        r=A[i]+i+1
        if (l in R.keys()):
            res+=len(R[l])
        if (r in R.keys()):
            R[r].append(i+1)
        else:
            R[r]=[i+1]


    print(res)

if __name__=="__main__":
    main()





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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

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

signed main() {
  int A; cin >> A;
  if(A == 1) A = 0;
  else A = 1;
  cout << A << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c,d;
    cin>>n;
    ll arr[n+10];
    c=0;
    for(i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    for(i=1;i<=n;i++)
    {
        if(arr[i]!=i)
        {
            for(j=i+1;j<=n;j++)
            {
                if(arr[j]==i)
                {
                    arr[j]=arr[i];
                    arr[i]=i;
                    break;
                    break;

                }
            }
            break;
        }
    }
    c=-1;
    for(i=1;i<=n;i++)
    {
        if(arr[i]==i){c=1;}
        else{c=0;break;}
    }
    if(c==1)
    {
        cout<<"YES"<<endl;
    }
    else if(c==0)
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a, b, c, d, e, f, x;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	x = 1 * a + 5 * b + 10 * c + 50 * d + 100 * e + 500 * f;
	if(x >= 1000){
		printf("1\n");
		}
	else if(x <= 1000)
		printf("0\n");
	return 0;
}

Measured memory_bytes: 1016
#include<cstdio>
#include<algorithm>
typedef long long ll;
ll a[200005];
ll abs(ll x) {return x>0?x:-x;}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]),a[i]-=i;
	std::sort(a+1,a+n+1);ll b=a[n/2+1],ans=0;
	for(int i=1;i<=n;i++) ans+=abs(b-a[i]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1664
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>
#include <cassert>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const int INF = INT_MAX/10;

int main()
{
	int n, u, v, m;
	cin >> n >> u >> v >> m;

	vvi ufield(n, vi(n));
	map<int, vector<pii> > utable;
	REP(i, n) {
		REP(j, n) {
			cin >> ufield[i][j];
			utable[ufield[i][j]].push_back(make_pair(i, j));
		}
	}
	vvi nfield(n, vi(n));
	map<int, vector<pii> > ntable;
	REP(i, n) {
		REP(j, n) {
			cin >> nfield[i][j];
			ntable[nfield[i][j]].push_back(make_pair(i, j));
		}
	}

	vvi usagi(n, vi(n, INF));
	vvi neko(n, vi(n, INF));
	int num;
	FOR(i, 1, m+1) {
		cin >> num;
		REP(j, utable[num].size()) {
			usagi[utable[num][j].first][utable[num][j].second] = i;
		}
		REP(j, ntable[num].size()) {
			neko[ntable[num][j].first][ntable[num][j].second] = i;
		}
	}

	vi ut, nt;
	REP(i, n) {
		int um = 0, nm = 0;
		REP(j, n) {
			um = max(um, usagi[i][j]);
			nm = max(nm, neko[i][j]);
		}
		ut.push_back(um);
		nt.push_back(nm);
	}
	REP(i, n) {
		int um = 0, nm = 0;
		REP(j, n) {
			um = max(um, usagi[j][i]);
			nm = max(nm, neko[j][i]);
		}
		ut.push_back(um);
		nt.push_back(nm);
	}
	int um = 0, nm = 0;
	REP(i, n) {
		um = max(um, usagi[i][i]);
		nm = max(nm, neko[i][i]);
	}
	ut.push_back(um);
	nt.push_back(nm);

	um = 0, nm = 0;
	REP(i, n) {
		um = max(um, usagi[i][n-i-1]);
		nm = max(nm, neko[i][n-i-1]);
	}
	ut.push_back(um);
	nt.push_back(nm);

	sort(ALL(ut));
	sort(ALL(nt));

	if(n==1){
		FOR(i,1,ut.size()){
			ut[i]=INF;
			nt[i]=INF;
		}
	}
	FOR(i, ut.size(), 13) {
		ut.push_back(INF);
		nt.push_back(INF);
	}

	//if(u-1 >= ut.size()) {
	//	if(v-1 >= nt.size()) {
	//		cout << "DRAW" << endl;
	//		return 0;
	//	} else {
	//		if(nt[v-1] != INF) {
	//			cout << "NEKO" << endl;
	//			return 0;
	//		}
	//	}
	//} 

	//if(v-1 >= ut.size()) {
	//	if(u-1 >= nt.size()) {
	//		assert(0);
	//	} else {
	//		if(ut[u-1] != INF) {
	//			cout << "USAGI" << endl;
	//			return 0;
	//		}
	//	}
	//}

	if(ut[u-1] < nt[v-1]) {
		cout << "USAGI" << endl;
	} else if(ut[u-1] > nt[v-1]) {
		cout << "NEKO" << endl;
	} else {
		cout << "DRAW" << endl;
	}
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    each(e, list) out << e << '\n';
    printf("\n");
    return out;
}


template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        double n;
        cin >> n;
        vector<double> v(n);
        cin >> v;

        sort(all(v));
        double now = (v[0] + v[1]) / 2;
        for (ll i = 2; i < n; ++i) {
            now = (now + v[i]) / 2;
        }
        cout << now << endl;
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
D, G = 0, 0
P, C = [], []


def set_inputs():
    global D, G, P, C
    D, G = get_li()
    P, C = get_data(D, [int, int])
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    all_d = set(range(1, D+1))
    ans = inf
    for i in range(2 ** D):
        comp_d = {j + 1 for j in range(D) if ((1 << j) & i) != 0}
        p = sum(100 * d * P[d-1] + C[d-1] for d in comp_d)
        s = sum(P[d-1] for d in comp_d)
        additional_p = 0
        available_p = 0
        if p < G and i != 2 ** D - 1:
            max_other_d = max(all_d - comp_d)
            additional_p = 100 * max_other_d
            available_p = additional_p * (P[max_other_d-1] - 1)
        if p + available_p < G:
            continue
        tmp = s
        if additional_p:
            tmp += (G - p + additional_p - 1) // additional_p
        ans = min(ans, tmp)
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
long long int n,x;
struct test{
	long long int b,l,u;
	bool operator<(const test& rhs)const{
		return l*b+u*(x-b)>rhs.l*rhs.b+rhs.u*(x-rhs.b);
	}
}T[100000];

int now=0;

bool check(long long int s,long long int t){
	long long int res=0;
	for(int i=now;i<n;i++){
		long long int tmp;
		if(s>T[i].b)
			tmp=T[i].l*T[i].b+(s-T[i].b)*T[i].u;
		else
			tmp=s*T[i].l;
		res=max(res,tmp);
	}
	return res>=t;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>x;
	for(int i=0;i<n;i++)
		cin>>T[i].b>>T[i].l>>T[i].u;
	long long int target=0;
	for(int i=0;i<n;i++)
		target+=T[i].l*T[i].b;
	sort(T,T+n);
	while(target-((T[now].l*T[now].b)+T[now].u*(x-T[now].b))>=0){
		target-=((T[now].l*T[now].b)+T[now].u*(x-T[now].b));
		now++;
	}
	if(now==n){
		cout<<n*x<<endl;
		return 0;
	}
	long long int ans=n*x;
	int here=now-1;
	for(int i=n-1;i>=0;i--){
		long long int res=0;
		if(i<=here){
			target+=((T[i].l*T[i].b)+T[i].u*(x-T[i].b));
			if(i!=here)
				target-=((T[i+1].l*T[i+1].b)+T[i+1].u*(x-T[i+1].b));
		}
		while(now<n&&target-((T[now].l*T[now].b)+T[now].u*(x-T[now].b))>=0){
			target-=((T[now].l*T[now].b)+T[now].u*(x-T[now].b));
			now++;
		}
		if(i<=here)
			res=x*(now-1);
		else
			res=x*now;
		long long int tmp=target;
		if(target<=T[i].l*T[i].b)
			res+=target/T[i].l+((target%T[i].l)?1:0);
		else{
			res+=T[i].b;
			tmp-=T[i].l*T[i].b;
			res+=tmp/T[i].u+((tmp%T[i].u)?1:0);
		}
		ans=min(ans,res);
		
	}
	cout<<ans<<endl;

	/*while(now>0&&!(T[now]<T[now-1])&&!(T[now-1]<T[now]))
		now--;
	long long int L=0,R=x;
	while(L<R){
		long long int mid=(L+R)/2;
		if(check(mid,target))
			R=mid;
		else
			L=mid+1;
	}

	cout<<ans+L<<endl;*/
}


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

int main (){
    int N, M, C;
    cin >> N >> M >> C;
    int B[M];
    int A[N][M];
    int D[N];
    int k;
    for (k = 0; k < N; k++){
        D[k] = C;
    }
    int i, j, l;
    int ans = 0;
    for (l = 0; l < M; l++){
        cin >> B[l];
    }
    for (i = 0; i < N; i++){
        for (j = 0; j < M; j++){
            
            cin >> A[i][j];
            D[i] += A[i][j] * B[j];
        }
        if (D[i] > 0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
int main() {
    int sum = 0,n,maxn = 0;
    cin>>n;
    for(int i = 0;i < n;i++){
        int k;
        cin>>k;
        sum += k;
        maxn = max(k,maxn);
    }
    cout<<sum-maxn/2;
    return 0;
}


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

using namespace std;

constexpr unsigned Mod = 1000000007;

constexpr unsigned Add(unsigned a, unsigned b) { return (a + b) % Mod; }

int main() {
  int N;
  scanf("%d", &N);
  static char S[3000];
  scanf("%s", S);
  static unsigned F[3000];
  fill(F, F + N, 1);
  for (auto i = 1; i < N; ++i) {
    if (S[i - 1] == '<')
      for (auto j = 1; j < N - i; ++j)
        F[j] = Add(F[j - 1], F[j]);
    else {
      auto f = exchange(F[N - i - 1], F[N - i]);
      for (auto j = N - i - 2; j >= 0; --j)
        f = exchange(F[j], Add(f, F[j + 1]));
    }
  }
  printf("%u\n", F[0]);
  return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
	{
		Console.ReadLine();
		var a = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));

		var dictionary = new Dictionary<int, int>();

		var contains = false;
		for (var i = 0; i < a.Length && !contains; ++i) {
			if (dictionary.ContainsKey(a[i])) {
				contains = true;
			} else {
				dictionary.Add(a[i], 0);
			}
		}

		Console.WriteLine(contains ? "NO" : "YES");
	}
}


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

int main(){
   int n,m;
   long long ans=1,INF=1000000007;
   cin >> n >> m;
   if(n!=1||m!=1){
        if(n-1==m||n+1==m){
            int a=max(n,m),b=min(n,m);
            while(true){
                if(b==1)break;
                ans *= b;
                ans %= INF;
                b -= 1;
            }
            ans *= ans;
            ans %= INF;
            ans *= a;
            ans %= INF;
            cout << ans << endl;
        }
        else if(n==m){
            while(true){
                if(n==1)break;
                ans *= n;
                ans %= INF;
                n -= 1;
                
            }
            ans *= ans;
            ans %= INF;
            ans *= 2;
            ans %= INF;
            cout << ans << endl;
        }
        else cout << 0 << endl;
   }
   else cout << 2 << endl;
    return 0;
}

Measured memory_bytes: 256
'''catupper
ポイントA.再帰DFSで全ての頂点というか、辺をチェック。
ポイントB.入力に注意。頂点の連結が辺になっている。
辺は頂点を結ぶので(a[i], b[i])で表現され、対応する色を
color_dict[(a[i], b[i])]としている。
配列が二重配列になっているので、注意。
ポイントC.色を頂点の順番で辺毎に出力する。辺の数は頂点-1個。
for i in range(n-1):  
    print(color_dict[(a[i], b[i])])
'''

import sys
sys.setrecursionlimit(1000000)#DFSは再帰の上限回数に注意

n = int(input())
edge = [[] for i in range(n)]
#どの頂点とどの頂点が繋がっているかを格納しておく配列
a = [0] * n#頂点aに繋がっている頂点bの番号を格納しておく配列
b = [0] * n

color_dict = {}#色を覚えておく
k = 0

def dfs(x, last = -1, ban_color = -1):
#lastは、どこから来たか、逆走を防ぐ。使っちゃいけない色も引数
    global k#グローバル変数
    color = 1
    for to in edge[x]:
    #配列edgeに格納されている次の頂点toを順番にチェック。
    #全ての頂点をチェックすればオシマイ。
        if to == last:continue
        #来た頂点に戻ろうとしたら、何もしない
        if color == ban_color:color += 1
        #使っちゃいけない色なら、新しい色にする
        color_dict[(x, to)] = color
        dfs(to, x, color)#深さ優先探索なので深く探索できる限り探索する。
        #次の頂点toについてDFS。来たのはxから。前の頂点で使った色はダメ。
        color += 1#色を新しくする
    k = max(k, color-1)    #何色を使ったか、覚えておく。
    #新しくした色は次のDFS用なので、まだ使っていないからcolor-1。

for i in range(n-1):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1#0-indexにする
    b[i] -= 1
    edge[a[i]].append(b[i])#無向グラフ
    edge[b[i]].append(a[i])

dfs(0)#最初の頂点をDFSに入れてスタート
#print(color_dict)　　DFSして始めて、color_dictが出来る

print(k)#まず、何色必要かを出力
for i in range(n-1):#辺の色を1から頂点番号-1まで出力
    print(color_dict[(a[i], b[i])])
'''  以下の場合分けは不要。
    if (a[i], b[i]) in color_dict:#辞書から答を出力
        print(color_dict[(a[i], b[i])])
    else:
        print(color_dict[(b[i], a[i])])
'''

Measured memory_bytes: 84516
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	string s,t;
	while(cin>>s>>t,t!="X"){
		if(t=="L"){
			rep(i,s.size())if(s[i]=='_'){
				s[i+1]=toupper(s[i+1]);
				s.erase(s.begin()+i);
				i--;
			}
			s[0]=tolower(s[0]);
		}else if(t=="U"){
			rep(i,s.size())if(s[i]=='_'){
				s[i+1]=toupper(s[i+1]);
				s.erase(s.begin()+i);
				i--;
			}
			s[0]=toupper(s[0]);
		}else{
			rep(i,s.size())if(i&&isupper(s[i])){
				s[i]=tolower(s[i]);
				s.insert(i,"_");
			}
			s[0]=tolower(s[0]);
		}
		cout<<s<<endl;	
	}
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	a[0]--;
	for(int i=1;i<n-1;i++){
		if(a[i]==a[i+1]){
			if(a[i] > a[i-1]){
				a[i]--; 
			}
		}
		else if(a[i] > a[i+1]){
			a[i]--;
		}
	}
	for(int i=1;i<n;i++){
		if(a[i] < a[i-1]){
			cout<<"No"; return 0;
		}
	}
	cout<<"Yes";
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main() {
  string a, b;
  cin >> a >> b;
  if (a.size() > b.size()) {
    P("GREATER");
    return 0;
  } else if (a.size() < b.size()) {
    P("LESS");
    return 0;
  }
  rep (i, a.size()) {
    if (a[i] - '0' > b[i] - '0') {
      P("GREATER");
      return 0;
    } else if (a[i] - '0' < b[i] - '0') {
      P("LESS");
      return 0;
    }
  }
  P("EQUAL");
  return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use std::cmp::{min};

#[fastout]
fn main() {
    input! {
        x: isize,
        k: isize,
        d: isize
    }

    let x = x.abs();
    let a = k - min(x / d, k);
    let b = x - (min(x / d, k) * d);
    if a % 2 == 0 {
        println!("{}", b.abs());
    }else{
        println!("{}", (b - d).abs());
    }

}


Measured memory_bytes: 2168
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}
int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

class CLinearApproximation {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> cum_sum(N + 1, 0);
    rep(i, N) {
      cin >> A[i];
      A[i] -= (i + 1);
    }
    sort(ALL(A));
    rep(i, N) {
      cum_sum[i + 1] = cum_sum[i] + A[i];
    }
    int sum = INF * 10000;
    for (auto &i : A) {
      int sep = LOWER_BOUND(A, i) + 1;
      if (sep > 1 && sep != N) {
        sum = min(sum, ((cum_sum[N] - cum_sum[sep - 1]) - i * (N - sep + 1)) + (i * (sep - 1) - cum_sum[sep - 1]));
      } else if (sep <= 1) {
        sum = min(sum, cum_sum[N] - i * N);
      }
    }
    cout << sum << endl;
  }
};


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


Measured memory_bytes: 3328
K, X = map(int, input().split())
ans = []
for i in range(K):
  if i == 0:
    ans.append(X)
  else:
    ans.append(X-i)
    ans.append(X+i)
ans = sorted(ans)
ans = [str(x) for x in ans]
print(" ".join(ans))

Measured memory_bytes: 9176
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let q = Array.to_list @@ Array.init n @@ fun _ -> Scanf.sscanf (read_line ()) "%d %d %d" @@ fun t x y -> (t, x, y)

let rec loop (pt, px, py) = function
  | [] -> "Yes"
  | (p, x, y) as t :: rest ->
      let dd = abs (x - px) + abs (y - py) in
      let dt = p - pt in
      if dd > dt || dd mod 2 <> dt mod 2 then "No"
      else loop t rest

let () = print_endline @@ loop (0, 0, 0) q

Measured memory_bytes: 10768
from sys import stdin

def solve():
    file_input = stdin
    data_sets_num = int(file_input.readline())
    for i in range(data_sets_num):
        xa, ya, xb, yb = map(int, file_input.readline().split())
        x_ab = xb - xa
        y_ab = yb - ya
        n = int(file_input.readline())
        cross_points = []
        for j in range(n):
            xs, ys, xt, yt, o, l = map(int, file_input.readline().split())
            # Intersection judgment
            c_abs = x_ab * (ys - ya) - y_ab * (xs - xa)
            c_abt = x_ab * (yt - ya) - y_ab * (xt - xa)
            if c_abs * c_abt <= 0:
                x_st = xt - xs
                y_st = yt - ys
                c_sta = x_st * (ya - ys) - y_st * (xa - xs)
                c_stb = x_st * (yb - ys) - y_st * (xb - xs)
                if c_sta * c_stb < 0:
                    # find cross point
                    r = -c_abs / (x_ab * y_st - y_ab * x_st)
                    cross_points.append((xs + r * x_st, ys + r * y_st, o, l))
        if cross_points:
            cross_points.sort()
            owner = cross_points[0][2]
            pos = cross_points[0][3]
            ans = 0
            for x_cp, y_cp, o, l in cross_points[1:]:
                if (o == owner and l != pos ) or (o != owner and l == pos):
                    ans += 1
                owner = o
                pos = l
            print(ans)
        else:
            print(0)

solve()


Measured memory_bytes: 5728
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string s;
    cin>>s;
    string ans;
    rep(i,s.size()){
        if(s[i]=='0'||s[i]=='1'){
            ans+=s[i];
        }
        else{
            if(!ans.empty())ans.pop_back();
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int func(int a){return (!(a%4))-(!(a%100))+(!(a%400));}

int main(){
	int a, b, f = 0;
	while(cin >> a >> b, a+b){
		if(f)cout << endl;f = 1;
		int u = 1;
		for(int i = a;i <= b;i++){
			if(func(i))cout << i << endl, u = 0;
		}
		if(u)cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
ans=''
l='abcdefghijklmnopqrstuvwxyz'
for i in range(len(l)):
  c=10**9
  for j in range(n):
    c=min(c,s[j].count(l[i]))
  for j in range(c):
    ans+=l[i]
print(ans)

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

using lli = int64_t;

int main()
{
    lli q, h, s, d; cin >> q >> h >> s >> d;
    lli n; cin >> n;

    lli ch = min({q * 4, h * 2, s});

    lli ans1 = n * ch;
    lli ans2 = n / 2 * d + (n % 2) * ch;

    lli ans = min(ans1, ans2);

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int n,m,a[100],b[100];
int x,y;

int main()
{
    scanf("%d%d%d%d",&m,&n,&x,&y);
    for(int i=0;i<m;i++)
        scanf("%d",&a[i]);
    for(int i=0;i<n;i++)
        scanf("%d",&b[i]);
    sort(a,a+m);
    sort(b,b+n);
    if(a[m-1]>=b[0])
    {
        printf("War\n");
        return 0;
    }
    for(int i=a[m-1]+1;i<=b[0];i++)
    {
        if(i>x&&i<=y)
        {
            printf("No War\n");
            return 0;
        }
    }
    printf("War\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String [] args){
        Scanner scan = new Scanner(System.in);
        int c = 1;
        
        while(true){
            int n = scan.nextInt();
            
            if(n == 0) break;
            
            System.out.println("Case " + c++ + ": " + n);
        }
    }
}

Measured memory_bytes: 32980