akhauriyash/Code-Regression huggingface dataset:
import static java.util.Arrays.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	long[] sum;
	void solve() {
		int n = sc.nextInt();
		if (n == 0) return;

		if (primes == null) {
			makePrimes();
			sum = new long[10000 + 10];
			sum[0] = 0;
			for (int i = 1; i < sum.length; i++) {
				sum[i] = sum[i-1] + primes[i-1];
			}
		}
		System.out.println(sum[n]);
	}


	static final int MAX_N = 1024 * 1024;
	boolean[] isPrime = new boolean[MAX_N];
	int[] primes;
	void makePrimes(){
		if (primes != null) return;
		for (int i = 0; i < isPrime.length; i++) isPrime[i] = true;
		isPrime[0] = isPrime[1] = false;
		for (int i = 2; i * i < isPrime.length; i++)
			if (isPrime[i])
				for(int j = i * i; j < isPrime.length; j += i)
					isPrime[j] = false;
		int p = 0;
		for (int i = 2; i < isPrime.length; i++) p += isPrime[i] ? 1 : 0;
		primes = new int[p];
		p = 0;
		for (int i = 2; i < isPrime.length; i++) if (isPrime[i]) primes[p++] = i;
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 23604
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

#define all(v) (v).begin(),(v).end()
using ll = long long;
constexpr ll INF = 1e18;

int main(void) {
    ll N;
    cin >> N;

    vector<ll> min_factor(N+1);
    iota(all(min_factor), 0);
    for (ll i = 2; i*i < N+1; i++) {
        if (min_factor[i] < i) continue;
        for (ll j = i*i; j < N+1; j += i)
            if (min_factor[j] == j) min_factor[j] = i;
    }

    ll ans = 0;
    for (ll c = 1; c < N; c++) {
        ll x = N - c;
        ll p = 1;
        ll cp = 1;
        ll f = -1;
        while (x > 1) {
            if (f != min_factor[x]) {
                f = min_factor[x];
                p *= cp;
                cp = 1;
            }
            cp++;
            x /= min_factor[x];
            if (x <= 1) {
                p *= cp;
            }
        }
        ans += p;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10800
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;

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

class MyList {
private:
    const int MAX_N = 2000000;
    int *lst = new int[MAX_N];
    int first = MAX_N - 1;
    int last = MAX_N - 1;
public:
    MyList();
    void insert(int x);
    void remove(int x);
    void deleteFirst();
    void deleteLast();
    int size();
    void print();
};

MyList::MyList() {
    REP(i,MAX_N) lst[i] = -1;
}

void MyList::insert(int x) {
    lst[first] = x;
    first--;
}

void MyList::deleteLast() {
    last--;
}

void MyList::deleteFirst() {
    first++;
}

int MyList::size() {
    return last - first;
}

void MyList::remove(int x) {
    int xpos = -1;
    for(int i = first+1; i <= last; i++) {
        if (lst[i] == x) {
            xpos = i;
            break;
        }
    }
    if (xpos == -1) return;
    else {
        for(int i = xpos; i > first+1; i--) {
            lst[i] = lst[i-1];
        }
        first++;
    }
}

void MyList::print() {
    for(int i = first+1; i < last; i++) {
        cout << lst[i] << " ";
    }
    cout << lst[last] << endl;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    MyList mylist;
    REP(i,n) {
        string s;
        cin >> s;
        if (s == "insert") {
            int k;
            cin >> k;
            mylist.insert(k);
        }else if (s == "deleteFirst") {
            mylist.deleteFirst();
        }else if (s == "deleteLast"){
            mylist.deleteLast();
        }else {
            int k;
            cin >> k;
            mylist.remove(k);
        }
        //mylist.print();
    }
    mylist.print();
    return 0;
}

Measured memory_bytes: 11040
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	if(a<b){
		cout << "a < b" <<endl;
	}else if(a>b){
		cout << "a > b" <<endl;
	}else{
		cout << "a == b" <<endl;
	}
}


Measured memory_bytes: 3092
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}
long long gcd(long long a,long long b){
  if(b==0){
    return a;
  }
  return gcd(b,a%b);
}
long long lcm(long long a,long long b){
  long long g=gcd(a,b);
  return a/g*b;
}
long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}







