akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define dump(x) cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else
const bool test = false;
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

void solve();

signed main()
{
    cout << fixed << setprecision(20);
    solve();
    while (true)
    {
        char s[MAX];
        if (scanf("%s", s) == EOF)
            break;
        int n = strlen(s);
        for (int i = n - 1; i > -1; i--)
        {
            ungetc(s[i], stdin);
        }
        solve();
    }
    return 0;
}

int N, M;
vector<int> c(55);

void solve()
{
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        c[a]++;
        c[b]++;
    }
    rep(i, N) {
        cout << c[i] << endl;
    }
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define inf 2147483647
#define eps 1e-9
using namespace std;
typedef long long ll;
int n,tot,a[800001];
char s[500001];
void mul(int a[],int &n,int k){
    // a[n]a[n-1]...a[1]是长度为n(a[1]a[2]...a[n]才是n)的大数(ans)，求ans*k之后得到的各个位数的数字之和
    // tot保存的是之和，a[n]a[n-1]...a[1]是保留ans*k
    int p=0;
    tot=0;
    for(int i=1;i<=n;i++){
        p=a[i]*k+p;
        a[i]=p%10;
        tot+=a[i];
        p/=10;
    }
    if(p)a[++n]=p;
    tot+=p;
}
void add(int a[],int &n,int k){
    int p=0;//p是进位
    tot-=a[1];//tot保留的的到ans+k之后的数字各位数之和.a[n]a[n-1]..a[1]也就变成了ans+k
    a[1]+=k;
    p=a[1]/10;
    a[1]%=10;
    tot+=a[1];
    for(int i=2;i<=n;i++){
        tot-=a[i];
        a[i]+=p;
        p=a[i]/10;
        a[i]%=10;
        tot+=a[i];
        if(!p)break; //加法没有进位，
    }
    if(p)a[++n]=p;
    tot+=p;
}
int main(){
    scanf("%s",s);
    n=strlen(s);
    for(int i=1;i<=n;i++){
        a[i]=s[n-i]-'0';
    }
    mul(a,n,9);
    for(int i=1;i<=n;i++){
        add(a,n,9);//cout<<tot<<endl;
        if(tot%9==0&&i*9>=tot)return printf("%d",i),0;
    }
    return 0;
}


Measured memory_bytes: 2688
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out = "";
    while (scanner.hasNext()) {
      String line = scanner.nextLine();
      String[] work = line.split(" |,|\\.");
      for (String str : work) {
        if (3 <= str.length() && str.length() <= 6) {
          out += str + " ";
        }
      }
    }
    System.out.print(out.trim() + "\n");
  }
}

