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

const int N = 505;

const int M = N*N;
int x[M];

int rem[M];

int color[M];

int ret[M];

void solve(){
	int n;
	scanf("%d",&n);
	memset(color,0,sizeof(color));
	for(int i=1;i<=n;++i){
		scanf("%d",&x[i]);
		rem[i] = i-1;
		color[x[i]] = i;
	}
	vector<pair<int,int> > in;
	for(int i=1;i<=n;++i){
		in.push_back(make_pair(x[i],i));
	}
	queue<int> must;
	sort(in.begin(),in.end());
	for(int i=0;i<in.size();++i){
		int c  = in[i].second;
		for(int j=0;j<c-1;++j){
			must.push(c);
		}
	}
	queue<int> free;
	for(int i=1;i<=n*n;++i){
		if(color[i]!=0){
			int c = color[i];
			if(rem[c]!=0){
				printf("No\n");
				return;
			}
			ret[i] = c;
			for(int j=0;j<n-c;++j){
				free.push(c);
			}
			continue;
		}
		if(!must.empty()){
			int c = must.front();
			ret[i] = c;
			--rem[c];
			must.pop();
		} else if(!free.empty()){
			int c = free.front();
			ret[i] = c;
			free.pop();
		} else {
			printf("No\n");
			return;
		}
	}
	printf("Yes\n");
	for(int i=1;i<=n*n;++i){
		printf("%d ",ret[i]);
	}
	putchar('\n');
}
int main(){
	//freopen("input.txt","r",stdin);
	solve();
}

Measured memory_bytes: 3968
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int i=0; i<n; i++) {
    std::cin >> a.at(i);
  }
  
  std::sort(a.begin(), a.end());
  for (int i=1; i<n; i++) {
    if (a.at(i) == a.at(i-1)) {
      std::cout << "NO" << std::endl;
      return 0;
    }
  }
  std::cout << "YES" << std::endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
using namespace std;

#define MAX 100000

typedef struct _node{
	char name[10];
	int time;
} node;

node queue[MAX];
int head, tail;

void initialize(void) {
	head = tail = 0;
}

int isempty(void) {
	return head == tail;
}

int isfull(void) {
	return head == (tail + 1) % MAX;
}

void enqueue(node x) {
	if (isfull()) {
		cout << "Queue is full" << endl;
		exit(-1);
	}
	else {
		queue[tail] = x;
		tail = (tail + 1) % MAX;
	}
}

node dequeue(void) {
	if (isempty()) {
		cout << "Queue is empty" << endl;
		exit(-1);
	}
	else {
		node x = queue[head];
		head = (head + 1) % MAX;
		return x;
	}
}

int main(void) {
	int elaps = 0, c, q, n;
	node u;
	scanf("%d %d", &n, &q);
	for (int i = 0; i < n; i++) {
		cin >> queue[i].name >> queue[i].time;
	}
	head = 0;
	tail = n;

	while (head != tail) {
		u = dequeue();
		c = min(q, u.time);
		u.time -= c;
		elaps += c;
		if (u.time > 0) {
			enqueue(u);
		}
		else {
			printf("%s %d\n", u.name, elaps);
		}
	}
	return 0;
}


Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
long long a,b,c,d;

int main(){
    cin>>a>>b>>c>>d;
    while(a>0&&c>0){
        c-=b;
        a-=d;
    }
    if(c<=0)cout<<"Yes";
    else if(a<=0)cout<<"No";

    return 0;}




Measured memory_bytes: 3596
k=int(input())
li=[str(i) for i in range(1,10)]

for j in range(k):
    t=li[j]
    if t[-1]!="0":
        li.append(t+str(int(t[-1])-1))
    
    li.append(t+str(int(t[-1])))
        
    if t[-1]!="9":
        li.append(t+str(int(t[-1])+1))

print(li[k-1])
    

Measured memory_bytes: 23704
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;

int main(){
    int p, q, r;
    cin >> p >> q >> r;
    cout << min(p+q, min(p+r, q+r)) << endl;
    
    return 0;
}


Measured memory_bytes: 888
import java.util.List;
import java.util.Scanner;
import java.util.Vector;

public class Main {
	static Vector<Integer> a[];
	static long dp[][];
	static int n;
	static long mod = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new Vector[n];
		dp = new long[n][2];
		for (int i = 0; i < n; i++)
			a[i] = new Vector<>();
		for (int i = 0; i < n - 1; i++) {
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			a[x].add(y);
			a[y].add(x);
		}
		int root = 0;
		for (int i = 0; i < n; i++)
			if (a[root].size()>a[i].size()) root = i;

		f(root,-1);
		System.out.println((dp[root][0]+dp[root][1])%mod);
	}

	private static void f(int r,int f) {
			dp[r][0] = dp[r][1] = 1;
		
		for (int i=0;i<a[r].size();i++) {
			int c = a[r].get(i);
			if (c==f) continue;
			f(c,r);
			dp[r][0] = (dp[r][0] * (dp[c][0]+dp[c][1])%mod)%mod;
			dp[r][1] = (dp[r][1] * dp[c][0])%mod;
		}
	}
}


Measured memory_bytes: 124584
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_INPUT_SIZE  1024

