akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

struct Edge {
	int to, id;
};

vector<vector<Edge>> G;
vi ans;

void dfs(int v, int c = -1, int p = -1) {
	int k = 1;
	rep(i, G[v].size()) {
		int u = G[v][i].to, ei = G[v][i].id;
		if (u == p) continue;
		if (k == c) ++k;
		ans[ei] = k; ++k;
		dfs(u, ans[ei], v);
	}
}

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

	G.resize(n);
	ans.resize(n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		
		Edge tmp1 = { b, i }, tmp2 = { a, i };
		G[a].push_back(tmp1);
		G[b].push_back(tmp2);
	}

	dfs(0);
	int mx = 0;
	rep(i, n) mx = max(mx, int(G[i].size()));
	cout << mx << endl;
	rep(i, n - 1) {
		cout << ans[i] << endl;
	}
}

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

int main()
{
  int N, sum = 0, sum1 = 0;
  cin >> N;
  int W[N];
  for (int i = 0; i < N; i++)
  {
    int n;
    cin >> n;
    sum += n;
    W[i] = n;
  }

  int min = sum;
  for (int i = 0; i < N; i++)
  {
    sum -= W[i];
    sum1 += W[i];
    int m = abs(sum - sum1);
    if (m < min)
      min = m;
  }

  cout << min << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        string S;
        cin >> S;

        int ans = 0;
        for (int i = 0; i < 4; i++)
        {
                if (S[i] == '+')
                {
                        ans++;
                }
                else
                {
                        ans--;
                }
        }
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    int ans = 0;
    rep(i,n) {
        if(i%2==0) ans += a[i];
        else ans -= a[i];
    }

    cout << ans << endl;

    return 0;
}

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

if len(str(N)) == 1:
    print(N)
elif len(str(N)) == 2:
    print(9)
elif len(str(N)) == 3:
    print(N-99+9)
elif len(str(N)) == 4:
    print(909)
elif len(str(N)) == 5:
    print(N-9999+909)
elif len(str(N)) == 6:
    print(90909)


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

typedef long long ll;