Measured memory_bytes: 17184
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    ll n,x,m;
    cin>>n>>x>>m;
    ll ans =0;
    vector<int> lasta(m+1);
    vector<ll> lastans(m+1);
    ll a = x;
    ans +=a;
    bool f=true;
    for (ll i=2;i<=n;i++)
    {
        
        a = (a*a)%m;
        if(lasta[a]==0||f==false)
        {
            lasta[a]= i;
            ans +=a;
            lastans[a] = ans;
            
        }

        else
        {
            ans +=a;
            ll loop = i - lasta[a];
            
            ll nloop = (n-i)/loop;
            ll dans = ans - lastans[a] ;

            ans +=dans *nloop;
            i += nloop * loop;
            f = false;

        }

    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           ((ll)x.size())
#define hell            (1000000007)
#define inf             ((ll)5e18 + 5)
#define PI              ((double)3.14159265358979323844)
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll n;
    cin>>n;
    ll arr[n];
    ll cnt=0;
    rep(i,0,n){
        cin>>arr[i];
        if (i%2==0 && arr[i]%2){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

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

int li[3];

int main(){
	for(int i=0;i<3;i++) cin >> li[i];
	sort(li,li+3);
	if(li[0] == 5 && li[1] == 5 && li[2] == 7) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
int main(int argc,char ** argv){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n , w;
    cin >> n >> w;
    vector< int > val(n) , wei(n);
    vector< ll > dp(w + 1,0);
    for(int i = 0 ; i < n ; i++ ){
    	cin >> wei[i] >> val[i]; 
  	}

    for(int i = 0 ; i < n ; i++){
        if(wei[i] <= w){
            for(int j = w - wei[i] ; j >= 0 ; j--){
                dp[j + wei[i]] = max(dp[j + wei[i]] , dp[j] + val[i]);
            }
        }
      /*  for(int x = 0 ; x <= w ; x++)
            cout << dp[x] <<" ";*/


    }
    ll ans = 0;
    for(int i = 0 ; i <= w ; i++)
  	{    
       // cout << dp[i] << " " ;
        ans = max(ans , dp[i]);
    }
	cout << ans << endl;
	return 0; 
}

Measured memory_bytes: 1024
/* Volume0 0004 Simultaneous Equation */
import java.util.ArrayList;
import java.util.Scanner;

class Main{
	public static void main(String[] args){

		double a,b,c,d,e,f,x,y;

		Scanner stdIn = new Scanner(System.in);

		while( stdIn.hasNext()){
			
			a = stdIn.nextDouble();
			b = stdIn.nextDouble();
			c = stdIn.nextDouble();
			d = stdIn.nextDouble();
			e = stdIn.nextDouble();
			f = stdIn.nextDouble();
			
			if( a*e-b*d == 0 ){
				x = 0.0;
				y = 0.0;
			} else if( c*e-b*f==0 ){
				x = 0.0;
				y = c/b;
			} else if( c*d-a*f==0 ){
				x = c/a;
				y = 0.0;
			} else {
				x = (c*e-b*f)/(a*e-b*d);
				y = (c*d-a*f)/(b*d-a*e);
			}
			
			System.out.printf("%.3f",x);
			System.out.print(" ");
			System.out.printf("%.3f",y);
			System.out.println();
			
		}
	}
}

Measured memory_bytes: 28328
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<queue>
#define For(i,j,k)  for(int i=j;i<=k;++i)
#define Dow(i,j,k)  for(int i=k;i>=j;--i)
#define ll long long
#define inf 1e9
#define pb push_back
#define local freopen("in.in","r",stdin);
#define c(x,y)  ((x-1))*m+(y)
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read()
{
	int t=0,f=1;char c=gc();
	while(!isdigit(c))  {if(c=='-') f=-1;c=gc();}
	while(isdigit(c))   t=t*10+c-'0',c=gc();
	return t*f;
}
inline void write(ll x){if(x<0) {putchar('-');write(-x);return;}if(x>=10)    write(x/10);putchar(x%10+'0');}
inline void writeln(ll x){write(x);puts("");}
inline void write_p(ll x){write(x);putchar(' ');}
ll n,x,y,ans,sum,flag;
int main()
{
	n=read();sum=1e15;flag=0;
	For(i,1,n)
	{
		x=read();y=read();	
		ans+=x;
		if (x!=y)flag=1;
		if (x>y)sum=min(sum,y);
	}
	if (!flag)writeln(0);else writeln(ans-sum);
}

Measured memory_bytes: 256
def p_b():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    ans = 0

    l = []
    r = []
    for i in range(N):
        lc = 0
        rc = 0
        for j in range(N):
            if A[i] > A[j]:
                if i > j:
                    lc += 1
                else:
                    rc += 1
        l.append(lc)
        r.append(rc)
        
    an = K * (K + 1) // 2 % mod
    for i in range(N):
        sum_r = an * r[i]
        sum_l = (an - K) * l[i]
        ans += sum_r + sum_l
        ans %= mod
	
    print(ans)


if __name__ == '__main__':
    p_b()


Measured memory_bytes: 43324
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define MIN(a, b) ((a<b) ? a : b)

int main() {
  int n;
  scanf("%d", &n);
  int a[n+2], sum=0, ans;
  a[0]=0; a[n+1]=0;
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
    sum+=abs(a[i-1]-a[i]);
  }
  sum+=abs(a[n]);
  for (int i=1; i<=n; i++) {
    ans = sum;
    ans -= abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]);
    ans += abs(a[i-1]-a[i+1]);
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef pair<string,string> SP;

struct Rule {
  int type;
  string a, b;
};

const int type_permit = 0;
const int type_deny   = 1;

int N, M;
vector<Rule> rules;

bool isMatch(const string &s, const string &t) {
  if(s.size() != t.size()) return false;
  for(int i = 0; i < s.size(); ++i) {
    if(s[i] == '?' || t[i] == '?') continue;
    if(s[i] != t[i]) return false;
  }
  return true;
}


bool isPermit(const string &a, const string &b) {
  for(int i = rules.size()-1; i >= 0; --i) {
    if(isMatch(rules[i].a, a) && isMatch(rules[i].b, b)) {
      return rules[i].type == type_permit;
    }
  }
  return false;
}

int main() {
  while(cin >> N >> M && (N|M)) {
    rules.clear();
    for(int i = 0; i < N; ++i) {
      Rule r;
      string t;
      cin >> t >> r.a >> r.b;
      if(t == "permit") {
        r.type = type_permit;
      } else {
        r.type = type_deny;
      }
      rules.push_back(r);
    }

    vector<vector<string> > v;
    for(int i = 0; i < M; ++i) {
      string a, b, s;
      cin >> a >> b >> s;
      if(isPermit(a,b)) {
        vector<string> u(3);
        u[0] = a;
        u[1] = b;
        u[2] = s;
        v.push_back(u);
      }
    }

    cout << v.size() << endl;
    for(int i = 0; i < v.size(); ++i) {
      for(int j = 0; j < v[i].size(); ++j) {
        if(j) cout << " ";
        cout << v[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1424
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct UnionFind {
    vector<int> par; // uf(x,y)->y
    UnionFind() {}
    UnionFind(int NV) { init(NV); }
    void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); }
    void reset() { rep(i, 0, par.size()) par[i] = i; }
    int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
    void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) par[x] = y; }
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, H, W;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> H >> W;
    vector<pair<int,pair<int,int>>> E;
    rep(i, 0, N) {
        int y, x, a; cin >> y >> x >> a;
        y--; x--;
        E.push_back({a, {x, y + W}});
    }

    UnionFind uf(H + W + 1);
    sort(all(E));
    reverse(all(E));

    ll ans = 0;
    fore(p, E) {
        int c = p.first;
        int a = p.second.first;
        int b = p.second.second;

        if(uf[a] == uf[b]) {
            if(uf[a] == uf[H + W]) continue;

            ans += c;
            uf(a, H + W);
        } else {
            ans += c;
            uf(a, b);
        }
    }
    cout << ans << endl;
}







Measured memory_bytes: 3572
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1 << 29;

int main(){
	int a,b;scanf("%d%d",&a,&b);
	if(1ll*a*b<=0){puts("Zero");return 0;}
	if(a>0){puts("Positive");return 0;}
	int delt=abs(a)-abs(b)+1;
	if(delt&1){puts("Negative");return 0;}
	puts("Positive");

	return 0;
}


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

int main() {
	int a;
	cin >> a;
	if(a>81){cout << "No" << endl;return 0;}

		int flag = 0;
		for(int i = 1 ; i < 10 && flag == 0; i++)
		{
			for(int j = 1 ;j < 10; j++)
			{
				if(i*j == a)
				{
					cout << "Yes" << endl;
					flag = 1;
					break;
				}
			}
		
		}
		if(flag == 0)
		{
			cout << "No" << endl;
		}
		
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;
int a[5][5],b[5][5];
int main(int argc, char *argv[]) {
	for(int i=1;i<=3;++i)
		for(int j=1;j<=3;++j){
			cin>>b[i][j];
		}
	int t; cin>>t;
	for(int i=1;i<=t;++i){
		int n; cin>>n;
		for(int i=1;i<=3;++i)
			for(int j=1;j<=3;++j)
				if(b[i][j]==n){
					a[i][j]=1;
				}
	}
	int flag=0;
	if(a[1][1]==1&&a[1][2]==1&&a[1][3]==1) flag=1;
	else if(a[2][1]==1&&a[2][2]==1&&a[2][3]==1) flag=1;
	else if(a[3][1]==1&&a[3][2]==1&&a[3][3]==1) flag=1;
	else if(a[1][1]==1&&a[2][1]==1&&a[3][1]==1) flag=1;
	else if(a[1][2]==1&&a[2][2]==1&&a[3][2]==1) flag=1;
	else if(a[1][3]==1&&a[2][3]==1&&a[3][3]==1) flag=1;
	else if(a[1][1]==1&&a[2][2]==1&&a[3][3]==1) flag=1;
	else if(a[3][1]==1&&a[2][2]==1&&a[1][3]==1) flag=1;
	if(flag==1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 難易度数
        int D = scanner.nextInt();
        // 要求点数
        int G = scanner.nextInt();

        int[] P = new int[D];
        int[] C = new int[D];

        for (int i = 0; i < D; i++) {
            P[i] = scanner.nextInt();
            C[i] = scanner.nextInt();
        }

        int minNum = 0;
        // 2^n
        for (int bit = 0; bit < (1 << D); bit++) {
            int point = 0;
            int problemNum = 0;

            // その時たったbitに応じて全問正解する難易度を決定(決め打ち)する
            for (int i = 0; i < D; i++) {
                if (((bit >> i) & 1) == 1) {
                    // そのbitが立ってるとき全問正解したとする
                    point += P[i] * 100 * (i + 1) + C[i];
                    problemNum += P[i];
                }
            }

            // 全問正解のみで要求点数をクリアしていた場合
            if (point >= G) {
                if (minNum == 0 || minNum > problemNum) {
                    minNum = problemNum;
                    continue;
                }
            }

            // 配点の高い問題をいくつか解くことでクリアできるはずなので配点の高い問題から確認する
            for (int i = D - 1; i >= 0; i--) {
                // 全問正解ですでにカウントした問題
                if (((bit >> i) & 1) == 1) continue;

                for (int j = 0; j < P[i]; j++) {
                    if (point >= G) {
                        if (minNum == 0 || minNum > problemNum) {
                            minNum = problemNum;
                        }
                        break;
                    }
                    point += (i + 1) * 100;
                    problemNum++;
                }
            }
        }
        System.out.println(minNum);
    }
}


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

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


ds = make_divisors(N)
ans = list()

for d in ds:
    if d < 2:
        continue
    a = d - 1
    if (N // a) == (N % a):
        ans.append(a)

print(sum(ans))

Measured memory_bytes: 3296
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>


using namespace std;


void security()
{
  string s;
  cin >> s;

  for (int i = 1; i < s.size(); ++i)
  {
    if (s[i - 1] == s[i])
    {
      cout << "Bad\n";
      return;
    }
  }
  cout << "Good\n";
}


void fifty_fify()
{
  string s;
  cin >> s;

  sort(s.begin(), s.end());

  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes\n";
  else cout << "No\n";
}


void dodecagon()
{
  int r;
  cin >> r;

  cout << 3 * r * r << "\n";
}


void harmony()
{
  int a, b;
  cin >> a >> b;

  if (a % 2 == b % 2) cout << (a + b) / 2 << "\n";
  else cout << "IMPOSSIBLE\n";
}


void transfer()
{
  int a, b, c;
  cin >> a >> b >> c;

  cout << max(0, c - (a - b)) << "\n";
}


void A_137()
{
  int a, b;
  cin >> a >> b;

  cout << max(a + b, max(a - b, a * b)) << "\n";
}


void red_or_not()
{
  int a;
  cin >> a;
  string s;
  cin >> s;

  if (a >= 3200) cout << s << "\n";
  else cout << "red\n";
}


void tenki()
{
  string s, t;
  cin >> s >> t;

  int cnt = 0;
  for (int i = 0; i < 3; ++i)
  {
    if (s[i] == t[i]) ++cnt;
  }
  cout << cnt << "\n";
}


void password()
{
  int n;
  cin >> n;

  cout << pow(n, 3) << "\n";
}


void swap_0or1()
{
  int n;
  cin >> n;

  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    int p;
    cin >> p;
    if (p != i) ++cnt;
  }

  if (cnt <= 2) cout << "YES\n";
  else cout << "NO\n";
}


void uneven_numbers()
{
  int n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i <= n; ++i)
  {
    string s = to_string(i);
    if (s.size() % 2 == 1) ++ans;
  }
  cout << ans << "\n";
}


void one_clue()
{
  int k, x;
  cin >> k >> x;

  for (int i = x - k + 1; i < x + k; ++i)
  {
    if (i == x + k - 1) cout << i << "\n";
    else cout << i << " ";
  }
}



void resistors_in_parallel()
{
  int n;
  cin >> n;
  vector<float> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  float ans = 0.0;
  for (int i = 0; i < n; ++i) ans += 1.0 / a[i];
  cout << 1.0 / ans << "\n";
}


void power_socket()
{
  int a, b;
  cin >> a >> b;

  if (b == 1) cout << 0 << "\n";

  int cnt = 1, tap = (a - 1) * cnt + 1;
  while (tap < b)
  {
    ++cnt;
    tap += a - 1;
  }
  
  cout << cnt << "\n";
}


void buffet()
{
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n - 1; ++i) cin >> c[i];

  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
    ans += b[a[i] - 1];
    if (i > 0 && a[i - 1] + 1 == a[i]) ans += c[a[i - 1] - 1];
  }
  cout << ans << "\n";
}




int main()
{
  //security();
  //fifty_fify();
  //dodecagon();
  //harmony();
  //transfer();
  //A_137();
  //red_or_not();
  //tenki();
  //password();


  swap_0or1();
  //uneven_numbers();
  //one_clue();
  //resistors_in_parallel();
  //power_socket();
  //buffet();
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
D = list(map(int,input().split()))

CD = Counter(D)
CD=list(CD.items())
count=0
for i in range(len(CD)):
    if CD[i][0]<CD[i][1]:
        count=count+CD[i][1]-CD[i][0]
    elif CD[i][0]>CD[i][1]:
        count=count+CD[i][1]
print(count)

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

int a, b, c;

void solve() {
    if (a == b) {
        cout << c << endl;
    } else if (a == c) {
        cout << b << endl;
    } else {
        cout << a << endl;
    }
}

int main() {
    cin >> a >> b >> c;
    solve();
    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
using ll = long long;

constexpr i64 INF = 1010000000000000017LL;

constexpr i64 MOD = 1000000007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

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

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        return mod_pow(x * x % MOD, n / 2) % MOD;
    } else {
        return x * mod_pow(x, (n - 1)) % MOD;
    }
}

ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;

    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }
    return ret;
}

ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) {
        ret *= (i + 1);
        ret %= MOD;
    }
    return ret;
}

ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);

    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    string s; cin >> s;
    size_t len = s.size();
    string ans = "";
    string rs = s;
    reverse(rs.begin(), rs.end());
    if (s != rs) ans = "No";
    else 
    {
        auto first = s.substr(0, (len-1)/2);
        auto second = s.substr((len+1)/2);
        if (first == second) ans = "Yes";
        else ans = "No";
    }
    cout << ans;
}

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

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
n, k = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
ans = 1
mod = 10**9+7
def dfs(node, p_node=-1):
    if p_node==-1:
        tmp = k
        kk = k-1
    else:
        tmp = 1
        kk = k-2
    for c_node in graph[node]:
        if c_node==p_node:
            continue
        tmp *= dfs(c_node, node)
        tmp *= kk
        tmp %= mod
        kk -= 1
    return tmp