int main(){
  int N,M;
  cin>>N>>M;
  int a[M],b[M];
  for(int i=0;i<M;i++){
    cin>>a[i]>>b[i];
  }
  vector<int>x;
  for(int i=0;i<M;i++){
    if(b[i]==N){
      x.push_back(a[i]);
    }
  }
  
  bool ok=false;
  sort(x.begin(),x.end());
  for(int i=0;i<M;i++){
    if(a[i]==1){
      auto result=binary_search(x.begin(),x.end(),b[i]);
      if(result){
        ok=true;

      }
    }
  }
  if(ok){
    cout<<"POSSIBLE"<<endl;

  }else{
    cout<<"IMPOSSIBLE"<<endl;
  }
  

}



  
  


  

Measured memory_bytes: 2428
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,r) RFOR(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define lower(a,x) lower_bound(all(a), x) - a.begin();
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x);
#define MCOUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x);
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end());
#define scan(x) scanf("%lld",&x);
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 5555555555555555555;
const ll mod = 1000000007;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {
  cin >> n;
  while (tmp <= n) {
	cnt++;
	tmp += cnt;
  }

  FOR(i, 1, cnt + 1) {
	if (i != tmp - n) cout << i << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007 
long long int dp[101][100001];
int main()
{
	long long int arr[101],n,k,i,j;
	cin>>n>>k;
	for(i=1;i<=n;i++)
		cin>>arr[i];
	dp[1][0]=1;
	if(n==1&&k<=arr[1])
		cout<<"1"<<endl;
	else if(n==1&&k>arr[1])
		cout<<"0"<<endl;
	else
	{
	for(i=1;i<=arr[1];i++)
		dp[1][i]=dp[1][i-1]+1;
	for(i=arr[1]+1;i<=k;i++)
		dp[1][i]=dp[1][i-1];
	for(i=2;i<=n;i++)
	{
		for(j=0;j<=k;j++)
		{
			if(j-arr[i]>0)
				dp[i][j]=(dp[i-1][j]-dp[i-1][j-arr[i]-1]+MOD)%MOD;
			else
				dp[i][j]=dp[i-1][j];
		}
		if(i!=n)
		{
			for(j=1;j<=k;j++)
				dp[i][j]=(dp[i][j]+dp[i][j-1])%MOD;
		}
	}	
	cout<<dp[n][k];
     }
	return 0;
}

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

using namespace std;

int main()
{
    int n, k, ans = 0;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    for (int i = 0; i < k; i++)
    {
        ans += arr[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <stdio.h>

#define DIV 1000000007

char S[100008];
int Snum=0;

long long dp[100008][4];

int main()
{
    scanf("%s", S);
    for (Snum = 0; S[Snum]!='\0'; Snum++);
    
    dp[Snum][3]=1;
    dp[Snum][2]=0;
    dp[Snum][1]=0;
    dp[Snum][0]=0;
    
    for(int i=Snum-1;i>=0;i--){
        bool isq=S[i]=='?'?true:false;
        dp[i][3]=(isq?3:1)*dp[i+1][3]%DIV;
        //printf("%d",dp[i][3]);
        for(int j=2;j>=0;j--){
            dp[i][j]=((isq?3:1)*dp[i+1][j]
            +((isq||S[i]-'A'==j)?1:0)*dp[i+1][j+1])%DIV;
            //printf(",%d",dp[i][j]);
        }
        //printf("\n");
    }
    printf("%lld\n",dp[0][0]);

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

ll n, x;
ll h[52];
ll p[52];
ll j_ans;

ll dfs(ll a, ll b) {
	ll ans = 0;
	if (a == 0) return 1;
	if (b >= 1) b--;
	if (b >= 1) {
		if (b >= h[a - 1]) {
			b -= h[a - 1];
			ans += p[a - 1];
		}
		else {
			ans += dfs(a - 1, b);
			b = 0;
		}
	}
	if (b >= 1) {
		b--;
		ans++;
	}
	if (b >= 1) {
		if (b >= h[a - 1]) {
			b -= h[a - 1];
			ans += p[a - 1];
		}
		else {
			ans += dfs(a - 1, b);
			b = 0;
		}
	}
	if (b >= 1)b--;
	return ans;
	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> x;
	h[0] = 1;
	rrep(i, n + 1) {
		h[i] = h[i - 1] * 2 + 3;
	}
	p[0] = 1;
	rrep(i, n + 1) {
		p[i] = 2 * p[i - 1] + 1;
	}
	ll ans = dfs(n, x);
	dunk(ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
/*
 j>iとする
 j - i   = A_j + A_i
 j - A_j = i + A_i
*/

int main(){
	int N, sa, wa;
	long long ans=0;
	std::map<int, int> mp;
	//<i+A_i, i+A_iの個数>

	std::cin >> N;
	int A[N];
	for(int i=0; i<N; i++){
		std::cin >> A[i];
	}

	//jを固定して、条件式を満たすi(<j)を探す
	for(int j=0; j<N; j++){
		sa = j-A[j];
		ans += mp[sa];

		//終了したjは、以降のjの候補(i+A_i)になる。
		wa = j+A[j];
		mp[wa]++;
	}

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

Measured memory_bytes: 21336
f (x:s) (y:t) n =case n of 
 0 -> if null s then (x:y:[]) else (x:(f s (y:t) 1))
 1 -> if null t then (y:x:[]) else (y:(f (x:s) t 0))
main=getLine>>=(\s->getLine>>=(\t->putStrLn (f s t 0)))

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


int main(){
    ll n;
    cin >> n;
    bool has_odd = false;
    REP(i, n){
        ll ai;
        cin >> ai;
        has_odd = has_odd || (ai % 2 == 1);
    }
    if(has_odd){
        cout << "first" << endl;
    }else{
        cout << "second" << endl;
    }
    return 0;
}


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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

ll const mod = 1e9+7;


int main() {
  int N,a;
  ll cnt = 1;
  cin >> N;
  vector<int> memo(N,0);
  rep(i,N) {
    cin >> a;
    if (a==0) cnt *= (3-memo[a]);
    else  cnt = (cnt*(memo[a-1] - memo[a]))%mod;
    memo[a]++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 640
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto s = sread();
    writeln(s.map!(x => 'x'));
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2832
s = input()
k = int(input())

t = []
for i in range(len(s)):
    d = 0 if s[i] == 'a' else ord('z') - ord(s[i]) + 1 
    if d <= k:
        t.append('a')
        k -= d
    else:
        t.append(s[i])

k %= 26
for _ in range(k):
    if t[-1] == 'z':
        t[-1] = 'a'
    else:
        t[-1] = chr(ord(t[-1]) + 1)

print(''.join(t))

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

int main(){
  int N, n, s;
  cin >> N;
  n = N;
  for(int i =0;i < 8;i++){
    s += n % 10;
    n /= 10;
  }
  if(N % s == 0){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}

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

#define LL long long

int main(){
	LL x;
	cin>>x;
	LL z=2*(x/11);
	LL y=0;
	if((x%11<=6)&&(x%11!=0)){
		y=1;
	}else if((x%11>6)){
		y=2;
	}
	cout<<z+y;
	return 0;
}

Measured memory_bytes: 256
// coffee と似ているかを判定
#include <iostream>

int main(int argc, char const *argv[]) {
  std::string input;
  std::cin >> input;

  if (input.at(2) == input.at(3) && input.at(4) == input.at(5)) {
    std::cout << "Yes\n";
  } else {
    std::cout << "No\n";
  }

  return 0;
}


Measured memory_bytes: 256
using System;
class Hello{
static void Main(){

string [] str=Console.ReadLine().Split(' ');
int a=int.Parse(str[0]);
int b=int.Parse(str[1]);
int c=int.Parse(str[2]);

int d=0;
for(int i=a;i<=b;i++)
{
if(c%i==0)d++;

}
Console.WriteLine(d);

}
}


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

int main(){
  int n,m;
  int h[1500],w[1500];
  int y[1500000],x[1500000];
  int tmp;

  while(1){
    cin >> n >> m;
    if(!n && !m)break;


    int max;
    if(n>m)max = n;
    else max = m;

    for(int i=0;i<n;i++)cin >> h[i];
    for(int i=0;i<m;i++)cin >> w[i];

    for(int i=0;i<max*1000;i++){
      y[i] = 0;
      x[i] = 0;
    }

    for(int i=0;i<n;i++){
      tmp = 0;
      for(int j=i;j<n;j++){
	tmp += h[j];
	y[tmp]++;
      }
    }
    
    for(int i=0;i<m;i++){
      tmp = 0;
      for(int j=i;j<m;j++){
	tmp += w[j];
	x[tmp]++;
      }
    }

    int ans = 0;
    for(int i=0;i<max*1000;i++)ans += y[i] * x[i];

    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 
char X[1001];
char Y[1001];
 
LongestCommonSubsequence(int x,int y){
  int i,j;
  int z[1001][1001];
   
  for(i = 0;i <= x;i++){
    z[i][0] = 0;
  }
   
  for(i = 0;i <= y;i++){
    z[0][j] = 0;
  }
   
  //printf("o");
   
  for(i = 1;i <= x;i++){
    for(j = 1;j <= y;j++){
      if(X[i-1] == Y[j-1]){
    z[i][j] = z[i-1][j-1]+1;
      }
      else if(z[i-1][j-1] >= z[i][j-1]){
    z[i][j] = z[i-1][j];
      }
      else{
    z[i][j] = z[i][j-1];
      }
    }
  }
  //printf("o");
   
  if(i == 0 || j == 0){
    return 0;
  }
  else if(i > 0 && j > 0 && x == y){
    return z[i-1][j-1];
  }
  else if(i > 0 && j > 0 && x != y){
    return z[x][y];
  }
}
 
int main(){
  int n;
  int i;
  int length1,length2;
  int conclusion;
   
  scanf("%d", &n);
 
  for(i = 0;i < n;i++){
    scanf("%s",X);
    scanf("%s",Y);
     
    length1 = strlen(X);
    length2 = strlen(Y);
 
    //printf("%d %d\n",length1,length2);
     
    conclusion = LongestCommonSubsequence(length1,length2);
    printf("%d\n",conclusion);
  }
  return 0;
}

Measured memory_bytes: 4512
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a;
        int b;
        String op;
        String plus="+";
        String minus="-";
        String mul="*";
        String div="/";
        String que="?";
        int answer=0;

        while(true){
            a=sc.nextInt();
            op=sc.next();
            b=sc.nextInt();

            if(op.equals(plus)){
                answer = a+b;
            }
            if(op.equals(minus)){
                answer = a-b;
            }
            if(op.equals(mul)){
                answer = a*b;
            }
            if(op.equals(div)){
                answer = a/b;
            }
            if(op.equals(que)){
                break;
            }
            System.out.println(answer);
        }

        sc.close();
    }
}


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

using namespace std;

int N, M;
vector<int> graph[100005];
int dist[100005][3];
queue<pair<int, int>> qu;

int main(){
    cin >> N >> M;
    for(int i = 1; i<=M; i++){
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
    }
    int S, T;
    cin >> S >> T;
    for(int k =0; k<3; k++){
        for(int i =1; i<=N; i++){
            dist[i][k] = INT_MAX;
        }
    }
    dist[S][0] = 0;
    qu.push({S, 0});
    while(qu.size()){
        int n = qu.front().first, k = qu.front().second;
        qu.pop();
        for(int e : graph[n]){
            if(dist[e][(k+1)%3] > dist[n][k] + 1){
                dist[e][(k+1)%3] = dist[n][k] + 1;
                qu.push({e, (k+1)%3});
            }
        }
    }
    int ans = dist[T][0];
    if(ans == INT_MAX){
        ans = -3;
    }
    cout << ans/3 << endl;
}


Measured memory_bytes: 6912
N = int(input())
Xlist = [0]*(10**4)
for i in range(100):
    for j in range (100):
        for k in range(100):
            A = (i + j + 2)**2 + (k + j + 2)**2 + (i + k + 2)**2
            if ((A % 2) == 0)and(A <= 20000):
                Xlist[(A//2 -1)] += 1

for a in range (N):
    print(Xlist[a])


Measured memory_bytes: 9300
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main(){

    string a, b;
    cin>>a>>b;
    int ar[27];
    int br[27];
    SET(ar);
    SET(br);

    for(auto i: a){
        ar[i - 'a']++;
    }
    for(auto i: b){
        br[i - 'a']++;
    }
    sort(ar , ar + 26 );
    sort(br, br + 26);
    for(int i = 0; i <= 25;i++){
        if(ar[i] != br[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3928
#include<iostream>

using namespace std;

int gcd(int a, int b){
    int temp;
    while(a % b != 0 && b % a != 0){
        if(a < b){
            b -= a;
        }else{
            a -= b;
        }
    }
    if(a < b) return a;
    else return b;
}

int main(){
    int A,B;
    long long int p;
    cin >> A;
    cin >> B;
    p = (long long int)A*B/gcd(A,B);
    cout << p;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double eps = 1e-9;
const double pi = 3.141592653589793238462;

const int MAXN = 1e5 + 10;

int p[MAXN];
int h[MAXN];
int L[MAXN], R[MAXN];
ll len[MAXN];

int fin(int x) {
    return (p[x] == -1 ? x : p[x] = fin(p[x]));
}

void join(int x, int y) {
    x = fin(x), y = fin(y);
    if (h[x] > h[y]) {
        p[y] = x;
        len[x] += len[y];
        L[x] = min(L[x], L[y]);
        R[x] = max(R[x], R[y]);
    } else {
        if (h[x] == h[y]) h[y]++;
        p[x] = y;
        len[y] += len[x];
        L[y] = min(L[y], L[x]);
        R[y] = max(R[y], R[x]);
    }
}

set<pair<ll, int> > knots;

int main() {
    //freopen("", "rt", stdin);
    //freopen("", "wt", stdout);
    int N, LENGTH;
    scanf("%d %d", &N, &LENGTH);
    for (int i = 1; i <= N; i++) {
        scanf("%lld", &len[i]);
        p[i] = -1;
        h[i] = 0;
        L[i] = i-1;
        R[i] = i;
    }
    for (int i = 1; i < N; i++) {
        knots.insert({len[i] + len[i+1], i});
    }
    vi ans;
    while (!knots.empty()) {
//puts("your set:");
//for (auto haha : knots)
//printf("(%d, %d)\n", haha.fi, haha.se);
        auto it = *prev(knots.end());
        if (it.fi < LENGTH) {
            puts("Impossible");
            return 0;
        }
        ans.pb(it.se);
        knots.erase(prev(knots.end()));
        ll leftlen = len[fin(it.se)];
        ll rightlen = len[fin(it.se+1)];
        join(it.se, it.se+1);
        int cur = fin(it.se);
        if (L[cur] > 0) {
            knots.erase(knots.find({len[fin(L[cur])] + leftlen, L[cur]}));
        }
        if (R[cur] < N) {
            knots.erase(knots.find({rightlen + len[fin(R[cur]+1)], R[cur]}));
        }
        if (L[cur] > 0) {
            knots.insert({len[fin(L[cur])] + len[fin(L[cur]+1)], L[cur]});
        }
        if (R[cur] < N) {
            knots.insert({len[fin(R[cur])] + len[fin(R[cur]+1)], R[cur]});
        }
    }
    reverse(all(ans));
    puts("Possible");
    for (auto it : ans)
        printf("%d\n", it);
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

int bo[310][310];
bool f[310][310];

void solve() {
  int N; cin >> N;
  rep(i, N) rep(j, N) {
    int a; cin >> a; bo[i][j] = a;
  }
  rep(k, N) rep(i, N) rep(j, N) if (bo[i][j] > bo[i][k] + bo[k][j]) {
    cout << -1 << '\n';
    return;
  }
  i64 sum = 0;
  rep(i, N) rep(j, N) sum += bo[i][j];
  rep(k, N) rep(i, N) rep(j, N) {
    if (k == i || i == j || j == k) continue;
    if (f[i][j]) continue;
    if (bo[i][j] == bo[i][k] + bo[k][j]) {
      sum -= bo[i][j];
      f[i][j] = true;
    }
  }
  cout << sum / 2 << '\n';
}


Measured memory_bytes: 768
// E - Coprime
#include <bits/stdc++.h>
using namespace std;
#define rpd(i,s,e,d) for(int i=(s);i<(int)(e);i+=(d))

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

	int N; cin>>N;
	vector<int> C(1e6+1, 0);
	int g = 0;
	rpd(i, 0, N, 1){ int a; cin>>a; C[a]++; g = gcd(g, a); }

	auto not_pairwise = [&]{
		int c = 0;
		rpd(j, 2, C.size(), 2) c += C[j];
		if(c > 1) return true;
		rpd(i, 3, C.size(), 2){
			int c = 0;
			rpd(j, i, C.size(), i) c += C[j];
			if(c > 1) return true;
		}
		return false;
	};

	cout<< vector<string>{"pairwise","setwise","not"}[(g > 1) + not_pairwise()] <<" coprime\n";
}


Measured memory_bytes: 7164
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;

int main(void){
  int N; cin >> N;
  int a=N%100,b=N/100;
  int i = 0;
  if(a>0 && a<=12) i+=1;
  if(b>0 && b<=12) i+=2;
  if(i==3) cout << "AMBIGUOUS" << endl;
  else if(i==2) cout << "MMYY" << endl;
  else if(i==1) cout << "YYMM" << endl;
  else cout << "NA" << endl;
  return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

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

  string s; cin >> s;
  deque<char> dq;
  for(int i=0;i<SZ(s);++i) {
    dq.push_back(s[i]);
  }

  bool inv = false;
  int q; cin >> q;
  while(q) {
    q--;
    int t; cin >> t;
    if(t == 1) {
      inv = !inv;
    } else {
      int f; char c; cin >> f >> c;
      f--;
      if(inv ^ f) {
        dq.push_back(c);
      } else {
        dq.push_front(c);
      }
    }
  }

  string ans = "";
  while(!dq.empty()) {
    ans.push_back(dq.front());
    dq.pop_front();
  }
  if(inv) reverse(ans.begin(), ans.end());
  cout << ans << endl;

}


Measured memory_bytes: 1368
#include<iostream>
    #include<fstream>
    #include<cstdio>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<queue>
    #include<deque>
    #include<utility>
    #include<map>
    #include<set>
    #include<cmath>
    #include<cstdlib>
    #include<ctime>
    #include<functional>
    #include<sstream>
    #include<cstring>
    #include<bitset>
    #include<stack>
    using namespace std;
     
    int n;
    long long t[100005],a[100005],h[100005],ans=1,mx;
     
    int main()
    {
    	cin>>n;
    	
    	for(int i=1;i<=n;i++)
    	{
    		cin>>t[i];
    		if(i==1)continue;
    		if(t[i]<t[i-1])
    		{
    			cout<<0<<endl;
    			return 0;
    		}
    		if(t[i]>t[i-1])
    		{
    			h[i]=t[i];
    		}
    	}
    	
    	for(int i=1;i<=n;i++)
    	{
    		cin>>a[i];
    		if(i==1)continue;
    		if(a[i]>a[i-1])
    		{
    			cout<<0<<endl;
    			return 0;
    		}
    		if(a[i]<a[i-1])
    		{
    			if(h[i-1]>0 && h[i-1]!=a[i-1])
    			{
    				cout<<0<<endl;
    				return 0;
    			}
    			h[i-1]=a[i-1];
    		}
    	}
    	
    	if(t[n]!=a[1])
    	{
    		cout<<0<<endl;
    		return 0;
    	}
    	
    	mx=0;
    	for(int i=1;i<=n;i++)
    	{
    		mx=max(mx,h[i]);
    		if(mx>t[i]){printf("0\n");return 0;}
    	}
    	
    	mx=0;
    	for(int i=n;i>=1;i--)
    	{
    		mx=max(mx,h[i]);
    		if(mx>a[i]){printf("0\n");return 0;}
    	}
    	
    	h[1]=t[1];
    	h[n]=a[n];
    	for(int i=1;i<=n;i++)
    	{
    		if(h[i]>0)continue;
    		ans=(ans*min(a[i],t[i]))%1000000007;
    	}
    	
    	cout<<ans<<endl;
    	return 0;
    }

Measured memory_bytes: 2560
l = [0] * 4

for i in range(3):
    a, b = map(int, input().split())
    l[a-1] += 1
    l[b-1] += 1

l.sort()
r = [1, 1, 2, 2]
if l == r:
    print("YES")
else:
    print("NO")




Measured memory_bytes: 2940
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  string s; cin >> s;
  string t,u;
  int q; cin >> q;
  int cnt=0;
  rep(i,q){
    int p; cin >> p;
    if(p==1){
      cnt++;
    }
    else{
      int f; cin >> f;
      string c; cin >> c;
      if(f==1){
        if(cnt%2==0){
          t+=c;
        }
        else{
          u+=c;
        }
      }
      else{
        if(cnt%2==0){
          u+=c;
        }
        else{
          t+=c;
        }
      }
    }
  }
  reverse(all(t));
  string tsu=t+s+u;
  if(cnt%2==1) reverse(all(tsu));
  cout << tsu << endl;
  
}


Measured memory_bytes: 1348
//How Many Islands?
#include<bits/stdc++.h>
using namespace std;

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

int nx[8]={1,1,1,0,0,-1,-1,-1}, ny[8]={1,0,-1,1,-1,1,0,-1};
int w, h;
int mp[60][60];

void solve(int x, int y){
  if(x<0 || h<=x || y<0 || w<=y || mp[x][y]!=1)return;
  mp[x][y]=0;
  rep(i,8)solve(x+nx[i], y+ny[i]);
}

int main(){
  while(true){
    cin>>w>>h;
    if(w==0&&h==0)break;
    memset(mp, 0, sizeof(mp));
    rep(i,h)rep(j,w)cin>>mp[i][j];
    int cnt=0;
    rep(i,h)rep(j,w)if(mp[i][j]==1){solve(i, j); cnt++;}
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define ll long long int 
using namespace std; 
ll dp[102][100005];
ll solve(ll wt[],ll val[],ll w,ll n)
{
  if(n<=0)
    return 0;
  if(dp[n][w]!=-1)
    return dp[n][w];

  if(wt[n-1]<=w)
  {
    return dp[n][w]=max(val[n-1]+solve(wt,val,w-wt[n-1],n-1),solve(wt,val,w,n-1));
  }  
  else
  {
    return dp[n][w]=solve(wt,val,w,n-1);
  }
  
}
int main() 
{ 
  ll n,w;
  cin>>n>>w;
  memset(dp,-1,sizeof(dp));
  ll wt[n],val[n];
  for(int i=0;i<n;i++)
  {
    cin>>wt[i]>>val[i];
  }
cout<<solve(wt,val,w,n)<<endl;

} 


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

int main() {
    std::ios::sync_with_stdio(false);
    int a,b,m; cin >>a>> b>>m;
    int x = a; int y = b;
    int arr1[a];
    int arr2[b];
    for (int i = 0; i < a;i++){cin >> arr1[i];}
    for (int i = 0; i < b;i++){cin >> arr2[i];}
    int ans = 100000007;
    map<pair<int , int> , bool>m1; 
    for (int i =0; i < m; i++){
        int c; 
        cin >> a >> b>> c;
        m1[make_pair(a,b)]= 1;
        a--; b--;
        ans = min (ans , arr1[a]+arr2[b]-c);
    }
    sort(arr1 , arr1+x);
    sort(arr2 , arr2+y);
    int i =0; int j = 0;
    while (i< x || j < y){
        if (!m1[make_pair(i,j)]){ans = min(ans, arr1[i]+ arr2[j]); break;}
        if (arr1[i+1] <= arr2[j+1])i++;
        else {j++;}
        
    }
    cout << ans;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

int main() {
  int n,m,num;
  int sum = 0;
  cin >> n >> m;
  std::vector<int> x(m),dis(m-1);
  for (int i = 0; i < m; i++) {
    cin >> x[i];
  }
  if (n >= m) {
    num = 0;
  } else {
    VSORT(x);
    for (int i = 1; i < m; i++) {
      dis[i-1] = x[i] - x[i-1];
    }
    VSORT(dis);
    for(int i = 0; i < n-1; i++) {
      sum += dis[m-2-i];
    }
    num = x[m-1] - x[0] - sum;
  }
  cout << num << endl;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 1e3 + 5;

int ind_c[MAXN * MAXN], ind_r[MAXN * MAXN];

void solve(){
	int n, m, v;
	scanf("%d%d", &n, &m);
	REP(i, 0, n) {
		scanf("%d", &v);
		if (ind_r[v]) {
			printf("0\n");
			return;
		}
		ind_r[v] = i + 1;
	}
	REP(i, 0, m) {
		scanf("%d", &v);
		if (ind_c[v]) {
			printf("0\n");
			return;
		}
		ind_c[v] = i + 1;
	}
	ll ans = 1ll, cnt_r = 0ll, cnt_c = 0ll;
	for(int i = n * m; i > 0; i--) {
		if (ind_r[i] && ind_c[i]) {
			cnt_r++;
			cnt_c++;
		} else if (ind_r[i]) {
			cnt_r++;
			ans = (ans * cnt_c) % MOD;
		} else if (ind_c[i]) {
			cnt_c++;
			ans = (ans * cnt_r) % MOD;
		} else {
			ll mul = cnt_r * cnt_c - (n * m - i);
			ans = (ans * mul) % MOD;
		}
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  string s;
  cin >> s;
  if(s.find("7") != string::npos) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

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

int r,g,b;

int main(){

cin>>r>>g>>b;

int n=100*r+10*g+b;

if(n%4) puts("NO");
else puts("YES");

}


Measured memory_bytes: 256
import sys
stdin=sys.stdin

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()

n=ip()
ans=[]
a=[-1]
out=0
now_max=0

for i in range(n):
  s=ip()
  if a[-1]+2<=s:
    out+=1
    break
  elif a[-1]>s:
    ans.append(now_max)
    now_max=s
    if i==n-1:
      ans.append(now_max)
  elif a[-1]==s:
    ans.append(now_max)
    if i==n-1:
      ans.append(now_max)
  elif a[-1]+1==s:
    now_max=s
    if i==n-1:
      ans.append(now_max)
  a.append(s)
      
if out==0:
  print(sum(ans))
else:
  print(-1)
  
  

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; cin >> N;
  vector<int> A(N + 1);
  rep(i, N) cin >> A[i + 1];
  vector<bool> B(N + 1);
  for (int i = N; i >= 1; i--) {
    bool sum = 0;
    for (int j = 2 * i; j <= N; j += i) {
      sum ^= B[j];
    }
    if (sum ^ A[i]) {
      B[i] = 1;
    }
  }
  vector<int> ans;
  rep(i, N) {
    if (B[i + 1]) {
      ans.push_back(i + 1);
    }
  }
  cout << ans.size() << "\n";
  if (ans.size()) {
    rep(i, ans.size()) {
      if (i) cout << " ";
      cout << ans[i];
    }
    cout << "\n";
  }
}


Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

double dp[3001][3001] = {};

int main()
{
  int n;
  cin >> n;
  vector<double> p(n);
  REP(i, n)
  {
    cin >> p[i];
  }
  dp[1][0] = 1 - p[0];
  dp[1][1] = p[0];

  FOR(i, 2, n + 1)
  {
    REP(j, i + 1)
    {
      dp[i][j] = dp[i - 1][j - 1] * p[i - 1] + dp[i - 1][j] * (1 - p[i - 1]);
    }
  }

  double ans = 0.0;
  FOR(j, (n + 1) / 2, n + 1)
  {
    ans += dp[n][j];
  }

  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 68992
#include <iostream>
#include <cmath>

int main() {
  int n;

  std::cin >> n;

  long long t[1000], a[1000];
  long long ans_t, ans_a;
  for (int i = 0; i < n; i++) {
    std::cin >> t[i] >> a[i];
  }

  ans_t = t[0];
  ans_a = a[0];
  for (int i = 1; i < n; i++) {
    long long x;
    if ((ans_t + t[i] - 1) / t[i] < (ans_a + a[i] - 1) / a[i]) {
      x = (ans_a + a[i] - 1) / a[i];
      ans_t = t[i] * x;
      ans_a = a[i] * x;
    } else {
      x = (ans_t + t[i] - 1) / t[i];
      ans_a = a[i] * x;
      ans_t = t[i] * x;
    }
  }

  std::cout << ans_a + ans_t << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int n,sum,ans,a[55];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i];
	for(int i=1;i<=n;i++)ans+=(sum-a[i])*a[i];
	printf("%d\n",ans/2);
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main{

	static PrintWriter out;
	static InputReader ir;

	static void solve(){
		while(true){
			int[] a=ir.nextIntArray(4);
			if(a[0]==0)
				break;
			if(a[1]*a[2]<a[0])
				out.println(0);
			else{
				int ext=a[1]*a[2]-a[0];
				out.println(ext%a[3]==0?ext/a[3]:(int)ext/a[3]+1);
			}
		}
	}

	public static void main(String[] args) throws Exception{
		ir=new InputReader(System.in);
		out=new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer=new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}

		public boolean hasNextByte() {
			if(curbuf>=lenbuf){
				curbuf= 0;
				try{
					lenbuf=in.read(buffer);
				}catch(IOException e) {
					throw new InputMismatchException();
				}
				if(lenbuf<=0) return false;
			}
			return true;
		}

		private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

		private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}

		private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

		public boolean hasNext(){skip(); return hasNextByte();}

		public String next(){
			if(!hasNext()) throw new NoSuchElementException();
			StringBuilder sb=new StringBuilder();
			int b=readByte();
			while(!isSpaceChar(b)){
				sb.appendCodePoint(b);
				b=readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if(!hasNext()) throw new NoSuchElementException();
			int c=readByte();
			while (isSpaceChar(c)) c=readByte();
			boolean minus=false;
			if (c=='-') {
				minus=true;
				c=readByte();
			}
			int res=0;
			do{
				if(c<'0'||c>'9') throw new InputMismatchException();
				res=res*10+c-'0';
				c=readByte();
			}while(!isSpaceChar(c));
			return (minus)?-res:res;
		}

		public long nextLong() {
			if(!hasNext()) throw new NoSuchElementException();
			int c=readByte();
			while (isSpaceChar(c)) c=readByte();
			boolean minus=false;
			if (c=='-') {
				minus=true;
				c=readByte();
			}
			long res = 0;
			do{
				if(c<'0'||c>'9') throw new InputMismatchException();
				res=res*10+c-'0';
				c=readByte();
			}while(!isSpaceChar(c));
			return (minus)?-res:res;
		}

		public double nextDouble(){return Double.parseDouble(next());}

		public int[] nextIntArray(int n){
			int[] a=new int[n];
			for(int i=0;i<n;i++) a[i]=nextInt();
			return a;
		}

		public long[] nextLongArray(int n){
			long[] a=new long[n];
			for(int i=0;i<n;i++) a[i]=nextLong();
			return a;
		}

		public char[][] nextCharMap(int n,int m){
			char[][] map=new char[n][m];
			for(int i=0;i<n;i++) map[i]=next().toCharArray();
			return map;
		}
	}
}

Measured memory_bytes: 24316