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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		scan.nextLine();
		String[] array = new String[N];
		for (int i = 0; i < N; i++) {
			String s = scan.nextLine();
			char[] chars = s.toCharArray();
			Arrays.sort(chars);
			array[i] = String.valueOf(chars);
		}
		Arrays.sort(array);
		String before = array[0];
		long cnt = 0;
		long addCnt = 0;
		for (int i = 1; i < N; i++) {
			if (before.equals(array[i])) {
				cnt += addCnt;
				addCnt++;
				cnt++;
			}
			else {
				addCnt = 0;
			}
			before = array[i];
		}

		System.out.println(cnt);
	}
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    if(k > v.back()){
        cout << "IMPOSSIBLE" << endl;
    }else{
        int g = v.at(0);
        for(int i=1; i<n; i++){
            g = __gcd(g, v.at(i));
        }
        if(k%g == 0){
            cout << "POSSIBLE" << endl;
        }else{
            cout << "IMPOSSIBLE" << endl;
        }
    }

    return 0;
}

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

int main(void){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int x[N];
    int MAX = -200;
    int MIN = 200;
    int y[M];
    for(int i = 0; i < N; i++){
        cin >> x[i];
        if(MAX < x[i])
            MAX = x[i];
    }
    for(int i = 0; i < M; i++){
        cin >> y[i];
        if(MIN > y[i])
            MIN = y[i];
    }
    int check = 0;
    for(int i = X+1; i <= Y; i++){
        if(i > MAX && i <= MIN)
            check++;
    }
    if(check >= 1)
        cout << "No War" << endl;
    else if(check == 0)
        cout << "War" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP priority_queue
#define heap(T) priority_queue<T,vector<T>,greater<T> > 
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
const int BufferSize=1<<25;
char buffer[BufferSize],*Bufferhead,*Buffertail;
int Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T> inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	x=rev?-x:x;
	return 1;
}
template<class T>inline void print(T x,const char c){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[10];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n=50;
ll k,a[N];

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	cin>>k;
	for(int i=1;i<=n;i++)
		a[i]=n-1;
	for(int i=1;i<=n;i++)
		a[i]+=k/n;
	k%=n;
	for(int p=1;p<=k;p++){
		a[p]+=n;
		for(int i=1;i<=n;i++)
			if(i!=p) a[i]--;
	}
	cout<<n<<endl;
	for(int i=1;i<=n;i++) cout<<a[i]<<(i<n?' ':'\n');
	return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int  n, m ;  cin >> n >> m ; 
    int gcd=__gcd(n,m);
    string f,s; cin >> f >> s;
    if (gcd>1){
        bool ok=true;
        int i=n/gcd,j=m/gcd;
        for (int ii=0,jj=0;ii<n and jj<m;ii += i,jj += j){
            if (f[ii] != s[jj]) ok=false;
        }
        if (ok) cout << (n*m)/__gcd(n,m) << endl; 
        else cout << -1 << endl;
    }
    else {
        if (f[0]==s[0]) cout << (n*m)/__gcd(n,m) << endl;
        else cout << -1 << endl;
    }
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3744
#include<iostream>
#include<string>
#include<iomanip>

using namespace std;
int main(void) {
	char n;
	cin >> n;
	if (n >= 'a'&&n <= 'z') {
		cout << "a";

	}
	else if (n >= 'A'&&n <= 'Z') {
		cout << "A";
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define LIM 1+2+4+8+16+32+64+128
#define int long long 
#define F first
#define S second
using namespace std;
typedef struct{
  int per;
  int ko;
  int kyoda;
  int konoko;
}TRE;
int ace(int a,int b){
  int ss=0;
  for(int i=b;i<=a;i++){
    ss+=i;
  }
  return(ss);
}
typedef pair<int,int>P;
void sai(P n[],int x){
  if(x==1){
    return;
  }else{
    if(x%2==0){
      if(n[x].S<n[x+1].S){
	n[x/2].S=n[x+1].S;
	n[x/2].F=n[x+1].F;
	sai(n,x/2);
      }else{
	n[x/2].S=n[x].S;
	n[x/2].F=n[x].F;
	sai(n,x/2);
      }
    }else{
      if(n[x].S<=n[x-1].S){
	n[x/2].S=n[x-1].S;
	n[x/2].F=n[x-1].F;
	sai(n,x/2);
      }else{      
	n[x/2].S=n[x].S;
	n[x/2].F=n[x].F;
	sai(n,x/2);
      }
    }
  }
  return;
}
signed  main(){
  int rui[17]={2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072};
  int n,r,l;
  cin>>n>>r>>l;
  int gg=0;
  while(1){
    if(n<=rui[gg]){
      break;
    }
    gg++;
  }
  int ss=rui[gg];
  P seg[ss*2-1];
  for(int i=0;i<ss;i++){
    seg[ss+i].F=i+1;
    seg[ss+i].S=0;
  }
  for(int i=ss-1;i>0;i--){
    seg[i].F=seg[i*2].F;
    seg[i].S=0;
  }
  int ans[n+1];
  for(int i=0;i<=n;i++){
    ans[i]=0;
  }
  int now=0;
  for(int i=0;i<r;i++){
    int d,t,x;
    cin>>d>>t>>x;
    ans[seg[1].F]+=t-now;
    seg[ss+d-1].S+=x;
    sai(seg,ss+d-1);
    now=t;
  }
  ans[seg[1].F]+=l-now-1;
  int mx=1;
  for(int i=2;i<=n;i++){
    if(ans[mx]<ans[i]){
      mx=i;
    }
  }
  cout<<mx<<endl;
  return(0);
}



Measured memory_bytes: 7976
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int seg[(1<<24)][26];
int LEN=(1<<23)-1;

void add(char a, int x) {
  x += LEN;
  while(true) {
    seg[x][a-'a']++;
    if(x==0) break;
    x = (x-1)/2;
  }
  return;
}

void change(char bef, char newchr, int x) {
  x += LEN;
  while(true) {
    seg[x][bef-'a']--;
    seg[x][newchr-'a']++;
    if(x==0) break;
    x = (x-1)/2;
  }
  return;
}

int sum(int l, int r) {
  l += LEN;
  r += LEN;
  vector<char> ans;
  map<char, int> amap;
  while(l<r) {
    if(l%2==0) {
      for(int i=0;i<26;++i) {
        if(seg[l][i]>0) {
          if(amap['a'+i]==0) ans.push_back('a'+i);
          amap['a'+i]++;
        }
      }
      l++;
    }
    l /= 2;
    if(r%2==0) {
      for(int i=0;i<26;++i) {
        if(seg[r-1][i]>0) {
          if(amap['a'+i]==0) ans.push_back('a'+i);
          amap['a'+i]++;
        }
      }
      r--;
    }
    r /= 2;
  }
  return ans.size();
}

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  for(int i=0;i<N;++i) {
    add(S[i], i);
  }
  int Q;
  cin>>Q;
  int query;
  int l, r, x;
  char a;
  vector<int> ans;
  for(int i=0;i<Q;++i) {
    cin>>query;
    if(query==1) {
      cin>>x>>a;
      x--;
      change(S[x], a, x);
      S[x] = a;
    }
    else {
      cin>>l>>r;
      l--;
      ans.push_back(sum(l, r));
    }
  }
  for(int i=0;i<ans.size();++i) cout<<ans[i]<<endl;
}



Measured memory_bytes: 105660
#include <stdio.h>
#include <algorithm>

using namespace std;

const long long maxn = 310;
const long long mod = 998244353;
long long n , m;
long long a[maxn][maxn];
long long s[maxn][maxn];
long long r;
long long pow ( long long x ) {
	long long s = 1 , f = 2;
	while ( x ) {
		if ( x % 2 ) s = ( s * f ) % mod;
		f = ( f * f ) % mod; x = x / 2;
	}
	return s;
}
void work () {
	long long i , j , k;
	scanf ( "%lld%lld" , &n , &m );
	for ( i = 1 ; i <= n ; i++ )
		for ( j = 1 ; j <= m ; j++ )
			scanf ( "%lld" , &a[i][j] );
	for ( i = 1 ; i <= n ; i++ ) {
		for ( j = 1 ; j <= m ; j++ ) {
			if ( s[j][j] == 0 && a[i][j] == 1 ) {
				for ( k = 1 ; k <= m ; k++ ) {
					s[j][k] = a[i][k];
				}
				r++;
				break;
			}
			if ( a[i][j] == 1 && s[j][j] == 1 )
				for ( k = 1 ; k <= m ; k++ ) {
					a[i][k] ^= s[j][k];
				}
		}
	}
	printf ( "%lld\n" , ( pow ( n + m - 1 ) - pow ( n + m - r - 1 ) + mod ) % mod );
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using L = __int128;

int main(){
    int n;
    while(scanf(" %d", &n),n){
        vector<vector<ll>> b(n+1, vector<ll>(n+1));
        rep(i,n+1){
            for(int j=i+1; j<n+1; ++j) scanf(" %lld", &b[i][j]);
        }

        L sq_a0 = (L)b[0][1]*b[0][2];
        sq_a0 /= b[1][2];

        ll ng=0, ok=(1LL<<31)-1;
        while(ok-ng>1){
            ll mid = (ng+ok)/2;
            if(sq_a0 <= mid*mid) ok = mid;
            else ng = mid;
        }

        ll a0 = ok;
        printf("%lld\n", a0);

        vector<ll> a;
        for(int i=1; i<=n; ++i) a.pb(b[0][i]/a0);
        sort(all(a));
        rep(i,n) printf("%lld%c", a[i], " \n"[i==n-1]);
    }
    return 0;
}



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

using namespace std;

int main() {
	
	int r, g, b;

	scanf("%d %d %d", &r, &g, &b);

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

	if (num % 4 == 0)
		puts("YES");
	else
		puts("NO");
	return 0;
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d", $k);
  fscanf(STDIN, "%d %d", $a,$b);
$ans="NG";
 for($i=$a;$i<=$b;++$i){
   if($i%$k==0){
   $ans="OK";
   break;
   }
}
 echo $ans;
?>

Measured memory_bytes: 16248
n = int(input())
a = list(map(lambda s: int(s) - 1, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += b[a[i]]
for i in range(n - 1):
    if a[i] + 1 == a[i+1]:
        ans += c[a[i]]
print(ans)

Measured memory_bytes: 3064
//It's time to be who I am, rather than who I am supposed to be.
#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;

const int N = 1e5 + 10;
const int inf = 1e12;

int n, a[N], dp[N];

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		dp[a[i]]++;
		dp[a[i] - 1]++;
		dp[a[i] + 1]++;
	}

	cout << *max_element(dp , dp + N) << '\n';

}

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

using namespace std;

constexpr int INF = 1145141919;

vector<int> vertex;
vector<int> sorted;
vector<vector<int>> graph;

vector<int> ret;

int index(int x) {
    return lower_bound(sorted.begin(), sorted.end(), vertex[x]) - sorted.begin();
}

void dfs(int here, int prev, vector<int> &LIS) {
    int pos = lower_bound(LIS.begin(), LIS.end(), index(here)) - LIS.begin();
    int value = LIS[pos];
    LIS[pos] = index(here);

    ret[here] = lower_bound(LIS.begin(), LIS.end(), INF) - LIS.begin();

    for (auto next:graph[here]) {
        if (next == prev)continue;
        dfs(next, here, LIS);
    }

    LIS[pos] = value;
}

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

    vertex.resize(n);
    for (int i = 0; i < n; i++)cin >> vertex[i];
    sorted = vertex;
    sort(sorted.begin(), sorted.end());

    graph.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v, u--, v--;
        graph[u].push_back(v), graph[v].push_back(u);
    }

    ret.resize(n);
    vector<int> tmp(n, INF);
    dfs(0, -1, tmp);

    for (auto x:ret)cout << x << "\n";
    cout << endl;
    return 0;
}

Measured memory_bytes: 31776
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <tuple>
#include <queue>

using namespace std;

#define D(x)
#define REP(i,a,b) for (int i = (a); i < (b); ++i)

int cost[100000];

struct cmp {
    bool operator() (int a, int b) {
        return cost[a] > cost[b];
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;

    int N, M; scanf("%d%d", &N, &M);

    vector<map<int, vector<int> > > G(N);

    REP(m,0,M) {
        int a,b,c;
        scanf("%d%d%d", &a, &b, &c);
        a--;b--;c--;
        G[a][c].push_back(b);
        G[b][c].push_back(a);
    }

    fill_n(cost, N, N);

    cost[0] = 0;
    priority_queue<int, vector<int>, cmp> pq;
    pq.push(0);

    while (!pq.empty()) {
        int start = pq.top();
        pq.pop();
        int ccost = cost[start] + 1;
        for (auto ce : G[start]) {
            int c = ce.first;
            vector<int> active = ce.second;
            while (!active.empty()) {
                int v = active.back();
                if (v == N-1) {
                    printf("%d\n", ccost);
                    return 0;
                }
                active.pop_back();
                if (ccost <= cost[v]) {
                    for (auto w : G[v][c]) {
                        active.push_back(w);
                    }
                    G[v][c].clear();
                    if (ccost < cost[v]) {
                        cost[v] = ccost;
                        pq.push(v);
                    }
                }
            }
        }
    }

    printf("-1\n");

    return 0;
}


Measured memory_bytes: 49408
#include <iostream>
using namespace std;
int main() {
  int n;
  long long k,k1;
  cin>>n>>k;
  int a[n+1],b[n+1];
  for(int i=1;i<=n;i++){
    cin>>a[i];
    b[i]=0;
  }
  int i=1,x=0;
  while(b[i]==0){
    b[i]=x+1;
    if(x==k){
      cout<<i;
      return 0;
    }
    i=a[i];
    x++;
  }
  k1=(k-b[i]+1)%(x+1-b[i]);
  while(k1--)
    i=a[i];
  cout<<i;
}


Measured memory_bytes: 5200
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
mi = 1000000000
for i in range(n):
    if mi > abs(a-(t-h[i]*0.006)):
        mi = abs(a-(t-h[i]*0.006))
        ans = i+1
print(ans)


Measured memory_bytes: 9156
import sys
from operator import itemgetter
n = int(input())
a = [0]*n
b = [0]*n
box = []
for i in range(n):
     a[i],b[i] = map(int,input().split())
     box.append((a[i],b[i]))
box1 = sorted(box,key=itemgetter(1,0))
ans=0
for i in range(n):
     ans += box1[i][0]
     if ans > box1[i][1]:
          print('No')
          sys.exit()

print('Yes')




Measured memory_bytes: 49164
'use strict';(function(input){
  input=input.trim().split(/\n/);
  const N=input[0]-0,
        d=input[1].split(/\s+/).map(x=>x-0).sort((a,b)=>a-b);
  console.log(d[N/2]-d[N/2-1]);
})(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 25788
#include<cstdio>
using namespace std;
int X,W;char ch;
inline int read()
{
	X=0,W=1;ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')W=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){X=(X<<1)+(X<<3)+ch-48;ch=getchar();}
	return X*W;
}
int n,m,c;
int k[1005],map[1005][1005],ans=0;
int main()
{
	n=read(),m=read(),c=read();
	for(int i=1;i<=m;i++)k[i]=read();
	for(int j=1;j<=n;j++){
		for(int i=1;i<=m;i++){
			map[j][i]=read();
		}
	}
	for(int j=1;j<=n;j++){
		int now=c;
		for(int i=1;i<=m;i++)now+=map[j][i]*k[i];
		if(now>0)ans++;
	}
	printf("%d",ans);
	return 0;
}

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

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

    string s = to_string(N);
    int sum = 0;
    for (char c : s) {
        sum += c - '0';
    }

    if (N % sum == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

class Program{
    static void Main(string[] args){
        string str = Console.ReadLine();
        int N = str.Length;
        for(int i=0;i<N-1;i++){
            if(str[i]==str[i+1]){
                Console.WriteLine("{0} {1}",i+1,i+2);
                return;
            }
        }
        for(int i=0;i<N-2;i++){
            if(str[i]==str[i+2]){
                Console.WriteLine("{0} {1}",i+1,i+3);
                return;
            }
        }
        Console.WriteLine("-1 -1");
    }
}

Measured memory_bytes: 3032
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Integer Cards
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;

/* global variables */

int as[MAX_N];
pii cbs[MAX_M];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) scanf("%d", as + i);
  sort(as, as + n);

  for (int i = 0; i < m; i++) {
    int b, c;
    scanf("%d%d", &b, &c);
    cbs[i] = pii(c, b);
  }
  sort(cbs, cbs + m);

  for (int i = 0, j = m - 1; i < n && j >= 0; i++) {
    int &cj = cbs[j].first, &bj = cbs[j].second;
    if (as[i] == cj) break;
    if (as[i] < cj) {
      as[i] = cj;
      if (--bj <= 0) j--;
    }
  }

  ll sum = 0;
  for (int i = 0; i < n; i++) sum += as[i];

  printf("%lld\n", sum);
  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(i<n)cout<<s[i];
        else
        {
            cout<<"..."<<endl;
            break;
        }
    }
}


Measured memory_bytes: 3624
# N = int(input())

# power = 1
# for i in range(1, N+1):
#    power *= i
# print(power % (10 ** 9 + 7))

# TLEとなってしまう
# modの世界を使う

N = int(input())
power = 1
for i in range(1, N+1):
    power = power * i % (10 ** 9 + 7)

print(power)

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int
main(int argc, char *argv[])
{
  ll n;
  char s[200010];
  scanf("%lld", &n);
  scanf("%s", s);

  if (s[0] == 'W') printf("0\n");
  else {
    ll ans = 1;
    ll x = 0;
    ll i = 0;
    while (i < 2 * n) {
      if (i == 2 * n - 1) {
	if ((s[i] == 'B' && x % (ll)2 == 0) || (s[i] == 'W' && x % (ll)2 == 1) || x > 1) {
	  printf("0\n");
	  return 0;
	}
      }
      if (s[i] == 'W' && x == 0) {
	printf("0\n");
	return 0;
      }
      if ((s[i] == 'B' && x % (ll)2 == 0) || (s[i] == 'W' && x % (ll)2 == (ll)1)) {
	x++;
      } else if ((s[i] == 'B' && x % (ll)2 == (ll)1) || (s[i] == 'W' && x % (ll)2 == 0)) {
	ans *= x;
	ans %= MOD;
	x--;
      }
      i++;
    }
    ll z = 1;
    for (ll i = 0; i < n; i++) {
      z *= i + (ll)1;
      z %= MOD;
    }
    printf("%lld\n", (z * ans) % MOD);
  }

  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int n;
  scanf("%d", &n);
  if(n>=64){
    printf("64\n");
  }
  else if(n>=32 && n<64){
    printf("32\n");
  }
  else if(n>=16 && n<32){
    printf("16\n");
  }
  else if(n>=8 && n<16){
    printf("8\n");
  }
  else if(n>=4 && n<8){
    printf("4\n");
  }
  else if(n>=2 && n<4){
    printf("2\n");
  }
  else{
    printf("1\n");
  }
}


Measured memory_bytes: 128
n=int(input())
h=list(map(int,input().split()))
h[0]-=1
for i in range(1,n):
  if h[i]-h[i-1]<-1 or (i>=2 and h[i]-h[i-1]==-1 and h[i-2]==h[i-1]):
    print('No')
    exit()
  elif i>=2 and h[i-2]<h[i-1]:
    h[i-1]-=1
print('Yes')

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;

ll gcd(ll A, ll B){
    if(A<B) swap(A,B);
    while(B){
        ll w = A%B;
        A = B;
        B = w;
    }
    return A;
}

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

    // solution comes here
    ll N, ans;
    cin >> N;
    vl A(N);
    rep(i, N) {
        cin >> A[i];
        if(i==1) ans = gcd(A[0],A[1]);
        if(i>2)  ans = gcd(ans, A[i]);
    }
    cout << ans << nl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(){

  int n;

  scanf("%d",&n);

  char tarou[1000][150];

  char hanako[1000][150];

  int a;

  for(a=0;a<=n-1;a++){

    scanf("%*c%s %s",tarou[a],hanako[a]);

  }

  int b;

  int ptt=0,pth=0;

  for(b=0;b<=n-1;b++){

    if(strcmp(tarou[b],hanako[b])>0)

      ptt+=3;

    if(strcmp(tarou[b],hanako[b])<0)

      pth+=3;

    if(strcmp(tarou[b],hanako[b])==0){

      ptt++;

      pth++;

    }

  }

    printf("%d %d\n",ptt,pth);

    return 0;

}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000
bool pr[MAX];
void era(){
    for(int i=0;i<MAX;i++) pr[i]=true;
    pr[0]=false;
    pr[1]=false;
      
    for(int i=0;i*i<MAX;i++){
        if(pr[i]){
            for(int j=i*i;j<=MAX;j=j+i){
                pr[j]=false;
            }
        }
    }
}

void solve(int a,int d,int n){
    int count=0;
    for(int i=a;1;i+=d){
        if(pr[i])count++;
        if(count==n){cout<<i<<endl;return;}
    }
    
    
}

int main (){
    era();
    int a,b,c;
    while(cin>>a>>b>>c,a){
        solve(a,b,c);
    }
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


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

	co(A + B / 2);

	Would you please return 0;
}

Measured memory_bytes: 256
while true
    n = gets.to_i
    break if n == 0
    l = gets.chomp.split.map(&:to_i).inject(:+)
    j = gets.chomp.split.map(&:to_i).sort.reverse
    l += j.inject(:+)
    max = l
    m = 2
    while sub = j.pop
        l -= sub
        max = l * m if max < l * m
        m += 1
    end
    puts max
end


Measured memory_bytes: 28800
#include <bits/stdc++.h>
#define y1 __zzd001
using namespace std;
const int N=2005;
int n,d,v[N][N],s[3][N][N];
int S(int x1,int y1,int x2,int y2,int t){
	return s[t][x2][y2]-s[t][x2][y1-1]-s[t][x1-1][y2]+s[t][x1-1][y1-1];
}
int check(int x){
	int r=x%d;
	for (int i=1;i<=d;i++)
		for (int j=1;j<=d;j++){
			int x1=i,y1=j,x2=x1+r,y2=y1+r,x3=x1+d-1,y3=y1+d-1;
			if (!S(x1,y2+1,x3,y3,1)&&!S(x2+1,y1,x3,y3,1)&&!S(x2+1,y2+1,x3,y3,0))
				return 1;
		}
	return 0;
}
int main(){
	scanf("%d%d",&n,&d);
	memset(v,0,sizeof v);
	while (n--){
		int x,y;
		scanf("%d%d",&x,&y);
		v[x%d+1][y%d+1]++;
	}
	int Mx=0,t;
	for (int i=1;i<=d;i++)
		for (int j=1;j<=d;j++)
			v[i+d][j]=v[i][j+d]=v[i+d][j+d]=v[i][j],Mx=max(Mx,v[i][j]);
	for (t=0;(t+1)*(t+1)<Mx;t++);
	int l[3]={t*t+1,t*(t+1)+1,(int)1e9};
	for (int i=1;i<=d*2;i++)
		for (int j=1;j<=d*2;j++)
			for (int t=0;t<2;t++){
				s[t][i][j]=s[t][i-1][j]+s[t][i][j-1]-s[t][i-1][j-1];
				if (l[t]<=v[i][j])
					s[t][i][j]++;
			}
	int L=t*d,R=t*d+d-1,ans=R,mid;
	while (L<=R)
		if (check(mid=(L+R)>>1))
			R=mid-1,ans=mid;
		else
			L=mid+1;
	cout << ans;
	return 0;
}


Measured memory_bytes: 48768
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,k;
  cin >> n >> k;
  cout << n-(n/k)*k << endl;
  return 0;
}

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

int main(void){
    int n = 0;
    int x[101] = {0};
    int ans = 1000000000;
    int min = 100, max = 0;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        scanf("%d", &x[i]);
        if(max < x[i]){
            max = x[i];
        }
        if(min > x[i]){
            min = x[i];
        }
    }

    for(int i = min; i <= max; i++){
        int tmp_ans = 0;
        for(int j = 0; j < n; j++){
            tmp_ans += (x[j] - i) * (x[j] - i);
        }
        if(ans > tmp_ans){
            ans = tmp_ans;
        }
    }
    printf("%d\n", ans);

    return 0;

} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int>a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  
  int max1=0 , max2=0 ,count=0;
  for(int i=0; i<n; i++){
    max1=max(max1,a[i]);
  }
  for(int i=0; i<n; i++){
    if(a[i]==max1){
      count++;
      continue;
    }
    else max2=max(max2,a[i]);
  }
  
  for(int i=0; i<n; i++){
   if(a[i]==max1 && count==1) cout << max2 << endl;
    else cout << max1 << endl;
  }
  
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 1e5 + 2;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i], b[i] = a[i];
    }
    sort(b, b + n);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) cnt++;
    }
    cout << (cnt > 2 ? "NO" : "YES");
    return 0;
}


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