int main() {
	ll n, a, b;
	scanf("%lld %lld %lld", &n, &a, &b);
	ll ans = b * (n - 2) - a * (n - 2) + 1;
	if (ans < 0) ans = 0;
	printf("%lld", ans);
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
#define ls rt<<1
#define rs rt<<1|1
const int maxn=1e5+10;
const int N=2e5+10;
using namespace std;
int id(int l,int r){return l+r|l!=r;}
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}return f;}
int n,m,k,t;
map<pair<int,pii>,int>pq;
void gao(int &a,int &b,int &c)
{
    int d=(a+b)/2,e=(a+c)/2,f=(b+c)/2;
    a=d,b=e,c=f;
}
int main()
{
    int i,j;
    scanf("%d%d%d",&n,&m,&k);
    while(true)
    {
        if(n&1||m&1||k&1)break;
        ++t;
        if(n>m)swap(n,m);
        if(n>k)swap(n,k);
        if(m>k)swap(m,k);
        if(pq[mp(n,mp(m,k))])return 0*puts("-1");
        pq[mp(n,mp(m,k))]=1;
        gao(n,m,k);
    }
    printf("%d\n",t);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;
int n , a , b , c , d;
bool intersect(long long a , long long b , long long c , long long d){
	return min(d , b) - max(a , c) + 1 > 0;
}
int main(){
	scanf("%d %d %d %d %d" , &n , &a , &b , &c , &d);
	for(int i = 1 ; i <= n ; ++i){
		long long lftmin , lftmax;
		long long rgtmin , rgtmax;
		lftmin = a + 1LL * (i - 1LL) * c;
		lftmax = a + 1LL * (i - 1LL) * d;
		rgtmin = b + 1LL * (n - i) * c;
		rgtmax = b + 1LL * (n - i) * d;
		if(intersect(lftmin , lftmax , rgtmin , rgtmax)){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
int main()
{
    int k;
    string s;
    cin >> k >> s;
    for (int i = 0; i < k && i < s.size(); i++)
    {
        cout << s.at(i);
    }

    if (s.size() > k)
    {
        cout << "..." << endl;
    }
    else
    {
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3588
//
// Created by yamunaku on 2020/05/10.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    int n;
    ll k;
    cin >> n >> k;
    mti to(61, vi(n));
    rep(i, n) cin >> to[0][i], to[0][i]--;
    repl(t, 1, 61){
        rep(i, n) to[t][i] = to[t - 1][to[t - 1][i]];
    }
    int now = 0;
    int x = 0;
    while(k){
        if(k & 1) now = to[x][now];
        k >>= 1;
        x++;
    }
    cout << now + 1 << endl;
    return 0;
}

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

using ll = long long;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    char c;
    cin >> c;
    if (isupper(c)) cout << 'A' << endl;
    else cout << 'a' << endl;
    return 0;
}

Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
	int a, b;
	scanf("%d%d", &a, &b);
	if (a*b == 15) {
		printf("*\n");
	}
	else if (a + b == 15) {
		printf("+\n");
	}
	else {
		printf("x\n");
	}





}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
S = list(input())[: -1]
T = list(input())[: -1]
css = [0] * (len(S) + 1)
cst = [0] * (len(T) + 1)

for i in range(len(S)): css[i + 1] = css[i] + (S[i] == "A") + (S[i] == "B") * 2
for i in range(len(T)): cst[i + 1] = cst[i] + (T[i] == "A") + (T[i] == "B") * 2

#print(css, cst)

for _ in range(int(input())):
  a, b, u, v = map(int, input().split())
  if (css[b] - css[a - 1]) % 3 == (cst[v] - cst[u - 1]) % 3: print("YES")
  else: print("NO")

Measured memory_bytes: 62704
#pragma warning disable

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

static class MainClass
{
    public static void Main(string[] args)
    {
        var NM = Console.ReadLine().SplittedStringToInt32List();
        var N = NM[0];
        var M = NM[1];
        var toN = new List<int>();
        var for1 = new List<int>();
        for (int i = 0; i < M; i++)
        {
            var ab = Console.ReadLine().SplittedStringToInt32List();
            if (ab[0] == 1)
                for1.Add(ab[1]);
            else if (ab[1] == N)
                toN.Add(ab[0]);
        }
        var news = toN.Except(for1);
        if (news.Count() == toN.Count)
            Console.WriteLine("IMPOSSIBLE");
        else
            Console.WriteLine("POSSIBLE");
        Console.ReadLine();
    }


    #region ライブラリ

    #region 文字列処理
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    #endregion


    #endregion
}


Measured memory_bytes: 27024
#include <iostream>
using namespace std;
int main() {
  int r, c, a[101][101] = {0};                                                                                                                                
  cin >> r >> c;                                                                                                                                              
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {                                                                                                                             
      cin >> a[i][j];
      a[i][c] += a[i][j];                                                                                                                                     
      a[r][j] += a[i][j];
      a[r][c] += a[i][j];                                                                                                                                     
    }                                                                                                                                                         
  }                                                                                                                                                           
  for (int i = 0; i <= r; i++) {                                                                                                                              
    for (int j = 0; j <= c; j++) {                                                                                                                            
      if (j) cout << ' ';
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

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

    string a, b, c;
    cin >> a >> b >> c;
    cout << "A" << b[0] << "C" << endl;

    return 0;
}

Measured memory_bytes: 3588
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod  10000007
#define pii pair<int, int>
#define PI 2*acos(0.0)
#define forn(i, n) for(int i = 0; i < n; i++)


int main()
{
    io;
    int n;
    cin>>n;
    ll dp[n+1][3];
    for(int i = 1;i<= n;i++)
        cin>>dp[i][0] >>dp[i][1] >>dp[i][2];
    for(int i = 0; i< 3;i++)
        dp[0][i] = 0;
    for(int i= 1; i<=n; i++)
    {
        for(int j = 0;j <3;j++)
        {
            ll ma = 0;
            for(int a = 0; a < 3;a++)
            {
                if(a == j)
                    continue;
                ma = max(ma, dp[i-1][a]);
            }
            dp[i][j] += ma;
        }
    }
    ll ans = 0;
    for(int i = 0; i<3;i++)
        ans =  max(ans, dp[n][i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2560
import sys
sys.setrecursionlimit(10**6)
n = int(input())
tree = [[] for i in range(n)]
edge = []

for i in range(n-1):
    a, b = map(int, input().split())
    a-=1; b-=1
    tree[a].append((b, i))
    tree[b].append((a, i))
    edge.append([a, b])

ans = []
def color(a, c=-1, fromnode=None):
    i = 0
    cp = 0
    while i < len(tree[a]):
        nxt, idn = tree[a][i]
        if nxt==fromnode:
            i+=1
            continue 
        if cp == c:
            cp+=1
        ans.append([idn, cp])
        color(nxt, cp, a)
        i+=1
        cp+=1

color(0)

ans.sort()
ans = [c+1 for idn, c in ans]
print(max(ans))
for a in ans:
    print(a)

Measured memory_bytes: 94772
N=int(input())
xy =[[]for i in range(N)]
ans=0

for i in range(N):
    A=int(input())
    for j in range(A):
        x, y = map(int, input().split())
        xy[i].append((x,y))


for i in range(2**N):
    ans_kouho=0
    #発言に矛盾があればflag=-1,矛盾がなければflag=1
    flag=1
    #Torf[i]=1ならi+1人目は正直者、0なら不親切な人
    #注意、不親切な人＝「嘘つき」ではない（不親切な人でも正しいことを言うことがある）
    TorF=[0]*N
    for j in range(N):
        if (i>>j) & 1:
            TorF[j]=1

    for j in range(N):
        for k in range(len(xy[j])):
            
            if TorF[j]==1:#発言者が正直者ならば
                if TorF[xy[j][k][0]-1]!=xy[j][k][1]:
                    flag=-1
                    break
    
    if flag==1:
        
        ans_kouho=TorF.count(1)
        if(ans<ans_kouho):
            ans=ans_kouho   
    
               
print(ans)  
        


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

struct _node_table {
    int* next_node;
    int* cost;
    int size;
    int capacity;
} node_table[100005];

int dp[100005];

void init_node(int i) {
    node_table[i].capacity = 10;
    node_table[i].next_node = (int*)malloc(node_table[i].capacity*sizeof(int));
    node_table[i].cost = (int*)malloc(node_table[i].capacity*sizeof(int));
    node_table[i].size = 0;
}

void free_node(int i) {
    free(node_table[i].next_node);
    free(node_table[i].cost);
}

void grow_node(int s) {
    if(node_table[s].capacity < node_table[s].size+2) {
        int size, i;
        int* next_node = node_table[s].next_node;
        int* cost = node_table[s].cost;
        node_table[s].capacity *= 1.5;
        node_table[s].next_node = (int*)malloc(node_table[s].capacity*sizeof(int));
        node_table[s].cost = (int*)malloc(node_table[s].capacity*sizeof(int));
        for(i=0,size=node_table[s].size;i<size;i++) {
            node_table[s].next_node[i] = next_node[i];
            node_table[s].cost[i] = cost[i];
        }
        free(next_node);
        free(cost);
    }
}

void add_next_node(int s, int t, int d) {
    int size = node_table[s].size;
    node_table[s].next_node[size] = t;
    node_table[s].cost[size] = d;
    node_table[s].size++;

    grow_node(s);
}

void solve(int r, int V) {
    int i, size, from, to, cost;
    int queue[SHRT_MAX];
    int wp, rp;

	dp[0] = 0;
    for(i=1;i<V;i++) dp[i] = INT_MAX;

    wp = rp = 0;
    queue[wp++%SHRT_MAX] = r;

    while(wp>rp) {
        from = queue[rp++%SHRT_MAX];

        for(i=0,size=node_table[from].size;i<size;i++) {
            to = node_table[from].next_node[i];
            cost = node_table[from].cost[i];

            if(cost+dp[from] < dp[to]) {
                queue[wp++%SHRT_MAX] = to;
                dp[to] = cost+dp[from];
            }
        }
    }
}

int main(void) {
	int i, n;
    for(i=0;i<100005;i++) init_node(i);

	scanf("%d\n", &n);
    for(i=0;i<n;i++) {
        int j, u, k, v, c;
        scanf("%d %d", &u, &k);
        for(j=0;j<k;j++) {
	        scanf("%d %d", &v, &c);
	        add_next_node(u, v, c);
        }
    }

    solve(0, n);

    for(i=0;i<n;i++) {
        free_node(i);
        if(dp[i] == INT_MAX) {
            printf("INF\n");
        } else {
            printf("%d %d\n", i, dp[i]);
        }
    }

    return 0;
}

Measured memory_bytes: 12368
#include <iostream>
#include <fstream>
#include <climits>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <list>

#define FOR(i,n)    for(int i = 0 ; i < n ; i++)
#define FORrev(i,n) for(int i = n - 1 ; i >= 0 ; i--)
#define ALL(a)      a.begin(),a.end()
#define pii			pair<int , int>
#define mp(a , b)	make_pair(a , b)

typedef long long int ll; 

using namespace std;

/* 

	Wrong solution

*/

int main() {
	int n; 
	cin>>n;
	int a[n + 1][n];
	for(int i = 1 ; i <= n ; i++) {
		for(int j = 1 ; j < n ; j++) {
			cin>>a[i][j];
		}
	}
	int pos[n + 1];
	FOR(i , n + 1)
		pos[i] = 1;
	int days = 0;
	int matches = 0;
	while(true) {
		int dryday = true;
		set<int> played;
		for(int i = 1 ; i <= n ; i++) {
			if(pos[i] >= n || pos[a[i][pos[i]]] >= n)
				continue;
			int x = i , y = a[i][pos[i]];
			if(x > y)
				swap(x , y);
			if(x == a[y][pos[y]] && y == a[x][pos[x]] 
				&& played.find(x) == played.end() 
				&& played.find(y) == played.end()) {
				dryday = false;
				played.insert(x);
				played.insert(y);
				pos[x]++;
				pos[y]++;
				matches++;
			}
		}
		if(dryday)
			break;
		days++;
	}
	if(matches == (n * (n - 1)) / 2) 
		cout<<days;
	else
		cout<<"-1";
}

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

int main(){
  int N;
  cin>>N;
  int a[4];
  a[0]=N/1000;
  a[1]=N/100-10*a[0];
  a[2]=N/10-10*a[1]-100*a[0];
  a[3]=N-10*a[2]-100*a[1]-1000*a[0];
  int counter=0;
  for (int  i=0;i<4;i++){
    if (a[i]==2){
      counter+=1;
    }
  }
  cout<<counter;
  return 0;
}

Measured memory_bytes: 256
def LinearSearch(n, S, t):
    """ ????????????????????¢????????? """
    S.append(t)
    i = 0

    while S[i] != t:
        i += 1

    if i == n:
        return -1
    else:
        return i

n = int(input())
S = [int(s) for s in input().split()]

q = int(input())
T = [int(t) for t in input().split()]

cnt = 0

for t in T:
    if LinearSearch(n, S[:], t) != -1:
        cnt += 1

print(cnt)

Measured memory_bytes: 8524
#include<stdio.h>

int main(void) {
    int a[10000] = {};
    int i, j;
    
    for(i = 0; i < 10000; i++) {
        scanf("%d", &a[i]);
        if(a[i] == 0) {
            break;
        }
    }
        
    for(j = 0; j < i; j++) {
        printf("Case %d: %d\n", j + 1, a[j]);
    }
    
    return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

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

    int L;
    cin >> L;

    int SIZE = -1;
    for (int i = 19; i > 0; i--) {
        if ((L >> i)&1) {
            SIZE = i + 1;
            break;
        }
    }
    assert(SIZE != -1);
    assert(SIZE <= 20);

    // reverse the labels at the end
    vector<vector<array<int, 2>>> g(SIZE);

    // build the default edges
    for (int i = 0; i + 1 < SIZE; i++) {
        g[i+1].push_back({ i, 0 });
        g[i+1].push_back({ i, 1 << i });
    }

    // add extra edges to the root
    int pref = 0;
    for (int i = 19; i >= 0; i--) {
        if ((L >> i)&1) {
            if (i < SIZE - 1) {
                g[SIZE - 1].push_back({ i, pref });
            }
            pref += 1 << i;
        }
    }

    int ec = 0;
    for (auto &v : g) ec += v.size();
    assert(ec <= 60);

    cout << SIZE << " " << ec << "\n";
    for (int i = 0; i < SIZE; i++) {
        for (auto e : g[i]) {
            cout << SIZE - i << " " << SIZE - e[0] << " " << e[1] << "\n";
        }
    }

    return 0;
}



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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{

  ll N, H; cin >> N >> H;
  vector<ll> a(N), b(N); rep(i, N) cin >> a[i] >> b[i];
  ll amax = 0;
  ll ans = 0;
  rep(i, N) {
    amax = max(amax, a[i]);
  }
  sort(b.rbegin(), b.rend());
  rep(i, N) {
    if(b[i] > amax) {
      H -= b[i];
      ans ++;
    }
    if(H <= 0) break;
  }
  if(H > 0) {
    ans += ((H - 1) / amax) + 1;
  }
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 4892
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

int main(){
    ll n ; cin >> n;
    set<string> s;
    rep(i,n){
        string x; cin >> x;
        s.insert(x);
    }
    cout << (int)s.size() << endl;
    return 0;
}

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

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

  double ans = (double) W * H / 2.0;
  int center;
  if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y) center = 1;
  else center = 0;

  cout << ans << " " << center << endl;

  return 0;
}

Measured memory_bytes: 3796
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int n, s, st;
vector <pair <int, ll> > vp;
ll ans = 0;

int solve(int l, int r) {
	// eprintf("solve %d %d\n", l, r);
	if (l == r) return l;
	if (l == st) {ans += vp[r].first - vp[solve(l, r - 1)].first; return r;}
	if (r == st) {ans += vp[solve(l + 1, r)].first - vp[l].first; return l;}
	if (vp[l].second >= vp[r].second) {
		vp[l].second += vp[r].second;
		ans += vp[r].first - vp[solve(l, r - 1)].first;
		return r;
	} else {
		vp[r].second += vp[l].second;
		ans += vp[solve(l + 1, r)].first - vp[l].first;
		return l;
	}
}

int main() {
	scanf("%d %d", &n, &s);
	vp.pb(mp(s, 0LL));
	rep(i, n) {
		int x, p; scanf("%d %d", &x, &p);
		vp.pb(mp(x, p));
	}
	sort(vp.begin(), vp.end());
	st = lower_bound(vp.begin(), vp.end(), mp(s, 0LL)) - vp.begin();
	solve(0, vp.size() - 1);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 5104
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

H,W,A,B=map(int,input().split())
ans=cmb(H+W-2,H-1,mod)
for i in range(H-A,H):
    ans-=cmb(i+B-1,B-1,mod)*cmb(H+W-2-i-B,W-B-1,mod)
    ans%=mod
print(ans)

Measured memory_bytes: 81136
#include <iostream>
using namespace std;
int main(){
  int W,H,N;
  cin >> W >> H >> N;
  int h_mn = 0, h_mx = H, w_mn = 0, w_mx = W;
  int x,y,a;
  for(int i = 0; N > i; i++){
    cin >> x >> y >> a;
    switch(a){
      case 1:
        if(x > w_mn){
          w_mn = x;
        }
        break;
      case 2:
        if(x < w_mx){
          w_mx = x;
        }
        break;
      case 3:
        if(y > h_mn){
          h_mn = y;
        }
        break;
      case 4:
        if(y < h_mx){
          h_mx = y;
        }
       break;
      default:
        break;
    }
  }
  int kekka = ((h_mx - h_mn < 0 ? 0 : h_mx - h_mn)) * ((w_mx - w_mn < 0 ? 0 : w_mx - w_mn));
  cout <<(kekka < 0 ? 0 : kekka) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;

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;
}

int main() {
    int N;
    cin >> N;
    int odda[N/2];
    int evea[N/2];
    map<int, int> mo;
    map<int, int> me;
    for (int i = 0; i < N/2; i++)
    {
        cin >> odda[i];
        cin >> evea[i];
        mo[odda[i]]++;
        me[evea[i]]++;
    }
    int omax = -1;
  	int osecm = -1;
    int numo = -1;
    int seco = -1;
    int emax = -1;
  	int esecm = -1;
    int nume = -1;
    int sece = -1;
    for (auto x : mo)
    {
        if(x.second>omax){
            seco = numo;
          	osecm = omax;
            numo = x.first;
            omax = x.second;
        }else if(x.second>osecm){
          	seco = x.first;
          	osecm = x.second;
        }
    }
    for (auto x : me)
    {
        if(x.second>emax){
            sece = nume;
          	esecm = emax;
            nume = x.first;
            emax = x.second;
        }else if(x.second>esecm){
          	sece = x.first;
          	esecm = x.second;
        }
    }
    int ans = 0;
    if(numo!=nume){
        for (int i = 0; i < N/2; i++)
        {
            if(odda[i]!=numo)ans++;
        }
        for (int i = 0; i < N/2; i++)
        {
            if(evea[i]!=nume)ans++;
        }
        
    }else{
        int tmp1=0, tmp2=0;
        for (int i = 0; i < N/2; i++)
        {
            if(odda[i]!=seco)tmp1++;
        }
        for (int i = 0; i < N/2; i++)
        {
            if(evea[i]!=nume)tmp1++;
        }
        for (int i = 0; i < N/2; i++)
        {
            if(odda[i]!=numo)tmp2++;
        }
        for (int i = 0; i < N/2; i++)
        {
            if(evea[i]!=sece)tmp2++;
        }
        ans = min(tmp1, tmp2);
    }
    cout << ans << endl;
}

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

def primes(n):
    primes = [1] * (n+1)
    primes[0] = 0
    primes[1] = 0
    for i in range(2, int(n**0.5) + 1):
        if not primes[i] :
            continue
        for j in range(i * 2, n + 1, i):
            primes[j] = 0

    for i in range(len(primes)):
        if i %5 != 1:
            primes[i] = 0
    return primes

# n<= 55555
primes_list = primes(55556)
# 考え方
# 以下のような。5で割ってあまりが1になるような素数だけを出力しておく
# [11, 31, 41, 61, 71, 101,...]
# ここからどの5つをとっても、5で割れば割り切れるので、条件を満たすことができる

ans = []
for i in range(len(primes_list)):
    if primes_list[i]:
        ans.append(i)
        if len(ans) == n:
            break
ans = map(str, ans)
print(" ".join(ans))

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

int main(){
  int n, m;
  cin >> n;
  map<int, int> d, t;
  for(int i = 0; i < n; i++){
    int k;
    cin >> k;
    d[k]++;
  }
  cin >> m;
  for(int i = 0; i < m; i++){
    int k;
    cin >> k;
    t[k]++;
  }
  
  bool ok = true;
  if(m > n) ok = false;
  else{
    for(auto now : t){
      int dif = now.first, num = now.second;
      if(!d.count(dif)) ok = false;
      else if(d.at(dif) < num) ok = false;
      if(!ok) break;
    }
  }
  
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll n, m; cin>>n>>m;
  char a[n];
  rep(i, n) a[i]='x';
  bool d=true;
  rep(i, m) {
    ll s; char c;
    cin>>s>>c;
    if(a[s-1]=='x') {
      a[s-1]=c;
    }
    else {
      if(a[s-1]!=c) {
        d=false;
        break;
      }
      else {
      }
    }
  }
  
  if(a[0]=='0'&&n!=1) d=false;
  
  if(d==true) {
    for(ll i=0; i<n; i++) {
      if(a[i]=='x') {
        if(i==0&&n!=1) cout << 1;
        else cout<<0;
      }
      else cout << a[i];
    }
  }
  else cout << -1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	while(cin>>a>>b>>c){
		for(int i=0; i<a; i++){
			if(i<b){
				printf("%d ", c);
			}else{
				if(c==1000000000){
					printf("%d ", 1);
				}else{
					printf("%d ", c+1);
				}
			}
		}
		cout << endl;
	}
		
}

Measured memory_bytes: 1280
{-# LANGUAGE TupleSections #-}

import Control.Monad
import Data.Array
import qualified Data.ByteString.Char8 as C
import Data.List

main = sol <$> get >>= mapM_ put

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines <$> C.getContents 

put = putStrLn . show

sol ([n,_]:es) = elems . accumArray (+) 0 (1,n) $ fmap (,1) (concat es)

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mxn = 1e5 + 5;
int n, m;

struct UF {
	int fa[mxn];
	UF() { rep(i, mxn) fa[i] = i; }
	int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
	void merge(int x, int y) { fa[find(x)] = find(y); }
} uf;

int main() {
	scanf("%d %d", &n, &m);
	rep(i, m) {
		int u, v;
		scanf("%d %d", &u, &v);
		-- u; -- v;
		uf.merge(u, v);
	}
	int cnt = 0;
	rep(i, n) {
		if (uf.find(i) == i) {
			++ cnt;
		}
	}
	printf("%d\n", cnt - 1);
	return 0;
}

Measured memory_bytes: 4100
#pragma warning(disable:4996)

#include <algorithm>
#include <bitset>
// #include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <chrono>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPC(i, a) REP(i, 0, a)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define RREPC(i, a) RREP(i, a, 0)
#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr ll LL2_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = { { typeid(int), "%d" },
{ typeid(ll), "%lld" },
{ typeid(double), "%lf" },
{ typeid(char), "%c" } };

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
// static boost::dynamic_bitset<> scan(char trueValue = 'o');

int main(int argc, char *argv[]) {
	// INFILE();
	ll age;
	cin >> age;

	if (age == 7 || age == 5 || age == 3)
	{
		cout << "YES\n";
		return 0;
	}
	cout << "NO" << "\n";
	return 0;
}

template <class T> static void scan(vector<T> &v) {
	auto tFormat = scanType[typeid(T)];
	for (T &n : v) {
		scanf(tFormat, &n);
	}
}

static void scan(vector<string> &v, bool isWord) {
	if (isWord) {
		for (auto &n : v) {
			cin >> n;
		}
		return;
	}

	int i = 0, size = v.size();
	string s;
	getline(cin, s);

	if (s.size() != 0) {
		i++;
		v[0] = s;
	}

	for (; i < size; ++i) {
		getline(cin, v[i]);
	}
}

//static boost::dynamic_bitset<> scan(char trueValue) {
//	string s;
//	getline(cin, s);
//
//	if (s.size() == 0) {
//		getline(cin, s);
//	}
//
//	for_each(begin(s), end(s),
//		[trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
//	return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
//}

Measured memory_bytes: 888
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int K = sc.nextInt();

    sc.close();

    if (C <= B && B <= A) {
      for (int i = 0; i < K; i++) {
        A = A * 2;
      }
    } else if (C <= B && A <= B) {
      for (int i = 0; i < K; i++) {
        B = B * 2;
      }
    } else {
      for (int i = 0; i < K; i++) {
        C = C * 2;
      }
    }
    
    System.out.println(A + B + C);
    
  }

}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size();i++)
		ans+=(s[i]-'0');
	//cout<<ans<<endl;
	if(ans%9==0)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
        {
        	
        	ll n,i;
        	cin>>n;
        	string a,b;
        	cin>>a>>b;
        	
     for(i=0;i<n;i++)
      {
      	 cout<<a[i]<<b[i];
	  }
	  cout<<endl;
}


Measured memory_bytes: 256
def LI(): return [int(x) for x in input().split()]
def II(): return int(input())

N,W=LI()
LIS=[tuple(LI()) for _ in range(N)]

DP = [[0]*(W+1) for i in range(N+1)]

for i,(w,v) in enumerate(LIS, 1):
    for wb in range(0, W+1):
        DP[i][wb] = DP[i-1][wb]
        if wb >= w :
            DP[i][wb] = max(DP[i][wb], DP[i-1][wb-w]+v)
# for lis in DP:
#     print(lis)

print(DP[N][W])


Measured memory_bytes: 119916
#include "bits/stdc++.h"
using namespace std;
int main(){
  int n,m,ans=0,c=0,c2=0;
  cin >> n >> m;
  int x[m],miner[m],maxer[m];
  for(int i=0;i<m;i++){
    cin >> x[i];
  }
  if(m == 1){
    cout << 0;
    return 0;
  }
  if(n > m){
    n = m;
  }
  sort(x,x+m);
  for(int i=0;i<m-1;i++){
    if(abs(x[i]-x[i+1]) <= m){
      maxer[c2] = abs(x[i]-x[i+1]);
      ans += abs(x[i]-x[i+1]);
      c2++;
    }else{
      miner[c] = abs(x[i]-x[i+1]);
      c++;
      n--;
    }
  }
  n--;
  sort(maxer,maxer+c2,greater<int>());
  sort(miner,miner+c);
  int l=0;
  while(n > 0 && l <= c2){
    ans -= maxer[l];
    l++;
    n--;
  }
  l = 0;
  while(n < 0){
    ans += miner[l];
    l++;
    n++;
  }
  cout << ans;
}

Measured memory_bytes: 1024
def main():
    n = int(input())
    c = []
    mod = 10 ** 9 + 7
    state = [0 for i in range(n+200000)]
    dp = [0 for i in range(n+1)]
    dp[0] = 1
    for i in range(n):
        c_i = int(input())

        if state[c_i] >= 1 and state[c_i] != i:
            dp[i+1] = (dp[state[c_i]] + dp[i]) % mod
        else:
            dp[i+1] = dp[i] % mod

        state[c_i] = i + 1
    print(dp[-1] % mod)

main()

Measured memory_bytes: 14176
#divisor
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

N = int(input())
li = make_divisors(N)
ans = 10**10
for i in li:
    b = N//i
    ans = min(ans,max(len(str(i)),len(str(b))))

print(ans)


Measured memory_bytes: 3188
#include<stdio.h>
using namespace std;
int main()
{
   int A, B;
   scanf("%d %d", &A, &B);
   if(A >= 1 && A <= 13 && B >= 1 && B <= 13){
        if(A==B){
            printf("Draw\n");
        }
    else if(A==1){
        printf("Alice\n");
    }
    else if(B == 1){
        printf("Bob\n");
    }
    else{
        if(A>B){
            printf("Alice\n");
        }
        else{
            printf("Bob\n");
        }
    }
   }
   return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[5],i,ans;
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    sort(a,a+3);
    ans=a[2]-a[1];
    ans=ans+a[1]-a[0];
    printf("%d",ans);
    return 0;
}

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

using namespace std;

#define DIV 1000000007
#define SIZE 10001
long long facts[10001];

long long fact(uint64_t n)
{
  long long val = 1;
  for (uint32_t i = 1; i <= n; i++) {
    val *= i;
    val %= DIV;
  }

  return val;
}

int32_t main()
{
  uint64_t n, m;
  cin >> n >> m;

  if (n == m) {
    cout << (fact(n) * fact(m) * 2) % DIV;
  } else if ((n == m + 1) || (n + 1 == m)) {
    cout << (fact(n) * fact(m)) % DIV;
  } else {
    cout << 0;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    for i in range(1,4):
        if s[i]==s[i-1]:
            print('Bad')
            return
    print('Good')




if __name__ == "__main__":
    main()

Measured memory_bytes: 77484
#include<bits/stdc++.h>
using namespace std;
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define F first
#define int long long int
#define S second
#define boost ios_base::sync_with_stdio(false),cin.tie(NULL);
const int MOD = 998244353;
//#include <ext/pb_ds/assoc_container.hpp> // Common file 
//#include <ext/pb_ds/tree_policy.hpp>  
//using namespace __gnu_pbds; 
//stringstream ss; string temp; ss<<str(original string) ss>>temp;

int32_t main()
{   
    boost
   
    int n; cin>>n;
    string s;
     cin>>s;
    int ans = 1;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
} 


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

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

  string s;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> s;
      if(s == "snuke"){
        printf("%c%d\n", 'A' + j, i + 1);
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<double, double> P;

int n;

P naibun(P p1, P p2, double r) { // p1 と p2をr:1-rに内分する点
    P dp = P(p2.first - p1.first, p2.second - p1.second);
    return P(p1.first + r * dp.first, p1.second + r * dp.second);
}

P tri(P p1, P p2) { // p1を中心としp2を60度半時計回りに回転させた点
    P dp = P(p2.first - p1.first, p2.second - p1.second);
    P ndp = P(dp.first / 2 - (sqrt(3) / 2.0) * dp.second,
              dp.second / 2 + (sqrt(3) / 2.0) * dp.first);
    return P(p1.first + ndp.first, p1.second + ndp.second);
}

vector<P> koch_curve(P p1, P p2, int n) {
    vector<P> res;
    if(n >= 1) {
        P np1 = naibun(p1, p2, 1.0 / 3.0);
        P np3 = naibun(p1, p2, 2.0 / 3.0);
        P np2 = tri(np1, np3);

        vector<P> v1 = koch_curve(p1, np1, n - 1);
        vector<P> v2 = koch_curve(np1, np2, n - 1);
        vector<P> v3 = koch_curve(np2, np3, n - 1);
        vector<P> v4 = koch_curve(np3, p2, n - 1);

        for(int i = 0; i < v1.size(); i++)
            res.push_back(v1[i]);
        res.push_back(np1);
        for(int i = 0; i < v2.size(); i++)
            res.push_back(v2[i]);
        res.push_back(np2);
        for(int i = 0; i < v3.size(); i++)
            res.push_back(v3[i]);
        res.push_back(np3);
        for(int i = 0; i < v4.size(); i++)
            res.push_back(v4[i]);
    }
    return res;
}

int main() {
    cin >> n;
    P p1 = P(0.0, 0.0);
    P p2 = P(100.0, 0.0);
    vector<P> ans;
    ans.push_back(p1);
    vector<P> koch = koch_curve(p1, p2, n);
    for(int i = 0; i < koch.size(); i++)
        ans.push_back(koch[i]);

    ans.push_back(p2);
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}


Measured memory_bytes: 3372
s=input()
def change(s,x):
    if s.count(x)==len(s):
        return 0
    t=s
    u=''
    for i in range(1,len(s)):
        for j in range(len(t)-1):
            if t[j]==x or t[j+1]==x:
                u+=x
            else:
                u+=t[j]
        if u.count(x)==len(u):
            return i
        t=u
        u=''
m=[]
for i in s:
    m.append(change(s,i))
print(min(m))

Measured memory_bytes: 41324
import Control.Monad
main = do
  rc_in <- (return . map (read::String->Int) . words) =<< getLine
  let r:c:[] = rc_in
  v <- replicateM r $ (return . map (read::String->Int) . words) =<< getLine
  let v1 = [i ++ [sum i]|i<-v]
  let v2 = v1 ++ [[(sum [j!!i | j<-v1]) |i<-[0..c]]]
  forM_ [0..r] $ \i -> do
    forM_ [0..c] $ \j -> do
      putStr $ show ((v2!!i)!!j)
      putStr $ if j == c then "\n" else " "


Measured memory_bytes: 6524