int calcGCD(int x, int y);

int
main(int argc, char* argv[])
{
    char input[MAX_INPUT_SIZE];

    fgets(input, sizeof(input), stdin);
    int x = atoi(strtok(input, " "));
    int y = atoi(strtok(NULL, " "));

    int ret = calcGCD(x, y);
    printf("%d\n", ret);

    return 0;
}

int
calcGCD(int x, int y)
{
    //printf("x : %d, y : %d\n", x, y);
    int bigger = 0, smaller = 0;
    if (x >= y) {
        bigger  = x;
        smaller = y;
    } else {
        bigger  = y;
        smaller = x;
    }

    if (bigger % smaller == 0) {
        return smaller;
    } else {
        return calcGCD(bigger % smaller, smaller);
    }
}

Measured memory_bytes: 956
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]) {
    long n;
    scanf("%ld", &n);
    long long *as = malloc(sizeof(long long) * n);
    memset(as, 0, sizeof(as[0]));
    long long sum = 0;
    for (long i = 0; i < n; i++) {
        scanf("%lld", &as[i]);
        sum += as[i];
        sum %= (long long)(1E9 + 7);
    }
    long long all = 0;
    for (long i = 0; i < n; i++) {
        sum -= as[i];
        if (sum < 0) {
            sum += (long long)(1E9 + 7);
        }
        all = (all + sum * as[i]) % (long long)(1E9 + 7);
    }
    printf("%lld", all);

    return 0;
}


Measured memory_bytes: 3676
#include<iostream>
using namespace std;
	long long int Wa=0;
	long long int Sa[2];
	long long int ans=0;
	
	int a[200000];
int main(){
	int N;
	
	int i,j,k;
	            
	cin>>N;
	
	for(i=0;i<N;i++){
		cin>>a[i];
		Wa=Wa+a[i];
	}                    //////////////
	j=0;
	Sa[0]=Wa-(a[0]*2);
	if(Sa[0]<0){
		Sa[0]=0-Sa[0];
		j=-1;
	}
	ans=Sa[0];
	for(i=1;i<N-1;i++){
		if(j==0){
			Sa[1]=Sa[0]-a[i]*2;
		}else{
			Sa[1]=-Sa[0]-a[i]*2;
		}
		if(Sa[1]<0){
			Sa[1]=0-Sa[1];
			j=-1;
		}else{
			j=0;
		}
		if(ans>Sa[1]){
			ans=Sa[1];
		}
		Sa[0]=Sa[1];
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = 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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

const int MAX_N = 100, MAX_V = 10001;
int v[MAX_N + 5], w[MAX_N + 5], dp[MAX_N + 5][MAX_V + 5];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int N, W;
   cin >> N >> W;
   rep(i, 0, N) cin >> v[i] >> w[i];
   rep(i, 0, MAX_V + 5) { dp[0][i] = INF; }
   dp[0][0] = 0;
   rep(i, 0, N) rep(j, 0, MAX_V + 5) {
      if (j >= v[i])
         dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]);
      else
         dp[i + 1][j] = dp[i][j];
   }
   int ans = 0;
   rep(j, 0, MAX_V) if (dp[N][j] <= W) ans = max(ans, j);
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 7172
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
using namespace std;
#define dbg(x) cerr << #x " = " << x <<endl;
typedef pair<int, int> P;
typedef long long ll;