using namespace std;

int main(){
    long long s,t,d;
    cin>>s>>t>>d;
    long long moku=t-s;
    map<long long,long long> mp;
    long long dif=0;
    long long mx=-1,mn=200000;
    for (int i = 1; i <= d; ++i) {
        long long w;
        cin>>w;
        dif+=w;
        if(dif<=moku){
            cout<<i<<endl;
            return 0;
        }
        if(mp.find(dif)==mp.end())mp[dif]=i;
        mx=max(mx,dif);mn=min(mn,dif);
    }

    for (long long yaru = 1; yaru <= 200000; ++yaru) {
        moku-=dif;
        if(moku>=0){
            cout<<d*yaru<<endl;
            return 0;
        }
        auto it=mp.upper_bound(moku);
        if(it!=mp.begin()){
            long long ans=200000;
            for(auto jt:mp){
                if(jt.first<=moku)ans=min(ans,jt.second);
            }
            cout<<d*yaru+ans<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 8572
#include<stdio.h>

int main(){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if(x-r >= 0 && x+r <= W && y-r >=0 && y+r <= H){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            if(n == 0){
                break;
            }
            int m = scan.nextInt() - (n<<1);
            char[] ch = (scan.next()).toCharArray();
            int count = 0;
            for(int i = 0;i < m;i++){
                if(ch[i] == 'I'){
                    for(int j = 0;j < n;j++){
                        if(ch[i+1+(j<<1)] != 'O' || ch[i+((j+1)<<1)] != 'I'){
                            break;
                        }else if(j == n-1){
                            count++;
                            i++;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 32704
#include <iostream>

using namespace std;

int main(){
    int a,b,c,tmp;
    cin >> a;
    cin >> b;
    cin >> c;

    if(a > b){
      tmp = b;
      b = a;
      a = tmp;
    }

    if(b > c){
      tmp = c;
      c = b;
      b = tmp;
    }

    if(a > b){
      tmp = b;
      b = a;
      a = tmp;
    }

    cout << a << ' ' << b << ' ' << c << endl;
    return 0;
}



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

using namespace std;
long long b[100005];
long long a[100005];
int main()
{
    long long i,j,k,n,m,x=0,y,z;
    cin>>n;
    for(i=1; i<=n-1; i++)
    {
        cin>>b[i];
        x=max(x,b[i]);
    }
    for(i=1;i<=n;i++)
    {
        a[i]=x;
    }
    a[n]=b[n-1];
    for(i=1;i<n;i++)
    {
        if(max(a[i],a[i+1])>b[i])
        {
            a[i]=b[i];
            a[i+1]=b[i];
        }
    }
    y=0;
    for(i=1;i<=n;i++)
    {
        y=y+a[i];
        //cout<<a[i]<<" ";
    }
    //cout<<"\n";
    for(i=n;i>=1;i--)
    {
        if(max(a[i],a[i-1])>b[i-1] && i>1)
        {
            a[i]=b[i-1];
            a[i-1]=b[i-1];
        }
    }
    z=0;
    for(i=1;i<=n;i++)
    {
        z=z+a[i];
        //cout<<a[i]<<" ";
    }
    cout<<min(y,z)<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,i,x;
	scanf("%d",&n);
        for(i=1;i<=n;i++){
		if(i%3==0){
			printf(" %d",i);
		}else{
			x=i;
			while(x!=0){
				if(x%10==3){
					printf(" %d",i);
					break;
				}else{
					x/=10;
				}
			}
		}
	}
	printf("\n");
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for(int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if(k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n);
  rep(i, n) cin >> a[i];
  combination c(n);
  sort(all(a));
  mint ans = 0;
  rep(i, n - k + 1) {
    mint now = a[n - i - 1] - a[i];
    now *= c(n - i - 1, k - 1);
    ans += now;
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> P;
int main(){
    ll a,b,c;
    ll aa,bb,cc;
    cin >> a >> b >> c;
    if(a%2==1||b%2==1||c%2==1){
        cout << 0 << endl;
        return 0;
    }
    rep(i,100000){
        aa = (b+c)/2;
        bb = (a+c)/2;
        cc = (a+b)/2;
        a = aa;
        b = bb;
        c = cc;
        if(a%2==1||b%2==1||c%2==1){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define each(e,v) for(auto&& e:(v))
#define DEBUG(x) cout<<#x<<": "<<x<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
using vlong = vector<ll>;

const ll MOD = 1e9 + 7;

int main() {
    int n; cin >> n;
    vlong t(n), a(n);
    rep(i, n) cin >> t[i];
    rep(i, n) cin >> a[i];
    if(t[n-1] != a[0]) {
        cout << 0 << endl;
        return 0;
    }
    vlong c(n); // 候補数
    rep(i, n) {
        c[i] = min(t[i], a[i]);
        if(i > 0) if(t[i] != t[i-1]) {
            c[i] = 1;
            if(a[i] < t[i]) c[i] = 0;
        }
        if(i < n-1) if(a[i] != a[i+1]) {
            c[i] = 1;
            if(t[i] < a[i]) c[i] = 0;
        }
    }
    c[0] = c[n-1] = 1;
    ll ans = 1;
    rep(i, n) ans = (ans * c[i]) % MOD;
    cout << ans % MOD << endl;

    // cout << "DEBUG:" << endl;
    // rep(i, n) cout << c[i] << " ";

    return 0;
}


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

int main(){
	int N,sum;
	cin>>N;
	sum=0;
	for (int i=0;i<N;i++){
			int l,r;
			cin>>l>>r;
			sum+=r-l+1;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long n, a, b;
	cin >> n;
	b = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		for (int j = 2; j*j <= a;j++) {
			if (a%j == 0) {
				b++;
				break;
			}
		}
	}
	cout << n - b << endl;
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;
 
long long mod = 1000000007;
 
long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}
 
void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
 
int main() {
    int k, s, ans = 0;
    cin >> k >> s;
    if (k < 10){
        cout << s + 1000 - k * 100 << endl;
    }else{
        cout << s << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	int a, b;
	cin >> a;
	cin >> b;
	int c = a % 500;
	if (c <= b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

const int64_t MOD = 1000000007;

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

  int a[n+1] = {};
  for(int i=1;i<=n;i++){
    cin >> a[i];
  }
  
  unordered_map<int, char> b;
  for(int i=n;i>=1;i--){
    int sum = 0;
    for(int j=i*2;j<=n; j += i ){
      if(b.count(j)!=0){
      	sum += b[j];
      	sum %= 2;
      }
    }
    if(a[i]==1){
      if(sum==0){
        b[i] = 1;
      }
    }
    else{ // if(a[i]==0){
      if(sum==1){
        b[i] = 1;
      }
    }
  }

  cout << b.size() << endl;
  for(auto box:b){
    cout << box.first << " ";
  }
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 10784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

int N;

void dfs(string s, char c){
    if(s.size()==N){
        cout<<s<<endl;
    }
    else{
        for(int i='a';i<=c+1;i++){
            char j=i;
            int c1=c;
            int k=max(i, c1);
            char d=k;
            dfs(s+j, d);
        }
    }
}

int main() {
    cin>>N;
    dfs("a", 'a');
}

Measured memory_bytes: 1536
#include<cstdio>
#include<iostream>
using namespace std;
const int step[8][2]={-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};
char a[55][55];
int s[55][55];
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	    cin>>a[i][j];
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	    if(a[i][j]=='.')
	      for(int k=0;k<8;k++)
	        if(a[i+step[k][0]][j+step[k][1]]=='#') s[i][j]++;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		  if(a[i][j]=='#') putchar('#');
		  else printf("%d",s[i][j]);
		puts("");
	}
	return 0;
}

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

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

    int x1 = 0, y1 = 0;
    rep(i, 0, n) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            x1 = max(x1, x);
        } else if (a == 2) {
            w = min(w, x);
        } else if (a == 3) {
            y1 = max(y1, y);
        } else {
            h = min(h, y);
        }
    }
    if (w <= x1 || h <= y1) {
        cout << "0" << endl;
        return 0;
    } else {
        cout << (w - x1) * (h - y1) << endl;
    }
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using T = tuple<int, int, int>;
const int INF = 1e+8;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> field(h, vector<char>(w));
    for(int x = 0; x < h; x++){
        for(int y = 0; y < w; y++){
            cin >> field[x][y];
        }
    }
    int ans = 0;
    for(int sx = 0; sx < h; sx++){
        for(int sy = 0; sy < w; sy++){
            if(field[sx][sy] == '#') continue;
            vector<vector<bool>> dst(h, vector<bool>(w, false));
            int mxdst = 0;
            queue<T> q;
            q.push(T{sx, sy, 0});
            while(!q.empty()){
                int x,y,d;
                tie(x,y,d) = q.front();
                q.pop();
                if(dst[x][y]) continue;
                dst[x][y] = true;
                mxdst = max(mxdst, d);
                for(int i = 0; i < 4; i++){
                    if(x + dx[i] < 0 || 
                       y + dy[i] < 0 ||
                       x + dx[i] >= h ||
                       y + dy[i] >= w ||
                       dst[x + dx[i]][y + dy[i]] ||
                       field[x + dx[i]][y + dy[i]] == '#') continue;
                    q.push(T{x + dx[i], y + dy[i], d+1});
                }
            }
            ans = max(mxdst, ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll dp[SIZE][5][5][5];

/*

 */

int main(){
  // AGC, A*GC, GAC, ACG, AG*C

  int n;

  cin >> n;

  dp[0][0][0][0] = 1;

  for(int i=0;i<n;i++){
    for(int a=0;a<5;a++){
      for(int b=0;b<5;b++){
        for(int c=0;c<5;c++){

          for(int d=1;d<5;d++){
            if(b == 1 && c == 2 && d == 3) continue;
            if(a == 1 && c == 2 && d == 3) continue;
            if(b == 2 && c == 1 && d == 3) continue;
            if(b == 1 && c == 3 && d == 2) continue;
            if(a == 1 && b == 2 && d == 3) continue;

            dp[i+1][b][c][d] += dp[i][a][b][c];
            dp[i+1][b][c][d] %= mod;
          }
        }
      }
    }
  }

  ll ans = 0;

  for(int a=0;a<5;a++)
    for(int b=0;b<5;b++)
      for(int c=0;c<5;c++)
        ans += dp[n][a][b][c];

  cout << ans % mod << endl;

  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int A,R;
char p,c;

int main()
{
	for(scanf("%d\n%c",&R,&p);scanf("%d\n%c",&A,&c);)
	{
		if(p=='+')R+=A;
		if(p=='-')R-=A;
		if(p=='*')R*=A;
		if(p=='/')R/=A;
		if(c=='=')break;
		p=c;
	}
	printf("%d\n",R);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void){
  int n;
  long long int min,max,sum;
  
  scanf("%d",&n);
  
  int  a[n];
  sum=0;
  
  int i;
 
  for(i=0;i<n;i++){
	  scanf("%d",&a[i]);
	  if(i==0){min=a[i]; max=a[i]; sum=a[i];}
	  else{
	  if(min>a[i]) min=a[i];
	  if(max<a[i]) max=a[i];
	  sum+=a[i];
	  }
  }
	  
  printf("%lld %lld %lld\n",min,max,sum);
    
  return 0;
}
  

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

using namespace std;
const int max_n = 1e5 + 20;
int n, k;
int a[max_n], DP[max_n];
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 1; i < n; i++) {
        DP[i] = 1e9;
        for (int j = 1; j <= k; j++) {
            int tmp = max(0, i - j);
            DP[i] = min(DP[i], DP[tmp] + abs(a[tmp] - a[i]));
        }
    }
    cout << DP[n - 1];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct UnionFind
{
	std::vector<int> par, cou;
	UnionFind(int N = 0) : par(N), cou(N, 1) {
		iota(par.begin(), par.end(), 0);
	}
	int find(int x) {
		while (x != par[x])x = par[x];
		return x;
	}
	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		if (cou[x] < cou[y]) std::swap(x, y);
		par[y] = x, cou[x] += cou[y];
		return true;
	}
	int count(int x) { return cou[find(x)]; }
	bool same(int x, int y) { return find(x) == find(y); }
	int f() {
		set<int> s;
		for (int i = 0; i < par.size(); i++) {
			int cur = find(i);
			s.insert(cur);
		}
		return int(s.size());
	}
};

void solve() {
	int n, m; cin >> n >> m;
	UnionFind temp(n);
	while (m--) {
		int a, b; cin >> a >> b;
		a--; b--;
		temp.unite(a, b);
	}
	cout << max(0, temp.f() - 1);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--)
	solve();

}

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

int main (void)
{
    long s[250000] = {0};
    long n;
    long i,j=0;
    long k;
    long type[250000] = {0}; //個数
    long ans = 0;
    long a[250000] = {0};
    scanf("%ld %ld",&n,&k);
    for(i=0;i<n;i++){
        scanf("%ld",&a[i]);
    }
    sort(a,a+n);
    /*for(i=0;i<n;i++){
        printf("%ld\n",a[i]);
    }*/
    for(i=0;i<n;i++){
        if(i==0){
            s[j] = a[i];
            //printf("s[%ld] = %ld",j,s[j]);
            type[j]++;
        }else{
            if(s[j] != a[i]){
                j++;
                s[j] = a[i];
                //printf("s[%ld] = %ld",j,s[j]);
                type[j]++;
            }else{
                type[j]++;
            }
        }
    }
    sort(type,type+j+1);
    for(i=0;i<=j;i++){
        //printf("%ld\n",type[i]);
    }
    if(j-k+1 > 0){
        for(i=0;i<j-k+1;i++){
            ans+=type[i];
        }
        printf("%ld\n",ans);
    }else{
        printf("0\n");
    }
    
    

    return 0;
    
}

Measured memory_bytes: 6776