akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back 
 #define fo(i,n) for(int i=0;i<n;i++)
#define ll long long
#define mod 1000000009 
#define MAX 4294967296  // 2^32
 
using namespace std;
 
long long gcd(int x,int y){
    if(y==0)return x;
    return gcd(y,x%y);
}
 
 
long long power(int x,int y){
if(y==0)return 1;
long long t=power(x,y/2);
if(y%2==1)return x*t*t;
return t*t;
 
 
 
}ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result
 
    x = x % p;  // Update x if it is more than or
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
 
// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}






void solve(int a[],int& ans,int n){
  int b[n]={0};
  if(n==2){
  ans=abs(a[0]-a[1]);
  return ;
  }
  if(n==1){
   
    return ;}
    
  b[1]=abs(a[0]-a[1]);

for(int i=2;i<n;i++){
    
b[i]=min((b[i-1]+abs(a[i]-a[i-1])),(b[i-2]+abs(a[i]-a[i-2])));
 

}
ans=b[n-1];
  return ;
 
 
}
 
 
int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
    int ans=0;
  solve(a,ans,n);
    
    cout<<ans;
    
}

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

long int dp[100001][13]={};

int d[100001];

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}


int main(){
    string S;
    cin>>S;
    //cout<<dp[1][0]<<endl;

    int N=S.size();

    for(int i=1;i<=N;i++){
        d[i]=ctoi(S.at(N-i));
    }

    //for(int i=1;i<=N;i++) cout<<d[i];
    //cout<<endl;

    dp[0][0]=1;

    for(int i=1;i<=N;i++){
        int p;
        if(i%6==1) p=1;
        if(i%6==2) p=10;
        if(i%6==3) p=9;
        if(i%6==4) p=12;
        if(i%6==5) p=3;
        if(i%6==0) p=4;

        if(d[i]!=-1) {
            int x=(d[i]*p)%13;
            for(int j=0;j<13;j++) dp[i][j]=dp[i-1][(j-x+130)%13];
        }

        else{    
            for(int k=0;k<10;k++){
                int x=(k*p)%13;
                for(int j=0;j<13;j++) {
                    dp[i][j]+=dp[i-1][(j-x+130)%13]; 
                    dp[i][j]=(dp[i][j]%1000000007);
                }
            }
        }
        //cout<<i<<' '<<p<<':';
        //for(int j=0;j<13;j++) cout<<dp[i][j]<<' ';
        //cout<<endl;

    }
    //cout<<N<<endl;
    cout<<dp[N][5]<<endl;



}

Measured memory_bytes: 11008
#include<iostream>

using namespace std;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	int ans;
	if(a + b >= c)
		ans = b + c;
	if(a + b < c)
		ans = a + 2 * b + 1;
	cout << ans << endl;
	
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val (a, b, n) = (sc.nextInt(), sc.nextLong(), sc.nextLong())

  val bDouble = b.toDouble
  println(f(Math.min(b -1, n)))

  def f(x: Long): Int = (Math.floor(a * x / bDouble) - a * Math.floor(x / bDouble)).toInt
}


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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;

int n;
// Map for parity
map<ll, int> m;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		m[a[i]] = i % 2;
	}
	
	sort(all(a));
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (i % 2 != m[a[i]]) ++cnt;
	}
	
	cout << cnt / 2;
}


Measured memory_bytes: 10320
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int n;
    string s;
    cin >> n >> s;
    
    vector<int> L, R;
    L.eb(0), R.eb(0);
    for (int i = 0; i < n; ++i) {
        L.eb(L.back() + (s[i] == 'W'));
        R.eb(R.back() + (s[n-i-1] == 'E'));
    }
    
    int minAns = n;
    for (int i = 0; i <= n; ++i) {
        minAns = min(minAns, L[i] + R[n-i]);
    }
    
    cout << minAns << "\n";
    
    return 0;
}