print(dfs(0))

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

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

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}



const int N = 2e5 + 10;

vector<int> lastprime(N,-1);

void sieve_lastprime()
{
  lastprime[0] = lastprime [1] = 0;
    
  //-1 is prime
    
  for(int i=2;i<N;i++)
  {
    if(lastprime[i] == -1)
        for(int j=i*i;j<N;j+=i) 
            lastprime[j] = i;  
  }
}

vector<int> phi(N);

void sieve_phi()
{
    for(int i=0;i<N;i++) phi[i] = i;
    
    for(int i=2;i<N;i++)
    {
      if(phi[i] == i)
          for(int j=i;j<N;j+=i)
             phi[j] -= (phi[j]/i);
    }
}

vector<int> mobius(N);

void sieve_mobius()
{
  sieve_lastprime();  
    
  mobius[0] = 0;
  mobius[1] = 1;
    
  for(int i=2;i<N;i++)
  {
      if(lastprime[i] == -1) mobius[i] = -1;
      else if( (i/lastprime[i]) % lastprime[i] == 0) mobius[i] = 0;
      else mobius[i] = (mobius[lastprime[i]]*mobius[i/lastprime[i]]);
  }
}

void solve()
{
    int n,k;
    cin >> n >> k;
    
    int res = 0;
    
    for(int i=1;i<=k;i++)  
      for(int j=i;j<=k;j+=i) 
    {
        int ways = mod_pow((k/j),n);
        
        ways*=i;
        ways%=MOD;
        ways*=mobius[j/i];
        ways%=MOD;
        ways+=MOD;
        ways%=MOD;
        
        res=(res+ways)%MOD;
    }
    
    cout << res;
    
}