struct interval
{
	int L, R, A, B;
};
const int MAXN = 1e5+5;
int cnt[MAXN];
char a[MAXN];
vector<interval> v;
int main()
{
	//freopen("in.txt", "r", stdin);
	memset(cnt, 0, sizeof(cnt));
	ios::sync_with_stdio(0);
	cin >> a;
	int n = strlen(a);
	int j;
	for(int i = 0; i < n-1; )
	{
		if(a[i] == 'R' && a[i+1] == 'L')
		{
			interval tmp;
			tmp.L = tmp.A = i;
			tmp.R = tmp.B = i+1;
			cnt[i] = cnt[i+1] = 1;
			if(i > 0)
			{
				for(int k = i-1; k >= 0; k--)
				{
					if(a[k] == 'R')
					{
						tmp.L = k;
					}
					else
					{
						break;
					}
				}
			}
			
			if(i < n-1)
			{
				for(j = i+2; j < n; j++)
				{
					if(a[j] == 'L')
					{
						tmp.R = j;
					}
					else
					{
						break;
					}
				}
			}
			v.push_back(tmp);
			i = j;
		}
		else
		{
			i++;
		}
	}
	
	int tot = v.size();
//	dbg(tot);
	for(int i = 0; i < tot; i++)
	{
		
		int l = v[i].L;
		int r = v[i].R;
		int AA = v[i].A;
		int BB = v[i].B;
//		dbg(l);
//		dbg(r);
//		dbg(AA);
//		dbg(BB);
		for(int k = l; k <= r; k++)
		{
			if(k == AA || k == BB)
			{
				continue;
			}
			else if(k < AA)
			{
				if((AA - k)%2)
				{
					cnt[BB]++;
				}
				else
				{
					cnt[AA]++;
				}
			}
			else if(k > BB)
			{
				if((k-BB)%2)
				{
					cnt[AA]++;
				}
				else
				{
					cnt[BB]++;
				}
			}
		}
	}
	for(int i = 0; i < n; i++)
	{
		cout << cnt[i] << ' ';
	}
	cout << endl;
}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m;
    cin >> n >> m;
    lint a, b;
    cin >> a >> b;
    lint col = m / 2;
    lint row = n / 2;

    lint colr = m % 2;
    lint rowr = n % 2;

    vector<string> ret(n, string(m, '.'));
    if (colr == 1) {
        lint mx = 2 * min(row, b);
        for (int i = 0; i < mx; i += 2) {
            ret[i][m - 1]     = '^';
            ret[i + 1][m - 1] = 'v';
            b--;
        }
    }
    if (rowr == 1) {
        lint mx = 2 * min(col, a);
        for (int i = 0; i < mx; i += 2) {
            ret[n - 1][i]     = '<';
            ret[n - 1][i + 1] = '>';
            a--;
        }
    }
    if (a % 2 == 1 && b % 2 == 1 && n % 2 == 1 && m % 2 == 1) {
        if (2 * (a + b) == (n - 1) * (m - 1)) {
            a--, b--;
            ret[n - 3][m - 3] = '<';
            ret[n - 3][m - 2] = '>';
            ret[n - 2][m - 3] = '^';
            ret[n - 1][m - 3] = 'v';
            ret[n - 1][m - 2] = '<';
            ret[n - 1][m - 1] = '>';
        }
    }
    for (int i = 0; i < row * 2; i += 2) {
        for (int j = 0; j < col * 2; j += 2) {
            if (b > 0) {
                ret[i][j]     = '^';
                ret[i + 1][j] = 'v';
                b--;
                if (b > 0) {
                    ret[i][j + 1]     = '^';
                    ret[i + 1][j + 1] = 'v';
                    b--;
                }
            } else if (a > 0) {
                ret[i][j]     = '<';
                ret[i][j + 1] = '>';
                a--;
                if (a > 0) {
                    ret[i + 1][j]     = '<';
                    ret[i + 1][j + 1] = '>';
                    a--;
                }
            } else {
                break;
            }
        }
    }
    if (a + b > 0) {
        cout << "NO"
             << "\n";
    } else {
        cout << "YES"
             << "\n";
        for (auto &r : ret) {
            cout << r << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 4184
#include<stdio.h>
int main(void){
	int a,b,a1,b1,a2,b2;
	int k,n,min,ans,i;
	scanf("%d",&n);
	scanf("%d",&k);
	for(i=0;i<k;i++){
		scanf("%d %d",&a,&b);
		min=a;
		a2=n-a;
		b1=b;
		b2=n-b;
		if(min>a2){
			min=a2+1;
		}
		if(min>b1){
			min=b1;
		}
		if(min>b2){
			min=b2+1;
		}
		//printf("%d\n",min);
		ans=min%3;
		if(ans==0){
			printf("3\n");
		}
		else {
			printf("%d\n",ans);
		}
	}
	return 0;
}

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

#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 ANS(ans) cout << ans << endl
#define FLG(flg) if(flg) cout << "Yes" << endl; else cout << "No" << endl;
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
#define COUT(s) cout << s << endl;
#define AN vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i];
#define IN  int n;  cin >> n;
#define VI  vector<int> 
#define SS stringstream ss;
#define SOLVE cout << solve() << endl;


int main() {
    int a,b;
    cin >> a >> b;
    if ( a <= 2*b) {
        cout << 0 << endl;
    }
    else {
        cout << a - 2 * b << endl;
    }
}


Measured memory_bytes: 256
///-----Bismillahir Rahmanir Rahim-----///

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

///---FAST I/O---///
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///---DATA TYPE---///
typedef long long ll;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

///---LOOP---///
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)

///---I/O---///
#define sf scanf
#define pf printf

///---OTHERS---///
#define pb push_back
#define all(c)		c.begin(),c.end()
#define MK make_pair
#define F first
#define S second
#define endl '\n'


///---INITIALIZATION---//
#define mem(a,b) memset(a, b, sizeof(a) )

///---CALCULATE---///
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

///---BIT OPERATION---///
inline bool checkBit(ll n, int i)
{
    return n&(1LL<<i);
}
inline ll setBit(ll n, int i)
{
    return n|(1LL<<i);;
}
inline ll resetBit(ll n, int i)
{
    return n&(~(1LL<<i));
}

///------String/Char Related Functions-----///
string makeintString(int x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
string makellString(ll x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
char cpp(char c)
{
    return static_cast<char>(c + 1);
}

///------------Sorting STL----------///
struct func
{
	//this is a sample overloading function for sorting stl
	bool operator()(pii const &a, pii const &b)
	{
		if(a.F==b.F)
			return (a.S<b.S);
		return (a.F<b.F);
	}
};

///---CONSTANT---///
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

int main()
{
    Boost();

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int n,cnt=0;
        cin>>n;
        int a[n+5];
        for(int i=1;i<=n;i++)
        {
           cin>>a[i];
        }
        for(int i=1;i<=n;i+=2)
        {
           if(a[i]%2==1) cnt++;
        }
        cout<<cnt<<endl;

    }
    return 0;
}


Measured memory_bytes: 3612
h,w=map(int,input().split())
a = []
a.append([u'はしっこ' for i in range(w+2)])
for i in range(h):
    a.append([u'はしっこ']+list(input())+[u'はしっこ'])
a.append([u'はしっこ' for i in range(w+2)])
#print(a)
for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j]=='.':
            p=0
            if a[i-1][j-1]=='#':
                p+=1
            if a[i-1][j]=='#':
                p+=1
            if a[i-1][j+1]=='#':
                p+=1
            if a[i][j-1]=='#':
                p+=1
            if a[i][j+1]=='#':
                p+=1
            if a[i+1][j-1]=='#':
                p+=1
            if a[i+1][j]=='#':
                p+=1
            if a[i+1][j+1]=='#':
                p+=1
            a[i][j]=str(p)
for i in range(1,h+1):
    print(''.join(a[i][1:w+1]))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    string s1,s2,s3;
    int a,b,c;
    cin >> s1 >> s2;
    cin >> a >> b;
    cin >> s3;
    if(s3==s1)
    {
        a--;
    }
    else if(s3==s2)
    {
        b--;
    }
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define rsort(x) sort(all(x));reverse(all(x))
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  int n,ans=1,now;
  int a[100005];
  vector<bool> v;
  cin>>n;
  rep(i,n)cin>>a[i];
  for(int i=1;i<n;i++){
    if(a[i]<a[i-1])v.pb(false);
    else if(a[i]>a[i-1])v.pb(true);
  }
  for(int i=1;i<v.size();i++){
    //cout<<v[i]<<endl;
    if(v[i]!=v[i-1]){ans++;i++;}
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  string n;
  cin >> n;
  lll sum=0;
  int temp;
  char cal[2] ;
  cal[1] = '\0';
  for(ii=0;ii<n.size();ii++){
    cal[0] = n[ii];
    temp = atoi(cal);
    sum += temp;
  }
  if((sum % 9) == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint a, b, c, k;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> b >> c >> k;
	
	if(k <= a) cout << k << endl;
	else if(k <= a+b) cout << a << endl;
	else cout << a - (k-(a+b)) << endl;
	
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}
const ll MOD = 1e9+7;
long long Comb(int n, int i){long long ans = 1; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){
      ans *=(n+1-j);
      ans /= j;
      ans %= MOD;} }return ans;}