Measured memory_bytes: 10876
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main()
{
    int x, y, W, H, r;

    while (cin >> W >> H >> x >> y >> r) {
        int d1 = x - 0;
        int d2 = y - 0;
        int d3 = W - x;
        int d4 = H - y;
        if (d1 >= r && d2 >= r && d3 >= r && d4 >= r) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}



Measured memory_bytes: 3096
K, N = map(int,input().split())
A = list(map(int,input().split()))
ans = float("inf")
for i in range(N):
    if i == 0:
        ans = min(K+A[i]-A[1], -A[i]+A[N-1], ans)
    elif i == N-1:
        ans = min(A[i]-A[0], K-A[i]+A[i-1], ans)
    else:
        ans = min(K+A[i]-A[i+1], K-A[i]+A[i-1], ans)
print(ans)

Measured memory_bytes: 26444
#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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






string S;
//---------------------------------------------------------------------------------------------------
#define yes "AC"
#define no "WA"
string solve() {
    int n = S.length();

    if (S[0] != 'A') return no;
    if (S[1] < 'a' or 'z' < S[1]) return no;
    if (S[n-1] < 'a' or 'z' < S[n-1]) return no;

    int C = 0, x = 0;
    rep(i, 2, n - 1) {
        if ('a' <= S[i] and S[i] <= 'z') x++;
        else if (S[i] == 'C') C++;
        else return no;
    }
    if (C == 1) return yes;
    return no;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;
    cout << solve() << endl;
}

Measured memory_bytes: 256
input = gets.chomp

count = 0
max = 0

for i in 0..input.length - 1 do
  if input[i] == 'A'
    count += 1
  elsif input[i] == 'C'
    count += 1
  elsif input[i] == 'G'
    count += 1
  elsif input[i] == 'T'
    count += 1
  else
    count = 0
  end

  max = count if max < count
end

puts max

Measured memory_bytes: 1788
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

struct UnionFindTree{

    vector<int> pr,sz;

    UnionFindTree(int n){
        pr.resize(n);
        sz.resize(n);

        for(int i = 0;i<n;i++){
            pr[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x){
        return x==pr[x]? x: pr[x] = find(pr[x]); 
    }

    void unite(int x, int y){
        x = find(x); y = find(y);

        if(sz[x]<sz[y])swap(x,y);

        sz[x]+=sz[y];
        pr[y] = x; 
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){return sz[find(x)];}


};

void solve(){
    
    int n,m;
    cin >> n >> m;
    UnionFindTree dsu(n);

    int a[m+1],b[m+1];

    for(int i = 0;i<m;i++){
        cin >> a[m-1-i] >> b[m-1-i];
        a[m-1-i]--;
        b[m-1-i]--;

    }

    int ans, res[m+2];
    ans = (n)*(n-1)/2LL;

    for(int i = 0;i<m;i++){
        res[m-i-1] = ans;

        if(!dsu.same(a[i],b[i])){
            ans-=dsu.size(a[i])*dsu.size(b[i]);
            dsu.unite(a[i], b[i]);
        }
        //unite(a[i], b[i]);
    }

    for(int i = 0;i<m;i++)cout << res[i] << endl;

} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 5248
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};
#[allow(unused_imports)]
use rand::prelude::*;

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

#[allow(unused)]
fn calc(i: usize, day: usize, s: &Vec<Vec<isize>>, c: &Vec<isize>, last: &mut Vec<usize>) -> isize {
    last[i] = day;
    let up = s[day - 1][i];
    let mut down = 0;

    for j in 0..26 {
        down += (day - last[j]) as isize * c[j];
    }

    up - down
}

fn calc_all(contests: &Vec<usize>, s: &Vec<Vec<isize>>, c: &Vec<isize>) -> isize {
    let mut last = vec![0; 26];
    let mut score = 0;

    for (day, &i) in contests.iter().enumerate() {
        score += calc(i, day + 1, s, c, &mut last);
    }

    score
}

fn main() {
    input! {
        d: usize,
        c: [isize; 26],
        s: [[isize; 26]; d],
    }

    let now = std::time::SystemTime::now();

    let mut last = vec![0; 26];
    let mut score = 0;
    let mut contests = vec![];

    // greedy
    for day in 1..=d {
        let mut max = std::isize::MIN;
        let mut best_i = 0;
        for i in 0..26 {
            let tmp = last[i];
            let score = calc(i, day, &s, &c, &mut last);
            if score > max {
                max = score;
                best_i = i;
            }
            last[i] = tmp;
        }
        score += calc(best_i, day, &s, &c, &mut last);
        last[best_i] = day;
        contests.push(best_i);
    }

    let seed = [13; 32];
    let mut rng: rand::rngs::StdRng = rand::SeedableRng::from_seed(seed);

    while std::time::SystemTime::now().duration_since(now).unwrap()
        < std::time::Duration::new(1, 900)
    {
        let contest = rng.gen_range(0, 26);
        let day = rng.gen_range(1, d + 1);
        let tmp = contests[day - 1];

        contests[day - 1] = contest;
        let new_score = calc_all(&contests, &s, &c);

        if new_score > score {
            score = new_score;
        } else {
            contests[day - 1] = tmp;
        }
    }

    for e in contests {
        echo!(e + 1);
    }
    // dbg!(score);
}


Measured memory_bytes: 2284
#include <iostream>
#include <string>
using namespace std;
int main(){
  string S[4] ={"Sunny","Cloudy","Rainy","Sunny"};
  string t;
  cin >> t;
  for(int i = 0; i < 3; i++){
    if(S[i] == t) {
      cout << S[i+1] << endl;
      return 0;
    }
  }
}


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

using ll=long long;

int main() {
  string N; cin >>N;
  int ans=0;
  rep(i,0,N.size()) {
    ans+=(int)(N[i]-'0');
  }
  cout <<(ans%9==0 ? "Yes":"No") <<endl;
  return 0;
}


Measured memory_bytes: 3740
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>

struct Point {
    Point() : x(0), y(0), h(0) {}
    Point(int _x, int _y, int _h) : x(_x), y(_y), h(_h) {}
    int x, y, h;
};

int main() {
    size_t n;
    std::cin >> n;
    std::vector<Point> points(n);
    for (size_t i = 0; i < n; ++i) {
        std::cin >> points[i].x >> points[i].y >> points[i].h;
    }
    Point c;
    for (c.x = 0; c.x <= 100; ++c.x) {
        for (c.y = 0; c.y <= 100; ++c.y) {
            for (auto&& p : points) {
                if (p.h == 0) continue;
                c.h      = abs(c.x - p.x) + abs(c.y - p.y) + p.h;
                size_t i = 0;
                for (; i < n; ++i) {
                    int h = std::max(c.h - abs(c.x - points[i].x) -
                                         abs(c.y - points[i].y),
                                     0);
                    if (points[i].h != h) break;
                }
                if (i == n) {
                    std::cout << c.x << ' ' << c.y << ' ' << c.h << '\n';
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 1000005;
const ld EPS = 1e-11;
int hp = 179;

signed main()
{
	fastio();
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	vector<int> a(n);
	vin(a);
	sort(all(a));
	vector<int> b(m);
	vin(b);
	sort(all(b));
	for (int ans = x + 1; ans <= y; ++ans)
	{
		if (ans > a.back() && ans <= b[0])
		{
			cout << "No War";
			return 0;
		}
	}
	cout << "War";
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n= sc.nextInt();
    int [] a = new int[n];
    for(int i =0;i<n;i++){
      a[i] = sc.nextInt();
    }
    int count = 0;
    Arrays.sort(a);
    for(int i =0;i<n-2;i++){
      for(int j =i+1;j<n-1;j++){
        for(int k =j+1;k<n;k++){
          // System.out.println(a[i] + " "+ a[j] +  " " +a[k]);
          if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i]){
            if(a[i]+a[j]>a[k]){
              // System.out.println("!"+a[i] + " "+ a[j] +  " " +a[k]);
              count++;
          }
        }
      }  
    }
  }
  System.out.println(count);
  }
}



Measured memory_bytes: 36432
N = int(input())
songs = []
for _ in range(N):
    s, t = input().split()
    t = int(t)
    songs.append((s, t))
X = input()

ans = 0
isAsleep = False
for s, t in songs:
    if isAsleep:
        ans += t
    if s == X:
        isAsleep = True

print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
using namespace std;

#define rep(i,N) for(int (i)=0; (i)<(N); (i)++)
#define revrep(i,N) for(int (i)=(N)-1; (i)>=0; (i)--)
#define coutline cout<<"------------ ("<<__LINE__<<")"<<endl;

typedef long long ll;

int main(void)
{
    int A,P;
    cin >> A >> P;

    P = P + A * 3;
    cout << (int)(P/2) << endl;

    return 0;
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}

int A,B;
inline void solve(){
  IN2(A,B);
  OUT(max(A+B,max(A-B,A*B)));
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e7 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;

int main() {
    string s, t;
    cin >> s >> t;
    ll ans = 0;
    unordered_map<char, int> sc, tc;
    for (int i = 0; i < s.size(); ++i) {
        ans += s[i] != t[i];
    }

    cout << ans << endl;
}


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

#define REP(i,n) for(int i=0; i< int(n); (i)++)
int odd(int *);
int main()
{
    int n, sum_all=1, sum_odd=1, a[101]={0};
    cin >> n;
    REP(i,n)
    {
        cin >> a[i];
    }
    
    REP(i,n)
    {
        sum_odd *= odd(&a[i]);
    }
    
    REP(i,n)
    {
            sum_all *= 3;
    }
    
    cout << sum_all - sum_odd << endl;
    return 0;
}
int odd(int *a)
{
    if(*a%2==0)
    {
        return 2;
    }
    else
    {
        return 1;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
if(a*b>c*d)
{printf("%d",a*b);
}
else if(a*b<c*d)
{
printf("%d",c*d);
}
else
{printf("%d",a*b);
}
}

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

int main() {
    int k, x;
    std::cin >> k >> x;
    
    int min_a = -1000000, max_a = 1000000;
    
    int tmpmax = min(x + (k-1), max_a), tmpmin = max(x - (k-1), min_a);
    
    for (int i = tmpmin; i <= tmpmax; i++) {
        std::cout << i << " ";
    }
    
	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		while(true) {
			int n = Integer.parseInt(as.next());
			if(n == 0) {
				break;
			}
			HashMap<String, Integer> b = new HashMap<String, Integer>();
			for(int i=0;i<n;i++) {
				b.put(as.next(), Integer.parseInt(as.next()));
			}
			int m = Integer.parseInt(as.next());
			HashMap<String, String[]> c = new HashMap<String, String[]>();
			for(int i=0;i<m;i++) {
				String cc = as.next();
				int mm = Integer.parseInt(as.next());
				String[] d = new String[mm];
				for(int j=0;j<mm;j++) {
					d[j] = as.next();
				}
				c.put(cc, d);
			}
			String t = as.next();
			int sub;
			for(int i = 0; i<c.size(); i++) {
				for(String ccc: c.keySet()){
					sub = 0;
					for(String dd: c.get(ccc)) {
						sub += b.get(dd);
					}
					b.put(ccc, Math.min(b.get(ccc), sub));
				}
			}
			System.out.println(b.get(t));
		}
	}
}


Measured memory_bytes: 33720
#include<stdio.h>
#include<algorithm>
char a[502][502],X='#',C='.';
int F(int x,int y)
{
	if(a[y][x]-C)return 0;
	char*p,c[4],t;
	int d[]={0,1,0,-1,0},e[4],i,j,r=0;
	for(i=0;i<4;++i)
	{
		for(j=1;t=a[y+j*d[i]][x+j*d[i+1]],t==C;++j);
		c[i]=t;
		e[i]=j;
	}
	for(i=0;i<3;++i)
	{
		if(c[i]-X && (p=std::find(c+i+1,c+4,c[i]))<c+4)
		{
			a[y+e[i]*d[i]][x+e[i]*d[i+1]]=C;
			j=p-c;
			a[y+e[j]*d[j]][x+e[j]*d[j+1]]=C;
			r+=2;
		}
	}
	return r;
}
int main()
{
	int m,n,x,y,f,r,t;
	scanf("%d%d",&m,&n);
	for(y=1;y<=m;++y)scanf("%s",&a[y][1]);
	for(y=0;y<m+2;++y)a[y][0]=a[y][n+1]=X;
	for(r=x=0;x<n+2;++x)a[0][x]=a[m+1][x]=X;
	do
	{
		f=0;
		for(y=1;y<=m;++y)for(x=1;x<=n;++x)if(t=F(x,y))f=1,r+=t;
	}while(f);
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 972
import java.util.Scanner;

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

		for (int i = 0; i < length; i++)
			list[i] = scanner.nextInt();

		for (int i = length - 1; i >= 0; i--)
			System.out.print(list[i % length] + (i > 0 ? " " : ""));

		System.out.println();
	}
}

Measured memory_bytes: 26292
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;

int A,B;
int main(){
    cin>>A>>B;
    int ans=0;
    for(int i=A;i<=B;i++){
        string s=to_string(i);
        string temp=s;
        reverse(s.begin(),s.end());
        if(s==temp){
            ans++;
        }
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
  ll X;
  cin >> X;
  ll d = 1;
  while((d*X)% 360 != 0){
    d++;
  }
  cout << d << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>

using namespace std;

struct Node {
  int parent = -1;
  int left = -1, right = -1;
};

int sibling(int id, vector<Node> &tree) {
  int parent = tree[id].parent;
  if (parent == -1) {
    return -1;
  }
  if (tree[parent].left == id) {
    return tree[parent].right;
  } else {
    return tree[parent].left;
  }
}

int child_num(int id, vector<Node> &tree) {
  int res = 0;
  if (tree[id].left != -1) {
    res++;
  }
  if (tree[id].right != -1) {
    res++;
  }
  return res;
}

int get_depth(int id, vector<Node> &tree) {
  int depth = 0;
  while (tree[id].parent != -1) {
    id = tree[id].parent;
    depth++;
  }
  return depth;
}

int get_height(int id, vector<Node> &tree, vector<int> &h) {
  int h1 = 0, h2 = 0;
  if (tree[id].left != -1) {
    h1 = get_height(tree[id].left, tree, h) + 1;
  }
  if (tree[id].right != -1) {
    h2 = get_height(tree[id].right, tree, h) + 1;
  }
  return h[id] = max(h1, h2);
}

string get_info(int id, vector<Node> &tree) {
  if (tree[id].parent == -1) {
    return "root";
  }
  if (tree[id].left == -1 && tree[id].right == -1) {
    return "leaf";
  }
  return "internal node";
}

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

  vector<Node> tree(n);
  vector<int> h(n, 0);

  for (int i = 0; i < n; i++) {
    int id, left, right;
    cin >> id >> left >> right;
    tree[id].left = left;
    tree[id].right = right;
    tree[left].parent = id;
    tree[right].parent = id;
  }

  for (int id = 0; id < n; id++) {
    cout << "node " << id << ": ";
    cout << "parent = " << tree[id].parent << ", ";
    cout << "sibling = " << sibling(id, tree) << ", ";
    cout << "degree = " << child_num(id, tree) << ", ";
    cout << "depth = " << get_depth(id, tree) << ", ";
    cout << "height = " << get_height(id, tree, h) << ", ";
    cout << get_info(id, tree);
    cout << endl;
  }
  return 0;
}


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

int main() {
	int n ; 
	cin>>n;
	set<string> s ;
	vector<string> v;
	string ex ;
	for( int i = 0 ; i < n ; ++i ){
		cin>>ex;
		v.push_back(ex);
		s.insert(ex);
	}
	if(s.size()!=n){
		cout<<"No";
		return 0;
	}
	for( int i = 0 ; i < n-1 ; ++i ){
		int siz =v[i].length();
		if(v[i][siz-1]!=v[i+1][0]){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[888][888];
int d[888][888];
int ceiling(int x, int y) {
    if(x % y == 0) return (x / y);
    else return 1 + (x / y);
}
int main() {
    int h, w, k;
    scanf("%d %d %d", &h, &w, &k);

    int srx, sry;
    for(int i = 0; i < h; i++) {
        scanf("%s", s[i]);
        for(int j = 0; j < w; j++) {
            if(s[i][j] == 'S') {
                srx = i;
                sry = j;
            }
        }
    }

    memset(d, -1, sizeof d);
    queue < pair <int, int> > Q;
    Q.push(make_pair(srx, sry));
    d[srx][sry] = 0;

    while(!Q.empty()) {
        int x = Q.front().first;
        int y = Q.front().second;
        Q.pop();

        for(int i = -1; i <= 1; i++) {
            for(int j = -1; j <= 1; j++) {
                if(abs(i) == abs(j)) continue;
                int dx = x + i;
                int dy = y + j;
                if(0 <= dx && 0 <= dy && dx < h && dy < w && d[dx][dy] == -1 && s[dx][dy] == '.') {
                    d[dx][dy] = d[x][y] + 1;
                    Q.push(make_pair(dx, dy));
                }
            }
        }
    }
    int ans = h * w;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(d[i][j] == -1 || d[i][j] > k) continue;
            int res = 1 + min(min(ceiling(h - i - 1, k), ceiling(w - j - 1, k)), min(ceiling(i, k), ceiling(j, k)));
            ans = min(ans, res);
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3968
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int num=scan.nextInt();
    int app;
    boolean flag=true;
    for(int x=0; x<num; x++){
      app=scan.nextInt();
      if(app%2==0){
        if(app%3==0 || app%5==0){
          flag=true;
        }else{
          flag=false;
          break;
        }
      }
    }
    if(flag){
      System.out.println("APPROVED");
    }else{
      System.out.println("DENIED");
    }
  }
}

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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)

typedef pair<int, int> P;

const int inf = 1 << 25;

struct edge
{
  int to, cost;
  edge(){}
  edge(int to, int cost):to(to), cost(cost){}
};

vector< vector<edge> > graph;
vector< vector<int> > mincost;

void dijkstra(int s)
{
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  mincost[s][s] = 0;
  while(!que.empty()) {
    int cost, now;
    tie(cost, now) = que.top(); que.pop();
    if(mincost[s][now] < cost) continue;
    for(edge& e : graph[now]) {
      if(e.cost + cost < mincost[s][e.to]) {
	mincost[s][e.to] = e.cost + cost;
	que.push(P(mincost[s][e.to], e.to));
      }
    }
  }
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, R;
  cin >> N >> R;
  graph.resize(N);
  rep(i, R) {
    int s, t, d;
    cin >> s >> t >> d; s--, t--;
    graph[s].emplace_back(t, d);
    graph[t].emplace_back(s, d);
  }

  mincost.resize(N, vector<int>(N, inf));
  int maxdist = 0;
  rep(i, N) dijkstra(i);
  rep(i, N) reps(j, i+1, N) maxdist = max(maxdist, mincost[i][j]);

  vector<P> ep;
  //vector<int> S, T;
  rep(i, N) reps(j, i+1, N) {
    if(mincost[i][j] == maxdist) {
      ep.emplace_back(i, j);      
      //S.push_back(i), T.push_back(j);
    }
  }

  vector<int> ans;
  rep(i, N) {
    bool flag = true;
    for(auto& p : ep) {
      //rep(j, S.size()) {
      int s, t; tie(s, t) = p;
      if(mincost[s][i] + mincost[i][t] == maxdist) {      
      //if(mincost[S[j]][i] + mincost[i][T[j]] == maxdist) {
	flag = false;
	break;
      }
    }
    if(flag) ans.push_back(i+1);
  }
  
  cout << ans.size() << endl;
  rep(i, ans.size()) cout << ans[i] << endl;
  
  return 0;
}

Measured memory_bytes: 28232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int sum = 0;
    FOR(i, 0, 3) {
        int a; cin >> a;
        sum += a;
    }
    cout << (22 <= sum ? "bust\n" : "win\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
const int maxn = 1e5+500;  //数据范围

const ll mod = 1e9+7;
int A[maxn];

int main(){
    int n;cin>>n;
    FOR(i,1,n)scanf("%d",&A[i]);
    int cnt=0;
    FOR(i,1,n)if(A[i]!=i)cnt++;
    if(cnt<=2)puts("YES");
    else puts("NO");
    
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n, m; cin >> n >> m;
	vector<int> a(m);

	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}

	sort(a.rbegin(), a.rend());


	vector<int> num = {-1,2,5,5,4,5,6,3,7,6 };
	vector<int> digit(10000,-1000000);

	digit[0] = 0;

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

		for (int j = 0; j < m; j++) {

			int from = i - num[a[j]];
			if (from< 0)continue;

			digit[i] = max(digit[i], digit[from]+1);
		}
		
	}

	while (n > 0) {
		for (int i = 0; i < m; i++) {
			if (n - num[a[i]] < 0)continue;

			if (digit[n-num[a[i]]]==(digit[n]-1)) {
				cout << a[i];
				n -= num[a[i]];
				break;
			}
		}
	}
	
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
bool p( string s )
{
	int n,i;
	n=s.size()-1;
	for(i=0;i<=n/2;i++)
	  if(s[i]!=s[n-i])
	    return false;
	return true;
}
int main()
{
    int count=0;
    cin>>s;
    int m=s.size();
    string a=s.substr(0,(m-1)/2);
    string b=s.substr((m+3)/2-1,(m-3)/2+1);
    if(p(a))
        count++;
    if(p(b))
        count++;
    if(p(s))
        count++;
   if(count==3)
   {
       cout<<"Yes"<<endl;
   }
   else
    cout<<"No"<<endl;
}



Measured memory_bytes: 256
K = gets.chomp.to_i
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
# A = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

p A[K-1]

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string a, b, c;
  cin >> a >> b >> c;
  cout << (a.back() == b[0] && b.back() == c[0]? "YES": "NO") << endl;

  return 0;
}


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

memo = []
ans = "Yes"
for _ in range(N):
  W = input()
  if memo == []:
    memo.append(W)
  else:
    if W in memo:
      ans = "No"
      break
    if W[0] != memo[-1][-1]:
      ans = "No"
      break
    memo.append(W)
print(ans)

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;
use std::cmp;


macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }
 
 

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 main() {
    input!{
        N: u64,
        A: u64
    }
    if (N % 500 <= A){
    	println!("Yes");
	}else{
    	println!("No");
    }

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;

string X,Y;

void solve(){
    int n=X.size(),m=Y.size();
    vector<vector<int>> dp(n+1,vector<int>(m+1,-INF));
    dp[0][0]=0;
    for (int i=0;i<=n;++i){
        for (int j=0;j<=m;++j){
            if (i+1<=n) dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            if (j+1<=m) dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
            if (i<n&&j<m&&X[i]==Y[j]) dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
        }
    }
    cout << dp[n][m] << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q; cin >> q;
    for (;q--;){
        cin >> X >> Y;
        solve();
    }
}


Measured memory_bytes: 6924
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;

////////////////いろいろあるよ//////////////////////////////////
int main(){
	int N,M;
  	ll X;
  	cin >> N >> M >> X;
  	ll money[N];
  	ll data[N][M];
  	REP(i,N){
  		cin >> money[i];
      	REP(j,M)cin >> data[i][j];
    }
  
  	bool ans = false;
  priority_queue<ll, vector<ll>, greater<ll>> moneyans;
 
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp); 
 	//
    //cout << s << endl;
    //
    ll tmoney=0;
    ll sum[M];
    REP(i,M)sum[i]=0;
    for (int i = 0; i < N; i++) {
      //cout << s << endl;
      if (s.test(i)) {
        REP(j,M){
        	sum[j] += data[i][j];
          //cout << sum[j] << endl;
        }
        tmoney+=money[i];
        
        
      }
    }
    bool sumtest=true;
    //
    REP(i,M){
      if(sum[i]<X)sumtest=false;
      //cout << " "<<sum[i];
    }
    //cout << endl;
    //
    if (sumtest == true) {
      moneyans.push(tmoney);
    }
  }
 
  if (moneyans.size()!=0){
    //moneyans.pop();
  	ll a = moneyans.top();
    cout << a << endl; 
  }else{
  	cout << -1 << endl;
  }
    
    
  
}

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

int main(){
  int N;
 
  cin >> N;
   vector<int> pa(N);
  for(int i=0 ; i<N ; i++){
    cin >> pa.at(i);
  }

  vector<int> check(N);
  check = pa;
  sort(check.begin(), check.end());
 
  if( check == pa){
    cout << "YES";
  }
  
  int count = 0 ;
  
  for(int i=0; i <N ; i++){
    if(pa.at(i) != check.at(i)){
      count += 1;
    }
  }
  
  if(count == 2){
    cout << "YES";
  }else if(count != 0){
    cout <<"NO";
  }
}


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

using namespace std;

int main()
{
    string str;
    cin >> str;
    int len = str.length();
    int flag = 0;
    len--;

    while(1)
    {
        if(len % 2 != 0) len--;

        flag = 0;
        for(int i = 0; i < len / 2; i++)
        {
            if(str[i] != str[i + len/2])
            {
                flag = 1;
                break;
            }
        }
        if(!flag) break;
        else len--;
    }
    cout << len << endl;
}

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

const int maxn = 2005;
int n, a[maxn];
int p[maxn];
vector<pair<int,int>> v(n);
ll dp[maxn][maxn];

ll f(int l, int r) {
    ll& res = dp[l][r];
    if (res != -1) return res;
    if (l > r) return res = 0;
    int i = l + (n-1-r);
    ll val = v[i].first;
    int pos = v[i].second;
    res = max(val*abs(pos-l)+f(l+1,r),
              val*abs(pos-r)+f(l,r-1));
    return res;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        v.push_back({a[i],i});
    }
    sort(v.begin(),v.end(),greater<pair<int,int>>());
    memset(dp,-1,sizeof dp);
    cout << f(0,n-1) << '\n';
}


Measured memory_bytes: 35196
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 111111;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    cout<<n*(n-1)/2<<endl;
}

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

#define _u(i,a,b) for(int i=a;i<=b;++i)
#define _d(i,a,b) for(int i=a;i>=b;--i)
#define endl "\n"
#define ii pair<int,int>
#define fi first
#define se second
#define ll long long
#define FIO() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FI(task) freopen(task".inp","r",stdin)
#define FO(task) freopen(task".out","w",stdout)

using namespace std;

const int N = 1e5+7;
const int M = 1e9+7;

ll w[N], v[N];
ll f[107][N];
int g[N];
ll n, W;

#define task "test"

int main(){
    FIO();
    //FI(task);
    ///FO(task);

    cin >> n >> W;
    _u(i,1,n) cin >> w[i] >> v[i];
    memset(f, -1, sizeof f);
    _u(i,0,n) f[i][0] = 0;

    int res(0);
    _u(i,1,n)
    _d(j,100000,v[i]){
        if(f[g[j-v[i]]][j-v[i]] == -1) continue;
        if(f[i][j] == -1) f[i][j] = f[g[j-v[i]]][j-v[i]] + w[i];
        else f[i][j] = min(f[i][j], f[g[j-w[i]]][j-w[i]] + w[i]);
        if(f[i][j] > W) f[i][j] = -1;
        if(f[i][j] != -1){
            res= max(res, j);
            if(f[g[j]][j] == -1 || f[i][j] < f[g[j]][j]) g[j] = i;
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 84224
#include<stdio.h>
#define N 101

//static const int MAX = 500;
static const int INFTY = (1<<21);

int main(){
  int n, i, j, e, sum;
  //-------------------Kono timing nara...
  int M[N][N],p[N],cos[N],v[N],key,u;
  //-------------------Mondai nai!

  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }

  //-------------------Kokokara
  for (i=0;i<n;i++) {
    cos[i]=INFTY;
    if (i==0){
      cos[i]=0;
    }
    p[i]=-1;
    v[i]=0;
  }

  while(1) {
    key = INFTY;
    u = -1;
    for (i=0;i<n;i++){
      if (key>cos[i] && v[i]==0) {
	u = i;
	key = cos[i];
      }
    }

    if (u==-1){
      break;
    } else {
      v[u] = 1;
      for (j=0;j<n;j++){
	if (cos[j]>M[u][j] && v[j]==0){
	  p[j]=u;
	  cos[j]=M[u][j];
	}
      }
    }
  }
  //-------------------Kokomade

  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }

  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

const int INF = 1001001001;
// id = i - 1
const int need[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[100005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for(int i = 0; i < m; ++i){
        cin >> a[i];        
    }
    
    sort(a.begin(), a.end(), greater<int>());
    fill(dp, dp + n + 1, -INF);
    dp[0] = 0;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j < m; ++j){
            if(i - need[a[j] - 1] >= 0){
                dp[i] = max(dp[i], dp[i - need[a[j] - 1]] + 1);
            }
        }
    }
    
    int now = n;
    for(int i = 0; i < m; ++i){
        while(now - need[a[i] - 1] >= 0 && dp[now] == dp[now - need[a[i] - 1]] + 1){
            cout << a[i];
            now -= need[a[i] - 1];
        }
    }
    cout << endl;
}

Measured memory_bytes: 384
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
p=min(A)+min(B)
for i in range(m):
    x,y,c=map(int,input().split())
    p=min(p,A[x-1]+B[y-1]-c)
print(p)

Measured memory_bytes: 18612