signed main()
{
    sieve_mobius();
    
    fast;
    solve();
}

Measured memory_bytes: 7920
s=input()
l=len(s)
ans=''
anslen=0
for i in range(l):
    for j in range(i,l):
        ok=True
        for ss in s[i:j+1]:
            if ss not in ['A','C','G','T']:
                ok=False
                break
        if ok:
            if anslen<j-i+1:
                ans=s[i:j+1]
                anslen=j-i+1
print(anslen)

Measured memory_bytes: 3064
N=int(input())
B=[int(i) for i in input().split()]
TF=[True for _ in range(N)]
I=list(reversed(range(N)))
ans=[]
d=0
while N!=d:
  # print(TF)
  flag=True # -1 flag
  k=d
  for i in I:
    # print(d,k,i)
    if TF[i]:
      if i+1-k==B[i]:
        TF[i]=False
        flag=False
        ans.append(i)
        d+=1
        break
    else:
      k-=1
  if flag:
    ans=-1
    break
if ans==-1:
  print(ans)
else:
  for i in reversed(ans): print(B[i])

Measured memory_bytes: 3064
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


class SegmentTree {
public:
	SegmentTree(ll size)
	{
		n = 1;
		while (n < size)n *= 2;
		dat.resize(2 * n, INFL);
	}