void solve()
{
  int n, m; cin >> n >> m;
  ll ans = 1;
  if(abs(n-m) >1) {
    cout << 0 << endl;
    return;
  } else {
    int M = max(n, m);
    int mm = min(n, m);
    for(int i = 1; i <= mm; ++i){
      ans *= (ll)i;
      ans %= MOD;
      ans *= (ll)i;
      ans %= MOD;
    }
    if(abs(n-m) == 1){
      ans *= M; ans%=MOD;
    } else {
      ans *= 2;
      ans %= MOD;
    }
  } 
  cout << ans << endl;
}

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


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  string s=string(n,'0');
  vb check(n);
  bool ok=true;
  rep(i,m){
    ll idx; char c; cin>>idx>>c;
    idx--;
    if(check[idx]){
      if(s[idx]!=c) ok=false;
    }else{
      s[idx]=c;
      check[idx]=true;
    }
  }
  
  if(!ok || check[0]&&s[0]=='0'&&n>1){
    cout<<-1<<endl;
  }else{
    if(s[0]=='0'&&n>1) s[0]='1';
    cout<<s<<endl;
  }
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    Long D = sc.nextLong();
    Long A = (D==2)?10000L:(D==1)?100L:1L;
    Long N = sc.nextLong();
    Long ser = 0L;
    Long count = 0L;
    while(ser < N){
      count += 1L;
      if(search(count*A,D)){
        ser += 1L;
      }
      
    }
    System.out.println(count*A);
    sc.close();
  }
  public static boolean search(Long a,Long b){
    Long o = (a%1000000 == 0)?3L:(a%(10000)==0)?2L:(a%100==0)?1L:0L;
    if (b == o){
      return true;
    }
    else{
      return false;
    }
  }
}
  

Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int Mod=924844033,g=5,gi=554906420;
const int N=200005;
inline int qpow(int a,int b){
	int ans=1;
	while (b){
		if (b&1) ans=1ll*ans*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return ans;
}
int rev[N<<2],a[N<<2],b[N<<2],lim;
inline void NTT_init(int n){
	int l=0;for (lim=1;lim<=(n<<1);lim<<=1) ++l;
	for (int i=1;i<=lim;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(l-1));
}
inline void NTT(int*s,int t){
	for (int i=0;i<lim;i++) if (i<rev[i]) swap(s[i],s[rev[i]]);
	for (int mid=1;mid<lim;mid<<=1){
		int wn=qpow(t==1?g:gi,(Mod-1)/(mid<<1));
		for (int i=0;i<lim;i+=(mid<<1)){
			int w=1;
			for (int j=0;j<mid;j++,w=1ll*w*wn%Mod){
				int x=s[i+j],y=1ll*s[i+j+mid]*w%Mod;
				s[i+j]=(x+y)%Mod,s[i+j+mid]=(x-y+Mod)%Mod;
			}
		}
	}
	if (t==-1) {
		int inv=qpow(lim,Mod-2);
		for (int i=0;i<lim;i++) s[i]=1ll*s[i]*inv%Mod;
	}
}
int size[N],cnt[N],fac[N],fac_inv[N];
int n;
inline void binom_init(){
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%Mod;
	fac_inv[n]=qpow(fac[n],Mod-2);
	for (int i=n-1;i>=0;i--) fac_inv[i]=1ll*fac_inv[i+1]*(i+1)%Mod; 
}
inline int C(int x,int y){
	return 1ll*fac[x]*fac_inv[y]%Mod*fac_inv[x-y]%Mod;
}
int Head[N],Next[N<<1],Adj[N<<1],tot=0;
inline void addedge(int u,int v){
	Next[++tot]=Head[u];
	Head[u]=tot;
	Adj[tot]=v;
	Next[++tot]=Head[v];
	Head[v]=tot;
	Adj[tot]=u;
}
inline void dfs(int x,int f){
	size[x]=1;
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f){
			dfs(Adj[e],x);
			size[x]+=size[Adj[e]];
		}
	if (f) cnt[size[x]]++,cnt[n-size[x]]++;
}
int f[N];
int main (){
	scanf ("%d",&n);
	for (int i=1,u,v;i<n;i++){
		scanf ("%d%d",&u,&v);
		addedge(u,v);
	}
	dfs(1,0);
	binom_init();
	NTT_init(n);
	for (int i=1;i<=n;i++) a[i]=1ll*cnt[i]*fac[i]%Mod;
	for (int i=0;i<=n;i++) b[n-i]=fac_inv[i];
	NTT(a,1),NTT(b,1);
	for (int i=0;i<lim;i++) a[i]=1ll*a[i]*b[i]%Mod;
	NTT(a,-1);
	for (int i=1;i<=n;i++) f[i]=1ll*a[n+i]*fac_inv[i]%Mod;
	for (int i=1;i<=n;i++) printf ("%d\n",(1ll*n*C(n,i)%Mod-f[i]+Mod)%Mod);
	return 0;
}