	void update(ll k, ll a)
	{

		k += n - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}

	ll query(ll a, ll b) {
		return query_impl(a, b, 0, 0, n);
	}

private:
	ll n;
	vector<ll> dat;


	ll query_impl(ll a, ll b, ll k, ll l, ll r)
	{
		if (r <= a || b <= l)return INFL;
		if (a <= l && r <= b)return dat[k];
		else {
			ll vl = query_impl(a, b, k * 2 + 1, l, (l + r) / 2);
			ll vr = query_impl(a, b, k * 2 + 2, (l + r) / 2, r);
			return min(vl, vr);
		}
	}
};

int main()
{
	ll N, x;
	cin >> N >> x;
	SegmentTree st(N);
	vector<ll> a(N);
	REP(i, N) {
		cin >> a[i];
		st.update(i, a[i]);
	}

	ll res = INFL;
	REP(maxShift, N) {
		ll score = x * maxShift;
		REP(i, N) {
			ll l = i;
			ll r = i + maxShift + 1;
			ll tmp = st.query(l, min(r, N));
			if (r > N) {
				tmp = min(tmp, st.query(0, r - N));
			}
			score += tmp;
		}

		res = min(res, score);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>		/*()ñ]px!=iÞpxBOÉiñ¾pxðÜ½0Æ·éB*/
#include <math.h>

#define raz(a) (a * 3.14159 / 180.0)		/*math.hÌOpÖÌøÍWAÉÄB*/


int main()
{
	int r,a;	/*à(0<r<=100)Añ]px(-180<=a<=180)*/
	double x=0.0,y=0.0,angle=0.0;
							/*ñÂÆàfalseÉÈçÈ«áAUÉÈçÈ¢B*/
	while(scanf("%d,%d",&r,&a),r!=0 || a!=0){
		x += (double)r * sin(raz(angle));
		y += (double)r * cos(raz(angle));
		angle += (double)a;					/*pxXV(^C~Oª±±ÈÌÍAæ­âè¶ðÇñÅÝæ¤B)*/
	}
	printf("%d\n%d\n",(int)x,(int)y);			/*ë·ÍÇ¤µÜµå¤B©w¦Èµ*/
	
	return 0;
}

Measured memory_bytes: 0
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
d = inpl()
m = inp()
t = inpl()
cntd = Counter(d)
cntt = Counter(t)
for key in cntt:
    if cntt[key] > cntd[key]:
        print('NO')
        break
else:
    print('YES')

Measured memory_bytes: 118728
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    ll N;
    ll sunuke_sum, arai_sum, total;
    ll ans = 2000000000;
    sunuke_sum = 0;
    arai_sum = 0;
    total = 0;
    cin >> N;
    vector<ll>a(N);

    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
        total += a.at(i);
    }

    for (int i = 0; i < N-1; i++) {
        sunuke_sum += a[i];
        arai_sum = total-sunuke_sum;
        ans = min(ans, abs(sunuke_sum-arai_sum));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
from bisect import bisect
N = int(input())
A = list(map(int,input().split()))
#N = 10
#A = list(map(int,"10 71 84 33 6 47 23 25 52 64".split()))
AA = [0  for x in range(N)]
for i,a in enumerate(A):
    AA[i] = AA[i-1] + a
ans = 99999999999999999
ed = 2
st = 0
_bc = AA[-1]
_de = AA[-1]

for i in range(1, N-1):
    med = AA[i] / 2
    j = bisect(AA, med)
    if abs(AA[j-1] - med) < abs(AA[j] - med):
        j = j-1
    rmed = (AA[-1] + AA[i]) / 2
    k = bisect(AA, rmed)
    if abs(AA[k-1] - rmed) < abs(AA[k] - rmed):
        k = k-1
    m = min(AA[j], AA[i] - AA[j], AA[k] - AA[i], AA[-1] - AA[k])
    M = max(AA[j], AA[i] - AA[j], AA[k] - AA[i], AA[-1] - AA[k])
    ans = min(ans, M - m)
print(ans)




Measured memory_bytes: 25676
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>n;

    map<int , int> m;
    
    for(int i=1; i<=100; i++) {

        for(int j=1; j<=100; j++) {

            for(int k=1; k<=100; k++) {
                int val = i*i + j*j + k*k + i*j + j*k + i*k;
                m[val]++;
            }
        }
    }


    for(int i=1; i<=n; i++) {

        cout<<m[i]<<endl;
    }  
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 5992
//https://atcoder.jp/contests/abc124/tasks/abc124
#include<iostream>
#include<string>
#include <stdio.h>
#include<vector>
using namespace std;
//解説見た
int main() {
    int N,K;
    string S;

    cin>>N>>K;
    cin>>S;

    int Max=0;
    int checkPoint0=0;
    for(int i=0;i<N;i++){
        if(S[i]=='0'){
            checkPoint0++;
            for(i;i<N;i++){
                if(S[i]=='1'){
                    break;
                }
            }
        }
    }

    if(checkPoint0<=K){
        cout << N << endl;
        return 0;
    }

    vector<int> S1;
    int count = 0;
    for(int i=0;i<N;i++){
        if(S[i]=='0'){
            for(i;i<N;i++){
                
                if(S[i]=='1'){
                    break;
                }
                count++;
            }
            S1.push_back(count);
            count=0;
            i--;
        }else if(S[i]=='1'){
            for(i;i<N;i++){
                
                if(S[i]=='0'){
                    break;
                }
                count++;
            }
          S1.push_back(count);
            count=0;
            i--;
        }
    }

    if(S[0]=='0'){
        int front=0;
        for(int i=0;i<K*2;i++){
            front+=S1[i];
        }
        if(Max<front)Max=front;
        S1.erase(S1.begin());
    }

    if(S[N-1]=='0'){
        int end=0;
        for(int i=0;i<K*2;i++){
            end+=S1[S1.size()-1-i];
        }
        if(Max<end)Max=end;
        S1.pop_back();
    }

    if(S1.size()<=K){
        cout << Max << endl;
        return 0;
    }
    int *S1sum = new int[S1.size()];
    S1sum[0]=S1[0];
    for(int i=1;i<S1.size();i++){
        S1sum[i]=S1sum[i-1]+S1[i];
    }
    if(Max<S1sum[K*2])Max=S1sum[K*2];

    for(int i=0;i<(S1.size()-(K*2+1))/2;i++){
        if(Max<S1sum[K*2+(i+1)*2]-S1sum[i*2+1])Max=S1sum[K*2+(i+1)*2]-S1sum[i*2+1];
        //cout<<S1sum[K*2+(i+1)*2]-S1sum[i*2+1]<<endl;
    }

    //for(int i=0;i<S1.size();i++)cout<<S1sum[i]<<",";cout<<endl;
    //for (auto &num:S1)printf("%d,", num);cout<<endl;
    cout<<Max<<endl;
    return 0;
}

Measured memory_bytes: 1272
import java.util.Scanner;

public class Main {
  int INF = 1 << 20;

  long max(long a, long b, long c) {
    return Math.max(Math.max(a, b), c);
  }

  long min(long a, long b, long c) {
    return Math.min(Math.min(a, b), c);
  }

  long f(long h, long w) {
    long ans = INF;
    for (long i = 1; i < h; i++) {
      long j = w / 2;
      if (i < h - i) {
        long max = max(i * w, (h - i) * j, (h - i) * (w - j));
        long min = min(i * w, (h - i) * j, (h - i) * (w - j));
        ans = Math.min(ans, max - min);
      } else {
        long max = max(i * j, i * (w - j), (h - i) * w);
        long min = min(i * j, i * (w - j), (h - i) * w);
        ans = Math.min(ans, max - min);
      }
      long i2 = (h - i) / 2;
      long max = max(i * w, i2 * w, (h - i - i2) * w);
      long min = min(i * w, i2 * w, (h - i - i2) * w);
      ans = Math.min(ans, max - min);
    }
    return ans;
  }

  void run() {
    Scanner sc = new Scanner(System.in);

    int h = sc.nextInt();
    int w = sc.nextInt();
    long ans = Math.min(f(h, w), f(w, h));
    System.out.println(ans);
  }

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


Measured memory_bytes: 23636
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn counter(n: u32) -> u32 {
    if n % 2 == 0 {
        return 1 + counter(n / 2);
    } else {
        return 0;
    };
}

fn main() {
    let n : u32 = read();
    let avec :Vec<u32> = (0..n).map(|_| read()).collect();
    println!("{}", avec.iter().map(|n| counter(*n)).min().unwrap());
}


Measured memory_bytes: 4352
H,W=map(int,input().split())
S=[input() for _ in range(H)]

D=[(0,1),(0,-1),(1,0),(-1,0)]

ans=True
for h in range(H):
    for w in range(W):
        if (S[h][w]=='#'):
            f=False
            for dh,dw in D:
                h2=h+dh
                w2=w+dw
                if h2<0 or H<=h2 or w2<0 or W<=w2: continue
                if S[h2][w2]=='#':
                    f=True
                    break
            else:
                ans=False
print('Yes' if ans else 'No')

Measured memory_bytes: 9208
package main

import "fmt"

func max(x ...int) int {
	ans := x[0]
	for _, v := range x[1:] {
		if v > ans {
			ans = v
		}
	}
	return ans
}

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)

	ans := a + b + c
	mx := max(a, b, c)
	ans -= mx
	for i := 0; i < k; i++ {
		mx *= 2
	}
	ans += mx
	fmt.Println(ans)
}


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

using namespace std;

#define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))



int INF = 1e18;
int MOD = 1e9+7;


void solve()
{
    int n;cin>>n;
  	string s = "";
  	while(n--) s += "ACL";
  cout<<s<<endl;
}

signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3612
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int n, m;
	int[] a, b;

	void run(){
		n=sc.nextInt();
		m=sc.nextInt();
		a=new int[m];
		b=new int[m];
		for(int i=0; i<m; i++){
			a[i]=sc.nextInt()-1;
			b[i]=sc.nextInt()-1;
		}
		solve();
	}

	@SuppressWarnings("unchecked")
	void solve(){
		ArrayList<Integer>[] es=new ArrayList[n];
		ArrayList<Integer>[] rs=new ArrayList[n];
		for(int i=0; i<n; i++){
			es[i]=new ArrayList<Integer>();
			rs[i]=new ArrayList<Integer>();
		}
		for(int i=0; i<m; i++){
			es[a[i]].add(b[i]);
			rs[b[i]].add(a[i]);
		}
		int[] d1=new int[n];
		int[] d2=new int[n];
		for(int i=0; i<n; i++){
			for(int j : es[i]){
				d1[j]=max(d1[j], d1[i]+1);
			}
		}
		for(int i=n-1; i>=0; i--){
			for(int j : rs[i]){
				d2[j]=max(d2[j], d2[i]+1);
			}
		}
		// debug("d1", d1);
		// debug("d2", d2);
		int maxChain=0;
		for(int i=0; i<n; i++){
			maxChain=max(maxChain, d1[i]+d2[i]);
		}
		// debug("maxChain", maxChain);
		int[] ind=new int[n];
		for(int i=0; i<m; i++){
			if(d1[a[i]]+1+d2[b[i]]==maxChain){
				// 候補
				if(ind[d1[a[i]]]==0){
					ind[d1[a[i]]]=i+1;
				}else{
					ind[d1[a[i]]]=-1;
				}
			}
		}
//		debug(ind);
		sort(ind);
		int count=0;
		for(int i : ind){
			if(i>0){
				println(i+"");
				count++;
			}
		}
		if(count==0){
			println("-1");
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 157884
n=int(input())
a=list(map(int,input().split()))

a.sort()

side1=0
side2=0
num=0

for num in range(n-1):
    if a[num]==a[num+1]:
        side2=side1
        side1=a[num]
        a[num+1]=0

print(side1*side2)

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

int main()
{
	const double PI = acos(-1);
	double x[4], y[4];
	char c;

	while (cin >> x[0] >> c >> y[0] >> c >> x[1] >> c >> y[1] >> c
				>> x[2] >> c >> y[2] >> c >> x[3] >> c >> y[3]) {

		bool f = 1;
		int s = 0;

		double t = atan2(y[2] - y[1], x[2] - x[1]) - atan2(y[1] - y[0], x[1] - x[0]);

		if (t > 0)
			s = 1;

		for (int i = 1; i < 4; i++) {
			int j = (i + 1) % 4, k = (i + 2) % 4;
			t = atan2(y[k] - y[j], x[k] - x[j]) - atan2(y[j] - y[i], x[j] - x[i]);

			if (t < -PI)
				t += PI * 2;
			else if (t > PI)
				t -= PI * 2;

			if (!((s == 1 && t > 0) || (s == 0 && t < 0))) {
				f = 0;
				break;
			}
		}

		if (f)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}


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


int main() {
  ll N;
  cin >> N;
  map<string, ll> mp;
  rep(i, N) {
    string s;
    cin >> s;
    mp[s]++;
  }

  ll ans = 0;
  auto begin = mp.begin(), end = mp.end();
  for (auto iter = begin; iter != end; iter++) {
    // first: key, second: value
    if(iter->second > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 19252
/****************************>>>>HEADFILES<<<<****************************/
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
using namespace std;
/****************************>>>>>DEFINE<<<<<*****************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define FIN             freopen("input.txt","r",stdin)
#define rep(i,a,b)      for(int i = a;i <= b;i++)
#define MP(a,b)         make_pair(a,b)
#define PB(a)           push_back(a)
#define fst             first
#define snd             second
/****************************>>>>>>DEBUG<<<<<<****************************/
#define out(x)          cout<<x<<"  ";
/****************************>>>>SEPARATOR<<<<****************************/
const int maxn=1e5+10;
int N[maxn];
int l[maxn],r[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    rep(i,1,n)cin>>N[i];
    l[0]=N[1];
    r[n+1]=N[n];
    rep(i,1,n)l[i]=__gcd(l[i-1],N[i]);
    for(int i=n;i>=1;--i)r[i]=__gcd(r[i+1],N[i]);
    int ans=0;
    rep(i,2,n-1)
    ans=max(ans,__gcd(l[i-1],r[i+1]));
    ans=max(ans,r[2]);
    ans=max(ans,l[n-1]);
    cout<<ans<<endl;
}


Measured memory_bytes: 1408
import unittest


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(
            think(8, [[3, 30], [4, 50], [5, 60]]),
            90
        )

    def test_2(self):
        self.assertEqual(
            think(
                5, [
                    [1, 1000000000], [1, 1000000000], [1, 1000000000],
                    [1, 1000000000], [1, 1000000000]
                ]
            ),
            5000000000
        )

    def test_3(self):
        self.assertEqual(
            think(15, [[6, 5], [5, 6], [6, 4], [6, 6], [3, 5], [7, 2]]),
            17
        )


def solve():
    w, list_of_w_and_v = read()
    result = think(w, list_of_w_and_v)
    write(result)


def read():
    n, w = read_int(2)
    list_of_w_and_v = []
    for _ in range(n):
        list_of_w_and_v.append(read_int(2))
    return w, list_of_w_and_v


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(w, list_of_w_and_v):
    invalid = -1

    # dp[weight] = max value at 'weight'
    dp = [invalid for _ in range(w + 1)]
    dp[0] = 0

    for weight, value in list_of_w_and_v:
        for i in range(len(dp) - 1, -1, -1):
            if dp[i] == invalid:
                continue
            if i + weight >= len(dp):
                continue
            dp[i + weight] = max(
                    dp[i + weight],
                    dp[i] + value
            )
    return max(dp)


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 56428
#include <iostream>
#include <string.h>

using namespace std;

const int N=1e7+10;

int dp[N];

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j+=i)
        {
            dp[j]+=1;
        }
    }
    long long int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans+=(long long)i*dp[i];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 42648
#include <stdio.h>
int main(){
int n, i, a[100];
scanf("%d", &n);
for ( i = 0; i < n; i++ ){
scanf("%d", &a[i]);
}
printf("%d", a[n - 1]);
for ( i = n - 2; i >= 0; i-- ){
printf(" %d", a[i]);
}
printf("\n");
return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int LCM(int a, int b){
   return (a * b)/(GCD(a, b));
}

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

   cout << 180 * (n - 2) << endl;

   return 0;
}

Measured memory_bytes: 256