Measured memory_bytes: 22400
import java.util.*;
import java.io.*;

/*
   AtCoder contest code
   coder : yoichidon
 */

public class Main {
    public static int centerLength(String s){
        int N = s.length();
        if(N%2==0){
            if (s.charAt(N / 2) != s.charAt(N / 2 - 1)) return 0;
            char center = s.charAt(N / 2);
            int length = 2;
            int left = N / 2 - 2, right = N / 2 + 1;
            while (left >= 0 && s.charAt(left) == center && s.charAt(right) == center) {
                left--;
                right++;
                length += 2;
            }
            return length;
        }else{
            char center = s.charAt(N/2);
            int left = N/2-1, right = N/2+1;
            int length = 1;
            while (left >= 0 && s.charAt(left) == center && s.charAt(right) == center) {
                left--;
                right++;
                length += 2;
            }
            return length;
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        System.out.println(N - (N-centerLength(S))/2);

    }
}


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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    string prev = "";
    string cur = "";
    for (int i=0; i<s.size(); ++i) {
        cur += s[i];
        if (cur != prev) {
            ans++;
            prev = cur;
            cur = "";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
int main()
{
	long long n,s=0,sum=0;
	scanf("%lld",&n);
	while(n!=1)
	{
		n/=2;
		s++;
	}
	for(int k=0;k<=s;k++)
	{
		sum+=pow(2,k);
	}
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 128
import math

class BinaryIndexedTree:
    def __init__(self, size):
        self.N = size
        self.tree = [0] * (self.N + 1)

    def add(self, idx, val):
        while idx <= self.N:
            self.tree[idx] += val
            idx += (idx & -idx)

    def sum_to(self, idx):
        result = 0
        while idx > 0:
            result += self.tree[idx]
            idx -= (idx & -idx)
        return result

n, q = map(int, input().split())
bit = BinaryIndexedTree(n)
for _ in range(q):
    com, n1, n2 = map(int, input().split())
    if com == 0:
        bit.add(n1, n2)
    else:
        print(bit.sum_to(n2) - bit.sum_to(n1-1))



Measured memory_bytes: 7984
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    X = INT()

    i = 1
    ans = 0
    while 1:
        X -= i
        ans += 1
        if X <= 0: break
        i += 1

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 10060
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=[INT() for i in range(N)]

A2=[0]+list(accumulate(A, max))+[0]
A3=[0]+list(accumulate(A[::-1], max))[::-1]+[0]

for i in range(1, N+1):
    print(max(A2[i-1], A3[i+1]))


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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    long long int N,i,ans=0;
    cin >> N;
    long long int a[N];
    map<long long int,long long int>m;
    for(i = 0; i < N; i++) {
        cin >> a[i];
        m[a[i]]++;
    }

    for(i = 0; i < N; i++) {
        if(m[a[i]] > a[i]) {
            ans += m[a[i]] - a[i];
            m[a[i]] = a[i];
        }else if(m[a[i]] < a[i]) {
            ans += m[a[i]];
            m[a[i]] = 0;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
    int arr[5000],i,n,count=0,count1=0,j,min,max;
    cin>>n;
    for(i=0;i<n;i++){

            cin>>arr[i];
}
     for(i=0;i<n;i++)
       {
          if(arr[i]==(i+1))
          {
              count++;
          }
          else
         {
           count1++;
         }

        }
        if(count==(n-2) ||count == (n))
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
    }


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

using namespace std;

vector<vector<int> > d(10, vector<int>(10, 0));

int main() {

    int H, W; cin >> H >> W;
    

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> d[i][j];
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }


    int sum = 0, a;
    for (int i = 0; i < H; i++) {
        for (int j = 0 ;j < W; j++) {
            cin >> a;
            if (a != -1)
                sum += d[a][1];
        }
    }

    cout << sum << '\n';

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i=0, i##_len=(ll)(n); i<i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;



int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	string s;
	cin >> s;
	ll ma = 0;
	ll num = 0;
	for (char c : s) {
		if (c == 'T') num++;
		else num--;
		ma = max(ma, num);
	}

	cout << ma * 2 << endl;

	return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
typedef long long ll;

using namespace std;
int ma = 999999;
int ans;
ll N;

int keta (ll x) {
  int s = 0;
  while(x > 0) {
    x /= 10;
    s++;
  }
  return s;
}
int main() {

  cin >> N;
  ll a, b;
  for(ll i = 1; i * i <= N; i++) {
    
    if(N % i == 0) {
      a = N / i;
      b = i;
      ans = max(keta(a),keta(b));
      ma = min(ma,ans);
    }
    
  }

  cout << ma <<endl;
}
 

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
if S == "0":
    print(1)
    exit()
if S.count("0") == N:
    print(N)
    exit()
L = [0]
prev = S[0]
num = 1
for s in S[1:]:
    if s == prev:
        num += 1
    else:
        L.append(num)
        num = 1
        prev = s
L.append(num)
# print(L)
for i in range(1, len(L)):
    L[i] += L[i - 1]
# print(L)
left = 0
if S[0] == "1":
    right = min(2 * K + 1, len(L) - 1)
else:
    right = min(2 * K, len(L) - 1)
num = 0
while right < len(L):
    # print("L[" + str(right) + "] - L[" + str(left) + "] = " + str(L[right] - L[left]))
    num = max(num, L[right] - L[left])
    if left == 0 and S[0] == "0":
        left += 1
    else:
        left += 2
    right += 2
if S[-1] == "0":
    right -= 1
    # print("L[" + str(right) + "] - L[" + str(left) + "] = " + str(L[right] - L[left]))
    num = max(num, L[right] - L[left])
print(num)


Measured memory_bytes: 7176
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, input().split())
A = list(map(int, input().split()))

ans = n - sum(A)

if ans < 0:
    print(-1)
else:
    print(ans)



Measured memory_bytes: 10236
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define PER(a,b,c) for(int a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
using namespace std;
const int MAXN=1e6+5;
int n,m,t;
char s[MAXN];
int v[MAXN]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
    cin>>n;
    cout<<v[n-1];
}

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

unsigned get_digit_sum(unsigned num) {
    unsigned sum = 0;
    while (num > 0) {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

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



Measured memory_bytes: 256
#!/usr/bin/env ruby

a, b, c = gets.chomp.split.map(&:to_f)

c_rad = c * Math::PI / 180

l = Math.sqrt(a**2 + b**2 - 2 * a * b * Math.cos(c_rad)) + a + b
h = b * Math.sin(c_rad)
s = a * h / 2

puts s, l, h

Measured memory_bytes: 6956
#include <bits/stdc++.h>
using namespace std;
int d[1000];
int main() {
  int n; cin>>n; for (int i=1; i<=n; ++i) cin>>d[i];
  int sum=0;
  for (int i=1; i<=n; ++i)
    for (int j=i+1; j<=n; ++j)
      sum+=d[i]*d[j];
  cout<<sum;
}

Measured memory_bytes: 256
/*
     “You just can’t beat the person who won’t give up.”
                                                            */
#include <bits/stdc++.h>
#define ll long long
#define oo 0x3f3f3f3f3f3f3f3fLL
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
const int maxn=2e5+5;
const  double EPS = 1e-9;
const int mod = 1e9+7;

inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}

int main()
{
    ios_base::sync_with_stdio(0);
    File();
    int n;
    cin >> n;
    bool pir = true;
    set<int> primes;
    int all_gcd = 0;
    vector<int>arr(n);
    for(int &it : arr){
        cin >> it;
        all_gcd = __gcd(all_gcd, it);
        for(int i = 2; i * i <= it; i++){
            if(it % i)
                continue;
            if(primes.count(i)){
                pir = false;
                break;
            }
            primes.insert(i);
            while(it % i == 0)
                it /= i;
        }
        if(it > 1){
            if(primes.count(it))
                pir = false;
            primes.insert(it);
        }
    }
    if(all_gcd == 1){
        if(pir)
            puts("pairwise coprime");
        else
            puts("setwise coprime");
    }else{
        puts("not coprime");
    }
}


Measured memory_bytes: 53856
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,e;
	cin>>a>>b;
	c=a+b;
	if(c<a-b) c=a-b;
	if(c<a*b) c=a*b;
	cout<<c;
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const long long kcz=1000000007;
const double eps=1e-7;
long long n,f[1000],ans;
long long fastmi(long long i,long long j){
    long long ans=1,now=i;
    while (j){
        if (j&1)
          ans=ans*now%kcz;
        now=now*now%kcz;
        j>>=1;
    }
    return ans;
}
int main(){
    scanf("%lld",&n);
    for (long long i=1;i<=9;i++)
      f[i]=fastmi(10,i-1)*9;
    for (long long i=1;i<=min(n,(long long) (1.5e7));i++)
    {
	if (ans==966522777)
	{
		ans=ans;
	}
        double x=n*1.0/i;
        if (x<=8)
        {
            if ((n%i==0)&&(i<=f[n/i]))
            {   
	        ans=(ans-i+f[n/i]+1)%kcz;
                continue;	
            }
            bool flat=0;
            long long now=0,num=0;
            long long r=ceil(x-eps);
            for (long long l=r-1;l>=1;l--)
            {
                if (l!=(r-1))
                {
                    now+=f[l+1]*(l+1);
                    num+=f[l+1];
                }
                if ((num>i)||(now>n)) break;
                long long p=i-num;
                if (((n-now)<=(r*p))&&((n-now)>=(l*p))&&((n-now-l*p)%(r-l)==0))
                {
                    long long rnum=(n-now-l*p)/(r-l);
                    long long lnum=i-rnum-num;
                    if ((rnum>=0)&&(lnum>=0)&&(lnum<=f[l])&&(rnum<=f[r]))
                        flat=1;
                }
                if (flat) break;
            }
            if (flat) { ans=(ans+1)%kcz;continue;}
            now=0;num=0;
            r++;
            for (long long l=r-1;l>=1;l--)
            {
                if (l!=(r-1))
                {
                    now+=f[l+1]*(l+1);
                    num+=f[l+1];
                }
                if ((num>i)||(now>n)) break;
                long long p=i-num;
                if (((n-now)<=(r*p))&&((n-now)>=(l*p))&&((n-now-l*p)%(r-l)==0))
                {
                    long long rnum=(n-now-l*p)/(r-l);
                    long long lnum=i-rnum-num;
                    if ((rnum>=0)&&(lnum>=0)&&(lnum<=f[l])&&(rnum<=f[r]))
                        flat=1;
                }
                if (flat) break;
            }
            if (flat) { ans=(ans+1)%kcz;continue;}
        }
        else
        {
            if ((n%i)==0)
                ans=(ans-i+fastmi(10,n/i-1)*9+kcz+1)%kcz;
            else
                ans=(ans+1)%kcz;
        }
    }
    cout<<ans<<endl;
}
        

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const {
    return ModInt(*this) += p;
  }
  ModInt operator-(const ModInt &p) const {
    return ModInt(*this) -= p;
  }
  ModInt operator*(const ModInt &p) const {
    return ModInt(*this) *= p;
  }
  ModInt operator/(const ModInt &p) const {
    return ModInt(*this) /= p;
  }
  bool operator==(const ModInt &p) const {
    return x == p.x;
  }
  bool operator!=(const ModInt &p) const {
    return x != p.x;
  }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ans(1), mul(x);
    while(n) {
      if(n & 1) ans *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ans;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

LL N;
LL C[200000];

ModInt<mod> ans = 0;
 
void solve(){
	int pow2[200001];
	pow2[0] = 1;
	for(int i=1;i<=N;i++){
		pow2[i] = pow2[i-1]<<1;
		pow2[i]%=mod;
	}
	sort(C,C+N);
	//Sの変更箇所だけを見れば良いのでS xor T をXとおいたとき、Xの01の配列ごとに計算すれば良い
	//例えばX = 0....0とかなら変更箇所0、つまりコスト0
	//まずS=0に固定してansを求め、最後に2^Nをかける
	for(int i=0;i<N;i++){
		int r = N-1-i;//今見ている桁
		ModInt<mod> digit = r;
		ModInt<mod> cost = C[i];
		//diff_bit_numberはr桁目を見ているとき、反転させたいビットがいくつあるかを表す
		//diff_bit_number = (pow2[r] + r*pow2[r-1]) * pow2[i]
		ModInt<mod> diff_bit_number = pow2[r];
		if(r>0) diff_bit_number += (digit*pow2[r-1]);
		diff_bit_number *= pow2[i];
		ans += (cost*diff_bit_number);
	}
	ans *= pow2[N];
}
 
int main(){
	cin >> N;
	for(int i=0;i<N;i++) cin >> C[i];
 
	solve();

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

Measured memory_bytes: 2560
#include<stdio.h>

int main(void){
  
  int h[100],w[100],i,j,k,l;
  
  for(i=0;;i++){
    
    scanf("%d %d",&h[i],&w[i]);    
    
    if(h[i]==0&&w[i]==0)break;
    
  }
  
  for(l=0;l<i;l++){
    
    
    for(j=0;j<w[l];j++){
      
      printf("#");
      
    }
    
    printf("\n");
    
    for(j=2;j<h[l];j++){
      
      printf("#");
      
      for(k=2;k<w[l];k++){
	
	printf(".");
	
      }
      
      printf("#\n");
      
    }   
    
    for(j=0;j<w[l];j++){
      
      printf("#");
      
    }
    
    printf("\n\n");
    
  }
  
  return 0;  
  
}

Measured memory_bytes: 1016
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

//-------------------------------------------------------//

bool isPrime(ll x) {
	if(x <= 1) return false;
	
	for(long d = 2; d*d <= x; d++) 
		if(x%d == 0) return false;
	
	return true;	
}

int main() {
	ll x;
	cin >> x;
	
	while(true) {
		if(isPrime(x)) { cout << x << endl; break; }
		x++;
	}
	
	return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct P{
  int x,y;
  P(int x,int y):x(x),y(y){}
};
int n;
int w,h;
vector<P> o[2700];
//int dp[11111][11111];
int dp[2700][2700];
//int **dp;
//vector<int> dp[11111];

int solve(int m,int j){
  if(m > n) return 0;
  if(dp[m][j]){
    return dp[m][j];
  }

  int ret = 1<<22;
  for(int i = 0; i < (int)o[m].size(); i++){
    ret = min(ret,solve(m+1,i) + abs(o[m][i].x - o[m-1][j].x) + abs(o[m][i].y - o[m-1][j].y));
  }
  return dp[m][j] = ret;
}

int main(void){
  while(1){
    scanf("%d%d",&w,&h); if(!w) break;
    memset(dp,0,sizeof(dp));
    for(int i = 0; i < 2700; i++){ o[i].clear();/*dp[i].clear();*/};

    n = 0;
    int sx,sy;
    int gx,gy;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	char s[256];
	scanf("%s",s);
	if('0' <= s[0] && s[0] <= '9'){
	  int num = atoi(s);
	  //printf("%d\n",num);
	  o[num].push_back(P(j,i));
	  //dp[num].push_back(0);
	  n = max(n,num);
	  continue;
	}
	if(s[0] == 'S'){
	  sx = j;
	  sy = i;
	}else if(s[0] == 'G'){
	  gx = j;
	  gy = i;
	}
      }
    }
    //printf("s:%d,%d\ng:%d,%d\n",sx,sy,gx,gy);
    n++;
    o[n].push_back(P(gx,gy));
    //dp[n].push_back(0);
    o[0].push_back(P(sx,sy));
    //dp[0].push_back(0);
    /*
    dp = (int **)malloc(sizeof(int *) * (n + 1));
    for(int i = 0; i <= n; i++){
      dp[i] = (int *)calloc(o[i].size(),sizeof(int));
    }
    */
    printf("%d\n",solve(1,0));
  }
}

Measured memory_bytes: 30056
import fractions

def mygcd(a, b):
    if a == 0:
        return b
    elif b == 0:
        return a
    else:
        return fractions.gcd(a, b)
N = int(input())
A = list(map(int, input().split()))

L = [0] * N
R = [0] * N
for i in range(0, N-1):
    L[i+1] = mygcd(L[i], A[i])
for i in range(N-1, 0, -1):
    R[i-1] = mygcd(R[i], A[i])

M = []
for i in range(N):
    M.append(mygcd(L[i], R[i]))
print(max(M))

Measured memory_bytes: 16128
fun main(args: Array<String>) {
    readLine()
    val xs = readLine()!!.split(' ').map { it.toInt() }.sortedDescending()

    val n = xs[0]
    var r = xs[1]
    var d = Math.abs(n / 2.0 - r)

    for (i in 2 until xs.size) {
        Math.abs(n / 2.0 - xs[i]).let {
            if (it < d) {
                r = xs[i]
                d = it
            }
        }
    }

    println("$n $r")
}


Measured memory_bytes: 58216
#include <bits/stdc++.h>
#define N 100006
using namespace std;
int n,m,k;long long x;
int main()
{
	scanf("%d%d%d",&k,&n,&m);
	if(n>=m||k<n+1)printf("%d\n",1+k);
	else x=m+1LL*(k-n-1)/2*(m-n)+(k-n-1)%2,printf("%lld\n",max(x,1LL+k));
}

Measured memory_bytes: 256
#include<stdio.h>

int n,A[50];

int solve(int i,int m){
	if(m==0) return 1;
	if(i>=n) return 0;
	int res=solve(i+1,m) || solve(i+1,m-A[i]);
	return res;
}

int main(){
	int q,M,i;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&M);
		if(solve(0,M))printf("yes\n");
		else printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, a, b, ans = 0;
    cin >> n;
    while (n--) {
        cin >> a >> b;
        ans += b-a+1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<numeric> //求和 
#include<string>
#include<algorithm>
const int maxn=50001;
using namespace std;
int main(void)
{
	int n,temp,a=0,b=0,c=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>temp;
		if(temp%2==0){
			if(temp%4==0) a++;
			else b++;
		}else{
			c++;
		}
	}
	//cout<<a<<" "<<b<<" "<<c<<endl;
	if(a>=c || (b==0 && a+1==c)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 384